1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-12 21:39:26 +00:00
OpenMW/apps/openmw/mwgui/messagebox.hpp
Emanuel Guevel ba4b8a37e2 Remember pressed message box button longer
Remember which button was pressed until a new interactive message box is
displayed or until the pressed button number is read.

Before that, it was not possible to get the pressed button after the
message box was hidden/destroyed.
2013-10-14 12:55:06 +02:00

107 lines
3.0 KiB
C++

#ifndef MWGUI_MESSAGE_BOX_H
#define MWGUI_MESSAGE_BOX_H
#include "windowbase.hpp"
#include "../mwbase/windowmanager.hpp"
#undef MessageBox
namespace MyGUI
{
class Widget;
class Button;
class EditBox;
}
namespace MWGui
{
class InteractiveMessageBox;
class MessageBoxManager;
class MessageBox;
struct MessageBoxManagerTimer {
float current;
float max;
MessageBox *messageBox;
};
class MessageBoxManager
{
public:
MessageBoxManager ();
void onFrame (float frameDuration);
void createMessageBox (const std::string& message, bool stat = false);
void removeStaticMessageBox ();
bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
bool isInteractiveMessageBox ();
void removeMessageBox (float time, MessageBox *msgbox);
bool removeMessageBox (MessageBox *msgbox);
void setMessageBoxSpeed (int speed);
void okayPressed();
int readPressedButton ();
typedef MyGUI::delegates::CMultiDelegate1<int> EventHandle_Int;
// Note: this delegate unassigns itself after it was fired, i.e. works once.
EventHandle_Int eventButtonPressed;
void onButtonPressed(int button) { eventButtonPressed(button); eventButtonPressed.clear(); }
private:
std::vector<MessageBox*> mMessageBoxes;
InteractiveMessageBox* mInterMessageBoxe;
MessageBox* mStaticMessageBox;
std::vector<MessageBoxManagerTimer> mTimers;
float mMessageBoxSpeed;
int mLastButtonPressed;
};
class MessageBox : public OEngine::GUI::Layout
{
public:
MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message);
void setMessage (const std::string& message);
int getHeight ();
void update (int height);
bool mMarkedToDelete;
protected:
MessageBoxManager& mMessageBoxManager;
int mHeight;
const std::string& mMessage;
MyGUI::EditBox* mMessageWidget;
int mFixedWidth;
int mBottomPadding;
int mNextBoxPadding;
};
class InteractiveMessageBox : public WindowModal
{
public:
InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons);
void okayPressed ();
void mousePressed (MyGUI::Widget* _widget);
int readPressedButton ();
bool mMarkedToDelete;
private:
void buttonActivated (MyGUI::Widget* _widget);
MessageBoxManager& mMessageBoxManager;
MyGUI::EditBox* mMessageWidget;
MyGUI::Widget* mButtonsWidget;
std::vector<MyGUI::Button*> mButtons;
int mTextButtonPadding;
int mButtonPressed;
};
}
#endif