diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 43099e936..fac2a05f9 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -1,13 +1,19 @@ #include "stats_window.hpp" -#include "../mwmechanics/mechanicsmanager.hpp" -#include "window_manager.hpp" - #include #include #include + #include +#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" +#include "../mwbase/environment.hpp" + +#include "window_manager.hpp" + + using namespace MWGui; const int StatsWindow::lineHeight = 18; @@ -24,11 +30,12 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) , skillValues() , skillWidgetMap() , factionWidgetMap() - , factions() + , mFactions() , birthSignId() , reputation(0) , bounty(0) , skillWidgets() + , mChanged(true) { setCoord(0,0,498, 342); @@ -128,7 +135,8 @@ void StatsWindow::setBar(const std::string& name, const std::string& tname, int void StatsWindow::setPlayerName(const std::string& playerName) { - setTitle(playerName); + static_cast(mMainWidget)->setCaption(playerName); + adjustWindowCaption(); } void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& value) @@ -235,9 +243,24 @@ void StatsWindow::configureSkills (const std::vector& major, const std::vec } } -void StatsWindow::setFactions (const std::vector& factions) +void StatsWindow::onFrame () { - this->factions = factions; + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::NpcStats PCstats = MWWorld::Class::get(player).getNpcStats(player); + + setFactions(PCstats.mFactionRank); + + if (mChanged) + updateSkillArea(); +} + +void StatsWindow::setFactions (const FactionList& factions) +{ + if (mFactions != factions) + { + mFactions = factions; + mChanged = true; + } } void StatsWindow::setBirthSign (const std::string& signId) @@ -345,6 +368,8 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, void StatsWindow::updateSkillArea() { + mChanged = false; + for (std::vector::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); @@ -366,15 +391,15 @@ void StatsWindow::updateSkillArea() const ESMS::ESMStore &store = mWindowManager.getStore(); - if (!factions.empty()) + if (!mFactions.empty()) { // Add a line separator if there are items above if (!skillWidgets.empty()) addSeparator(coord1, coord2); addGroup(mWindowManager.getGameSettingString("sFaction", "Faction"), coord1, coord2); - FactionList::const_iterator end = factions.end(); - for (FactionList::const_iterator it = factions.begin(); it != end; ++it) + FactionList::const_iterator end = mFactions.end(); + for (FactionList::const_iterator it = mFactions.begin(); it != end; ++it) { const ESM::Faction *faction = store.factions.find(it->first); addItem(faction->name, coord1, coord2); diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 08c5148ec..ecda22ee0 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -18,13 +18,15 @@ namespace MWGui class StatsWindow : public WindowPinnableBase { public: - typedef std::pair Faction; - typedef std::vector FactionList; + typedef std::map FactionList; typedef std::vector SkillList; StatsWindow(WindowManager& parWindowManager); + /// automatically updates all the data in the stats window, but only if it has changed. + void onFrame(); + void setBar(const std::string& name, const std::string& tname, int val, int max); void setPlayerName(const std::string& playerName); @@ -36,7 +38,7 @@ namespace MWGui void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); void configureSkills (const SkillList& major, const SkillList& minor); - void setFactions (const std::vector& factions); + void setFactions (const FactionList& factions); void setBirthSign (const std::string &signId); void setReputation (int reputation) { this->reputation = reputation; } void setBounty (int bounty) { this->bounty = bounty; } @@ -69,11 +71,13 @@ namespace MWGui std::map > skillValues; std::map skillWidgetMap; std::map factionWidgetMap; - FactionList factions; ///< Stores a list of factions and the current rank + FactionList mFactions; ///< Stores a list of factions and the current rank std::string birthSignId; int reputation, bounty; std::vector skillWidgets; //< Skills and other information + bool mChanged; + protected: virtual void onPinToggled(); }; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 047d1da1e..2dcf7c7f8 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -47,12 +47,6 @@ namespace MWGui mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog8")->str); - mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); - mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); - mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); - mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str); - mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str); - // adjust size of buttons to fit text int curX = 0; mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f447c78e4..9246af1fe 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -40,7 +40,7 @@ WindowManager::WindowManager( , hud(NULL) , map(NULL) , menu(NULL) - , stats(NULL) + , mStatsWindow(NULL) , mToolTips(NULL) , mMessageBoxManager(NULL) , console(NULL) @@ -89,6 +89,8 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag); + // Get size info from the Gui object assert(gui); int w = MyGUI::RenderManager::getInstance().getViewSize().width; @@ -104,7 +106,7 @@ WindowManager::WindowManager( menu = new MainMenu(w,h); map = new MapWindow(*this); - stats = new StatsWindow(*this); + mStatsWindow = new StatsWindow(*this); console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); @@ -146,7 +148,7 @@ WindowManager::~WindowManager() delete hud; delete map; delete menu; - delete stats; + delete mStatsWindow; delete mJournal; delete mDialogueWindow; delete mContainerWindow; @@ -207,7 +209,7 @@ void WindowManager::updateVisible() // Start out by hiding everything except the HUD map->setVisible(false); menu->setVisible(false); - stats->setVisible(false); + mStatsWindow->setVisible(false); console->disable(); mJournal->setVisible(false); mDialogueWindow->setVisible(false); @@ -261,7 +263,7 @@ void WindowManager::updateVisible() // Show the windows we want map -> setVisible( (eff & GW_Map) != 0 ); - stats -> setVisible( (eff & GW_Stats) != 0 ); + mStatsWindow -> setVisible( (eff & GW_Stats) != 0 ); mInventoryWindow->setVisible(true); mInventoryWindow->openInventory(); break; @@ -299,7 +301,7 @@ void WindowManager::updateVisible() void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); static const char *ids[] = { @@ -329,13 +331,13 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) { - stats->setValue(parSkill, value); + mStatsWindow->setValue(parSkill, value); playerSkillValues[parSkill] = value; } void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); hud->setValue (id, value); if (id == "HBar") { @@ -368,7 +370,7 @@ MWMechanics::DynamicStat WindowManager::getValue(const std::string& id) void WindowManager::setValue (const std::string& id, const std::string& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); if (id=="name") playerName = value; else if (id=="race") @@ -377,46 +379,41 @@ void WindowManager::setValue (const std::string& id, const std::string& value) void WindowManager::setValue (const std::string& id, int value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); } void WindowManager::setPlayerClass (const ESM::Class &class_) { playerClass = class_; - stats->setValue("class", playerClass.name); + mStatsWindow->setValue("class", playerClass.name); } void WindowManager::configureSkills (const SkillList& major, const SkillList& minor) { - stats->configureSkills (major, minor); + mStatsWindow->configureSkills (major, minor); playerMajorSkills = major; playerMinorSkills = minor; } -void WindowManager::setFactions (const FactionList& factions) -{ - stats->setFactions (factions); -} - void WindowManager::setBirthSign (const std::string &signId) { - stats->setBirthSign (signId); + mStatsWindow->setBirthSign (signId); playerBirthSignId = signId; } void WindowManager::setReputation (int reputation) { - stats->setReputation (reputation); + mStatsWindow->setReputation (reputation); } void WindowManager::setBounty (int bounty) { - stats->setBounty (bounty); + mStatsWindow->setBounty (bounty); } void WindowManager::updateSkillArea() { - stats->updateSkillArea(); + mStatsWindow->updateSkillArea(); } void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) @@ -477,6 +474,8 @@ void WindowManager::onFrame (float frameDuration) } mInventoryWindow->update(); + + mStatsWindow->onFrame(); } const ESMS::ESMStore& WindowManager::getStore() const @@ -598,3 +597,10 @@ void WindowManager::setDragDrop(bool dragDrop) mToolTips->setEnabled(!dragDrop); MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop); } + +void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result) +{ + const ESM::GameSetting *setting = MWBase::Environment::get().getWorld()->getStore().gameSettings.search(_tag); + if (setting && setting->type == ESM::VT_String) + _result = setting->str; +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 82c494191..cdcace85d 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -14,11 +14,15 @@ #include #include +#include "MyGUI_UString.h" + #include #include #include + #include "../mwmechanics/stat.hpp" #include "../mwworld/ptr.hpp" + #include "mode.hpp" namespace MyGUI @@ -157,7 +161,6 @@ namespace MWGui void setPlayerClass (const ESM::Class &class_); ///< set current class of player void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group. - void setFactions (const FactionList& factions); ///< set faction and rank to display on stat window, use an empty vector to disable void setBirthSign (const std::string &signId); ///< set birth sign to display on stat window, use an empty string to disable. void setReputation (int reputation); ///< set the current reputation value void setBounty (int bounty); ///< set the current bounty value @@ -216,7 +219,7 @@ namespace MWGui MapWindow *map; MainMenu *menu; ToolTips *mToolTips; - StatsWindow *stats; + StatsWindow *mStatsWindow; MessageBoxManager *mMessageBoxManager; Console *console; JournalWindow* mJournal; @@ -270,6 +273,12 @@ namespace MWGui size_t mBatchCount; void onDialogueWindowBye(); + + /** + * Called when MyGUI tries to retrieve a tag. This usually corresponds to a GMST string, + * so this method will retrieve the GMST with the name \a _tag and place the result in \a _result + */ + void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result); }; template diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index b6a93e697..8a4e00433 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -6,11 +6,21 @@ - - - - - + + + + + + + + + + + + + + + @@ -36,8 +46,8 @@ - - + +