From a4217f8fb809f6f9c7efc11534a29ebd62f3934c Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 15 Jun 2011 22:53:05 +0200 Subject: [PATCH] Everything should work fine but deleting the existing MessageBox'es. --- apps/openmw/engine.cpp | 3 ++ apps/openmw/mwgui/messagebox.cpp | 47 +++++++++++++++++++++++++--- apps/openmw/mwgui/messagebox.hpp | 16 +++++++++- apps/openmw/mwgui/window_manager.cpp | 5 +++ apps/openmw/mwgui/window_manager.hpp | 2 ++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index b2ed0a767..1aa442c15 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -152,6 +152,9 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) try { mEnvironment.mFrameDuration = evt.timeSinceLastFrame; + + // + mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); // global scripts mEnvironment.mGlobalScripts->run (mEnvironment); diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 92d79d05f..43de3ff0d 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -5,6 +5,22 @@ using namespace MWGui; MessageBoxManager::MessageBoxManager (WindowManager *windowManager) { mWindowManager = windowManager; + // defines + mMessageBoxSpeed = 0.1; +} + +void MessageBoxManager::onFrame (float frameDuration) +{ + std::vector::const_iterator it; + for(it = mTimers.begin(); it != mTimers.end(); it++) + { + (*it)->current += frameDuration; + if((*it)->current >= (*it)->max) + { + // FIXME: delete the messagebox and erase it from the vector + std::cout << "delete MessageBox" << std::endl; + } + } } void MessageBoxManager::createMessageBox (const std::string& message) @@ -12,16 +28,18 @@ void MessageBoxManager::createMessageBox (const std::string& message) std::cout << "create non-interactive message box" << std::endl; MessageBox *box = new MessageBox(*this, message); - // create a timer and delete when ready. + removeMessageBox(message.length()*mMessageBoxSpeed, box); mMessageBoxes.insert(mMessageBoxes.begin(), box); int height = box->getHeight(); std::vector::const_iterator it; int i = 0; - for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it) { + for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it) + { if(i == 2) { delete (*it); + // FIXME: erase it from the vector without segfault :/ break; } else { @@ -30,6 +48,7 @@ void MessageBoxManager::createMessageBox (const std::string& message) i++; } } + std::cout << "mMessageBoxes.size() is " << mMessageBoxes.size() << std::endl; } void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) @@ -37,19 +56,39 @@ void MessageBoxManager::createInteractiveMessageBox (const std::string& message, std::cout << "create interactive message box" << std::endl; std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); - // delete all MessageBox'es + // FIXME: erase it from the vector without segfault :/ std::vector::const_iterator it; - for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); it++) { + for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); it++) + { delete (*it); } mMessageBoxes.clear(); } +void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox) +{ + MessageBoxManagerTimer *timer; + timer->current = 0; + timer->max = time; + timer->messageBox = msgbox; + + mTimers.insert(mTimers.end(), timer); +} + +void MessageBoxManager::setMessageBoxSpeed (int speed) +{ + mMessageBoxSpeed = speed; +} + + + + MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message) : Layout("openmw_messagebox_layout.xml") , mMessageBoxManager(parMessageBoxManager) , cMessage(message) { + // defines mFixedWidth = 300; mBottomPadding = 20; mNextBoxPadding = 20; diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 30e869a72..166a87011 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -3,27 +3,41 @@ #include #include +#include #include "window_base.hpp" #include "window_manager.hpp" + namespace MWGui { - + class MessageBoxManager; class MessageBox; + struct MessageBoxManagerTimer { + float current; + float max; + MessageBox *messageBox; + }; + class MessageBoxManager { public: MessageBoxManager (WindowManager* windowManager); + void onFrame (float frameDuration); void createMessageBox (const std::string& message); void createInteractiveMessageBox (const std::string& message, const std::vector& buttons); + void removeMessageBox (float time, MessageBox *msgbox); + void setMessageBoxSpeed (int speed); + WindowManager *mWindowManager; private: std::vector mMessageBoxes; + std::vector mTimers; + float mMessageBoxSpeed; }; class MessageBox : public OEngine::GUI::Layout diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 1c9217a92..8e9a14837 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -566,6 +566,11 @@ void WindowManager::onClassChoice(int _index) }; } +void WindowManager::onFrame (float frameDuration) +{ + mMessageBoxManager->onFrame(frameDuration); +} + namespace MWGui { diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 92f19cdc3..ebe115d30 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -249,6 +249,8 @@ namespace MWGui ///< Hides dialog and schedules dialog to be deleted. void messageBox (const std::string& message, const std::vector& buttons); + + void onFrame (float frameDuration); /** * Fetches a GMST string from the store, if there is no setting with the given