mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:53:52 +00:00
Everything should work fine but deleting the existing MessageBox'es.
This commit is contained in:
parent
94e010b790
commit
a4217f8fb8
5 changed files with 68 additions and 5 deletions
|
@ -153,6 +153,9 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
|
||||||
{
|
{
|
||||||
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
||||||
|
|
||||||
|
//
|
||||||
|
mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration);
|
||||||
|
|
||||||
// global scripts
|
// global scripts
|
||||||
mEnvironment.mGlobalScripts->run (mEnvironment);
|
mEnvironment.mGlobalScripts->run (mEnvironment);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,22 @@ using namespace MWGui;
|
||||||
MessageBoxManager::MessageBoxManager (WindowManager *windowManager)
|
MessageBoxManager::MessageBoxManager (WindowManager *windowManager)
|
||||||
{
|
{
|
||||||
mWindowManager = 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)
|
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;
|
std::cout << "create non-interactive message box" << std::endl;
|
||||||
MessageBox *box = new MessageBox(*this, message);
|
MessageBox *box = new MessageBox(*this, message);
|
||||||
|
|
||||||
// create a timer and delete when ready.
|
removeMessageBox(message.length()*mMessageBoxSpeed, box);
|
||||||
|
|
||||||
mMessageBoxes.insert(mMessageBoxes.begin(), box);
|
mMessageBoxes.insert(mMessageBoxes.begin(), box);
|
||||||
int height = box->getHeight();
|
int height = box->getHeight();
|
||||||
std::vector<MessageBox*>::const_iterator it;
|
std::vector<MessageBox*>::const_iterator it;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it) {
|
for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it)
|
||||||
|
{
|
||||||
if(i == 2) {
|
if(i == 2) {
|
||||||
delete (*it);
|
delete (*it);
|
||||||
|
// FIXME: erase it from the vector without segfault :/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -30,6 +48,7 @@ void MessageBoxManager::createMessageBox (const std::string& message)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "mMessageBoxes.size() is " << mMessageBoxes.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
|
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::cout << "create interactive message box" << std::endl;
|
||||||
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
|
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;
|
std::vector<MessageBox*>::const_iterator it;
|
||||||
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); it++) {
|
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); it++)
|
||||||
|
{
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
mMessageBoxes.clear();
|
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)
|
MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message)
|
||||||
: Layout("openmw_messagebox_layout.xml")
|
: Layout("openmw_messagebox_layout.xml")
|
||||||
, mMessageBoxManager(parMessageBoxManager)
|
, mMessageBoxManager(parMessageBoxManager)
|
||||||
, cMessage(message)
|
, cMessage(message)
|
||||||
{
|
{
|
||||||
|
// defines
|
||||||
mFixedWidth = 300;
|
mFixedWidth = 300;
|
||||||
mBottomPadding = 20;
|
mBottomPadding = 20;
|
||||||
mNextBoxPadding = 20;
|
mNextBoxPadding = 20;
|
||||||
|
|
|
@ -3,27 +3,41 @@
|
||||||
|
|
||||||
#include <openengine/gui/layout.hpp>
|
#include <openengine/gui/layout.hpp>
|
||||||
#include <MyGUI.h>
|
#include <MyGUI.h>
|
||||||
|
#include <OgreTimer.h>
|
||||||
|
|
||||||
#include "window_base.hpp"
|
#include "window_base.hpp"
|
||||||
#include "window_manager.hpp"
|
#include "window_manager.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
|
||||||
class MessageBoxManager;
|
class MessageBoxManager;
|
||||||
class MessageBox;
|
class MessageBox;
|
||||||
|
|
||||||
|
struct MessageBoxManagerTimer {
|
||||||
|
float current;
|
||||||
|
float max;
|
||||||
|
MessageBox *messageBox;
|
||||||
|
};
|
||||||
|
|
||||||
class MessageBoxManager
|
class MessageBoxManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageBoxManager (WindowManager* windowManager);
|
MessageBoxManager (WindowManager* windowManager);
|
||||||
|
void onFrame (float frameDuration);
|
||||||
void createMessageBox (const std::string& message);
|
void createMessageBox (const std::string& message);
|
||||||
void createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
|
void createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
|
||||||
|
|
||||||
|
void removeMessageBox (float time, MessageBox *msgbox);
|
||||||
|
void setMessageBoxSpeed (int speed);
|
||||||
|
|
||||||
WindowManager *mWindowManager;
|
WindowManager *mWindowManager;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<MessageBox*> mMessageBoxes;
|
std::vector<MessageBox*> mMessageBoxes;
|
||||||
|
std::vector<MessageBoxManagerTimer*> mTimers;
|
||||||
|
float mMessageBoxSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageBox : public OEngine::GUI::Layout
|
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
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -250,6 +250,8 @@ namespace MWGui
|
||||||
|
|
||||||
void messageBox (const std::string& message, const std::vector<std::string>& buttons);
|
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
|
* Fetches a GMST string from the store, if there is no setting with the given
|
||||||
* ID or it is not a string the default string is returned.
|
* ID or it is not a string the default string is returned.
|
||||||
|
|
Loading…
Reference in a new issue