From b72e9d3b2bac35a73ecb6d8c5684114d9ebd2733 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 16 Jun 2011 13:02:49 +0200 Subject: [PATCH] non-interactive MessageBox is finished. Didn't find any bugs. --- apps/openmw/mwgui/messagebox.cpp | 41 ++++++++++++++++++++++++-------- apps/openmw/mwgui/messagebox.hpp | 1 + 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 6baf496a4..76b35eab3 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -12,33 +12,39 @@ MessageBoxManager::MessageBoxManager (WindowManager *windowManager) void MessageBoxManager::onFrame (float frameDuration) { std::vector::iterator it; - for(it = mTimers.begin(); it != mTimers.end(); it++) + for(it = mTimers.begin(); it != mTimers.end();) { it->current += frameDuration; if(it->current >= it->max) { - // FIXME: delete the messagebox and erase it from the vector + removeMessageBox(it->messageBox); + it = mTimers.erase(it); + } + else + { + it++; } } } void MessageBoxManager::createMessageBox (const std::string& message) { - std::cout << "create non-interactive message box" << std::endl; + std::cout << "MessageBox: " << message << std::endl; + MessageBox *box = new MessageBox(*this, message); removeMessageBox(message.length()*mMessageBoxSpeed, box); mMessageBoxes.insert(mMessageBoxes.begin(), box); int height = box->getHeight(); - std::vector::const_iterator it; + std::vector::iterator it; int i = 0; for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it) { if(i == 2) { delete (*it); - // FIXME: erase it from the vector without segfault :/ + mMessageBoxes.erase(it); break; } else { @@ -47,19 +53,19 @@ 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) { - std::cout << "create interactive message box" << std::endl; + std::cout << "interactive MessageBox: " << message << " - "; std::copy (buttons.begin(), buttons.end(), std::ostream_iterator (std::cout, ", ")); + std::cout << std::endl; - // FIXME: erase it from the vector without segfault :/ - std::vector::const_iterator it; - for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); it++) + std::vector::iterator it = mMessageBoxes.begin(); + while(it != mMessageBoxes.end()) { delete (*it); + it = mMessageBoxes.erase(it); } mMessageBoxes.clear(); } @@ -74,6 +80,21 @@ void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox) mTimers.insert(mTimers.end(), timer); } +bool MessageBoxManager::removeMessageBox (MessageBox *msgbox) +{ + std::vector::iterator it; + for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it) + { + if((*it) == msgbox) + { + delete (*it); + mMessageBoxes.erase(it); + return true; + } + } + return false; +} + void MessageBoxManager::setMessageBoxSpeed (int speed) { mMessageBoxSpeed = speed; diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 94a4407be..37c4db77a 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -29,6 +29,7 @@ namespace MWGui void createInteractiveMessageBox (const std::string& message, const std::vector& buttons); void removeMessageBox (float time, MessageBox *msgbox); + bool removeMessageBox (MessageBox *msgbox); void setMessageBoxSpeed (int speed); WindowManager *mWindowManager;