some stats window cleanup

actorid
scrawl 12 years ago
parent 432c089434
commit bb267dddf6

@ -25,9 +25,7 @@ const int StatsWindow::sLineHeight = 18;
StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager) StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager)
: WindowPinnableBase("openmw_stats_window.layout", parWindowManager) : WindowPinnableBase("openmw_stats_window.layout", parWindowManager)
, mSkillAreaWidget(NULL) , mSkillAreaWidget(NULL)
, mSkillClientWidget(NULL) , mSkillView(NULL)
, mSkillScrollerWidget(NULL)
, mLastPos(0)
, mClientHeight(0) , mClientHeight(0)
, mMajorSkills() , mMajorSkills()
, mMinorSkills() , mMinorSkills()
@ -64,16 +62,10 @@ StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager)
} }
getWidget(mSkillAreaWidget, "Skills"); getWidget(mSkillAreaWidget, "Skills");
getWidget(mSkillClientWidget, "SkillClient"); getWidget(mSkillView, "SkillView");
getWidget(mSkillScrollerWidget, "SkillScroller");
getWidget(mLeftPane, "LeftPane"); getWidget(mLeftPane, "LeftPane");
getWidget(mRightPane, "RightPane"); getWidget(mRightPane, "RightPane");
mSkillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
mSkillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition);
updateScroller();
for (int i = 0; i < ESM::Skill::Length; ++i) for (int i = 0; i < ESM::Skill::Length; ++i)
{ {
mSkillValues.insert(std::pair<int, MWMechanics::Stat<float> >(i, MWMechanics::Stat<float>())); mSkillValues.insert(std::pair<int, MWMechanics::Stat<float> >(i, MWMechanics::Stat<float>()));
@ -84,38 +76,18 @@ StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager)
t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize);
} }
void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos)
{
int diff = mLastPos - pos;
// Adjust position of all widget according to difference
if (diff == 0)
return;
mLastPos = pos;
std::vector<MyGUI::WidgetPtr>::const_iterator end = mSkillWidgets.end();
for (std::vector<MyGUI::WidgetPtr>::const_iterator it = mSkillWidgets.begin(); it != end; ++it)
{
(*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff));
}
}
void StatsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) void StatsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
{ {
if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) if (mSkillView->getViewOffset().top + _rel*0.3 > 0)
mSkillScrollerWidget->setScrollPosition(0); mSkillView->setViewOffset(MyGUI::IntPoint(0, 0));
else if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 > mSkillScrollerWidget->getScrollRange()-1)
mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollRange()-1);
else else
mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollPosition() - _rel*0.3); mSkillView->setViewOffset(MyGUI::IntPoint(0, mSkillView->getViewOffset().top + _rel*0.3));
onScrollChangePosition(mSkillScrollerWidget, mSkillScrollerWidget->getScrollPosition());
} }
void StatsWindow::onWindowResize(MyGUI::Window* window) void StatsWindow::onWindowResize(MyGUI::Window* window)
{ {
mLeftPane->setCoord( MyGUI::IntCoord(0, 0, 0.44*window->getSize().width, window->getSize().height) ); mLeftPane->setCoord( MyGUI::IntCoord(0, 0, 0.44*window->getSize().width, window->getSize().height) );
mRightPane->setCoord( MyGUI::IntCoord(0.44*window->getSize().width, 0, 0.56*window->getSize().width, window->getSize().height) ); mRightPane->setCoord( MyGUI::IntCoord(0.44*window->getSize().width, 0, 0.56*window->getSize().width, window->getSize().height) );
updateScroller();
} }
void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max) void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max)
@ -299,7 +271,7 @@ void StatsWindow::setBirthSign (const std::string& signId)
void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
{ {
MyGUI::ImageBox* separator = mSkillClientWidget->createWidget<MyGUI::ImageBox>("MW_HLine", MyGUI::ImageBox* separator = mSkillView->createWidget<MyGUI::ImageBox>("MW_HLine",
MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18),
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
separator->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); separator->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
@ -311,7 +283,7 @@ void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
{ {
MyGUI::TextBox* groupWidget = mSkillClientWidget->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::TextBox* groupWidget = mSkillView->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height),
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
groupWidget->setCaption(label); groupWidget->setCaption(label);
@ -326,11 +298,11 @@ MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::st
{ {
MyGUI::TextBox *skillNameWidget, *skillValueWidget; MyGUI::TextBox *skillNameWidget, *skillValueWidget;
skillNameWidget = mSkillClientWidget->createWidget<MyGUI::TextBox>("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); skillNameWidget = mSkillView->createWidget<MyGUI::TextBox>("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
skillNameWidget->setCaption(text); skillNameWidget->setCaption(text);
skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
skillValueWidget = mSkillClientWidget->createWidget<MyGUI::TextBox>("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); skillValueWidget = mSkillView->createWidget<MyGUI::TextBox>("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top);
skillValueWidget->setCaption(value); skillValueWidget->setCaption(value);
skillValueWidget->_setWidgetState(state); skillValueWidget->_setWidgetState(state);
skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
@ -348,7 +320,7 @@ MyGUI::Widget* StatsWindow::addItem(const std::string& text, MyGUI::IntCoord &co
{ {
MyGUI::TextBox* skillNameWidget; MyGUI::TextBox* skillNameWidget;
skillNameWidget = mSkillClientWidget->createWidget<MyGUI::TextBox>("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); skillNameWidget = mSkillView->createWidget<MyGUI::TextBox>("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default);
skillNameWidget->setCaption(text); skillNameWidget->setCaption(text);
skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
@ -426,12 +398,11 @@ void StatsWindow::updateSkillArea()
} }
mSkillWidgets.clear(); mSkillWidgets.clear();
mSkillScrollerWidget->setScrollPosition(0); mSkillView->setViewOffset (MyGUI::IntPoint(0,0));
onScrollChangePosition(mSkillScrollerWidget, 0);
mClientHeight = 0; mClientHeight = 0;
const int valueSize = 40; const int valueSize = 40;
MyGUI::IntCoord coord1(10, 0, mSkillClientWidget->getWidth() - (10 + valueSize), 18); MyGUI::IntCoord coord1(10, 0, mSkillView->getWidth() - (10 + valueSize) - 24, 18);
MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height);
if (!mMajorSkills.empty()) if (!mMajorSkills.empty())
@ -555,15 +526,8 @@ void StatsWindow::updateSkillArea()
} }
mClientHeight = coord1.top; mClientHeight = coord1.top;
updateScroller();
}
void StatsWindow::updateScroller() mSkillView->setCanvasSize (mSkillView->getWidth(), std::max(mSkillView->getHeight(), mClientHeight));
{
mSkillScrollerWidget->setScrollRange(std::max(mClientHeight - mSkillClientWidget->getHeight(), 0));
mSkillScrollerWidget->setScrollPage(std::max(mSkillClientWidget->getHeight() - sLineHeight, 0));
if (mClientHeight != 0)
mSkillScrollerWidget->setTrackSize( (mSkillAreaWidget->getHeight() / float(mClientHeight)) * mSkillScrollerWidget->getLineSize() );
} }
void StatsWindow::onPinToggled() void StatsWindow::onPinToggled()

@ -48,12 +48,10 @@ namespace MWGui
void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
MyGUI::TextBox* addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); MyGUI::TextBox* addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
MyGUI::Widget* addItem(const std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); MyGUI::Widget* addItem(const std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void updateScroller();
void setFactions (const FactionList& factions); void setFactions (const FactionList& factions);
void setBirthSign (const std::string &signId); void setBirthSign (const std::string &signId);
void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos);
void onWindowResize(MyGUI::Window* window); void onWindowResize(MyGUI::Window* window);
void onMouseWheel(MyGUI::Widget* _sender, int _rel); void onMouseWheel(MyGUI::Widget* _sender, int _rel);
@ -62,8 +60,8 @@ namespace MWGui
MyGUI::Widget* mLeftPane; MyGUI::Widget* mLeftPane;
MyGUI::Widget* mRightPane; MyGUI::Widget* mRightPane;
MyGUI::WidgetPtr mSkillAreaWidget, mSkillClientWidget; MyGUI::WidgetPtr mSkillAreaWidget;
MyGUI::ScrollBar* mSkillScrollerWidget; MyGUI::ScrollView* mSkillView;
int mLastPos, mClientHeight; int mLastPos, mClientHeight;
SkillList mMajorSkills, mMinorSkills, mMiscSkills; SkillList mMajorSkills, mMinorSkills, mMiscSkills;

@ -218,8 +218,7 @@
<!-- Player skills, factions, birthsign and reputation --> <!-- Player skills, factions, birthsign and reputation -->
<Widget type="Widget" skin="MW_Box" position="8 8 248 292" align="ALIGN_LEFT ALIGN_STRETCH" name="Skills"> <Widget type="Widget" skin="MW_Box" position="8 8 248 292" align="ALIGN_LEFT ALIGN_STRETCH" name="Skills">
<Widget type="Widget" skin="" position="4 4 222 284" align="ALIGN_LEFT ALIGN_TOP ALIGN_STRETCH" name="SkillClient" /> <Widget type="ScrollView" skin="MW_ScrollView" position="4 4 240 284" align="ALIGN_LEFT ALIGN_TOP ALIGN_STRETCH" name="SkillView" />
<Widget type="ScrollBar" skin="MW_VScroll" position="230 4 14 284" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="SkillScroller" />
</Widget> </Widget>
</Widget> </Widget>

Loading…
Cancel
Save