From 37a6d7da761edb862d9a6af8fd0f11e1a9c9e846 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 11 Mar 2015 20:04:25 +0100 Subject: [PATCH] WindowManager refactoring --- apps/openmw/mwbase/windowmanager.hpp | 24 +++---- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 3 - apps/openmw/mwgui/dialogue.cpp | 43 ++----------- apps/openmw/mwgui/hud.cpp | 3 +- apps/openmw/mwgui/inventorywindow.cpp | 10 +-- apps/openmw/mwgui/windowmanagerimp.cpp | 64 +++++++++++++------ apps/openmw/mwgui/windowmanagerimp.hpp | 20 +++--- apps/openmw/mwinput/inputmanagerimp.cpp | 6 +- apps/openmw/mwworld/actionopen.cpp | 5 +- apps/openmw/mwworld/actionrepair.cpp | 1 - 10 files changed, 77 insertions(+), 102 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 2c4cb360d..b43dde4dd 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -149,17 +149,16 @@ namespace MWBase /// \todo investigate, if we really need to expose every single lousy UI element to the outside world virtual MWGui::DialogueWindow* getDialogueWindow() = 0; - virtual MWGui::ContainerWindow* getContainerWindow() = 0; virtual MWGui::InventoryWindow* getInventoryWindow() = 0; virtual MWGui::BookWindow* getBookWindow() = 0; virtual MWGui::ScrollWindow* getScrollWindow() = 0; virtual MWGui::CountDialog* getCountDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0; - virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow() = 0; - virtual MWGui::TravelWindow* getTravelWindow() = 0; - virtual MWGui::SpellWindow* getSpellWindow() = 0; - virtual MWGui::Console* getConsole() = 0; + + virtual void updateSpellWindow() = 0; + + virtual void setConsoleSelectedObject(const MWWorld::Ptr& object) = 0; virtual void wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount) = 0; @@ -181,12 +180,6 @@ namespace MWBase virtual void configureSkills (const SkillList& major, const SkillList& minor) = 0; ///< configure skill groups, each set contains the skill ID for that group. - virtual void setReputation (int reputation) = 0; - ///< set the current reputation value - - virtual void setBounty (int bounty) = 0; - ///< set the current bounty value - virtual void updateSkillArea() = 0; ///< update display of skills, factions, birth sign, reputation and bounty @@ -303,6 +296,10 @@ namespace MWBase virtual void startTraining(MWWorld::Ptr actor) = 0; virtual void startRepair(MWWorld::Ptr actor) = 0; virtual void startRepairItem(MWWorld::Ptr item) = 0; + virtual void startTravel(const MWWorld::Ptr& actor) = 0; + virtual void startSpellBuying(const MWWorld::Ptr& actor) = 0; + virtual void startTrade(const MWWorld::Ptr& actor) = 0; + virtual void openContainer(const MWWorld::Ptr& container, bool loot) = 0; virtual void showSoulgemDialog (MWWorld::Ptr item) = 0; @@ -332,9 +329,8 @@ namespace MWBase /// Does the current stack of GUI-windows permit saving? virtual bool isSavingAllowed() const = 0; - /// Returns the current Modal - /** Used to send exit command to active Modal when Esc is pressed **/ - virtual MWGui::WindowModal* getCurrentModal() const = 0; + /// Send exit command to active Modal window + virtual void exitCurrentModal() = 0; /// Sets the current Modal /** Used to send exit command to active Modal when Esc is pressed **/ diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 00e59e2a5..b928738dd 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -179,10 +179,7 @@ namespace MWDialogue bool isCompanion = !mActor.getClass().getScript(mActor).empty() && mActor.getRefData().getLocals().getIntVar(mActor.getClass().getScript(mActor), "companion"); if (isCompanion) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Companion); MWBase::Environment::get().getWindowManager()->showCompanionWindow(mActor); - } } bool DialogueManager::compile (const std::string& cmd,std::vector& code) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 3bc4292e3..1b07522f3 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -7,12 +7,14 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/world.hpp" #include "../mwbase/soundmanager.hpp" +#include "../mwbase/dialoguemanager.hpp" #include "../mwmechanics/npcstats.hpp" @@ -20,12 +22,7 @@ #include "../mwworld/containerstore.hpp" #include "../mwworld/esmstore.hpp" -#include "../mwdialogue/dialoguemanagerimp.hpp" - #include "widgets.hpp" -#include "tradewindow.hpp" -#include "spellbuyingwindow.hpp" -#include "travelwindow.hpp" #include "bookpage.hpp" #include "journalbooks.hpp" // to_utf8_span @@ -337,51 +334,25 @@ namespace MWGui MWBase::Environment::get().getWorld()->getStore().get(); if (topic == gmst.find("sPersuasion")->getString()) - { mPersuasionDialog.setVisible(true); - } else if (topic == gmst.find("sCompanionShare")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Companion); MWBase::Environment::get().getWindowManager()->showCompanionWindow(mPtr); - } else if (!MWBase::Environment::get().getDialogueManager()->checkServiceRefused()) { if (topic == gmst.find("sBarter")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Barter); - MWBase::Environment::get().getWindowManager()->getTradeWindow()->startTrade(mPtr); - } + MWBase::Environment::get().getWindowManager()->startTrade(mPtr); else if (topic == gmst.find("sSpells")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_SpellBuying); - MWBase::Environment::get().getWindowManager()->getSpellBuyingWindow()->startSpellBuying(mPtr); - } + MWBase::Environment::get().getWindowManager()->startSpellBuying(mPtr); else if (topic == gmst.find("sTravel")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Travel); - MWBase::Environment::get().getWindowManager()->getTravelWindow()->startTravel(mPtr); - } + MWBase::Environment::get().getWindowManager()->startTravel(mPtr); else if (topic == gmst.find("sSpellMakingMenuTitle")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_SpellCreation); MWBase::Environment::get().getWindowManager()->startSpellMaking (mPtr); - } else if (topic == gmst.find("sEnchanting")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Enchanting); MWBase::Environment::get().getWindowManager()->startEnchanting (mPtr); - } else if (topic == gmst.find("sServiceTrainingTitle")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Training); MWBase::Environment::get().getWindowManager()->startTraining (mPtr); - } else if (topic == gmst.find("sRepair")->getString()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_MerchantRepair); MWBase::Environment::get().getWindowManager()->startRepair (mPtr); - } } } } @@ -440,8 +411,6 @@ namespace MWGui bool isCompanion = !mPtr.getClass().getScript(mPtr).empty() && mPtr.getRefData().getLocals().getIntVar(mPtr.getClass().getScript(mPtr), "companion"); - bool anyService = mServices > 0 || isCompanion || mPtr.getTypeName() == typeid(ESM::NPC).name(); - const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); @@ -472,7 +441,7 @@ namespace MWGui if (isCompanion) mTopicsList->addItem(gmst.find("sCompanionShare")->getString()); - if (anyService) + if (mTopicsList->getItemCount() > 0) mTopicsList->addSeparator(); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 97a113527..eb458be50 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -24,7 +24,6 @@ #include "../mwmechanics/npcstats.hpp" #include "inventorywindow.hpp" -#include "console.hpp" #include "spellicons.hpp" #include "itemmodel.hpp" #include "draganddrop.hpp" @@ -309,7 +308,7 @@ namespace MWGui MWWorld::Ptr object = MWBase::Environment::get().getWorld()->getFacedObject(); if (mode == GM_Console) - MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object); + MWBase::Environment::get().getWindowManager()->setConsoleSelectedObject(object); else if ((mode == GM_Container) || (mode == GM_Inventory)) { // pick up object diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 919228195..a94df0b01 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -25,7 +25,6 @@ #include "bookwindow.hpp" #include "scrollwindow.hpp" -#include "spellwindow.hpp" #include "itemview.hpp" #include "inventoryitemmodel.hpp" #include "sortfilteritemmodel.hpp" @@ -317,8 +316,7 @@ namespace MWGui void InventoryWindow::updateItemView() { - if (MWBase::Environment::get().getWindowManager()->getSpellWindow()) - MWBase::Environment::get().getWindowManager()->getSpellWindow()->updateSpells(); + MWBase::Environment::get().getWindowManager()->updateSpellWindow(); mItemView->update(); mPreviewDirty = true; @@ -568,8 +566,7 @@ namespace MWGui void InventoryWindow::notifyContentChanged() { // update the spell window just in case new enchanted items were added to inventory - if (MWBase::Environment::get().getWindowManager()->getSpellWindow()) - MWBase::Environment::get().getWindowManager()->getSpellWindow()->updateSpells(); + MWBase::Environment::get().getWindowManager()->updateSpellWindow(); MWBase::Environment::get().getMechanicsManager()->updateMagicEffects( MWBase::Environment::get().getWorld()->getPlayerPtr()); @@ -626,8 +623,7 @@ namespace MWGui MWBase::Environment::get().getMechanicsManager()->itemTaken(player, newObject, MWWorld::Ptr(), count); - if (MWBase::Environment::get().getWindowManager()->getSpellWindow()) - MWBase::Environment::get().getWindowManager()->getSpellWindow()->updateSpells(); + MWBase::Environment::get().getWindowManager()->updateSpellWindow(); } void InventoryWindow::cycle(bool next) diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 815f342a4..fddc92dc1 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -715,16 +715,6 @@ namespace MWGui mPlayerMinorSkills = minor; } - void WindowManager::setReputation (int reputation) - { - mStatsWindow->setReputation (reputation); - } - - void WindowManager::setBounty (int bounty) - { - mStatsWindow->setBounty (bounty); - } - void WindowManager::updateSkillArea() { mStatsWindow->updateSkillArea(); @@ -1287,17 +1277,12 @@ namespace MWGui } MWGui::DialogueWindow* WindowManager::getDialogueWindow() { return mDialogueWindow; } - MWGui::ContainerWindow* WindowManager::getContainerWindow() { return mContainerWindow; } MWGui::InventoryWindow* WindowManager::getInventoryWindow() { return mInventoryWindow; } MWGui::BookWindow* WindowManager::getBookWindow() { return mBookWindow; } MWGui::ScrollWindow* WindowManager::getScrollWindow() { return mScrollWindow; } MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; } MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; } MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; } - MWGui::SpellBuyingWindow* WindowManager::getSpellBuyingWindow() { return mSpellBuyingWindow; } - MWGui::TravelWindow* WindowManager::getTravelWindow() { return mTravelWindow; } - MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; } - MWGui::Console* WindowManager::getConsole() { return mConsole; } bool WindowManager::isAllowed (GuiWindow wnd) const { @@ -1459,11 +1444,13 @@ namespace MWGui void WindowManager::startSpellMaking(MWWorld::Ptr actor) { + pushGuiMode(GM_SpellCreation); mSpellCreationDialog->startSpellMaking (actor); } void WindowManager::startEnchanting (MWWorld::Ptr actor) { + pushGuiMode(GM_Enchanting); mEnchantingDialog->startEnchanting (actor); } @@ -1474,16 +1461,19 @@ namespace MWGui void WindowManager::startTraining(MWWorld::Ptr actor) { + pushGuiMode(GM_Training); mTrainingWindow->startTraining(actor); } void WindowManager::startRepair(MWWorld::Ptr actor) { + pushGuiMode(GM_MerchantRepair); mMerchantRepair->startRepair(actor); } void WindowManager::startRepairItem(MWWorld::Ptr item) { + pushGuiMode(MWGui::GM_Repair); mRepair->startRepairItem(item); } @@ -1494,6 +1484,7 @@ namespace MWGui void WindowManager::showCompanionWindow(MWWorld::Ptr actor) { + pushGuiMode(MWGui::GM_Companion); mCompanionWindow->open(actor); } @@ -1744,12 +1735,10 @@ namespace MWGui mVideoWidget->autoResize(stretch); } - WindowModal* WindowManager::getCurrentModal() const + void WindowManager::exitCurrentModal() { - if(!mCurrentModals.empty()) - return mCurrentModals.top(); - else - return NULL; + if (!mCurrentModals.empty()) + mCurrentModals.top()->exit(); } void WindowManager::removeCurrentModal(WindowModal* input) @@ -1874,4 +1863,39 @@ namespace MWGui mInventoryWindow->cycle(next); } + void WindowManager::setConsoleSelectedObject(const MWWorld::Ptr &object) + { + mConsole->setSelectedObject(object); + } + + void WindowManager::updateSpellWindow() + { + if (mSpellWindow) + mSpellWindow->updateSpells(); + } + + void WindowManager::startTravel(const MWWorld::Ptr &actor) + { + pushGuiMode(GM_Travel); + mTravelWindow->startTravel(actor); + } + + void WindowManager::startSpellBuying(const MWWorld::Ptr &actor) + { + pushGuiMode(GM_SpellBuying); + mSpellBuyingWindow->startSpellBuying(actor); + } + + void WindowManager::startTrade(const MWWorld::Ptr &actor) + { + pushGuiMode(GM_Barter); + mTradeWindow->startTrade(actor); + } + + void WindowManager::openContainer(const MWWorld::Ptr &container, bool loot) + { + pushGuiMode(GM_Container); + mContainerWindow->open(container, loot); + } + } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index fbbc295b3..66125d4d0 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -154,17 +154,16 @@ namespace MWGui /// \todo investigate, if we really need to expose every single lousy UI element to the outside world virtual MWGui::DialogueWindow* getDialogueWindow(); - virtual MWGui::ContainerWindow* getContainerWindow(); virtual MWGui::InventoryWindow* getInventoryWindow(); virtual MWGui::BookWindow* getBookWindow(); virtual MWGui::ScrollWindow* getScrollWindow(); virtual MWGui::CountDialog* getCountDialog(); virtual MWGui::ConfirmationDialog* getConfirmationDialog(); virtual MWGui::TradeWindow* getTradeWindow(); - virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow(); - virtual MWGui::TravelWindow* getTravelWindow(); - virtual MWGui::SpellWindow* getSpellWindow(); - virtual MWGui::Console* getConsole(); + + virtual void updateSpellWindow(); + + virtual void setConsoleSelectedObject(const MWWorld::Ptr& object); virtual void wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount); @@ -182,8 +181,6 @@ namespace MWGui virtual void setPlayerClass (const ESM::Class &class_); ///< set current class of player virtual void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group. - virtual void setReputation (int reputation); ///< set the current reputation value - virtual void setBounty (int bounty); ///< set the current bounty value virtual void updateSkillArea(); ///< update display of skills, factions, birth sign, reputation and bounty virtual void changeCell(MWWorld::CellStore* cell); ///< change the active cell @@ -292,6 +289,10 @@ namespace MWGui virtual void startRepair(MWWorld::Ptr actor); virtual void startRepairItem(MWWorld::Ptr item); virtual void startRecharge(MWWorld::Ptr soulgem); + virtual void startTravel(const MWWorld::Ptr& actor); + virtual void startSpellBuying(const MWWorld::Ptr &actor); + virtual void startTrade(const MWWorld::Ptr &actor); + virtual void openContainer(const MWWorld::Ptr &container, bool loot); virtual void frameStarted(float dt); @@ -317,9 +318,8 @@ namespace MWGui /// Does the current stack of GUI-windows permit saving? virtual bool isSavingAllowed() const; - /// Returns the current Modal - /** Used to send exit command to active Modal when Esc is pressed **/ - virtual WindowModal* getCurrentModal() const; + /// Send exit command to active Modal window **/ + virtual void exitCurrentModal(); /// Sets the current Modal /** Used to send exit command to active Modal when Esc is pressed **/ diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 21576785c..355594204 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -33,8 +33,6 @@ #include "../mwdialogue/dialoguemanagerimp.hpp" -#include "../mwgui/windowbase.hpp" - #include using namespace ICS; @@ -887,7 +885,7 @@ namespace MWInput void InputManager::toggleMainMenu() { if (MyGUI::InputManager::getInstance().isModalAny()) { - MWBase::Environment::get().getWindowManager()->getCurrentModal()->exit(); + MWBase::Environment::get().getWindowManager()->exitCurrentModal(); return; } @@ -1061,7 +1059,7 @@ namespace MWInput } else if (MWBase::Environment::get().getWindowManager()->getMode () == MWGui::GM_QuickKeysMenu) { while(MyGUI::InputManager::getInstance().isModalAny()) { //Handle any open Modal windows - MWBase::Environment::get().getWindowManager()->getCurrentModal()->exit(); + MWBase::Environment::get().getWindowManager()->exitCurrentModal(); } MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); //And handle the actual main window } diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index e9d8b4716..0df451b18 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -3,8 +3,6 @@ #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" -#include "../mwgui/container.hpp" - #include "../mwmechanics/disease.hpp" #include "class.hpp" @@ -25,7 +23,6 @@ namespace MWWorld MWMechanics::diseaseContact(actor, getTarget()); - MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container); - MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(getTarget(), mLoot); + MWBase::Environment::get().getWindowManager()->openContainer(getTarget(), mLoot); } } diff --git a/apps/openmw/mwworld/actionrepair.cpp b/apps/openmw/mwworld/actionrepair.cpp index a86dc38b1..699440a01 100644 --- a/apps/openmw/mwworld/actionrepair.cpp +++ b/apps/openmw/mwworld/actionrepair.cpp @@ -19,7 +19,6 @@ namespace MWWorld return; } - MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Repair); MWBase::Environment::get().getWindowManager()->startRepairItem(getTarget()); } }