forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwindow_message.h
225 lines (183 loc) · 5.36 KB
/
window_message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_WINDOW_MESSAGE_H
#define EP_WINDOW_MESSAGE_H
// Headers
#include <string>
#include "window_gold.h"
#include "window_numberinput.h"
#include "window_selectable.h"
#include "pending_message.h"
#include "async_op.h"
/**
* Window Message Class.
* This class displays the message boxes from
* ShowMessageBox command code.
*/
class Window_Message: public Window_Selectable {
public:
Window_Message(int ix, int iy, int iwidth, int iheight);
~Window_Message() override;
enum WindowMessageValues {
LeftMargin = 8,
FaceSize = 48,
RightFaceMargin = 16,
TopMargin = 8
};
/**
* Starts message processing by reading all
* non-displayed from Game_Message.
*/
void StartMessageProcessing(PendingMessage pm);
/**
* Ends the message processing.
*/
void FinishMessageProcessing();
/**
* Does the initial steps to start a choice selection.
*/
void StartChoiceProcessing();
/**
* Does the initial steps to start a number input.
*/
void StartNumberInputProcessing();
/**
* Shows the Gold Window
*/
void ShowGoldWindow();
/**
* Clears the Messagebox and places the write pointer
* in the top left corner.
*/
void InsertNewPage();
/**
* Inserts a line break.
*/
void InsertNewLine();
void OnFinishPage();
/**
* Stub.
*/
void ResetWindow();
void Update() override;
/**
* Continues outputting more text. Also handles the
* CommandCode parsing.
*/
virtual void UpdateMessage();
/**
* Stub. For choice.
*/
void UpdateCursorRect() override;
/**
* Waits for a key press before the text output
* continutes.
*/
void WaitForInput();
/**
* Stub. Handles choice selection.
*/
void InputChoice();
/**
* Handles number input.
*/
void InputNumber();
/** @return the stored PendingMessage */
const PendingMessage& GetPendingMessage() const;
/** @return true if there is still text pending */
bool IsMessagePending() const;
/** @return true if we can push a new message this frame */
bool GetAllowNextMessage(bool foreground) const;
/** @return the last async operation */
AsyncOp GetAsyncOp() const;
/** @return the number of lines per page */
int GetMaxLinesPerPage() const;
/**
* Set the number of lines per page
*
* @param lines the number of lines
**/
void SetMaxLinesPerPage(int lines);
protected:
/** Async operation */
AsyncOp aop;
/** X-position of next char. */
int contents_x = 0;
/** Y-position of next char. */
int contents_y = 0;
/** Current number of lines on this page. */
int line_count = 0;
/** Maximum number of lines per page */
int max_lines_per_page = 4;
/** Index of the next char in text that will be output. */
const char* text_index = nullptr;
/** text message that will be displayed. */
std::string text;
/** Text color. */
int text_color = 0;
/** Current speed modifier. */
int speed = 1;
/** Used by Message kill command \^. */
bool kill_page = false;
/** If instant speed is enabled */
bool instant_speed = false;
// FIXME: This hacky flags exist because RPG_RT likely animates the message window
// after the game loop finishes. Our code isn't structured that way, so we must hack
// around it.
bool close_started_this_frame = false;
bool close_finished_this_frame = false;
/** Frames to wait when a message wait command was used */
int wait_count = 0;
/** Incremented by 1 each time we print a half width character with speed 1,
* or by 2 for any other character */
int line_char_counter = 0;
/** Did we wait for the prev character */
bool prev_char_waited = true;
/** Was the previous character printable? */
bool prev_char_printable = false;
/** Used by the number input event. */
std::unique_ptr<Window_NumberInput> number_input_window;
std::unique_ptr<Window_Gold> gold_window;
PendingMessage pending_message;
bool DrawGlyph(Font& font, const Bitmap& system, char32_t glyph, bool is_exfont);
void IncrementLineCharCounter(int width);
void SetWaitForCharacter(int width);
void SetWaitForNonPrintable(int frames);
void SetWait(int frames);
bool IsFaceEnabled() const;
};
inline const PendingMessage& Window_Message::GetPendingMessage() const {
return pending_message;
}
inline bool Window_Message::IsMessagePending() const {
return IsVisible() && !IsClosing();
}
inline AsyncOp Window_Message::GetAsyncOp() const {
return aop;
}
inline bool Window_Message::GetAllowNextMessage(bool foreground) const {
bool is_active = (IsVisible() || close_finished_this_frame);
return foreground ? !is_active || close_started_this_frame : !is_active;
}
inline int Window_Message::GetMaxLinesPerPage() const {
return max_lines_per_page;
}
/** @return the number of lines per page */
inline void Window_Message::SetMaxLinesPerPage(int lines) {
max_lines_per_page = lines;
}
#endif