mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 09:45:36 +00:00
Added a custom widget for displaying dynamic stats (health, magicka, fatigue). Can show a title/label, graphical bar and detailed text.
This commit is contained in:
parent
76ab7302b1
commit
c45811770a
4 changed files with 137 additions and 0 deletions
|
@ -244,6 +244,7 @@ void OMW::Engine::go()
|
|||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
|
||||
|
||||
// Create window manager - this manages all the MW-specific GUI windows
|
||||
MWScript::registerExtensions (mExtensions);
|
||||
|
|
|
@ -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<std::string>();
|
||||
if (name == "Text")
|
||||
{
|
||||
MYGUI_DEBUG_ASSERT( ! textWidget, "widget already assigned");
|
||||
textWidget = (*iter)->castType<StaticText>();
|
||||
}
|
||||
else if (name == "Bar")
|
||||
{
|
||||
MYGUI_DEBUG_ASSERT( ! barWidget, "widget already assigned");
|
||||
barWidget = (*iter)->castType<Progress>();
|
||||
}
|
||||
else if (name == "BarText")
|
||||
{
|
||||
MYGUI_DEBUG_ASSERT( ! barTextWidget, "widget already assigned");
|
||||
barTextWidget = (*iter)->castType<StaticText>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MWDynamicStat::shutdownWidgetSkin()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,4 +91,22 @@
|
|||
<Child type="StaticImage" skin="StaticImage" offset = "4 4 16 16" align = "ALIGN_LEFT ALIGN_TOP" name = "Image" />
|
||||
<Child type="StaticText" skin="SandText" offset = "24 0 176 20" align = "ALIGN_VCENTRE ALIGN_HSTRETCH" name = "Text" />
|
||||
</Skin>
|
||||
|
||||
<Skin name = "MW_DynamicStat_Red" size = "204 18">
|
||||
<Child type="StaticText" skin="SandText" offset = "0 0 70 18" align = "ALIGN_LEFT ALIGN_TOP" name = "Text" />
|
||||
<Child type="Progress" skin="MW_Progress_Red" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "Bar" />
|
||||
<Child type="StaticText" skin="SandTextC" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "BarText" />
|
||||
</Skin>
|
||||
|
||||
<Skin name = "MW_DynamicStat_Blue" size = "204 18">
|
||||
<Child type="StaticText" skin="SandText" offset = "0 0 70 18" align = "ALIGN_LEFT ALIGN_TOP" name = "Text" />
|
||||
<Child type="Progress" skin="MW_Progress_Blue" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "Bar" />
|
||||
<Child type="StaticText" skin="SandTextC" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "BarText" />
|
||||
</Skin>
|
||||
|
||||
<Skin name = "MW_DynamicStat_Green" size = "204 18">
|
||||
<Child type="StaticText" skin="SandText" offset = "0 0 70 18" align = "ALIGN_LEFT ALIGN_TOP" name = "Text" />
|
||||
<Child type="Progress" skin="MW_Progress_Green" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "Bar" />
|
||||
<Child type="StaticText" skin="SandTextC" offset = "74 0 130 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "BarText" />
|
||||
</Skin>
|
||||
</MyGUI>
|
||||
|
|
Loading…
Reference in a new issue