From 317c920e03eb9609196069cd0afffd827eedb750 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 20:05:04 +0200 Subject: [PATCH] everything works, also the readPressedButton function should do the job --- apps/openmw/mwgui/messagebox.cpp | 45 ++++++++++++++++++++++++++++ apps/openmw/mwgui/messagebox.hpp | 7 +++++ apps/openmw/mwgui/window_manager.cpp | 5 ++++ apps/openmw/mwgui/window_manager.hpp | 3 ++ 4 files changed, 60 insertions(+) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 2a1cb6a21..f0745bbbe 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -47,6 +47,12 @@ void MessageBoxManager::onFrame (float frameDuration) it++; } } + + if(mInterMessageBoxe != NULL && mInterMessageBoxe->mMarkedToDelete) { + delete mInterMessageBoxe; + mInterMessageBoxe = NULL; + mWindowManager->setNextMode(GM_Game); + } } void MessageBoxManager::createMessageBox (const std::string& message) @@ -124,6 +130,16 @@ void MessageBoxManager::setMessageBoxSpeed (int speed) } +int MessageBoxManager::readPressedButton () +{ + if(mInterMessageBoxe != NULL) + { + return mInterMessageBoxe->readPressedButton(); + } + return -1; +} + + MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message) @@ -186,6 +202,7 @@ int MessageBox::getHeight () InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons) : Layout("openmw_interactive_messagebox_layout.xml") , mMessageBoxManager(parMessageBoxManager) + , mButtonPressed(-1) { int fixedWidth = 500; int textPadding = 10; // padding between text-widget and main-widget @@ -195,6 +212,8 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan int buttonPadding = 5; // padding between button label and button itself int buttonMainPadding = 10; // padding between buttons and bottom of the main widget + mMarkedToDelete = false; + getWidget(mMessageWidget, "message"); getWidget(mButtonsWidget, "buttons"); @@ -222,6 +241,8 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan MyGUI::Align::Default); button->setCaption(*it); + button->eventMouseButtonClick = MyGUI::newDelegate(this, &InteractiveMessageBox::mousePressed); + mButtons.push_back(button); buttonWidth = button->_getTextSize().width + 2*buttonPadding + buttonLeftPadding; @@ -343,6 +364,30 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan } } +void InteractiveMessageBox::mousePressed (MyGUI::Widget* pressed) +{ + mMarkedToDelete = true; + int index = 0; + std::vector::const_iterator button; + for(button = mButtons.begin(); button != mButtons.end(); ++button) + { + if(*button == pressed) + { + mButtonPressed = index; + return; + } + index++; + } + std::cout << "Cant be possible :/" << std::endl; +} + +int InteractiveMessageBox::readPressedButton () +{ + int pressed = mButtonPressed; + mButtonPressed = -1; + return pressed; +} + diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index f7c7197fa..bf3307acc 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -34,6 +34,8 @@ namespace MWGui bool removeMessageBox (MessageBox *msgbox); void setMessageBoxSpeed (int speed); + int readPressedButton (); + WindowManager *mWindowManager; private: @@ -67,6 +69,10 @@ namespace MWGui { public: InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons); + void mousePressed (MyGUI::Widget* _widget); + int readPressedButton (); + + bool mMarkedToDelete; private: MessageBoxManager& mMessageBoxManager; @@ -75,6 +81,7 @@ namespace MWGui std::vector mButtons; int mTextButtonPadding; + int mButtonPressed; }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index b5a6e36a6..84e45859f 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -468,6 +468,11 @@ void WindowManager::messageBox (const std::string& message, const std::vectorreadPressedButton(); +} + const std::string &WindowManager::getGameSettingString(const std::string &id, const std::string &default_) { const ESM::GameSetting *setting = environment.mWorld->getStore().gameSettings.search(id); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index ebe115d30..293bac601 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -250,6 +250,9 @@ namespace MWGui void messageBox (const std::string& message, const std::vector& buttons); + int readPressedButton (); + ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) + void onFrame (float frameDuration); /**