Everything should work fine but deleting the existing MessageBox'es.

actorid
Sebastian Wick 14 years ago
parent 94e010b790
commit a4217f8fb8

@ -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);

@ -5,6 +5,22 @@ using namespace MWGui;
MessageBoxManager::MessageBoxManager (WindowManager *windowManager)
{
mWindowManager = windowManager;
// defines
mMessageBoxSpeed = 0.1;
}
void MessageBoxManager::onFrame (float frameDuration)
{
std::vector<MessageBoxManagerTimer*>::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<MessageBox*>::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<std::string>& 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::string> (std::cout, ", "));
// delete all MessageBox'es
// FIXME: erase it from the vector without segfault :/
std::vector<MessageBox*>::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;

@ -3,27 +3,41 @@
#include <openengine/gui/layout.hpp>
#include <MyGUI.h>
#include <OgreTimer.h>
#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<std::string>& buttons);
void removeMessageBox (float time, MessageBox *msgbox);
void setMessageBoxSpeed (int speed);
WindowManager *mWindowManager;
private:
std::vector<MessageBox*> mMessageBoxes;
std::vector<MessageBoxManagerTimer*> mTimers;
float mMessageBoxSpeed;
};
class MessageBox : public OEngine::GUI::Layout

@ -566,6 +566,11 @@ void WindowManager::onClassChoice(int _index)
};
}
void WindowManager::onFrame (float frameDuration)
{
mMessageBoxManager->onFrame(frameDuration);
}
namespace MWGui
{

@ -249,6 +249,8 @@ namespace MWGui
///< Hides dialog and schedules dialog to be deleted.
void messageBox (const std::string& message, const std::vector<std::string>& buttons);
void onFrame (float frameDuration);
/**
* Fetches a GMST string from the store, if there is no setting with the given

Loading…
Cancel
Save