From 63f686ffab006933e0e1f6bf495d94228f5a6fad Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 27 Jul 2010 15:59:41 +0200 Subject: [PATCH] update attribute values in stats window --- apps/openmw/mwgui/mw_layouts.hpp | 29 ++++++++++++++++++++ apps/openmw/mwgui/window_manager.cpp | 5 ++++ apps/openmw/mwgui/window_manager.hpp | 5 ++++ apps/openmw/mwmechanics/mechanicsmanager.cpp | 26 +++++++++++++++++- apps/openmw/mwmechanics/mechanicsmanager.hpp | 8 ++++++ apps/openmw/mwmechanics/stat.hpp | 13 +++++++++ apps/openmw/mwworld/world.cpp | 1 + 7 files changed, 86 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/mw_layouts.hpp b/apps/openmw/mwgui/mw_layouts.hpp index 6df5ee3914..fba2b411d5 100644 --- a/apps/openmw/mwgui/mw_layouts.hpp +++ b/apps/openmw/mwgui/mw_layouts.hpp @@ -205,6 +205,35 @@ namespace MWGui break; } } + + /// Set value for the given ID. + void setValue (const std::string& id, const MWMechanics::Stat& value) + { + static const char *ids[] = + { + "AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5", + "AttribVal6", "AttribVal7", "AttribVal8", + 0 + }; + + for (int i=0; ids[i]; ++i) + if (ids[i]==id) + { + std::ostringstream valueString; + valueString << value.getModified(); + setText (id, valueString.str()); + + if (value.getModified()>value.getBase()) + setTextColor (id, 0, 1, 0); + else if (value.getModified()setLabel (id, label); } +void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) +{ + stats->setValue (id, value); +} + diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index d576c10b22..007738fd17 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -12,6 +12,8 @@ #include +#include "../mwmechanics/stat.hpp" + namespace MyGUI { class Gui; @@ -139,6 +141,9 @@ namespace MWGui void setLabel (const std::string& id, const std::string& label); ///< Set label text for the value with the given ID. + + void setValue (const std::string& id, const MWMechanics::Stat& value); + ///< Set value for the given ID. }; } #endif diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 96f82c2876..06a04e7f0c 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -63,9 +63,33 @@ namespace MWMechanics ++iter; } - void MechanicsManager::update() + void MechanicsManager::watchActor (const MWWorld::Ptr& ptr) { + mWatched = ptr; + } + void MechanicsManager::update() + { + if (!mWatched.isEmpty()) + { + MWMechanics::CreatureStats& stats = mWatched.getCreatureStats(); + + static const char *attributeNames[8] = + { + "AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5", + "AttribVal6", "AttribVal7", "AttribVal8" + }; + + for (int i=0; i<8; ++i) + { + if (stats.mAttributes[i]!=mWatchedCreature.mAttributes[i]) + { + mWatchedCreature.mAttributes[i] = stats.mAttributes[i]; + + mWindowManager.setValue (attributeNames[i], stats.mAttributes[i]); + } + } + } } } diff --git a/apps/openmw/mwmechanics/mechanicsmanager.hpp b/apps/openmw/mwmechanics/mechanicsmanager.hpp index af01a2e2e7..ca4c1c47bf 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.hpp @@ -5,6 +5,8 @@ #include "../mwworld/ptr.hpp" +#include "creaturestats.hpp" + namespace ESMS { class ESMStore; @@ -22,6 +24,8 @@ namespace MWMechanics const ESMS::ESMStore& mStore; MWGui::WindowManager& mWindowManager; std::set mActors; + MWWorld::Ptr mWatched; + CreatureStats mWatchedCreature; public: @@ -38,6 +42,10 @@ namespace MWMechanics void dropActors (const MWWorld::Ptr::CellStore *cellStore); ///< Deregister all actors in the given cell. + void watchActor (const MWWorld::Ptr& ptr); + ///< On each update look for changes in a previously registered actor and update the + /// GUI accordingly. + void update(); ///< Update actor stats }; diff --git a/apps/openmw/mwmechanics/stat.hpp b/apps/openmw/mwmechanics/stat.hpp index e13c0aff29..1390366281 100644 --- a/apps/openmw/mwmechanics/stat.hpp +++ b/apps/openmw/mwmechanics/stat.hpp @@ -65,6 +65,19 @@ namespace MWMechanics mModified += diff; } }; + + template + inline bool operator== (const Stat& left, const Stat& right) + { + return left.getBase()==right.getBase() && + left.getModified()==right.getModified(); + } + + template + inline bool operator!= (const Stat& left, const Stat& right) + { + return !(left==right); + } } #endif diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index e450cc513a..55be70f1c2 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -465,6 +465,7 @@ namespace MWWorld // Actors mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer()); + mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer()); for (ESMS::CellRefList::List::iterator iter ( cell->creatures.list.begin());