From 3e611b5d4cec76297b31bf04cd5027c4d4dd8244 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Mon, 20 Sep 2010 13:36:55 +0200 Subject: [PATCH] Added widget for spells, updated race dialog to use that. --- apps/openmw/engine.cpp | 1 + apps/openmw/mwgui/race.cpp | 9 ++--- apps/openmw/mwgui/widgets.cpp | 70 ++++++++++++++++++++++++++++++++++- apps/openmw/mwgui/widgets.hpp | 39 +++++++++++++++++++ 4 files changed, 113 insertions(+), 6 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 7e7df4e21..6a2398c94 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -242,6 +242,7 @@ void OMW::Engine::go() mOgre.getScene()); 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/race.cpp b/apps/openmw/mwgui/race.cpp index e9cd78173..72f400a34 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -286,7 +286,7 @@ void RaceDialog::updateSpellPowers() if (currentRaceId.empty()) return; - MyGUI::StaticTextPtr spellPowerWidget; + MWSpellPtr spellPowerWidget; const int lineHeight = 18; MyGUI::IntCoord coord(0, 0, spellPowerList->getWidth(), 18); @@ -298,10 +298,9 @@ void RaceDialog::updateSpellPowers() for (int i = 0; it != end; ++it) { const std::string &spellpower = *it; - const ESM::Spell *spell = store.spells.find(spellpower); - assert(spell); - spellPowerWidget = spellPowerList->createWidget("SandText", coord, MyGUI::Align::Default, std::string("SpellPowerName") + boost::lexical_cast(i)); - spellPowerWidget->setCaption(spell->name); + spellPowerWidget = spellPowerList->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + boost::lexical_cast(i)); + spellPowerWidget->setEnvironment(&environment); + spellPowerWidget->setSpellId(spellpower); spellPowerItems.push_back(spellPowerWidget); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 573636932..d6cea2428 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -1,5 +1,8 @@ #include "widgets.hpp" #include "window_manager.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" +#include "components/esm_store/store.hpp" //#include #include @@ -7,6 +10,8 @@ using namespace MWGui; using namespace MWGui::Widgets; +/* MWSkill */ + MWSkill::MWSkill() : manager(nullptr) , skillId(ESM::Skill::Length) @@ -105,7 +110,7 @@ void MWSkill::shutdownWidgetSkin() { } -/* MWSkill */ +/* MWAttribute */ MWAttribute::MWAttribute() : manager(nullptr) @@ -204,3 +209,66 @@ void MWAttribute::initialiseWidgetSkin(ResourceSkin* _info) void MWAttribute::shutdownWidgetSkin() { } + +/* MWSpell */ + +MWSpell::MWSpell() + : env(nullptr) + , spellNameWidget(nullptr) +{ +} + +void MWSpell::setSpellId(const std::string &spellId) +{ + id = spellId; + updateWidgets(); +} + +void MWSpell::updateWidgets() +{ + if (spellNameWidget && env) + { + ESMS::ESMStore &store = env->mWorld->getStore(); + const ESM::Spell *spell = store.spells.search(id); + if (spell) + spellNameWidget->setCaption(spell->name); + else + spellNameWidget->setCaption(""); + } +} + +void MWSpell::_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); +} + +MWSpell::~MWSpell() +{ + shutdownWidgetSkin(); +} + +void MWSpell::baseChangeWidgetSkin(ResourceSkin* _info) +{ + shutdownWidgetSkin(); + Base::baseChangeWidgetSkin(_info); + initialiseWidgetSkin(_info); +} + +void MWSpell::initialiseWidgetSkin(ResourceSkin* _info) +{ + for (VectorWidgetPtr::iterator iter=mWidgetChildSkin.begin(); iter!=mWidgetChildSkin.end(); ++iter) + { + const std::string &name = *(*iter)->_getInternalData(); + if (name == "StatName") + { + MYGUI_DEBUG_ASSERT( ! spellNameWidget, "widget already assigned"); + spellNameWidget = (*iter)->castType(); + } + } +} + +void MWSpell::shutdownWidgetSkin() +{ +} diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index d6d59d803..7d115ec41 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -7,6 +7,11 @@ #include "../mwmechanics/stat.hpp" +namespace MWWorld +{ + class Environment; +} + /* This file contains various custom widgets used in OpenMW. */ @@ -92,6 +97,40 @@ namespace MWGui MyGUI::StaticTextPtr attributeNameWidget, attributeValueWidget; }; typedef MWAttribute* MWAttributePtr; + + class MYGUI_EXPORT MWSpell : public Widget + { + MYGUI_RTTI_DERIVED( MWSpell ); + public: + MWSpell(); + + typedef MWMechanics::Stat SpellValue; + + void setEnvironment(MWWorld::Environment *env_) { env = env_; } + void setSpellId(const std::string &id); + + MWWorld::Environment *getEnvironment() const { return env; } + const std::string &getSpellId() const { return id; } + + /*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 ~MWSpell(); + + void baseChangeWidgetSkin(ResourceSkin* _info); + + private: + void initialiseWidgetSkin(ResourceSkin* _info); + void shutdownWidgetSkin(); + + void updateWidgets(); + + MWWorld::Environment *env; + std::string id; + MyGUI::StaticTextPtr spellNameWidget; + }; + typedef MWSpell* MWSpellPtr; } }