Etterna 0.74.4
Loading...
Searching...
No Matches
ScreenTextEntry.h
1#ifndef SCREEN_TEXT_ENTRY_H
2#define SCREEN_TEXT_ENTRY_H
3
4#include <utility>
5
6#include "Etterna/Actor/Base/BitmapText.h"
7#include "Etterna/Models/Misc/InputEventPlus.h"
8#include "RageUtil/Sound/RageSound.h"
9#include "ScreenWithMenuElements.h"
10#include "Etterna/Models/Misc/ThemeMetric.h"
11
13enum KeyboardRow
14{
15 R1,
16 R2,
17 R3,
18 R4,
19 R5,
20 R6,
21 R7,
22 KEYBOARD_ROW_SPECIAL,
23 NUM_KeyboardRow,
24 KeyboardRow_Invalid
25};
27#define FOREACH_KeyboardRow(i) FOREACH_ENUM(KeyboardRow, i)
29const int KEYS_PER_ROW = 13;
31enum KeyboardRowSpecialKey
32{
33 SPACEBAR = 2,
34 BACKSPACE = 5,
35 CANCEL = 8,
36 DONE = 11
37};
38
41{
42 public:
43 void SetTextEntrySettings(
44 std::string sQuestion,
45 std::string sInitialAnswer,
46 int iMaxInputLength,
47 bool (*Validate)(const std::string& sAnswer,
48 std::string& sErrorOut) = nullptr,
49 void (*OnOK)(const std::string& sAnswer) = nullptr,
50 void (*OnCancel)() = nullptr,
51 bool bPassword = false,
52 bool (*ValidateAppend)(const std::string& sAnswerBeforeChar,
53 const std::string& sAppend) = nullptr,
54 std::string (*FormatAnswerForDisplay)(const std::string& sAnswer) =
55 nullptr);
56 void SetTextEntrySettings(
57 std::string sQuestion,
58 std::string sInitialAnswer,
59 int iMaxInputLength,
60 const LuaReference&,
61 const LuaReference&,
62 const LuaReference&,
63 const LuaReference&,
64 const LuaReference&,
65 bool (*Validate)(const std::string& sAnswer,
66 std::string& sErrorOut) = nullptr,
67 void (*OnOK)(const std::string& sAnswer) = nullptr,
68 void (*OnCancel)() = nullptr,
69 bool bPassword = false,
70 bool (*ValidateAppend)(const std::string& sAnswerBeforeChar,
71 const std::string& sAppend) = nullptr,
72 std::string (*FormatAnswerForDisplay)(const std::string& sAnswer) =
73 nullptr);
74 static void TextEntry(
75 ScreenMessage smSendOnPop,
76 std::string sQuestion,
77 std::string sInitialAnswer,
78 int iMaxInputLength,
79 bool (*Validate)(const std::string& sAnswer,
80 std::string& sErrorOut) = nullptr,
81 void (*OnOK)(const std::string& sAnswer) = nullptr,
82 void (*OnCancel)() = nullptr,
83 bool bPassword = false,
84 bool (*ValidateAppend)(const std::string& sAnswerBeforeChar,
85 const std::string& sAppend) = nullptr,
86 std::string (*FormatAnswerForDisplay)(const std::string& sAnswer) =
87 nullptr);
88 static void Password(ScreenMessage smSendOnPop,
89 const std::string& sQuestion,
90 void (*OnOK)(const std::string& sPassword) = nullptr,
91 void (*OnCancel)() = nullptr)
92 {
93 TextEntry(std::move(smSendOnPop),
94 sQuestion,
95 "",
96 255,
97 nullptr,
98 OnOK,
99 OnCancel,
100 true);
101 }
102
104 {
106 : smSendOnPop()
107 , sQuestion("")
108 , sInitialAnswer("")
109 , Validate()
110 , OnOK()
111 , OnCancel()
112 , ValidateAppend()
113 , FormatAnswerForDisplay()
114 {
115 }
116 ScreenMessage smSendOnPop;
117 std::string sQuestion;
118 std::string sInitialAnswer;
119 int iMaxInputLength{ 0 };
123 bool bPassword{ false };
125 Validate; // (std::string sAnswer, std::string sErrorOut; optional)
126 LuaReference OnOK; // (std::string sAnswer; optional)
127 LuaReference OnCancel; // (optional)
128 LuaReference ValidateAppend; // (std::string sAnswerBeforeChar,
129 // std::string sAppend; optional)
130 LuaReference FormatAnswerForDisplay; // (std::string sAnswer; optional)
131
132 // see BitmapText.cpp Attribute::FromStack() and
133 // OptionRowHandler.cpp LoadInternal() for ideas on how to implement the
134 // main part, and ImportOption() from OptionRowHandler.cpp for
135 // functions.
136 void FromStack(lua_State* L);
137 };
138 void LoadFromTextEntrySettings(const TextEntrySettings& settings);
139
140 static bool FloatValidate(const std::string& sAnswer,
141 std::string& sErrorOut);
142 static bool IntValidate(const std::string& sAnswer, std::string& sErrorOut);
143
144 std::string sQuestion{ "" };
145 std::string sInitialAnswer{ "" };
146 int iMaxInputLength{ 0 };
147 bool (*pValidate)(const std::string& sAnswer,
148 std::string& sErrorOut){ nullptr };
149 void (*pOnOK)(const std::string& sAnswer){ nullptr };
150 void (*pOnCancel)(){ nullptr };
151 bool bPassword{ false };
152 bool (*pValidateAppend)(const std::string& sAnswerBeforeChar,
153 const std::string& sAppend){ nullptr };
154 std::string (*pFormatAnswerForDisplay)(const std::string& sAnswer){
155 nullptr
156 };
157
158 // Lua bridge
159 LuaReference ValidateFunc;
160 LuaReference OnOKFunc;
161 LuaReference OnCancelFunc;
162 LuaReference ValidateAppendFunc;
163 LuaReference FormatAnswerForDisplayFunc;
164
165 void Init() override;
166 void BeginScreen() override;
167 void EndScreen() override;
168
169 void Update(float fDelta) override;
170 bool Input(const InputEventPlus& input) override;
171
172 static std::string s_sLastAnswer;
173 static bool s_bCancelledLast;
174
175 static bool s_bMustResetInputRedirAtClose;
176 static bool s_bResetInputRedirTo;
177 virtual void End(bool bCancelled);
178
179 void UpdateAnswerText();
180
181 // Lua
182 void PushSelf(lua_State* L) override;
183
184 protected:
185 void TryAppendToAnswer(const std::string& s);
186 void BackspaceInAnswer();
187 virtual void TextEnteredDirectly() {}
188
189
190 private:
191 bool MenuStart(const InputEventPlus& input) override;
192 bool MenuBack(const InputEventPlus& input) override;
193
194
195 std::wstring m_sAnswer;
196 bool m_bShowAnswerCaret = false;
197 // todo: allow Left/Right to change caret location -aj
198 // int m_iCaretLocation;
199
200 BitmapText m_textQuestion;
201 BitmapText m_textAnswer;
202
203 RageSound m_sndType;
204 RageSound m_sndBackspace;
205
206 RageTimer m_timerToggleCursor;
207};
208
212{
213 public:
214 ~ScreenTextEntryVisual() override;
215 void Init() override;
216 void BeginScreen() override;
217
218 protected:
219 void MoveX(int iDir);
220 void MoveY(int iDir);
221 void PositionCursor();
222
223 void TextEnteredDirectly() override;
224
225 bool MenuLeft(const InputEventPlus& input) override;
226 bool MenuRight(const InputEventPlus& input) override;
227 bool MenuUp(const InputEventPlus& input) override;
228 bool MenuDown(const InputEventPlus& input) override;
229
230 bool MenuStart(const InputEventPlus& input) override;
231
232 int m_iFocusX;
233 KeyboardRow m_iFocusY;
234
235 AutoActor m_sprCursor;
236 BitmapText* m_ptextKeys[NUM_KeyboardRow][KEYS_PER_ROW];
237
238 RageSound m_sndChange;
239
240 ThemeMetric<float> ROW_START_X;
241 ThemeMetric<float> ROW_START_Y;
242 ThemeMetric<float> ROW_END_X;
243 ThemeMetric<float> ROW_END_Y;
244};
245
246#endif
A smart pointer for Actor.
Definition AutoActor.h:13
An actor that holds a Font and draws text to the screen.
Definition BitmapText.h:11
Holds a device input plus Game/Menu translations.
Definition InputEventPlus.h:9
A self-cleaning Lua reference.
Definition LuaReference.h:10
Definition RageSound.h:130
Definition RageTimer.h:9
Displays a text entry box and keyboard over the top of another screen.
Definition ScreenTextEntry.h:212
void BeginScreen() override
This is called immediately before the screen is used.
Definition ScreenTextEntry.cpp:820
void Init() override
This is called immediately after construction, to allow initializing after all derived classes exist.
Definition ScreenTextEntry.cpp:773
Displays a text entry box over the top of another screen.
Definition ScreenTextEntry.h:41
void BeginScreen() override
This is called immediately before the screen is used.
Definition ScreenTextEntry.cpp:383
void Init() override
This is called immediately after construction, to allow initializing after all derived classes exist.
Definition ScreenTextEntry.cpp:359
void EndScreen() override
This is called when the screen is popped.
Definition ScreenTextEntry.cpp:551
Definition ScreenWithMenuElements.h:12
The theme specific data.
Definition ThemeMetric.h:52
Definition ScreenTextEntry.h:104
bool bPassword
Is there a password involved with this setting?
Definition ScreenTextEntry.h:123