From e77240dceb116438b9875cf9ac533960f8b444b0 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 18 Jun 2011 15:50:41 +0200 Subject: [PATCH 1/8] basics for InteractiveMessageBox --- apps/openmw/mwgui/messagebox.cpp | 19 +++++++++++++++++++ apps/openmw/mwgui/messagebox.hpp | 13 +++++++++++++ extern/mygui_3.0.1/CMakeLists.txt | 1 + .../openmw_interactive_messagebox_layout.xml | 19 +++++++++++++++++++ .../openmw_messagebox_layout.xml | 2 ++ 5 files changed, 54 insertions(+) create mode 100644 extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 28aae874f..1527bde4c 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -78,6 +78,10 @@ void MessageBoxManager::createInteractiveMessageBox (const std::string& message, std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); std::cout << std::endl; + InteractiveMessageBox *box = new InteractiveMessageBox(*this, message, buttons); + mInterMessageBoxes.push_back(box); + + // delete all non-interactive MessageBox'es std::vector::iterator it = mMessageBoxes.begin(); while(it != mMessageBoxes.end()) { @@ -174,3 +178,18 @@ int MessageBox::getHeight () { return mHeight+mNextBoxPadding; // 20 is the padding between this and the next MessageBox } + + + +InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons) + : Layout("openmw_interactive_messagebox_layout.xml") + , mMessageBoxManager(parMessageBoxManager) +{ + getWidget(mMessageWidget, "message"); + getWidget(mButtonsWidget, "buttons"); + + mMessageWidget->setOverflowToTheLeft(true); + mMessageWidget->addText(message); +} + + diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index fe58a31c8..e394b4c26 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -11,6 +11,7 @@ namespace MWGui { + class InteractiveMessageBox; class MessageBoxManager; class MessageBox; @@ -36,6 +37,7 @@ namespace MWGui private: std::vector mMessageBoxes; + std::vector mInterMessageBoxes; std::vector mTimers; float mMessageBoxSpeed; }; @@ -59,6 +61,17 @@ namespace MWGui int mBottomPadding; int mNextBoxPadding; }; + + class InteractiveMessageBox : public OEngine::GUI::Layout + { + public: + InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons); + + protected: + MessageBoxManager& mMessageBoxManager; + MyGUI::EditPtr mMessageWidget; + MyGUI::WidgetPtr mButtonsWidget; + }; } diff --git a/extern/mygui_3.0.1/CMakeLists.txt b/extern/mygui_3.0.1/CMakeLists.txt index 36467733d..566fea773 100644 --- a/extern/mygui_3.0.1/CMakeLists.txt +++ b/extern/mygui_3.0.1/CMakeLists.txt @@ -69,6 +69,7 @@ configure_file("${SDIR}/openmw_stats_window_layout.xml" "${DDIR}/openmw_stats_wi configure_file("${SDIR}/openmw_text.skin.xml" "${DDIR}/openmw_text.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_windows.skin.xml" "${DDIR}/openmw_windows.skin.xml" COPYONLY) configure_file("${SDIR}/openmw_messagebox_layout.xml" "${DDIR}/openmw_messagebox_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_interactive_messagebox_layout.xml" "${DDIR}/openmw_interactive_messagebox_layout.xml" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) configure_file("${SDIR}/VeraMono.ttf" "${DDIR}/VeraMono.ttf" COPYONLY) diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml new file mode 100644 index 000000000..4db91341e --- /dev/null +++ b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_messagebox_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_messagebox_layout.xml index fb4235ff1..890752db3 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_messagebox_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_messagebox_layout.xml @@ -12,6 +12,8 @@ + + From 5db8e8c449428371b5097a271daadccac5310835 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 19 Jun 2011 19:10:44 +0200 Subject: [PATCH 2/8] InterMessageBox game mode --- apps/openmw/mwgui/messagebox.cpp | 55 ++++++++++++++----- apps/openmw/mwgui/messagebox.hpp | 12 ++-- apps/openmw/mwgui/mode.hpp | 5 +- apps/openmw/mwgui/window_manager.cpp | 19 ++++--- .../openmw_interactive_messagebox_layout.xml | 8 +-- 5 files changed, 68 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 1527bde4c..c4334250d 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -2,11 +2,13 @@ using namespace MWGui; -MessageBoxManager::MessageBoxManager (WindowManager *windowManager) +MessageBoxManager::MessageBoxManager (WindowManager *windowManager, MyGUI::Gui *_gui) { mWindowManager = windowManager; + gui = _gui; // defines mMessageBoxSpeed = 0.1; + mInterMessageBoxe = NULL; } void MessageBoxManager::onFrame (float frameDuration) @@ -72,23 +74,24 @@ void MessageBoxManager::createMessageBox (const std::string& message) } } -void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) +bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) { + if(mInterMessageBoxe != NULL) { + std::cout << "there is a MessageBox already" << std::endl; + return false; + } std::cout << "interactive MessageBox: " << message << " - "; std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); std::cout << std::endl; - InteractiveMessageBox *box = new InteractiveMessageBox(*this, message, buttons); - mInterMessageBoxes.push_back(box); + mInterMessageBoxe = new InteractiveMessageBox(*this, gui, message, buttons); - // delete all non-interactive MessageBox'es - std::vector::iterator it = mMessageBoxes.begin(); - while(it != mMessageBoxes.end()) - { - delete (*it); - it = mMessageBoxes.erase(it); - } - mMessageBoxes.clear(); + return true; +} + +bool MessageBoxManager::isInteractiveMessageBox () +{ + return mInterMessageBoxe != NULL; } void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox) @@ -181,15 +184,41 @@ int MessageBox::getHeight () -InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons) +InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector& buttons) : Layout("openmw_interactive_messagebox_layout.xml") , mMessageBoxManager(parMessageBoxManager) + , mGUI(_gui) { getWidget(mMessageWidget, "message"); getWidget(mButtonsWidget, "buttons"); mMessageWidget->setOverflowToTheLeft(true); mMessageWidget->addText(message); + + MyGUI::IntSize textSize = mMessageWidget->_getTextSize(); + std::cout << "textSize.width " << textSize.width << " textSize.height " << textSize.height << std::endl; + + MyGUI::IntSize size; + size.width = 500; // 500 is fixed width + size.height = textSize.height + 100; // 100 is mButtonWidget high + + mMainWidget->setSize(size); + size.width = 480; // fixed width (500) - 2*padding (10) + size.height = textSize.height; + mMessageWidget->setSize(size); + + std::vector::const_iterator it; + for(it = buttons.begin(); it != buttons.end(); ++it) + { + std::cout << "add button " << *it << std::endl; + MyGUI::ButtonPtr button = mGUI->createWidget("button1", 10, textSize.height, 480, 100, MyGUI::Align::Default, "buttons"); + button->setCaption(*it); + //mButtons.push_back(button); + } + } + + + diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index e394b4c26..5e31cb346 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -24,10 +24,11 @@ namespace MWGui class MessageBoxManager { public: - MessageBoxManager (WindowManager* windowManager); + MessageBoxManager (WindowManager* windowManager, MyGUI::Gui *_gui); void onFrame (float frameDuration); void createMessageBox (const std::string& message); - void createInteractiveMessageBox (const std::string& message, const std::vector& buttons); + bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons); + bool isInteractiveMessageBox (); void removeMessageBox (float time, MessageBox *msgbox); bool removeMessageBox (MessageBox *msgbox); @@ -37,8 +38,9 @@ namespace MWGui private: std::vector mMessageBoxes; - std::vector mInterMessageBoxes; + InteractiveMessageBox* mInterMessageBoxe; std::vector mTimers; + MyGUI::Gui *gui; float mMessageBoxSpeed; }; @@ -65,12 +67,14 @@ namespace MWGui class InteractiveMessageBox : public OEngine::GUI::Layout { public: - InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons); + InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector& buttons); protected: MessageBoxManager& mMessageBoxManager; MyGUI::EditPtr mMessageWidget; MyGUI::WidgetPtr mButtonsWidget; + MyGUI::Gui *mGUI; + //std::vector mButtons; }; } diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 313b097cf..b0dc14029 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -26,7 +26,10 @@ namespace MWGui GM_ClassGenerate, GM_ClassPick, GM_ClassCreate, - GM_Review + GM_Review, + + // interactive MessageBox + GM_InterMessageBox }; // Windows shown in inventory mode diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 8e9a14837..55d0c93cf 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -61,7 +61,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment inventory = new InventoryWindow (); #endif console = new Console(w,h, environment, extensions); - mMessageBoxManager = new MessageBoxManager(this); + mMessageBoxManager = new MessageBoxManager(this, (MyGUI::Gui*)gui); // The HUD is always on hud->setVisible(true); @@ -329,6 +329,14 @@ void WindowManager::updateVisible() dialogueWindow->open(); return; } + + if(mode == GM_InterMessageBox) + { + if(!mMessageBoxManager->isInteractiveMessageBox()) { + setGuiMode(GM_Game); + } + return; + } // Unsupported mode, switch back to game @@ -449,14 +457,6 @@ void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) void WindowManager::messageBox (const std::string& message, const std::vector& buttons) { - /*std::cout << "message box: " << message << std::endl; - - if (!buttons.empty()) - { - std::cout << "buttons: "; - std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); - std::cout << std::endl; - }*/ if (buttons.empty()) { mMessageBoxManager->createMessageBox(message); @@ -464,6 +464,7 @@ void WindowManager::messageBox (const std::string& message, const std::vectorcreateInteractiveMessageBox(message, buttons); + setGuiMode(GM_InterMessageBox); } } diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml index 4db91341e..bba5d631c 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml @@ -1,8 +1,8 @@ - - + + @@ -12,8 +12,8 @@ - - + + From 23194a932f1eca63f080e6ef3bf663f961fa5cc2 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 19 Jun 2011 19:41:42 +0200 Subject: [PATCH 3/8] creating the buttons on the fly --- apps/openmw/mwgui/messagebox.cpp | 20 ++++++++++++------- apps/openmw/mwgui/messagebox.hpp | 12 +++++------ apps/openmw/mwgui/window_manager.cpp | 2 +- .../openmw_interactive_messagebox_layout.xml | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index c4334250d..17de1f504 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -2,10 +2,9 @@ using namespace MWGui; -MessageBoxManager::MessageBoxManager (WindowManager *windowManager, MyGUI::Gui *_gui) +MessageBoxManager::MessageBoxManager (WindowManager *windowManager) { mWindowManager = windowManager; - gui = _gui; // defines mMessageBoxSpeed = 0.1; mInterMessageBoxe = NULL; @@ -84,7 +83,7 @@ bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); std::cout << std::endl; - mInterMessageBoxe = new InteractiveMessageBox(*this, gui, message, buttons); + mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons); return true; } @@ -184,11 +183,12 @@ int MessageBox::getHeight () -InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector& buttons) +InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons) : Layout("openmw_interactive_messagebox_layout.xml") , mMessageBoxManager(parMessageBoxManager) - , mGUI(_gui) { + mTextButtonPadding = 10; + getWidget(mMessageWidget, "message"); getWidget(mButtonsWidget, "buttons"); @@ -207,13 +207,19 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan size.height = textSize.height; mMessageWidget->setSize(size); + MyGUI::IntCoord coord(10, textSize.height+mTextButtonPadding, 100, 50); + std::vector::const_iterator it; for(it = buttons.begin(); it != buttons.end(); ++it) { std::cout << "add button " << *it << std::endl; - MyGUI::ButtonPtr button = mGUI->createWidget("button1", 10, textSize.height, 480, 100, MyGUI::Align::Default, "buttons"); + MyGUI::ButtonPtr button = mButtonsWidget->createWidget( + MyGUI::WidgetStyle::Child, + std::string("MW_Button"), + coord, + MyGUI::Align::Default); button->setCaption(*it); - //mButtons.push_back(button); + mButtons.push_back(button); } } diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 5e31cb346..f7c7197fa 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -24,7 +24,7 @@ namespace MWGui class MessageBoxManager { public: - MessageBoxManager (WindowManager* windowManager, MyGUI::Gui *_gui); + MessageBoxManager (WindowManager* windowManager); void onFrame (float frameDuration); void createMessageBox (const std::string& message); bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons); @@ -40,7 +40,6 @@ namespace MWGui std::vector mMessageBoxes; InteractiveMessageBox* mInterMessageBoxe; std::vector mTimers; - MyGUI::Gui *gui; float mMessageBoxSpeed; }; @@ -67,14 +66,15 @@ namespace MWGui class InteractiveMessageBox : public OEngine::GUI::Layout { public: - InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector& buttons); + InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector& buttons); - protected: + private: MessageBoxManager& mMessageBoxManager; MyGUI::EditPtr mMessageWidget; MyGUI::WidgetPtr mButtonsWidget; - MyGUI::Gui *mGUI; - //std::vector mButtons; + std::vector mButtons; + + int mTextButtonPadding; }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 55d0c93cf..b5a6e36a6 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -61,7 +61,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment inventory = new InventoryWindow (); #endif console = new Console(w,h, environment, extensions); - mMessageBoxManager = new MessageBoxManager(this, (MyGUI::Gui*)gui); + mMessageBoxManager = new MessageBoxManager(this); // The HUD is always on hud->setVisible(true); diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml index bba5d631c..40c0787b8 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_interactive_messagebox_layout.xml @@ -13,7 +13,7 @@ - + From 9c2bb76869c01d60566d55e67594683b654262ef Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 19 Jun 2011 22:56:51 +0200 Subject: [PATCH 4/8] disigned the interactive messagebox. Have to center it and add button events --- apps/openmw/mwgui/messagebox.cpp | 98 +++++++++++++++++++++++++++----- apps/openmw/mwgui/messagebox.hpp | 2 - 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 17de1f504..61a359e7e 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -187,7 +187,13 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan : Layout("openmw_interactive_messagebox_layout.xml") , mMessageBoxManager(parMessageBoxManager) { - mTextButtonPadding = 10; + 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 + int buttonLeftPadding = 10; // padding between the buttons if horizontal + int buttonTopPadding = 5; // ^-- if vertical + int buttonPadding = 5; // padding between button label and button itself + getWidget(mMessageWidget, "message"); getWidget(mButtonsWidget, "buttons"); @@ -196,32 +202,98 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan mMessageWidget->addText(message); MyGUI::IntSize textSize = mMessageWidget->_getTextSize(); - std::cout << "textSize.width " << textSize.width << " textSize.height " << textSize.height << std::endl; - - MyGUI::IntSize size; - size.width = 500; // 500 is fixed width - size.height = textSize.height + 100; // 100 is mButtonWidget high - mMainWidget->setSize(size); - size.width = 480; // fixed width (500) - 2*padding (10) - size.height = textSize.height; - mMessageWidget->setSize(size); - MyGUI::IntCoord coord(10, textSize.height+mTextButtonPadding, 100, 50); + int buttonsWidth = 0; + int buttonHeight = 0; + MyGUI::IntCoord dummyCoord(0, 0, 0, 0); std::vector::const_iterator it; for(it = buttons.begin(); it != buttons.end(); ++it) { - std::cout << "add button " << *it << std::endl; MyGUI::ButtonPtr button = mButtonsWidget->createWidget( MyGUI::WidgetStyle::Child, std::string("MW_Button"), - coord, + dummyCoord, MyGUI::Align::Default); button->setCaption(*it); + mButtons.push_back(button); + + buttonsWidth += button->_getTextSize().width + 2*buttonPadding + 2*buttonLeftPadding; + buttonHeight = button->_getTextSize().height + 2*buttonPadding + 2*buttonTopPadding; } + MyGUI::IntSize mainWidgetSize; + if(buttonsWidth < fixedWidth) + { + // on one line + + int left; + if(textSize.width + 2*textPadding < buttonsWidth) + { + mainWidgetSize.width = buttonsWidth; + left = buttonLeftPadding; + } + else + { + mainWidgetSize.width = textSize.width + 2*textPadding; + left = (textSize.width - buttonsWidth)/2; + } + mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight; + mMainWidget->setSize(mainWidgetSize); + + mMessageWidget->setSize(textSize); + + MyGUI::IntCoord buttonCord; + MyGUI::IntSize buttonSize(0, buttonHeight); + + std::vector::const_iterator button; + for(button = mButtons.begin(); button != mButtons.end(); ++button) + { + buttonCord.left = left; + buttonCord.top = textSize.height + textButtonPadding; + + buttonSize.width = (*button)->_getTextSize().width + buttonPadding*2; + buttonSize.height = (*button)->_getTextSize().height + buttonPadding*2; + + (*button)->setCoord(buttonCord); + (*button)->setSize(buttonSize); + + left += buttonSize.width + 2*buttonLeftPadding; + } + } + else + { + // among each other + + mainWidgetSize.width = textSize.width + 2*textPadding; + mainWidgetSize.height = textSize.height + 2*textPadding + textButtonPadding + buttonHeight * buttons.size(); + mMainWidget->setSize(mainWidgetSize); + + mMessageWidget->setSize(textSize); + + MyGUI::IntCoord buttonCord; + MyGUI::IntSize buttonSize(0, buttonHeight); + + int top = textButtonPadding + buttonTopPadding + textSize.height; + + std::vector::const_iterator button; + for(button = mButtons.begin(); button != mButtons.end(); ++button) + { + buttonCord.top = top; + buttonCord.left = (textSize.width - (*button)->_getTextSize().width)/2; + + buttonSize.width = (*button)->_getTextSize().width + buttonPadding*2; + buttonSize.height = (*button)->_getTextSize().height + buttonPadding*2; + + (*button)->setCoord(buttonCord); + (*button)->setSize(buttonSize); + + top += buttonSize.height + 2*buttonTopPadding; + } + + } } diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index f7c7197fa..b8c205823 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -73,8 +73,6 @@ namespace MWGui MyGUI::EditPtr mMessageWidget; MyGUI::WidgetPtr mButtonsWidget; std::vector mButtons; - - int mTextButtonPadding; }; } From 537b2bf9636a3c8581701f85c7538bdda46722f7 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 17:57:16 +0200 Subject: [PATCH 5/8] set position on interactive MessageBox'es --- apps/openmw/mwgui/messagebox.cpp | 36 +++++++++++++++++++++----------- apps/openmw/mwgui/messagebox.hpp | 2 ++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 61a359e7e..9c0196147 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -193,6 +193,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan int buttonLeftPadding = 10; // padding between the buttons if horizontal int buttonTopPadding = 5; // ^-- if vertical int buttonPadding = 5; // padding between button label and button itself + int buttonMainPadding = 10; // padding between buttons and bottom of the main widget getWidget(mMessageWidget, "message"); @@ -203,6 +204,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan MyGUI::IntSize textSize = mMessageWidget->_getTextSize(); + MyGUI::IntSize gameWindowSize = mMessageBoxManager.mWindowManager->getGui()->getViewSize(); int buttonsWidth = 0; int buttonHeight = 0; @@ -220,33 +222,43 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan mButtons.push_back(button); - buttonsWidth += button->_getTextSize().width + 2*buttonPadding + 2*buttonLeftPadding; - buttonHeight = button->_getTextSize().height + 2*buttonPadding + 2*buttonTopPadding; + buttonsWidth += button->_getTextSize().width + 2*buttonPadding + buttonLeftPadding; + buttonHeight = button->_getTextSize().height + 2*buttonPadding + buttonTopPadding; } + buttonsWidth += buttonLeftPadding; MyGUI::IntSize mainWidgetSize; if(buttonsWidth < fixedWidth) { // on one line - - int left; + std::cout << "on one line" << std::endl; + if(textSize.width + 2*textPadding < buttonsWidth) { + std::cout << "width = buttonsWidth" << std::endl; mainWidgetSize.width = buttonsWidth; - left = buttonLeftPadding; } else { - mainWidgetSize.width = textSize.width + 2*textPadding; - left = (textSize.width - buttonsWidth)/2; + mainWidgetSize.width = textSize.width + 3*textPadding; } - mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight; + mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight + buttonMainPadding; + + MyGUI::IntCoord absCoord; + absCoord.left = (gameWindowSize.width - mainWidgetSize.width)/2; + absCoord.top = (gameWindowSize.height - mainWidgetSize.height)/2; + + std::cout << "width " << mainWidgetSize.width << " height " << mainWidgetSize.height << std::endl; + std::cout << "left " << absCoord.left << " top " << absCoord.top << std::endl; + + mMainWidget->setCoord(absCoord); mMainWidget->setSize(mainWidgetSize); - + mMessageWidget->setSize(textSize); MyGUI::IntCoord buttonCord; MyGUI::IntSize buttonSize(0, buttonHeight); + int left = (mainWidgetSize.width - buttonsWidth)/2 + buttonPadding; std::vector::const_iterator button; for(button = mButtons.begin(); button != mButtons.end(); ++button) @@ -254,13 +266,13 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan buttonCord.left = left; buttonCord.top = textSize.height + textButtonPadding; - buttonSize.width = (*button)->_getTextSize().width + buttonPadding*2; - buttonSize.height = (*button)->_getTextSize().height + buttonPadding*2; + buttonSize.width = (*button)->_getTextSize().width + 2*buttonPadding; + buttonSize.height = (*button)->_getTextSize().height + 2*buttonPadding; (*button)->setCoord(buttonCord); (*button)->setSize(buttonSize); - left += buttonSize.width + 2*buttonLeftPadding; + left += buttonSize.width + buttonLeftPadding; } } else diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index b8c205823..f7c7197fa 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -73,6 +73,8 @@ namespace MWGui MyGUI::EditPtr mMessageWidget; MyGUI::WidgetPtr mButtonsWidget; std::vector mButtons; + + int mTextButtonPadding; }; } From 0fc77dc1c3eb1b18e5c6a1ac869b77778bed2bd7 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 18:05:46 +0200 Subject: [PATCH 6/8] everything looks good if buttons are on one line --- apps/openmw/mwgui/messagebox.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 9c0196147..62e079657 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -254,6 +254,12 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan mMainWidget->setCoord(absCoord); mMainWidget->setSize(mainWidgetSize); + + MyGUI::IntCoord messageWidgetCoord; + messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2; + messageWidgetCoord.top = textPadding; + mMessageWidget->setCoord(messageWidgetCoord); + mMessageWidget->setSize(textSize); MyGUI::IntCoord buttonCord; From 16ed02baebfcae30b8e4fbbbd926bc4f4826db3a Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 19:17:07 +0200 Subject: [PATCH 7/8] all MessageBoxes look good; next: make them do something ;) --- apps/openmw/mwgui/messagebox.cpp | 41 +++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 62e079657..2a1cb6a21 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -206,6 +206,8 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan MyGUI::IntSize gameWindowSize = mMessageBoxManager.mWindowManager->getGui()->getViewSize(); + int biggestButtonWidth = 0; + int buttonWidth = 0; int buttonsWidth = 0; int buttonHeight = 0; MyGUI::IntCoord dummyCoord(0, 0, 0, 0); @@ -222,8 +224,14 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan mButtons.push_back(button); - buttonsWidth += button->_getTextSize().width + 2*buttonPadding + buttonLeftPadding; + buttonWidth = button->_getTextSize().width + 2*buttonPadding + buttonLeftPadding; + buttonsWidth += buttonWidth; buttonHeight = button->_getTextSize().height + 2*buttonPadding + buttonTopPadding; + + if(buttonWidth > biggestButtonWidth) + { + biggestButtonWidth = buttonWidth; + } } buttonsWidth += buttonLeftPadding; @@ -285,10 +293,31 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan { // among each other - mainWidgetSize.width = textSize.width + 2*textPadding; - mainWidgetSize.height = textSize.height + 2*textPadding + textButtonPadding + buttonHeight * buttons.size(); + if(biggestButtonWidth > textSize.width) { + mainWidgetSize.width = biggestButtonWidth + buttonTopPadding; + } + else { + mainWidgetSize.width = textSize.width + 3*textPadding; + } + mainWidgetSize.height = textSize.height + 2*textPadding + textButtonPadding + buttonHeight * buttons.size() + buttonMainPadding; + + std::cout << "biggestButtonWidth " << biggestButtonWidth << " textSize.width " << textSize.width << std::endl; + std::cout << "width " << mainWidgetSize.width << " height " << mainWidgetSize.height << std::endl; mMainWidget->setSize(mainWidgetSize); + MyGUI::IntCoord absCoord; + absCoord.left = (gameWindowSize.width - mainWidgetSize.width)/2; + absCoord.top = (gameWindowSize.height - mainWidgetSize.height)/2; + + mMainWidget->setCoord(absCoord); + mMainWidget->setSize(mainWidgetSize); + + + MyGUI::IntCoord messageWidgetCoord; + messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2; + messageWidgetCoord.top = textPadding; + mMessageWidget->setCoord(messageWidgetCoord); + mMessageWidget->setSize(textSize); MyGUI::IntCoord buttonCord; @@ -299,12 +328,12 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan std::vector::const_iterator button; for(button = mButtons.begin(); button != mButtons.end(); ++button) { - buttonCord.top = top; - buttonCord.left = (textSize.width - (*button)->_getTextSize().width)/2; - buttonSize.width = (*button)->_getTextSize().width + buttonPadding*2; buttonSize.height = (*button)->_getTextSize().height + buttonPadding*2; + buttonCord.top = top; + buttonCord.left = (mainWidgetSize.width - buttonSize.width)/2 - 5; // FIXME: -5 is not so nice :/ + (*button)->setCoord(buttonCord); (*button)->setSize(buttonSize); From 317c920e03eb9609196069cd0afffd827eedb750 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 20:05:04 +0200 Subject: [PATCH 8/8] 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); /**