forked from teamnwah/openmw-tes3coop
Added widget for spells, updated race dialog to use that.
This commit is contained in:
parent
cd8b88dea1
commit
3e611b5d4c
4 changed files with 113 additions and 6 deletions
|
@ -242,6 +242,7 @@ void OMW::Engine::go()
|
|||
mOgre.getScene());
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
|
||||
|
||||
// Create window manager - this manages all the MW-specific GUI windows
|
||||
MWScript::registerExtensions (mExtensions);
|
||||
|
|
|
@ -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<MyGUI::StaticText>("SandText", coord, MyGUI::Align::Default, std::string("SpellPowerName") + boost::lexical_cast<std::string>(i));
|
||||
spellPowerWidget->setCaption(spell->name);
|
||||
spellPowerWidget = spellPowerList->createWidget<MWSpell>("MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + boost::lexical_cast<std::string>(i));
|
||||
spellPowerWidget->setEnvironment(&environment);
|
||||
spellPowerWidget->setSpellId(spellpower);
|
||||
|
||||
spellPowerItems.push_back(spellPowerWidget);
|
||||
|
||||
|
|
|
@ -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 <boost/algorithm/string.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
@ -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<std::string>();
|
||||
if (name == "StatName")
|
||||
{
|
||||
MYGUI_DEBUG_ASSERT( ! spellNameWidget, "widget already assigned");
|
||||
spellNameWidget = (*iter)->castType<StaticText>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MWSpell::shutdownWidgetSkin()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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<int> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue