1 #ifndef MWGUI_MESSAGE_BOX_H
2 #define MWGUI_MESSAGE_BOX_H
3 
4 #include "windowbase.hpp"
5 
6 #undef MessageBox
7 
8 namespace MyGUI
9 {
10     class Widget;
11     class Button;
12     class EditBox;
13 }
14 
15 namespace MWGui
16 {
17     class InteractiveMessageBox;
18     class MessageBoxManager;
19     class MessageBox;
20     class MessageBoxManager
21     {
22         public:
23             MessageBoxManager (float timePerChar);
24             ~MessageBoxManager ();
25             void onFrame (float frameDuration);
26             void createMessageBox (const std::string& message, bool stat = false);
27             void removeStaticMessageBox ();
28             bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
29             bool isInteractiveMessageBox ();
30 
31             int getMessagesCount();
32 
getInteractiveMessageBox() const33             const InteractiveMessageBox* getInteractiveMessageBox() const { return mInterMessageBoxe; }
34 
35             /// Remove all message boxes
36             void clear();
37 
38             bool removeMessageBox (MessageBox *msgbox);
39 
40             /// @param reset Reset the pressed button to -1 after reading it.
41             int readPressedButton (bool reset=true);
42 
43             typedef MyGUI::delegates::CMultiDelegate1<int> EventHandle_Int;
44 
45             // Note: this delegate unassigns itself after it was fired, i.e. works once.
46             EventHandle_Int eventButtonPressed;
47 
onButtonPressed(int button)48             void onButtonPressed(int button) { eventButtonPressed(button); eventButtonPressed.clear(); }
49 
50         private:
51             std::vector<MessageBox*> mMessageBoxes;
52             InteractiveMessageBox* mInterMessageBoxe;
53             MessageBox* mStaticMessageBox;
54             float mMessageBoxSpeed;
55             int mLastButtonPressed;
56     };
57 
58     class MessageBox : public Layout
59     {
60         public:
61             MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message);
62             void setMessage (const std::string& message);
63             int getHeight ();
64             void update (int height);
65 
66             float mCurrentTime;
67             float mMaxTime;
68 
69         protected:
70             MessageBoxManager& mMessageBoxManager;
71             const std::string& mMessage;
72             MyGUI::EditBox* mMessageWidget;
73             int mBottomPadding;
74             int mNextBoxPadding;
75     };
76 
77     class InteractiveMessageBox : public WindowModal
78     {
79         public:
80             InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons);
81             void mousePressed (MyGUI::Widget* _widget);
82             int readPressedButton ();
83 
84             MyGUI::Widget* getDefaultKeyFocus() override;
85 
exit()86             bool exit() override { return false; }
87 
88             bool mMarkedToDelete;
89 
90         private:
91             void buttonActivated (MyGUI::Widget* _widget);
92 
93             MessageBoxManager& mMessageBoxManager;
94             MyGUI::EditBox* mMessageWidget;
95             MyGUI::Widget* mButtonsWidget;
96             std::vector<MyGUI::Button*> mButtons;
97 
98             int mButtonPressed;
99     };
100 
101 }
102 
103 #endif
104