#include "widgets.hpp" #include "window_manager.hpp" #include "components/esm_store/store.hpp" #include #undef min #undef max using namespace MWGui; using namespace MWGui::Widgets; /* Helper functions */ /* * Fixes the filename of a texture path to use the correct .dds extension. * This is needed on some ESM entries which point to a .tga file instead. */ void MWGui::Widgets::fixTexturePath(std::string &path) { int offset = path.rfind("."); if (offset < 0) return; path.replace(offset, path.length() - offset, ".dds"); } /* MWSkill */ MWSkill::MWSkill() : manager(nullptr) , skillId(ESM::Skill::Length) , skillNameWidget(nullptr) , skillValueWidget(nullptr) { } void MWSkill::setSkillId(ESM::Skill::SkillEnum skill) { skillId = skill; updateWidgets(); } void MWSkill::setSkillNumber(int skill) { if (skill < 0) setSkillId(ESM::Skill::Length); else if (skill < ESM::Skill::Length) setSkillId(static_cast(skill)); else throw new std::runtime_error("Skill number out of range"); } void MWSkill::setSkillValue(const SkillValue& value_) { value = value_; updateWidgets(); } void MWSkill::updateWidgets() { if (skillNameWidget && manager) { if (skillId == ESM::Skill::Length) { skillNameWidget->setCaption(""); } else { const std::string &name = manager->getGameSettingString(ESM::Skill::sSkillNameIds[skillId], ""); skillNameWidget->setCaption(name); } } if (skillValueWidget) { SkillValue::Type modified = value.getModified(), base = value.getBase(); skillValueWidget->setCaption(boost::lexical_cast(modified)); if (modified > base) skillValueWidget->setState("increased"); else if (modified < base) skillValueWidget->setState("decreased"); else skillValueWidget->setState("normal"); } } void MWSkill::onClicked(MyGUI::Widget* _sender) { eventClicked(this); } void MWSkill::_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); } MWSkill::~MWSkill() { shutdownWidgetSkin(); } void MWSkill::baseChangeWidgetSkin(ResourceSkin* _info) { shutdownWidgetSkin(); Base::baseChangeWidgetSkin(_info); initialiseWidgetSkin(_info); } void MWSkill::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( ! skillNameWidget, "widget already assigned"); skillNameWidget = (*iter)->castType(); } else if (name == "StatValue") { MYGUI_DEBUG_ASSERT( ! skillValueWidget, "widget already assigned"); skillValueWidget = (*iter)->castType(); } else if (name == "StatNameButton") { MYGUI_DEBUG_ASSERT( ! skillNameWidget, "widget already assigned"); MyGUI::ButtonPtr button = (*iter)->castType