From 001fc0c6e83fbd3f5f0872724ccff9a9a680d628 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Sat, 18 Sep 2010 21:24:05 +0200 Subject: [PATCH] The content of the skill list in the stat window is now scrollable with a vertical scroller. --- apps/openmw/mwgui/layouts.cpp | 89 +++++++++++++++++-- apps/openmw/mwgui/layouts.hpp | 49 ++-------- .../openmw_stats_window_layout.xml | 2 + 3 files changed, 94 insertions(+), 46 deletions(-) diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 884c3578d..8f67d2904 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -12,6 +12,74 @@ using namespace MWGui; const int StatsWindow::lineHeight = 18; +StatsWindow::StatsWindow (MWWorld::Environment& environment) + : Layout("openmw_stats_window_layout.xml") + , environment(environment) + , lastPos(0) +{ + setCoord(0,0,498, 342); + + const char *names[][2] = + { + { "Attrib1", "sAttributeStrength" }, + { "Attrib2", "sAttributeIntelligence" }, + { "Attrib3", "sAttributeWillpower" }, + { "Attrib4", "sAttributeAgility" }, + { "Attrib5", "sAttributeSpeed" }, + { "Attrib6", "sAttributeEndurance" }, + { "Attrib7", "sAttributePersonality" }, + { "Attrib8", "sAttributeLuck" }, + { "Health_str", "sHealth" }, + { "Magicka_str", "sMagic" }, + { "Fatigue_str", "sFatigue" }, + { "Level_str", "sLevel" }, + { "Race_str", "sRace" }, + { "Class_str", "sClass" }, + { 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"); + getWidget(skillClientWidget, "SkillClient"); + getWidget(skillScrollerWidget, "SkillScroller"); + + skillScrollerWidget->eventScrollChangePosition = MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition); + updateScroller(); + + for (int i = 0; i < ESM::Skill::Length; ++i) + { + skillValues.insert(std::pair >(i, MWMechanics::Stat())); + skillWidgetMap.insert(std::pair(i, nullptr)); + } + + static_cast(mMainWidget)->eventWindowChangeCoord = MyGUI::newDelegate(this, &StatsWindow::onWindowResize); +} + +void StatsWindow::onScrollChangePosition(MyGUI::VScrollPtr scroller, size_t pos) +{ + int diff = lastPos - pos; + // Adjust position of all widget according to difference + if (diff == 0) + return; + lastPos = pos; + + std::vector::const_iterator end = skillWidgets.end(); + for (std::vector::const_iterator it = skillWidgets.begin(); it != end; ++it) + { + (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); + } +} + +void StatsWindow::onWindowResize(MyGUI::WidgetPtr window) +{ + updateScroller(); +} + void StatsWindow::setStyledText(MyGUI::WidgetPtr widget, ColorStyle style, const std::string &value) { widget->setCaption(value); @@ -110,7 +178,7 @@ void StatsWindow::setBirthSign (const std::string& signId) void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::StaticImagePtr separator = skillAreaWidget->createWidget("MW_HLine", MyGUI::IntCoord(2 + 10, coord1.top, coord1.width + coord2.width - 8, 18), MyGUI::Align::Default); + MyGUI::StaticImagePtr separator = skillClientWidget->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default); skillWidgets.push_back(separator); coord1.top += separator->getHeight(); @@ -119,7 +187,7 @@ void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) 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); + MyGUI::StaticTextPtr groupWidget = skillClientWidget->createWidget("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default); groupWidget->setCaption(label); skillWidgets.push_back(groupWidget); @@ -131,10 +199,10 @@ MyGUI::WidgetPtr StatsWindow::addValueItem(const std::string text, const std::st { MyGUI::StaticTextPtr skillNameWidget, skillValueWidget; - skillNameWidget = skillAreaWidget->createWidget("SandText", coord1, MyGUI::Align::Default); + skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Default); skillNameWidget->setCaption(text); - skillValueWidget = skillAreaWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); + skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); setStyledText(skillValueWidget, style, value); skillWidgets.push_back(skillNameWidget); @@ -150,7 +218,7 @@ void StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI { MyGUI::StaticTextPtr skillNameWidget; - skillNameWidget = skillAreaWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); + skillNameWidget = skillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); skillNameWidget->setCaption(text); skillWidgets.push_back(skillNameWidget); @@ -204,7 +272,7 @@ void StatsWindow::updateSkillArea() skillWidgets.clear(); const int valueSize = 40; - MyGUI::IntCoord coord1(14, 4, skillAreaWidget->getWidth() - (14 + valueSize + 4), 18); + MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); if (!majorSkills.empty()) @@ -252,4 +320,13 @@ void StatsWindow::updateSkillArea() addValueItem(wm->getGameSettingString("sReputation", "Reputation"), boost::lexical_cast(static_cast(reputation)), CS_Normal, coord1, coord2); addValueItem(wm->getGameSettingString("sBounty", "Bounty"), boost::lexical_cast(static_cast(bounty)), CS_Normal, coord1, coord2); + + clientHeight = coord1.top; + updateScroller(); +} + +void StatsWindow::updateScroller() +{ + skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0)); + skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0)); } diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index bc45536d4..6615aba42 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -197,45 +197,7 @@ namespace MWGui setText(tname, out.str().c_str()); } - StatsWindow (MWWorld::Environment& environment) - : Layout("openmw_stats_window_layout.xml") - , environment(environment) - { - setCoord(0,0,498, 342); - - const char *names[][2] = - { - { "Attrib1", "sAttributeStrength" }, - { "Attrib2", "sAttributeIntelligence" }, - { "Attrib3", "sAttributeWillpower" }, - { "Attrib4", "sAttributeAgility" }, - { "Attrib5", "sAttributeSpeed" }, - { "Attrib6", "sAttributeEndurance" }, - { "Attrib7", "sAttributePersonality" }, - { "Attrib8", "sAttributeLuck" }, - { "Health_str", "sHealth" }, - { "Magicka_str", "sMagic" }, - { "Fatigue_str", "sFatigue" }, - { "Level_str", "sLevel" }, - { "Race_str", "sRace" }, - { "Class_str", "sClass" }, - { 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"); - - for (int i = 0; i < ESM::Skill::Length; ++i) - { - skillValues.insert(std::pair >(i, MWMechanics::Stat())); - skillWidgetMap.insert(std::pair(i, nullptr)); - } - } + StatsWindow (MWWorld::Environment& environment); void setPlayerName(const std::string& playerName) { @@ -328,11 +290,18 @@ namespace MWGui void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); MyGUI::WidgetPtr addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + void updateScroller(); + + void onScrollChangePosition(MyGUI::VScrollPtr scroller, size_t pos); + void onWindowResize(MyGUI::WidgetPtr window); static const int lineHeight; MWWorld::Environment& environment; - MyGUI::WidgetPtr skillAreaWidget; + MyGUI::WidgetPtr skillAreaWidget, skillClientWidget; + MyGUI::VScrollPtr skillScrollerWidget; + int lastPos, clientHeight; + SkillList majorSkills, minorSkills, miscSkills; std::map > skillValues; std::map skillWidgetMap; diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_stats_window_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_stats_window_layout.xml index 01896d1f1..14b282ce4 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_stats_window_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_stats_window_layout.xml @@ -54,6 +54,8 @@ + +