more spell buying window cleanup

actorid
scrawl 12 years ago
parent 0696a3b10e
commit 996e6280d8

@ -34,13 +34,7 @@ namespace MWGui
getWidget(mPlayerGold, "PlayerGold"); getWidget(mPlayerGold, "PlayerGold");
getWidget(mSelect, "Select"); getWidget(mSelect, "Select");
getWidget(mSpells, "Spells"); getWidget(mSpells, "Spells");
getWidget(mSpellsBoxWidget, "SpellsBox"); getWidget(mSpellsView, "SpellsView");
getWidget(mSpellsClientWidget, "SpellsClient");
getWidget(mSpellsScrollerWidget, "SpellsScroller");
mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel);
mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellBuyingWindow::onScrollChangePosition);
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onCancelButtonClicked); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onCancelButtonClicked);
@ -58,7 +52,7 @@ namespace MWGui
{ {
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId);
int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f;
MyGUI::Button* toAdd = mSpellsClientWidget->createWidget<MyGUI::Button>((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); MyGUI::Button* toAdd = mSpellsView->createWidget<MyGUI::Button>((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
mCurrentY += sLineHeight; mCurrentY += sLineHeight;
/// \todo price adjustment depending on merchantile skill /// \todo price adjustment depending on merchantile skill
toAdd->setUserData(price); toAdd->setUserData(price);
@ -73,11 +67,10 @@ namespace MWGui
void SpellBuyingWindow::clearSpells() void SpellBuyingWindow::clearSpells()
{ {
mSpellsScrollerWidget->setScrollPosition(0); mSpellsView->setViewOffset(MyGUI::IntPoint(0,0));
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
mCurrentY = 0; mCurrentY = 0;
while (mSpellsClientWidget->getChildCount()) while (mSpellsView->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mSpellsClientWidget->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(mSpellsView->getChildAt(0));
mSpellsWidgetMap.clear(); mSpellsWidgetMap.clear();
} }
@ -106,7 +99,8 @@ namespace MWGui
} }
updateLabels(); updateLabels();
updateScroller();
mSpellsView->setCanvasSize (MyGUI::IntSize(mSpellsView->getWidth(), std::max(mSpellsView->getHeight(), mCurrentY)));
} }
void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender) void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender)
@ -120,10 +114,9 @@ namespace MWGui
MWMechanics::Spells& spells = stats.getSpells(); MWMechanics::Spells& spells = stats.getSpells();
spells.add (mSpellsWidgetMap.find(_sender)->second); spells.add (mSpellsWidgetMap.find(_sender)->second);
mWindowManager.getTradeWindow()->addOrRemoveGold(-price); mWindowManager.getTradeWindow()->addOrRemoveGold(-price);
mSpellsScrollerWidget->setScrollPosition(0);
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
updateScroller();
startSpellBuying(mActor); startSpellBuying(mActor);
MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0);
} }
} }
@ -149,39 +142,12 @@ namespace MWGui
mWindowManager.removeGuiMode(GM_Dialogue); mWindowManager.removeGuiMode(GM_Dialogue);
} }
void SpellBuyingWindow::updateScroller()
{
mSpellsScrollerWidget->setScrollRange(std::max(mCurrentY - mSpellsClientWidget->getHeight(), 0));
mSpellsScrollerWidget->setScrollPage(std::max(mSpellsClientWidget->getHeight() - sLineHeight, 0));
if (mCurrentY != 0)
mSpellsScrollerWidget->setTrackSize( (mSpellsBoxWidget->getHeight() / float(mCurrentY)) * mSpellsScrollerWidget->getLineSize() );
}
void SpellBuyingWindow::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;
for (unsigned int i=0;i<mSpellsClientWidget->getChildCount();i++)
{
MyGUI::Widget* toMove = mSpellsClientWidget->getChildAt(i);
toMove->setCoord(toMove->getCoord() + MyGUI::IntPoint(0, diff));
}
}
void SpellBuyingWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) void SpellBuyingWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
{ {
if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 < 0) if (mSpellsView->getViewOffset().top + _rel*0.3 > 0)
mSpellsScrollerWidget->setScrollPosition(0); mSpellsView->setViewOffset(MyGUI::IntPoint(0, 0));
else if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 > mSpellsScrollerWidget->getScrollRange()-1)
mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollRange()-1);
else else
mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollPosition() - _rel*0.3); mSpellsView->setViewOffset(MyGUI::IntPoint(0, mSpellsView->getViewOffset().top + _rel*0.3));
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
} }
} }

@ -33,8 +33,7 @@ namespace MWGui
MyGUI::TextBox* mSpells; MyGUI::TextBox* mSpells;
MyGUI::TextBox* mSelect; MyGUI::TextBox* mSelect;
MyGUI::WidgetPtr mSpellsBoxWidget, mSpellsClientWidget; MyGUI::ScrollView* mSpellsView;
MyGUI::ScrollBar* mSpellsScrollerWidget;
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
@ -42,8 +41,6 @@ namespace MWGui
void onCancelButtonClicked(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender);
void onSpellButtonClick(MyGUI::Widget* _sender); void onSpellButtonClick(MyGUI::Widget* _sender);
void updateScroller();
void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos);
void onMouseWheel(MyGUI::Widget* _sender, int _rel); void onMouseWheel(MyGUI::Widget* _sender, int _rel);
void addSpell(const std::string& spellID); void addSpell(const std::string& spellID);
void clearSpells(); void clearSpells();

@ -678,6 +678,7 @@ void WindowManager::processChangedSettings(const Settings::CategorySettingVector
mScrollWindow->center(); mScrollWindow->center();
mBookWindow->center(); mBookWindow->center();
mQuickKeysMenu->center(); mQuickKeysMenu->center();
mSpellBuyingWindow->center();
mDragAndDrop->mDragAndDropWidget->setSize(MyGUI::IntSize(x, y)); mDragAndDrop->mDragAndDropWidget->setSize(MyGUI::IntSize(x, y));
mInputBlocker->setSize(MyGUI::IntSize(x,y)); mInputBlocker->setSize(MyGUI::IntSize(x,y));
} }

@ -15,9 +15,10 @@
</Widget> </Widget>
<Widget type="Widget" skin="MW_Box" position="6 31 430 225" align="ALIGN_LEFT ALIGN_STRETCH" name="SpellsBox"> <Widget type="Widget" skin="MW_Box" position="6 31 430 225" align="ALIGN_LEFT ALIGN_STRETCH">
<Widget type="Widget" skin="" position="4 4 404 217" align="ALIGN_LEFT ALIGN_TOP ALIGN_STRETCH" name="SpellsClient" /> <Widget type="ScrollView" skin="MW_ScrollView" position="4 4 422 217" align="ALIGN_LEFT ALIGN_TOP ALIGN_STRETCH" name="SpellsView">
<Widget type="ScrollBar" skin="MW_VScroll" position="412 4 14 217" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="SpellsScroller" /> <Property key="CanvasAlign" value="Left"/>
</Widget>
</Widget> </Widget>

Loading…
Cancel
Save