forked from teamnwah/openmw-tes3coop
training window
This commit is contained in:
parent
5e9153e2b8
commit
1a2034b4dd
14 changed files with 256 additions and 5 deletions
|
@ -30,7 +30,7 @@ add_openmw_dir (mwgui
|
|||
formatting inventorywindow container hud countdialog tradewindow settingswindow
|
||||
confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu
|
||||
itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog
|
||||
enchantingdialog
|
||||
enchantingdialog trainingwindow
|
||||
)
|
||||
|
||||
add_openmw_dir (mwdialogue
|
||||
|
|
|
@ -230,6 +230,7 @@ namespace MWBase
|
|||
|
||||
virtual void startSpellMaking(MWWorld::Ptr actor) = 0;
|
||||
virtual void startEnchanting(MWWorld::Ptr actor) = 0;
|
||||
virtual void startTraining(MWWorld::Ptr actor) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -801,6 +801,9 @@ namespace MWDialogue
|
|||
if (services & ESM::NPC::Spellmaking)
|
||||
windowServices |= MWGui::DialogueWindow::Service_CreateSpells;
|
||||
|
||||
if (services & ESM::NPC::Training)
|
||||
windowServices |= MWGui::DialogueWindow::Service_Training;
|
||||
|
||||
if (services & ESM::NPC::Enchanting)
|
||||
windowServices |= MWGui::DialogueWindow::Service_Enchant;
|
||||
|
||||
|
|
|
@ -147,6 +147,11 @@ void DialogueWindow::onSelectTopic(std::string topic)
|
|||
mWindowManager.pushGuiMode(GM_Enchanting);
|
||||
mWindowManager.startEnchanting (mPtr);
|
||||
}
|
||||
else if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sServiceTrainingTitle")->getString())
|
||||
{
|
||||
mWindowManager.pushGuiMode(GM_Training);
|
||||
mWindowManager.startTraining (mPtr);
|
||||
}
|
||||
else
|
||||
MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic));
|
||||
}
|
||||
|
@ -181,6 +186,9 @@ void DialogueWindow::setKeywords(std::list<std::string> keyWords)
|
|||
if (mServices & Service_Enchant)
|
||||
mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sEnchanting")->getString());
|
||||
|
||||
if (mServices & Service_Training)
|
||||
mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sServiceTrainingTitle")->getString());
|
||||
|
||||
if (anyService)
|
||||
mTopicsList->addSeparator();
|
||||
|
||||
|
|
|
@ -57,7 +57,8 @@ namespace MWGui
|
|||
Service_Trade = 0x01,
|
||||
Service_BuySpells = 0x02,
|
||||
Service_CreateSpells = 0x04,
|
||||
Service_Enchant = 0x08
|
||||
Service_Enchant = 0x08,
|
||||
Service_Training = 0x10
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace MWGui
|
|||
GM_SpellBuying,
|
||||
GM_SpellCreation,
|
||||
GM_Enchanting,
|
||||
GM_Training,
|
||||
|
||||
GM_Levelup,
|
||||
|
||||
|
|
152
apps/openmw/mwgui/trainingwindow.cpp
Normal file
152
apps/openmw/mwgui/trainingwindow.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include "trainingwindow.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <openengine/ogre/fader.hpp>
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "inventorywindow.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
#include "tooltips.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
TrainingWindow::TrainingWindow(MWBase::WindowManager &parWindowManager)
|
||||
: WindowBase("openmw_trainingwindow.layout", parWindowManager)
|
||||
, mFadeTimeRemaining(0)
|
||||
{
|
||||
getWidget(mTrainingOptions, "TrainingOptions");
|
||||
getWidget(mCancelButton, "CancelButton");
|
||||
getWidget(mPlayerGold, "PlayerGold");
|
||||
|
||||
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TrainingWindow::onCancelButtonClicked);
|
||||
}
|
||||
|
||||
void TrainingWindow::open()
|
||||
{
|
||||
center();
|
||||
}
|
||||
|
||||
void TrainingWindow::startTraining (MWWorld::Ptr actor)
|
||||
{
|
||||
mPtr = actor;
|
||||
|
||||
mPlayerGold->setCaptionWithReplacing("#{sGold}: " + boost::lexical_cast<std::string>(mWindowManager.getInventoryWindow()->getPlayerGold()));
|
||||
|
||||
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats (actor);
|
||||
|
||||
// NPC can train you in his best 3 skills
|
||||
std::vector< std::pair<int, int> > bestSkills;
|
||||
bestSkills.push_back (std::make_pair(-1, -1));
|
||||
bestSkills.push_back (std::make_pair(-1, -1));
|
||||
bestSkills.push_back (std::make_pair(-1, -1));
|
||||
|
||||
for (int i=0; i<ESM::Skill::Length; ++i)
|
||||
{
|
||||
int value = npcStats.getSkill (i).getBase ();
|
||||
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
if (value > bestSkills[j].second)
|
||||
{
|
||||
if (j<2)
|
||||
{
|
||||
bestSkills[j+1] = bestSkills[j];
|
||||
}
|
||||
bestSkills[j] = std::make_pair(i, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MyGUI::EnumeratorWidgetPtr widgets = mTrainingOptions->getEnumerator ();
|
||||
MyGUI::Gui::getInstance ().destroyWidgets (widgets);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ();
|
||||
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
/// \todo mercantile skill
|
||||
int price = pcStats.getSkill (bestSkills[i].first).getBase() * MWBase::Environment::get().getWorld ()->getStore ().gameSettings.find("iTrainingMod")->getInt ();
|
||||
|
||||
std::string skin = (price > mWindowManager.getInventoryWindow ()->getPlayerGold ()) ? "SandTextGreyedOut" : "SandTextButton";
|
||||
|
||||
MyGUI::Button* button = mTrainingOptions->createWidget<MyGUI::Button>(skin,
|
||||
MyGUI::IntCoord(5, 5+i*18, mTrainingOptions->getWidth()-10, 18), MyGUI::Align::Default);
|
||||
|
||||
button->setUserData(bestSkills[i].first);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &TrainingWindow::onTrainingSelected);
|
||||
|
||||
button->setCaptionWithReplacing("#{" + ESM::Skill::sSkillNameIds[bestSkills[i].first] + "} - " + boost::lexical_cast<std::string>(price));
|
||||
|
||||
button->setSize(button->getTextSize ().width+12, button->getSize().height);
|
||||
|
||||
ToolTips::createSkillToolTip (button, bestSkills[i].first);
|
||||
}
|
||||
|
||||
center();
|
||||
}
|
||||
|
||||
void TrainingWindow::onReferenceUnavailable ()
|
||||
{
|
||||
mWindowManager.removeGuiMode(GM_Training);
|
||||
}
|
||||
|
||||
void TrainingWindow::onCancelButtonClicked (MyGUI::Widget *sender)
|
||||
{
|
||||
mWindowManager.removeGuiMode (GM_Training);
|
||||
}
|
||||
|
||||
void TrainingWindow::onTrainingSelected (MyGUI::Widget *sender)
|
||||
{
|
||||
int skillId = *sender->getUserData<int>();
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ();
|
||||
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
|
||||
/// \todo mercantile skill
|
||||
int price = pcStats.getSkill (skillId).getBase() * MWBase::Environment::get().getWorld ()->getStore ().gameSettings.find("iTrainingMod")->getInt ();
|
||||
|
||||
if (mWindowManager.getInventoryWindow()->getPlayerGold()<price)
|
||||
return;
|
||||
|
||||
// increase skill
|
||||
MWWorld::LiveCellRef<ESM::NPC> *playerRef = player.get<ESM::NPC>();
|
||||
const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().classes.find (
|
||||
playerRef->base->mClass);
|
||||
pcStats.increaseSkill (skillId, *class_, true);
|
||||
|
||||
// remove gold
|
||||
mWindowManager.getTradeWindow()->addOrRemoveGold(-price);
|
||||
|
||||
// go back to game mode
|
||||
mWindowManager.removeGuiMode (GM_Training);
|
||||
mWindowManager.removeGuiMode (GM_Dialogue);
|
||||
|
||||
// advance time
|
||||
MWBase::Environment::get().getWorld ()->advanceTime (2);
|
||||
|
||||
MWBase::Environment::get().getWorld ()->getFader()->fadeOut(0.25);
|
||||
mFadeTimeRemaining = 0.5;
|
||||
}
|
||||
|
||||
void TrainingWindow::onFrame(float dt)
|
||||
{
|
||||
if (mFadeTimeRemaining <= 0)
|
||||
return;
|
||||
|
||||
mFadeTimeRemaining -= dt;
|
||||
|
||||
if (mFadeTimeRemaining <= 0)
|
||||
MWBase::Environment::get().getWorld ()->getFader()->fadeIn(0.25);
|
||||
}
|
||||
}
|
36
apps/openmw/mwgui/trainingwindow.hpp
Normal file
36
apps/openmw/mwgui/trainingwindow.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef MWGUI_TRAININGWINDOW_H
|
||||
#define MWGUI_TRAININGWINDOW_H
|
||||
|
||||
#include "window_base.hpp"
|
||||
#include "referenceinterface.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class TrainingWindow : public WindowBase, public ReferenceInterface
|
||||
{
|
||||
public:
|
||||
TrainingWindow(MWBase::WindowManager& parWindowManager);
|
||||
|
||||
virtual void open();
|
||||
|
||||
void startTraining(MWWorld::Ptr actor);
|
||||
|
||||
void onFrame(float dt);
|
||||
|
||||
protected:
|
||||
virtual void onReferenceUnavailable ();
|
||||
|
||||
void onCancelButtonClicked (MyGUI::Widget* sender);
|
||||
void onTrainingSelected(MyGUI::Widget* sender);
|
||||
|
||||
MyGUI::Widget* mTrainingOptions;
|
||||
MyGUI::Button* mCancelButton;
|
||||
MyGUI::TextBox* mPlayerGold;
|
||||
|
||||
float mFadeTimeRemaining;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -48,6 +48,7 @@
|
|||
#include "waitdialog.hpp"
|
||||
#include "spellcreationdialog.hpp"
|
||||
#include "enchantingdialog.hpp"
|
||||
#include "trainingwindow.hpp"
|
||||
|
||||
using namespace MWGui;
|
||||
|
||||
|
@ -79,6 +80,7 @@ WindowManager::WindowManager(
|
|||
, mWaitDialog(NULL)
|
||||
, mSpellCreationDialog(NULL)
|
||||
, mEnchantingDialog(NULL)
|
||||
, mTrainingWindow(NULL)
|
||||
, mPlayerClass()
|
||||
, mPlayerName()
|
||||
, mPlayerRaceId()
|
||||
|
@ -161,6 +163,7 @@ WindowManager::WindowManager(
|
|||
mWaitDialog = new WaitDialog(*this);
|
||||
mSpellCreationDialog = new SpellCreationDialog(*this);
|
||||
mEnchantingDialog = new EnchantingDialog(*this);
|
||||
mTrainingWindow = new TrainingWindow(*this);
|
||||
|
||||
mLoadingScreen = new LoadingScreen(mOgre->getScene (), mOgre->getWindow (), *this);
|
||||
mLoadingScreen->onResChange (w,h);
|
||||
|
@ -218,6 +221,7 @@ WindowManager::~WindowManager()
|
|||
delete mWaitDialog;
|
||||
delete mSpellCreationDialog;
|
||||
delete mEnchantingDialog;
|
||||
delete mTrainingWindow;
|
||||
|
||||
cleanupGarbage();
|
||||
|
||||
|
@ -269,6 +273,7 @@ void WindowManager::updateVisible()
|
|||
mWaitDialog->setVisible(false);
|
||||
mSpellCreationDialog->setVisible(false);
|
||||
mEnchantingDialog->setVisible(false);
|
||||
mTrainingWindow->setVisible(false);
|
||||
|
||||
mHud->setVisible(true);
|
||||
|
||||
|
@ -375,6 +380,9 @@ void WindowManager::updateVisible()
|
|||
case GM_Enchanting:
|
||||
mEnchantingDialog->setVisible(true);
|
||||
break;
|
||||
case GM_Training:
|
||||
mTrainingWindow->setVisible(true);
|
||||
break;
|
||||
case GM_InterMessageBox:
|
||||
break;
|
||||
case GM_Journal:
|
||||
|
@ -574,6 +582,9 @@ void WindowManager::onFrame (float frameDuration)
|
|||
|
||||
mHud->onFrame(frameDuration);
|
||||
|
||||
mTrainingWindow->onFrame (frameDuration);
|
||||
|
||||
mTrainingWindow->checkReferenceAvailable();
|
||||
mDialogueWindow->checkReferenceAvailable();
|
||||
mTradeWindow->checkReferenceAvailable();
|
||||
mSpellBuyingWindow->checkReferenceAvailable();
|
||||
|
@ -993,3 +1004,8 @@ void WindowManager::startEnchanting (MWWorld::Ptr actor)
|
|||
{
|
||||
mEnchantingDialog->startEnchanting (actor);
|
||||
}
|
||||
|
||||
void WindowManager::startTraining(MWWorld::Ptr actor)
|
||||
{
|
||||
mTrainingWindow->startTraining(actor);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ namespace MWGui
|
|||
class WaitDialog;
|
||||
class SpellCreationDialog;
|
||||
class EnchantingDialog;
|
||||
class TrainingWindow;
|
||||
|
||||
class WindowManager : public MWBase::WindowManager
|
||||
{
|
||||
|
@ -215,6 +216,7 @@ namespace MWGui
|
|||
|
||||
virtual void startSpellMaking(MWWorld::Ptr actor);
|
||||
virtual void startEnchanting(MWWorld::Ptr actor);
|
||||
virtual void startTraining(MWWorld::Ptr actor);
|
||||
|
||||
private:
|
||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||
|
@ -245,6 +247,7 @@ namespace MWGui
|
|||
WaitDialog* mWaitDialog;
|
||||
SpellCreationDialog* mSpellCreationDialog;
|
||||
EnchantingDialog* mEnchantingDialog;
|
||||
TrainingWindow* mTrainingWindow;
|
||||
|
||||
CharacterCreation* mCharGen;
|
||||
|
||||
|
|
|
@ -54,6 +54,6 @@ namespace MWSound
|
|||
#ifndef DEFAULT_DECODER
|
||||
#define DEFAULT_DECODER (::MWSound::FFmpeg_Decoder)
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,8 +18,6 @@ namespace ESM
|
|||
{
|
||||
// These are probabilities
|
||||
char mHello, mU1, mFight, mFlee, mAlarm, mU2, mU3, mU4;
|
||||
// The last u's might be the skills that this NPC can train you
|
||||
// in?
|
||||
int mServices; // See the Services enum
|
||||
}; // 12 bytes
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ set(MYGUI_FILES
|
|||
openmw_spellcreation_dialog.layout
|
||||
openmw_edit_effect.layout
|
||||
openmw_enchanting_dialog.layout
|
||||
openmw_trainingwindow.layout
|
||||
smallbars.png
|
||||
VeraMono.ttf
|
||||
markers.png
|
||||
|
|
31
files/mygui/openmw_trainingwindow.layout
Normal file
31
files/mygui/openmw_trainingwindow.layout
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 319 200" name="_Main">
|
||||
|
||||
<Widget type="TextBox" skin="NormalText" position="0 5 319 24" name="Select" align="Right Top">
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<Property key="Caption" value="#{sServiceTrainingTitle}"/>
|
||||
</Widget>
|
||||
<Widget type="TextBox" skin="SandText" position="5 30 319 24" name="Travel" align="Right Top">
|
||||
<Property key="TextAlign" value="Left"/>
|
||||
<Property key="Caption" value="#{sTrainingServiceTitle}"/>
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="Widget" skin="MW_Box" position="6 54 299 100" align="Left Top" name="TrainingOptions">
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="TextBox" skin="SandText" position="8 255 200 24" name="PlayerGold" align="Right Top">
|
||||
<Property key="TextAlign" value="Left"/>
|
||||
<Property key="Caption" value="Draken (754)"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedButton" skin="MW_Button" position="244 163 60 24" name="CancelButton" align="Right Top">
|
||||
<Property key="ExpandDirection" value="Left"/>
|
||||
<Property key="Caption" value="#{sCancel}"/>
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
|
||||
</MyGUI>
|
Loading…
Reference in a new issue