2011-06-14 16:41:30 +02:00
|
|
|
#ifndef MWGUI_MESSAGE_BOX_H
|
|
|
|
#define MWGUI_MESSAGE_BOX_H
|
|
|
|
|
2022-08-31 19:44:04 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2013-04-10 00:32:05 -04:00
|
|
|
#include "windowbase.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2013-03-03 13:11:02 +01:00
|
|
|
namespace MyGUI
|
|
|
|
{
|
|
|
|
class Widget;
|
|
|
|
class Button;
|
|
|
|
class EditBox;
|
|
|
|
}
|
|
|
|
|
2011-06-14 16:41:30 +02:00
|
|
|
namespace MWGui
|
|
|
|
{
|
2011-06-18 15:50:41 +02:00
|
|
|
class InteractiveMessageBox;
|
2011-06-14 18:29:55 +02:00
|
|
|
class MessageBoxManager;
|
|
|
|
class MessageBox;
|
2011-06-14 16:41:30 +02:00
|
|
|
class MessageBoxManager
|
|
|
|
{
|
|
|
|
public:
|
2014-01-10 22:27:31 +01:00
|
|
|
MessageBoxManager(float timePerChar);
|
2013-12-30 23:08:53 +01:00
|
|
|
~MessageBoxManager();
|
2011-06-15 22:53:05 +02:00
|
|
|
void onFrame(float frameDuration);
|
2022-08-23 22:14:27 +02:00
|
|
|
void createMessageBox(std::string_view message, bool stat = false);
|
2013-05-03 12:44:27 +02:00
|
|
|
void removeStaticMessageBox();
|
2023-11-18 17:57:15 +04:00
|
|
|
bool createInteractiveMessageBox(std::string_view message, const std::vector<std::string>& buttons,
|
|
|
|
bool immediate = false, int defaultFocus = -1);
|
2011-06-19 19:10:44 +02:00
|
|
|
bool isInteractiveMessageBox();
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2024-03-14 23:39:19 +00:00
|
|
|
std::size_t getMessagesCount();
|
2018-10-28 11:44:14 +04:00
|
|
|
|
2022-08-31 19:44:04 +02:00
|
|
|
const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe.get(); }
|
2018-01-14 00:27:53 +00:00
|
|
|
|
2014-06-14 21:52:54 +02:00
|
|
|
/// Remove all message boxes
|
|
|
|
void clear();
|
|
|
|
|
2011-06-16 13:02:49 +02:00
|
|
|
bool removeMessageBox(MessageBox* msgbox);
|
2013-04-10 00:32:05 -04:00
|
|
|
|
2015-01-10 23:58:55 +01:00
|
|
|
/// @param reset Reset the pressed button to -1 after reading it.
|
|
|
|
int readPressedButton(bool reset = true);
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2023-11-18 16:47:06 +04:00
|
|
|
void resetInteractiveMessageBox();
|
|
|
|
|
|
|
|
void setLastButtonPressed(int index);
|
|
|
|
|
2023-07-15 15:02:27 +02:00
|
|
|
typedef MyGUI::delegates::MultiDelegate<int> EventHandle_Int;
|
2013-03-30 15:51:07 +01:00
|
|
|
|
|
|
|
// Note: this delegate unassigns itself after it was fired, i.e. works once.
|
|
|
|
EventHandle_Int eventButtonPressed;
|
|
|
|
|
|
|
|
void onButtonPressed(int button)
|
|
|
|
{
|
|
|
|
eventButtonPressed(button);
|
|
|
|
eventButtonPressed.clear();
|
|
|
|
}
|
|
|
|
|
2021-05-25 21:04:05 +02:00
|
|
|
void setVisible(bool value);
|
|
|
|
|
2022-08-31 19:44:04 +02:00
|
|
|
const std::vector<std::unique_ptr<MessageBox>>& getActiveMessageBoxes() const;
|
2021-11-26 05:20:58 +08:00
|
|
|
|
2011-06-14 22:11:36 +02:00
|
|
|
private:
|
2022-08-31 19:44:04 +02:00
|
|
|
std::vector<std::unique_ptr<MessageBox>> mMessageBoxes;
|
|
|
|
std::unique_ptr<InteractiveMessageBox> mInterMessageBoxe;
|
2013-05-03 12:44:27 +02:00
|
|
|
MessageBox* mStaticMessageBox;
|
2011-06-15 22:53:05 +02:00
|
|
|
float mMessageBoxSpeed;
|
2013-10-14 11:15:23 +02:00
|
|
|
int mLastButtonPressed;
|
2021-05-25 21:04:05 +02:00
|
|
|
bool mVisible = true;
|
2011-06-14 16:41:30 +02:00
|
|
|
};
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2015-05-01 02:09:57 +02:00
|
|
|
class MessageBox : public Layout
|
2011-06-14 18:29:55 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-08-23 22:14:27 +02:00
|
|
|
MessageBox(MessageBoxManager& parMessageBoxManager, std::string_view message);
|
2022-10-05 23:45:17 +02:00
|
|
|
const std::string& getMessage() { return mMessage; }
|
2011-06-15 13:58:57 +02:00
|
|
|
int getHeight();
|
|
|
|
void update(int height);
|
2021-05-25 21:04:05 +02:00
|
|
|
void setVisible(bool value);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-11-20 05:49:05 +01:00
|
|
|
float mCurrentTime;
|
|
|
|
float mMaxTime;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2011-06-14 18:29:55 +02:00
|
|
|
protected:
|
|
|
|
MessageBoxManager& mMessageBoxManager;
|
2021-12-14 22:40:05 +08:00
|
|
|
std::string mMessage;
|
2013-03-03 13:11:02 +01:00
|
|
|
MyGUI::EditBox* mMessageWidget;
|
2011-06-15 19:42:20 +02:00
|
|
|
int mBottomPadding;
|
2011-06-15 19:53:32 +02:00
|
|
|
int mNextBoxPadding;
|
2011-06-14 18:29:55 +02:00
|
|
|
};
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2013-03-30 15:51:07 +01:00
|
|
|
class InteractiveMessageBox : public WindowModal
|
2011-06-18 15:50:41 +02:00
|
|
|
{
|
|
|
|
public:
|
2011-06-19 19:41:42 +02:00
|
|
|
InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message,
|
2023-11-18 17:57:15 +04:00
|
|
|
const std::vector<std::string>& buttons, bool immediate, int defaultFocus);
|
2011-07-12 20:05:04 +02:00
|
|
|
void mousePressed(MyGUI::Widget* _widget);
|
|
|
|
int readPressedButton();
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2018-01-14 00:27:53 +00:00
|
|
|
MyGUI::Widget* getDefaultKeyFocus() override;
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool exit() override { return false; }
|
2017-09-27 22:00:20 +02:00
|
|
|
|
2011-07-12 20:05:04 +02:00
|
|
|
bool mMarkedToDelete;
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2011-06-19 19:41:42 +02:00
|
|
|
private:
|
2013-02-10 14:58:46 +00:00
|
|
|
void buttonActivated(MyGUI::Widget* _widget);
|
2013-04-10 00:32:05 -04:00
|
|
|
|
2011-06-18 15:50:41 +02:00
|
|
|
MessageBoxManager& mMessageBoxManager;
|
2013-03-03 13:11:02 +01:00
|
|
|
MyGUI::EditBox* mMessageWidget;
|
|
|
|
MyGUI::Widget* mButtonsWidget;
|
|
|
|
std::vector<MyGUI::Button*> mButtons;
|
2011-07-12 17:57:16 +02:00
|
|
|
|
2011-07-12 20:05:04 +02:00
|
|
|
int mButtonPressed;
|
2023-11-18 17:57:15 +04:00
|
|
|
int mDefaultFocus;
|
2023-11-18 16:47:06 +04:00
|
|
|
bool mImmediate;
|
2011-06-18 15:50:41 +02:00
|
|
|
};
|
2011-06-14 18:29:55 +02:00
|
|
|
|
2011-06-14 16:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|