Cavestory Mod API
CSMAPI_MessageBoxMode.h
Go to the documentation of this file.
1 /*
2  Cavestory Multiplayer API
3  Copyright (C) 2021 Johnny Ledger
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
26 #pragma once
27 
28 #include <CSMAPI_begincode.h>
29 
30 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
31 
32 class MessageBoxMode;
33 
35 typedef void(*MessageBoxBusyFunc)(void*);
36 
37 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
38 
43 {
44  friend class MessageBoxMode;
45 
46 private: // Cache variables
47  struct
48  {
49  GUI_RECT rc_button;
50  GUI_RECT rc_text;
51  GUI_POINT pnt_lookup;
52  } m_Cache;
53 
54 public: // Button configuration
55 
58  unsigned int m_ReturnCode;
59 
62  const char* m_Text;
63 
66  const char* m_DefaultText;
67 
70  short m_NewLine;
71 
74  bool m_Default;
75 
78  bool m_Cancel;
79 
82  bool m_Enabled;
83 
84 public: // Constructor
85  inline MessageBoxButton()
86  {
87  memset(&m_Cache, 0, sizeof(m_Cache));
88 
89  m_ReturnCode = 0;
90  m_Text = NULL;
91  m_DefaultText = NULL;
92  m_NewLine = false;
93  m_Default = false;
94  m_Cancel = false;
95  m_Enabled = true;
96  }
97 
98  MessageBoxButton(const char* pText, const char* pDefaultText, int iReturnCode, bool bNewLine = false, bool bDefault = false, bool bCancel = false, bool bEnabled = true);
99  MessageBoxButton(const char* pText, int iReturnCode, bool bNewLine = false, bool bDefault = false, bool bCancel = false, bool bEnabled = true);
100 };
101 
102 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
103 
108 {
109  typedef BaseModeInstance Parent;
110  friend class MessageBoxButton;
111 
112 protected: // Pre-init variables
113  MessageBoxBusyFunc m_BusyFunc;
114  void* m_UserData;
115 
116  MessageBoxButton* m_Buttons;
117  int m_ButtonCount;
118 
119 public:
124  {
127  const char* title;
128 
131  const char* text;
132 
136 
140 
144 
148 
152 
156 
159  struct
160  {
163  bool enabled;
164 
170  char value[1024];
171 
175  } input_box;
176 
180  {
181  busy_func_before_draw = true;
182  draw_grab_on_exit = true;
183  title_margin = 1;
184  text_margin = 4;
185  btn_margin = 2;
186  line_padding = 2;
187  title = NULL;
188  text = NULL;
189  input_box.enabled = false;
190  *input_box.value = 0;
191  input_box.min_width = 32;
192  }
193  } m_Config;
194 
195 public: // Constructor
196 
199  inline MessageBoxMode() : m_Config()
200  {
201  m_BusyFunc = NULL;
202  m_UserData = NULL;
203  m_Buttons = NULL;
204  m_ButtonCount = 0;
205  }
206 
207 protected: // Memory management
208 
211  virtual int Init();
212 
215  virtual int Free();
216 
217 protected: // Processing
218 
221  virtual void ProcessLogic();
222 
225  virtual void ProcessMouse(GUI_POINT mouse_point);
226 
229  virtual void ProcessKeys();
230 
231 protected: // Button management
232 
235  void HandleSelection();
236 
239  int GetShiftedButtonIndex(GUI_POINT start, GUI_POINT shift);
240 
241 protected: // Text management
242 
245  GUI_POINT GetSpecialTextSize();
246 
249  void DrawSpecialText();
250 
251 protected: // Pre-rendering
252 
255  virtual void PreRender();
256 
257 protected: // Rendering
258 
261  virtual void Draw();
262 
263 public:
264 
268  {
270  QUIT_GAME = -1,
271  };
272 
284  static int ShowMessageBox(const char* pTitle, const char* pMessage, MessageBoxButton* pButtons, int iButtonCount, MessageBoxBusyFunc pBusyFunc = NULL, void* pUserData = NULL, MessageBoxConfigStruct* pConfig = NULL);
285 
295  static bool ShowMessageBoxForOneFrame(const char* pTitle, const char* pMessage, MessageBoxButton* pButtons, int iButtonCount, MessageBoxConfigStruct* pConfig = NULL);
296 };
297 
298 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
299 
300 #include <CSMAPI_endcode.h>
301 
302 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
303 
308 {
312  {
314  MBR_OK = 0,
316  MBR_YES = 0,
318  MBR_NO = 1,
323  };
324 
326  static MessageBoxButton LAYOUT_OK[] = { MessageBoxButton("#VARIOUS__OK", "OK", ReturnCodes::MBR_OK, false, true, true)};
327 
329  static MessageBoxButton LAYOUT_YES_NO[] = { MessageBoxButton("#VARIOUS__YES_L", "Yes", ReturnCodes::MBR_YES, false, true, false), MessageBoxButton("#VARIOUS__NO", "No", ReturnCodes::MBR_NO, false, false, true)};
330 
332  static MessageBoxButton LAYOUT_RETRY_CANCEL[] = { MessageBoxButton("#VARIOUS__RETRY_L", "Retry", ReturnCodes::MBR_RETRY, false, false, false), MessageBoxButton("#VARIOUS__CANCEL_L", "Cancel", ReturnCodes::MBR_CANCEL, false, true, true)};
333 
335  static MessageBoxButton LAYOUT_OK_CANCEL[] = { MessageBoxButton("#VARIOUS__OK", "OK", ReturnCodes::MBR_OK, false, true, false), MessageBoxButton("#VARIOUS__CANCEL_L", "Cancel", ReturnCodes::MBR_CANCEL, false, false, true)};
336 }
337 
338 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
void(* MessageBoxBusyFunc)(void *)
Function callback to call when.
Definition: CSMAPI_MessageBoxMode.h:35
Easy UI management.
Definition: CSMAPI_BaseModeInstance.h:469
Message box button.
Definition: CSMAPI_MessageBoxMode.h:43
bool m_Default
If true, the message box will init with this as the selected button.
Definition: CSMAPI_MessageBoxMode.h:74
short m_NewLine
Whether this button should be on a new line.
Definition: CSMAPI_MessageBoxMode.h:70
bool m_Enabled
Whether this button is clickable or not.
Definition: CSMAPI_MessageBoxMode.h:82
const char * m_Text
The text shown on this button.
Definition: CSMAPI_MessageBoxMode.h:62
const char * m_DefaultText
The text shown on this button.
Definition: CSMAPI_MessageBoxMode.h:66
bool m_Cancel
If this is 'true', then the message box mode will return this button's value if ESCAPE is pressed.
Definition: CSMAPI_MessageBoxMode.h:78
unsigned int m_ReturnCode
What code this button returns when pressed.
Definition: CSMAPI_MessageBoxMode.h:58
Message box mode.
Definition: CSMAPI_MessageBoxMode.h:108
virtual void PreRender()
Render everything to surfaces.
virtual void ProcessKeys()
Process key input.
static bool ShowMessageBoxForOneFrame(const char *pTitle, const char *pMessage, MessageBoxButton *pButtons, int iButtonCount, MessageBoxConfigStruct *pConfig=NULL)
Display a message box for this frame only.
virtual void Draw()
Draw rendered surfaces.
MessageBoxReturnCodes
Special return codes.
Definition: CSMAPI_MessageBoxMode.h:268
virtual void ProcessLogic()
Process the logic of this menu.
virtual int Free()
De-initialize this mode.
MessageBoxMode()
Default constructor.
Definition: CSMAPI_MessageBoxMode.h:199
virtual int Init()
Initialize this mode.
static int ShowMessageBox(const char *pTitle, const char *pMessage, MessageBoxButton *pButtons, int iButtonCount, MessageBoxBusyFunc pBusyFunc=NULL, void *pUserData=NULL, MessageBoxConfigStruct *pConfig=NULL)
Show a message box.
virtual void ProcessMouse(GUI_POINT mouse_point)
Process this menu's mouse.
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
Default layouts for MessageBoxMode::ShowMessageBox() .
Definition: CSMAPI_MessageBoxMode.h:308
ReturnCodes
A key table for the various modes.
Definition: CSMAPI_MessageBoxMode.h:312
@ MBR_RETRY
LAYOUT_RETRY_CANCEL: "Retry".
Definition: CSMAPI_MessageBoxMode.h:320
@ MBR_CANCEL
LAYOUT_RETRY_CANCEL: "Cancel".
Definition: CSMAPI_MessageBoxMode.h:322
@ MBR_NO
LAYOUT_YES_NO: "No".
Definition: CSMAPI_MessageBoxMode.h:318
@ MBR_YES
LAYOUT_YES_NO: "Yes".
Definition: CSMAPI_MessageBoxMode.h:316
@ MBR_OK
LAYOUT_OK: "Ok".
Definition: CSMAPI_MessageBoxMode.h:314
Manages points.
Definition: CSMAPI_types.h:546
Definition: CSMAPI_types.h:842
Configuration for MessageBoxMode.
Definition: CSMAPI_MessageBoxMode.h:124
const char * title
The title of the message box.
Definition: CSMAPI_MessageBoxMode.h:127
MessageBoxConfigStruct()
Default constructor.
Definition: CSMAPI_MessageBoxMode.h:179
int line_padding
Line padding.
Definition: CSMAPI_MessageBoxMode.h:155
bool busy_func_before_draw
If set to true, then the busy function will be called BEFORE the messagebox's draw function,...
Definition: CSMAPI_MessageBoxMode.h:135
int btn_margin
The button text margin.
Definition: CSMAPI_MessageBoxMode.h:151
bool enabled
Enable the input box.
Definition: CSMAPI_MessageBoxMode.h:163
bool draw_grab_on_exit
Perform a BaseModeInstance::GrabScreen() on messagebox exit.
Definition: CSMAPI_MessageBoxMode.h:139
int text_margin
The margin of the text.
Definition: CSMAPI_MessageBoxMode.h:143
int title_margin
The title margin.
Definition: CSMAPI_MessageBoxMode.h:147
int min_width
The minimum width of the input box.
Definition: CSMAPI_MessageBoxMode.h:174
const char * text
The text to display.
Definition: CSMAPI_MessageBoxMode.h:131