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 @@ - - + +