From 0868e76ffbf0c8779707d9538023b3b2767db22e Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Sat, 18 Sep 2010 01:30:23 +0200 Subject: [PATCH] Added display of skills in stat window, the skills are configured with MWGui::WindowManager::configureSkills(). --- apps/openmw/CMakeLists.txt | 1 + apps/openmw/mwgui/layouts.cpp | 107 +++++++++++++++++++++++++++ apps/openmw/mwgui/layouts.hpp | 22 +++++- apps/openmw/mwgui/window_manager.cpp | 7 +- apps/openmw/mwgui/window_manager.hpp | 5 ++ 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 apps/openmw/mwgui/layouts.cpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8abac820c..f4c9b4361 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -42,6 +42,7 @@ set(GAMEGUI_HEADER ) set(GAMEGUI mwgui/window_manager.cpp + mwgui/layouts.cpp mwgui/console.cpp mwgui/text_input.cpp mwgui/race.cpp diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp new file mode 100644 index 000000000..8510025cb --- /dev/null +++ b/apps/openmw/mwgui/layouts.cpp @@ -0,0 +1,107 @@ +#include "layouts.hpp" + +#include "../mwworld/class.hpp" +#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwgui/window_manager.hpp" + +#include + +using namespace MWGui; + +void StatsWindow::configureSkills (const std::set& major, const std::set& minor, const std::set& misc) +{ + majorSkills = major; + minorSkills = minor; + miscSkills = misc; + + updateSkillArea(); +} + +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 + MWWorld::Ptr ptr = environment.mWorld->getPlayerPos().getPlayer(); + MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + MWMechanics::NpcStats& npcStats = MWWorld::Class::get (ptr).getNpcStats (ptr); + + WindowManager *wm = environment.mWindowManager; + 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(); + } + + 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); + + 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) + { + int skillId = *it; + if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes + continue; + assert(skillId >= 0 && skillId < ESM::Skill::Length); + const std::string &skillNameId = ESMS::Skill::sSkillNameIds[skillId]; + assert(skillId < sizeof(npcStats.mSkill)/sizeof(npcStats.mSkill[0])); + MWMechanics::Stat &stat = npcStats.mSkill[skillId]; + 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))); + if (modified > base) + skillValueWidget->setTextColour(MyGUI::Colour(0, 1, 0)); + 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; + } +} + +void StatsWindow::updateSkillArea() +{ + for (std::vector::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it) + { + MyGUI::Gui::getInstance().destroyWidget(*it); + } + skillWidgets.clear(); + + const int valueSize = 40; + MyGUI::IntCoord coord1(14, 4, skillAreaWidget->getWidth() - (14 + valueSize + 4), 18); + MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); + + if (!majorSkills.empty()) + addSkills(majorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); + + if (!minorSkills.empty()) + addSkills(minorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); + + if (!miscSkills.empty()) + addSkills(miscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); +} diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index a370f9f13..2b4517d26 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -8,6 +8,11 @@ #include #include +#include + +#include "../mwmechanics/stat.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" /* This file contains classes corresponding to all the window layouts @@ -185,8 +190,9 @@ namespace MWGui setText(tname, out.str().c_str()); } - StatsWindow (const ESMS::ESMStore& store) + StatsWindow (MWWorld::Environment& environment) : Layout("openmw_stats_window_layout.xml") + , environment(environment) { setCoord(0,0,498, 342); @@ -209,10 +215,13 @@ namespace MWGui { 0, 0 } }; + const ESMS::ESMStore &store = environment.mWorld->getStore(); for (int i=0; names[i][0]; ++i) { setText (names[i][0], store.gameSettings.find (names[i][1])->str); } + + getWidget(skillAreaWidget, "Skills"); } void setPlayerName(const std::string& playerName) @@ -283,6 +292,17 @@ namespace MWGui setText("LevelText", text.str()); } } + + void configureSkills (const std::set& major, const std::set& minor, const std::set& misc); + + private: + void updateSkillArea(); + void addSkills(const std::set &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + + MWWorld::Environment& environment; + MyGUI::WidgetPtr skillAreaWidget; + std::set majorSkills, minorSkills, miscSkills; + std::vector skillWidgets; //< Skills and other information }; #if 0 diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 5138dc841..2ec3ab230 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -37,7 +37,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment hud = new HUD(w,h); menu = new MainMenu(w,h); map = new MapWindow(); - stats = new StatsWindow (environment.mWorld->getStore()); + stats = new StatsWindow (environment); #if 0 inventory = new InventoryWindow (); #endif @@ -166,6 +166,11 @@ void WindowManager::setValue (const std::string& id, int value) stats->setValue (id, value); } +void WindowManager::configureSkills (const std::set& major, const std::set& minor, const std::set& misc) +{ + stats->configureSkills (major, minor, misc); +} + void WindowManager::messageBox (const std::string& message, const std::vector& buttons) { std::cout << "message box: " << message << std::endl; diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 1f4c333a2..c683fca16 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -12,6 +12,7 @@ #include #include +#include #include "../mwmechanics/stat.hpp" #include "mode.hpp" @@ -137,6 +138,10 @@ namespace MWGui void setValue (const std::string& id, int value); ///< set value for the given ID. + void configureSkills (const std::set& major, const std::set& minor, const std::set& misc); + ///< configure skill groups, each set contains the skill ID for that group. + + void messageBox (const std::string& message, const std::vector& buttons); /**