diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 55a885512..a41869e32 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -34,13 +34,7 @@ namespace MWGui getWidget(mPlayerGold, "PlayerGold"); getWidget(mSelect, "Select"); getWidget(mSpells, "Spells"); - getWidget(mSpellsBoxWidget, "SpellsBox"); - getWidget(mSpellsClientWidget, "SpellsClient"); - getWidget(mSpellsScrollerWidget, "SpellsScroller"); - - mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel); - - mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellBuyingWindow::onScrollChangePosition); + getWidget(mSpellsView, "SpellsView"); 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); int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; - MyGUI::Button* toAdd = mSpellsClientWidget->createWidget((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); + MyGUI::Button* toAdd = mSpellsView->createWidget((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); mCurrentY += sLineHeight; /// \todo price adjustment depending on merchantile skill toAdd->setUserData(price); @@ -73,11 +67,10 @@ namespace MWGui void SpellBuyingWindow::clearSpells() { - mSpellsScrollerWidget->setScrollPosition(0); - onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); + mSpellsView->setViewOffset(MyGUI::IntPoint(0,0)); mCurrentY = 0; - while (mSpellsClientWidget->getChildCount()) - MyGUI::Gui::getInstance().destroyWidget(mSpellsClientWidget->getChildAt(0)); + while (mSpellsView->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mSpellsView->getChildAt(0)); mSpellsWidgetMap.clear(); } @@ -106,7 +99,8 @@ namespace MWGui } updateLabels(); - updateScroller(); + + mSpellsView->setCanvasSize (MyGUI::IntSize(mSpellsView->getWidth(), std::max(mSpellsView->getHeight(), mCurrentY))); } void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender) @@ -120,10 +114,9 @@ namespace MWGui MWMechanics::Spells& spells = stats.getSpells(); spells.add (mSpellsWidgetMap.find(_sender)->second); mWindowManager.getTradeWindow()->addOrRemoveGold(-price); - mSpellsScrollerWidget->setScrollPosition(0); - onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); - updateScroller(); startSpellBuying(mActor); + + MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0); } } @@ -149,39 +142,12 @@ namespace MWGui 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;igetChildCount();i++) - { - MyGUI::Widget* toMove = mSpellsClientWidget->getChildAt(i); - toMove->setCoord(toMove->getCoord() + MyGUI::IntPoint(0, diff)); - } - } - void SpellBuyingWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) { - if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 < 0) - mSpellsScrollerWidget->setScrollPosition(0); - else if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 > mSpellsScrollerWidget->getScrollRange()-1) - mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollRange()-1); + if (mSpellsView->getViewOffset().top + _rel*0.3 > 0) + mSpellsView->setViewOffset(MyGUI::IntPoint(0, 0)); else - mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollPosition() - _rel*0.3); - - onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); + mSpellsView->setViewOffset(MyGUI::IntPoint(0, mSpellsView->getViewOffset().top + _rel*0.3)); } } diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp index 6f94e91b2..970498cd9 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -33,8 +33,7 @@ namespace MWGui MyGUI::TextBox* mSpells; MyGUI::TextBox* mSelect; - MyGUI::WidgetPtr mSpellsBoxWidget, mSpellsClientWidget; - MyGUI::ScrollBar* mSpellsScrollerWidget; + MyGUI::ScrollView* mSpellsView; MWWorld::Ptr mActor; @@ -42,8 +41,6 @@ namespace MWGui void onCancelButtonClicked(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 addSpell(const std::string& spellID); void clearSpells(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 9545304af..02718f365 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -678,6 +678,7 @@ void WindowManager::processChangedSettings(const Settings::CategorySettingVector mScrollWindow->center(); mBookWindow->center(); mQuickKeysMenu->center(); + mSpellBuyingWindow->center(); mDragAndDrop->mDragAndDropWidget->setSize(MyGUI::IntSize(x, y)); mInputBlocker->setSize(MyGUI::IntSize(x,y)); } diff --git a/files/mygui/openmw_spell_buying_window.layout b/files/mygui/openmw_spell_buying_window.layout index ccbaf5f3a..1e18fda23 100644 --- a/files/mygui/openmw_spell_buying_window.layout +++ b/files/mygui/openmw_spell_buying_window.layout @@ -15,9 +15,10 @@ - - - + + + +