From 51204f098e77b7fc7767956045e1625eef7dbd84 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 30 Mar 2013 15:51:07 +0100 Subject: [PATCH] Added soulgem dialog; made interactive message boxes not close the previous UI --- apps/openmw/CMakeLists.txt | 4 +-- apps/openmw/mwbase/windowmanager.hpp | 3 +++ apps/openmw/mwclass/misc.cpp | 10 ++++++++ apps/openmw/mwclass/misc.hpp | 4 +++ apps/openmw/mwgui/enchantingdialog.cpp | 5 ++++ apps/openmw/mwgui/enchantingdialog.hpp | 1 + apps/openmw/mwgui/messagebox.cpp | 21 ++++++++------- apps/openmw/mwgui/messagebox.hpp | 9 ++++++- apps/openmw/mwgui/mode.hpp | 4 +-- apps/openmw/mwgui/soulgemdialog.cpp | 34 +++++++++++++++++++++++++ apps/openmw/mwgui/soulgemdialog.hpp | 28 ++++++++++++++++++++ apps/openmw/mwgui/windowmanagerimp.cpp | 29 +++++++++++++-------- apps/openmw/mwgui/windowmanagerimp.hpp | 7 +++++ apps/openmw/mwinput/inputmanagerimp.cpp | 8 +++--- apps/openmw/mwworld/actionsoulgem.cpp | 21 +++++++++++++++ apps/openmw/mwworld/actionsoulgem.hpp | 19 ++++++++++++++ 16 files changed, 177 insertions(+), 30 deletions(-) create mode 100644 apps/openmw/mwgui/soulgemdialog.cpp create mode 100644 apps/openmw/mwgui/soulgemdialog.hpp create mode 100644 apps/openmw/mwworld/actionsoulgem.cpp create mode 100644 apps/openmw/mwworld/actionsoulgem.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 9b1e5a02fe..41f56f9931 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -31,7 +31,7 @@ add_openmw_dir (mwgui confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons - merchantrepair repair + merchantrepair repair soulgemdialog ) add_openmw_dir (mwdialogue @@ -54,7 +54,7 @@ add_openmw_dir (mwworld containerstore actiontalk actiontake manualref player cellfunctors failedaction cells localscripts customdata weather inventorystore ptr actionopen actionread actionequip timestamp actionalchemy cellstore actionapply actioneat - esmstore store recordcmp fallback actionrepair + esmstore store recordcmp fallback actionrepair actionsoulgem ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 6760c89d07..58897dc740 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -237,10 +237,13 @@ namespace MWBase virtual void startSpellMaking(MWWorld::Ptr actor) = 0; virtual void startEnchanting(MWWorld::Ptr actor) = 0; + virtual void startSelfEnchanting(MWWorld::Ptr soulgem) = 0; virtual void startTraining(MWWorld::Ptr actor) = 0; virtual void startRepair(MWWorld::Ptr actor) = 0; virtual void startRepairItem(MWWorld::Ptr item) = 0; + virtual void showSoulgemDialog (MWWorld::Ptr item) = 0; + virtual void changePointer (const std::string& name) = 0; virtual const Translation::Storage& getTranslationDataStorage() const = 0; diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index b971fa6f34..b8a928becb 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -15,6 +15,7 @@ #include "../mwworld/physicssystem.hpp" #include "../mwworld/manualref.hpp" #include "../mwworld/nullaction.hpp" +#include "../mwworld/actionsoulgem.hpp" #include "../mwgui/tooltips.hpp" @@ -233,4 +234,13 @@ namespace MWClass } return newPtr; } + + boost::shared_ptr Miscellaneous::use (const MWWorld::Ptr& ptr) const + { + if (ptr.getCellRef().mSoul == "") + return boost::shared_ptr(new MWWorld::NullAction()); + else + return boost::shared_ptr(new MWWorld::ActionSoulgem(ptr)); + } + } diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index a5a79a8f6d..12a50af19d 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -49,6 +49,10 @@ namespace MWClass ///< Return name of inventory icon. virtual std::string getModel(const MWWorld::Ptr &ptr) const; + + virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) + const; + ///< Generate action for using via inventory menu }; } diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 536dafc01a..ef124bb430 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -92,6 +92,11 @@ namespace MWGui startEditing (); } + void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem) + { + /// \todo + } + void EnchantingDialog::onReferenceUnavailable () { mWindowManager.removeGuiMode (GM_Dialogue); diff --git a/apps/openmw/mwgui/enchantingdialog.hpp b/apps/openmw/mwgui/enchantingdialog.hpp index 60445a8dc3..347b37e908 100644 --- a/apps/openmw/mwgui/enchantingdialog.hpp +++ b/apps/openmw/mwgui/enchantingdialog.hpp @@ -22,6 +22,7 @@ namespace MWGui virtual void open(); void startEnchanting(MWWorld::Ptr actor); + void startSelfEnchanting(MWWorld::Ptr soulgem); protected: virtual void onReferenceUnavailable(); diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index b8a34c457e..46663b67a5 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -3,6 +3,7 @@ #include "messagebox.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" +#include "../mwbase/inputmanager.hpp" using namespace MWGui; @@ -62,7 +63,8 @@ void MessageBoxManager::onFrame (float frameDuration) if(mInterMessageBoxe != NULL && mInterMessageBoxe->mMarkedToDelete) { delete mInterMessageBoxe; mInterMessageBoxe = NULL; - mWindowManager->removeGuiMode(GM_InterMessageBox); + MWBase::Environment::get().getInputManager()->changeInputMode( + MWBase::Environment::get().getWindowManager()->isGuiMode()); } } @@ -90,11 +92,8 @@ void MessageBoxManager::createMessageBox (const std::string& message) bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) { - /// \todo Don't write this kind of error message to cout. Either discard the old message box - /// silently or throw an exception. if(mInterMessageBoxe != NULL) { - std::cout << "there is a MessageBox already" << std::endl; - return false; + throw std::runtime_error("There is a message box already"); } mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons); @@ -139,7 +138,8 @@ void MessageBoxManager::setMessageBoxSpeed (int speed) void MessageBoxManager::enterPressed () { - mInterMessageBoxe->enterPressed(); + if(mInterMessageBoxe != NULL) + mInterMessageBoxe->enterPressed(); } int MessageBoxManager::readPressedButton () @@ -213,10 +213,12 @@ int MessageBox::getHeight () InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons) - : Layout("openmw_interactive_messagebox.layout") + : WindowModal("openmw_interactive_messagebox.layout", *MWBase::Environment::get().getWindowManager()) , mMessageBoxManager(parMessageBoxManager) , mButtonPressed(-1) { + WindowModal::open(); + int fixedWidth = 500; int textPadding = 10; // padding between text-widget and main-widget int textButtonPadding = 20; // padding between the text-widget und the button-widget @@ -232,7 +234,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan getWidget(mButtonsWidget, "buttons"); mMessageWidget->setOverflowToTheLeft(true); - mMessageWidget->addText(message); + mMessageWidget->setCaptionWithReplacing(message); MyGUI::IntSize textSize = mMessageWidget->getTextSize(); @@ -252,7 +254,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan std::string("MW_Button"), dummyCoord, MyGUI::Align::Default); - button->setCaption(*it); + button->setCaptionWithReplacing(*it); button->eventMouseButtonClick += MyGUI::newDelegate(this, &InteractiveMessageBox::mousePressed); @@ -399,6 +401,7 @@ void InteractiveMessageBox::buttonActivated (MyGUI::Widget* pressed) if(*button == pressed) { mButtonPressed = index; + mMessageBoxManager.onButtonPressed(mButtonPressed); return; } index++; diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 149aa7e7f1..859e1806a7 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -44,6 +44,13 @@ namespace MWGui void enterPressed(); int readPressedButton (); + typedef MyGUI::delegates::CMultiDelegate1 EventHandle_Int; + + // Note: this delegate unassigns itself after it was fired, i.e. works once. + EventHandle_Int eventButtonPressed; + + void onButtonPressed(int button) { eventButtonPressed(button); eventButtonPressed.clear(); } + MWBase::WindowManager *mWindowManager; private: @@ -73,7 +80,7 @@ namespace MWGui int mNextBoxPadding; }; - class InteractiveMessageBox : public OEngine::GUI::Layout + class InteractiveMessageBox : public WindowModal { public: InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons); diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 4091f47acc..e9b01395f0 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -5,6 +5,7 @@ namespace MWGui { enum GuiMode { + GM_None, GM_Settings, // Settings window GM_Inventory, // Inventory mode GM_Container, @@ -41,9 +42,6 @@ namespace MWGui GM_ClassCreate, GM_Review, - // interactive MessageBox - GM_InterMessageBox, - GM_Loading, GM_LoadingWallpaper, diff --git a/apps/openmw/mwgui/soulgemdialog.cpp b/apps/openmw/mwgui/soulgemdialog.cpp new file mode 100644 index 0000000000..4530a13d0b --- /dev/null +++ b/apps/openmw/mwgui/soulgemdialog.cpp @@ -0,0 +1,34 @@ +#include "soulgemdialog.hpp" + +#include "../mwbase/windowmanager.hpp" +#include "../mwbase/environment.hpp" + +#include "messagebox.hpp" + +namespace MWGui +{ + + void SoulgemDialog::show(const MWWorld::Ptr &soulgem) + { + mSoulgem = soulgem; + std::vector buttons; + buttons.push_back("#{sRechargeEnchantment}"); + buttons.push_back("#{sMake Enchantment}"); + mManager->createInteractiveMessageBox("#{sDoYouWantTo}", buttons); + mManager->eventButtonPressed += MyGUI::newDelegate(this, &SoulgemDialog::onButtonPressed); + } + + void SoulgemDialog::onButtonPressed(int button) + { + if (button == 0) + { + /// \todo show recharge enchanted item dialog here + } + else + { + MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Enchanting); + MWBase::Environment::get().getWindowManager()->startSelfEnchanting(mSoulgem); + } + } + +} diff --git a/apps/openmw/mwgui/soulgemdialog.hpp b/apps/openmw/mwgui/soulgemdialog.hpp new file mode 100644 index 0000000000..9aea1f3393 --- /dev/null +++ b/apps/openmw/mwgui/soulgemdialog.hpp @@ -0,0 +1,28 @@ +#ifndef OPENMW_MWGUI_SOULGEMDIALOG_H +#define OPENMW_MWGUI_SOULGEMDIALOG_H + +#include "../mwworld/ptr.hpp" + +namespace MWGui +{ + + class MessageBoxManager; + + class SoulgemDialog + { + public: + SoulgemDialog (MessageBoxManager* manager) + : mManager(manager) {} + + void show (const MWWorld::Ptr& soulgem); + + void onButtonPressed(int button); + + private: + MessageBoxManager* mManager; + MWWorld::Ptr mSoulgem; + }; + +} + +#endif diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 718bb7106e..eadd657871 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -57,6 +57,7 @@ #include "spellicons.hpp" #include "merchantrepair.hpp" #include "repair.hpp" +#include "soulgemdialog.hpp" using namespace MWGui; @@ -94,6 +95,7 @@ WindowManager::WindowManager( , mTrainingWindow(NULL) , mMerchantRepair(NULL) , mRepair(NULL) + , mSoulgemDialog(NULL) , mPlayerName() , mPlayerRaceId() , mPlayerAttributes() @@ -186,6 +188,7 @@ WindowManager::WindowManager( mTrainingWindow = new TrainingWindow(*this); mMerchantRepair = new MerchantRepair(*this); mRepair = new Repair(*this); + mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); mLoadingScreen = new LoadingScreen(mRendering->getScene (), mRendering->getWindow (), *this); mLoadingScreen->onResChange (w,h); @@ -253,6 +256,7 @@ WindowManager::~WindowManager() delete mQuickKeysMenu; delete mMerchantRepair; delete mRepair; + delete mSoulgemDialog; delete mCursor; cleanupGarbage(); @@ -316,9 +320,6 @@ void WindowManager::updateVisible() mHud->setVisible(mHudEnabled); - // Mouse is visible whenever we're not in game mode - mCursor->setVisible(isGuiMode()); - bool gameMode = !isGuiMode(); mInputBlocker->setVisible (gameMode); @@ -444,8 +445,6 @@ void WindowManager::updateVisible() case GM_Repair: mRepair->setVisible(true); break; - case GM_InterMessageBox: - break; case GM_Journal: mJournal->setVisible(true); break; @@ -609,7 +608,7 @@ void WindowManager::messageBox (const std::string& message, const std::vectorcreateInteractiveMessageBox(message, buttons); - pushGuiMode(GM_InterMessageBox); + MWBase::Environment::get().getInputManager()->changeInputMode(isGuiMode()); } } @@ -648,6 +647,7 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); + mToolTips->onFrame(frameDuration); if (mDragAndDrop->mIsOnDragAndDrop) @@ -1033,12 +1033,12 @@ void WindowManager::toggleVisible (GuiWindow wnd) bool WindowManager::isGuiMode() const { - return !mGuiModes.empty(); + return !mGuiModes.empty() || mMessageBoxManager->isInteractiveMessageBox(); } bool WindowManager::isConsoleMode() const { - if (mGuiModes.back()==GM_Console) + if (!mGuiModes.empty() && mGuiModes.back()==GM_Console) return true; return false; } @@ -1046,8 +1046,7 @@ bool WindowManager::isConsoleMode() const MWGui::GuiMode WindowManager::getMode() const { if (mGuiModes.empty()) - throw std::runtime_error ("getMode() called, but there is no active mode"); - + return GM_None; return mGuiModes.back(); } @@ -1143,6 +1142,11 @@ void WindowManager::startEnchanting (MWWorld::Ptr actor) mEnchantingDialog->startEnchanting (actor); } +void WindowManager::startSelfEnchanting(MWWorld::Ptr soulgem) +{ + mEnchantingDialog->startSelfEnchanting(soulgem); +} + void WindowManager::startTraining(MWWorld::Ptr actor) { mTrainingWindow->startTraining(actor); @@ -1167,3 +1171,8 @@ void WindowManager::changePointer(const std::string &name) { mCursor->onCursorChange(name); } + +void WindowManager::showSoulgemDialog(MWWorld::Ptr item) +{ + mSoulgemDialog->show(item); +} diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 216ab9a6f8..5cf7bae02d 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -76,6 +76,7 @@ namespace MWGui class SpellIcons; class MerchantRepair; class Repair; + class SoulgemDialog; class WindowManager : public MWBase::WindowManager { @@ -230,14 +231,19 @@ namespace MWGui virtual void startSpellMaking(MWWorld::Ptr actor); virtual void startEnchanting(MWWorld::Ptr actor); + virtual void startSelfEnchanting(MWWorld::Ptr soulgem); virtual void startTraining(MWWorld::Ptr actor); virtual void startRepair(MWWorld::Ptr actor); virtual void startRepairItem(MWWorld::Ptr item); + virtual void showSoulgemDialog (MWWorld::Ptr item); + virtual void changePointer (const std::string& name); virtual const Translation::Storage& getTranslationDataStorage() const; + void onSoulgemDialogButtonPressed (int button); + private: OEngine::GUI::MyGUIManager *mGuiManager; OEngine::Render::OgreRenderer *mRendering; @@ -271,6 +277,7 @@ namespace MWGui EnchantingDialog* mEnchantingDialog; TrainingWindow* mTrainingWindow; MerchantRepair* mMerchantRepair; + SoulgemDialog* mSoulgemDialog; Repair* mRepair; Translation::Storage& mTranslationDataStorage; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index f49422747f..bd5367dad6 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -181,8 +181,7 @@ namespace MWInput break; case A_Activate: resetIdleTime(); - if( MWBase::Environment::get().getWindowManager()->isGuiMode() - && MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_InterMessageBox ) { + if( MWBase::Environment::get().getWindowManager()->isGuiMode()) { // Pressing the activation key when a messagebox is prompting for "ok" will activate the ok button MWBase::Environment::get().getWindowManager()->enterPressed(); } @@ -378,7 +377,7 @@ namespace MWInput void InputManager::changeInputMode(bool guiMode) { - // Are we in GUI mode now? + MWBase::Environment::get().getWindowManager()->setMouseVisible(guiMode); if(guiMode) { // Disable mouse look @@ -462,8 +461,7 @@ namespace MWInput bool InputManager::keyPressed( const OIS::KeyEvent &arg ) { if(arg.key == OIS::KC_RETURN - && MWBase::Environment::get().getWindowManager()->isGuiMode() - && MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_InterMessageBox ) + && MWBase::Environment::get().getWindowManager()->isGuiMode()) { // Pressing enter when a messagebox is prompting for "ok" will activate the ok button MWBase::Environment::get().getWindowManager()->enterPressed(); diff --git a/apps/openmw/mwworld/actionsoulgem.cpp b/apps/openmw/mwworld/actionsoulgem.cpp new file mode 100644 index 0000000000..6746f692f1 --- /dev/null +++ b/apps/openmw/mwworld/actionsoulgem.cpp @@ -0,0 +1,21 @@ +#include "actionsoulgem.hpp" + +#include "../mwbase/windowmanager.hpp" +#include "../mwbase/environment.hpp" + +namespace MWWorld +{ + +ActionSoulgem::ActionSoulgem(const Ptr &object) + : Action(false, object) +{ + +} + +void ActionSoulgem::executeImp(const Ptr &actor) +{ + MWBase::Environment::get().getWindowManager()->showSoulgemDialog(getTarget()); +} + + +} diff --git a/apps/openmw/mwworld/actionsoulgem.hpp b/apps/openmw/mwworld/actionsoulgem.hpp new file mode 100644 index 0000000000..0dd5266570 --- /dev/null +++ b/apps/openmw/mwworld/actionsoulgem.hpp @@ -0,0 +1,19 @@ +#ifndef GAME_MWWORLD_ACTIONSOULGEM_H +#define GAME_MWWORLD_ACTIONSOULGEM_H + +#include "action.hpp" +#include "ptr.hpp" + +namespace MWWorld +{ + class ActionSoulgem : public Action + { + virtual void executeImp (const MWWorld::Ptr& actor); + + public: + /// @param soulgem to use + ActionSoulgem (const Ptr& object); + }; +} + +#endif