diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 8510025cbc..bc0c0c7c1e 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -8,6 +8,8 @@ using namespace MWGui; +const int StatsWindow::lineHeight = 18; + void StatsWindow::configureSkills (const std::set& major, const std::set& minor, const std::set& misc) { majorSkills = major; @@ -17,6 +19,48 @@ void StatsWindow::configureSkills (const std::set& major, const std::setcreateWidget("MW_HLine", MyGUI::IntCoord(2 + 10, coord1.top, coord1.width + coord2.width - 8, 18), MyGUI::Align::Default); + skillWidgets.push_back(separator); + + coord1.top += separator->getHeight(); + coord2.top += separator->getHeight(); +} + +void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +{ + MyGUI::StaticTextPtr groupWidget = skillAreaWidget->createWidget("SandBrightText", MyGUI::IntCoord(4, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default); + groupWidget->setCaption(label); + skillWidgets.push_back(groupWidget); + + coord1.top += lineHeight; + coord2.top += lineHeight; +} + +void StatsWindow::addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +{ + MyGUI::StaticTextPtr skillNameWidget, skillValueWidget; + + skillNameWidget = skillAreaWidget->createWidget("SandText", coord1, MyGUI::Align::Default); + skillNameWidget->setCaption(text); + + skillValueWidget = skillAreaWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); + skillValueWidget->setCaption(value); + if (style == CS_Super) + skillValueWidget->setTextColour(MyGUI::Colour(0, 1, 0)); + else if (style == CS_Sub) + skillValueWidget->setTextColour(MyGUI::Colour(1, 0, 0)); + else + skillValueWidget->setTextColour(MyGUI::Colour(1, 1, 1)); + + skillWidgets.push_back(skillNameWidget); + skillWidgets.push_back(skillValueWidget); + + coord1.top += lineHeight; + coord2.top += lineHeight; +} + void StatsWindow::addSkills(const std::set &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { // Get player and stats @@ -28,26 +72,14 @@ void StatsWindow::addSkills(const std::set &skills, const std::string &titl MWMechanics::MechanicsManager *mm = environment.mMechanicsManager; ESMS::ESMStore &store = environment.mWorld->getStore(); - MyGUI::StaticTextPtr skillNameWidget, skillValueWidget; - const int lineHeight = 18; - // Add a line separator if there are items above if (!skillWidgets.empty()) { - MyGUI::StaticImagePtr separator = skillAreaWidget->createWidget("MW_HLine", MyGUI::IntCoord(2 + 10, coord1.top, coord1.width + coord2.width - 8, 18), MyGUI::Align::Default); - skillWidgets.push_back(separator); - coord1.top += separator->getHeight(); - coord2.top += separator->getHeight(); + addSeparator(coord1, coord2); } - skillNameWidget = skillAreaWidget->createWidget("SandBrightText", MyGUI::IntCoord(4, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default); - skillNameWidget->setCaption(wm->getGameSettingString(titleId, titleDefault)); - skillWidgets.push_back(skillNameWidget); + addGroup(wm->getGameSettingString(titleId, titleDefault), coord1, coord2); - coord1.top += lineHeight; - coord2.top += lineHeight; - - int i = 0; std::set::const_iterator end = skills.end(); for (std::set::const_iterator it = skills.begin(); it != end; ++it) { @@ -61,26 +93,12 @@ void StatsWindow::addSkills(const std::set &skills, const std::string &titl float base = stat.getBase(); float modified = stat.getModified(); - skillNameWidget = skillAreaWidget->createWidget("SandText", coord1, MyGUI::Align::Default, - std::string("SkillName") + boost::lexical_cast(i)); - skillNameWidget->setCaption(wm->getGameSettingString(skillNameId, skillNameId)); - - skillValueWidget = skillAreaWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default, - std::string("SkillValue") + boost::lexical_cast(i)); - skillValueWidget->setCaption(boost::lexical_cast(static_cast(modified))); + ColorStyle style = CS_Normal; if (modified > base) - skillValueWidget->setTextColour(MyGUI::Colour(0, 1, 0)); + style = CS_Super; else if (modified < base) - skillValueWidget->setTextColour(MyGUI::Colour(1, 0, 0)); - else - skillValueWidget->setTextColour(MyGUI::Colour(1, 1, 1)); - - skillWidgets.push_back(skillNameWidget); - skillWidgets.push_back(skillValueWidget); - - coord1.top += lineHeight; - coord2.top += lineHeight; - ++i; + style = CS_Sub; + addValueItem(wm->getGameSettingString(skillNameId, skillNameId), boost::lexical_cast(static_cast(modified)), style, coord1, coord2); } } diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index 2b4517d263..b7e7f722fa 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -296,8 +296,19 @@ namespace MWGui void configureSkills (const std::set& major, const std::set& minor, const std::set& misc); private: + enum ColorStyle + { + CS_Sub, + CS_Normal, + CS_Super + }; void updateSkillArea(); void addSkills(const std::set &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + void addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + + static const int lineHeight; MWWorld::Environment& environment; MyGUI::WidgetPtr skillAreaWidget;