From c45811770a4099ba99154ae90cff5f4092db2614 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Wed, 20 Oct 2010 21:39:18 +0200 Subject: [PATCH] Added a custom widget for displaying dynamic stats (health, magicka, fatigue). Can show a title/label, graphical bar and detailed text. --- apps/openmw/engine.cpp | 1 + apps/openmw/mwgui/widgets.cpp | 86 +++++++++++++++++++ apps/openmw/mwgui/widgets.hpp | 32 +++++++ .../openmw_resources/openmw_text.skin.xml | 18 ++++ 4 files changed, 137 insertions(+) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 6cd3ded1e..acf40f6fa 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -244,6 +244,7 @@ void OMW::Engine::go() MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index f23a884a2..e4819c80c 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -462,3 +462,89 @@ void MWSpellEffect::shutdownWidgetSkin() { } +/* MWDynamicStat */ + +MWDynamicStat::MWDynamicStat() +: value(0) +, max(1) +, textWidget(nullptr) +, barWidget(nullptr) +, barTextWidget(nullptr) +{ +} + +void MWDynamicStat::setValue(int cur, int max_) +{ + value = cur; + max = max_; + + if (barWidget) + { + barWidget->setProgressRange(max); + barWidget->setProgressPosition(value); + } + + + if (barTextWidget) + { + if (value >= 0 && max > 0) + { + std::stringstream out; + out << value << "/" << max; + barTextWidget->setCaption(out.str().c_str()); + } + else + barTextWidget->setCaption(""); + } +} +void MWDynamicStat::setTitle(const std::string text) +{ + if (textWidget) + textWidget->setCaption(text); +} + +void MWDynamicStat::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) +{ + Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name); + + initialiseWidgetSkin(_info); +} + +MWDynamicStat::~MWDynamicStat() +{ + shutdownWidgetSkin(); +} + +void MWDynamicStat::baseChangeWidgetSkin(ResourceSkin* _info) +{ + shutdownWidgetSkin(); + Base::baseChangeWidgetSkin(_info); + initialiseWidgetSkin(_info); +} + +void MWDynamicStat::initialiseWidgetSkin(ResourceSkin* _info) +{ + for (VectorWidgetPtr::iterator iter=mWidgetChildSkin.begin(); iter!=mWidgetChildSkin.end(); ++iter) + { + const std::string &name = *(*iter)->_getInternalData(); + if (name == "Text") + { + MYGUI_DEBUG_ASSERT( ! textWidget, "widget already assigned"); + textWidget = (*iter)->castType(); + } + else if (name == "Bar") + { + MYGUI_DEBUG_ASSERT( ! barWidget, "widget already assigned"); + barWidget = (*iter)->castType(); + } + else if (name == "BarText") + { + MYGUI_DEBUG_ASSERT( ! barTextWidget, "widget already assigned"); + barTextWidget = (*iter)->castType(); + } + } +} + +void MWDynamicStat::shutdownWidgetSkin() +{ +} diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 41b01032a..962cd5cbb 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -190,6 +190,38 @@ namespace MWGui MyGUI::StaticTextPtr textWidget; }; typedef MWSpellEffect* MWSpellEffectPtr; + + class MYGUI_EXPORT MWDynamicStat : public Widget + { + MYGUI_RTTI_DERIVED( MWDynamicStat ); + public: + MWDynamicStat(); + + void setValue(int value, int max); + void setTitle(const std::string text); + + int getValue() const { return value; } + int getMax() const { return max; } + + /*internal:*/ + virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name); + + protected: + virtual ~MWDynamicStat(); + + void baseChangeWidgetSkin(ResourceSkin* _info); + + private: + void initialiseWidgetSkin(ResourceSkin* _info); + void shutdownWidgetSkin(); + + int value, max; + MyGUI::StaticTextPtr textWidget; + MyGUI::ProgressPtr barWidget; + MyGUI::StaticTextPtr barTextWidget; + }; + typedef MWDynamicStat* MWDynamicStatPtr; + } } diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_text.skin.xml b/extern/mygui_3.0.1/openmw_resources/openmw_text.skin.xml index 4315ab694..66bf6cd10 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_text.skin.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_text.skin.xml @@ -91,4 +91,22 @@ + + + + + + + + + + + + + + + + + +