1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-14 06:40:40 +00:00
OpenMW/apps/openmw/mwgui/messagebox.hpp

115 lines
3.0 KiB
C++
Raw Normal View History

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