@@ -19,13 +19,18 @@ ClassDefine<SimpleFormClass> SimpleFormClassBuilder = defineClass<SimpleFormClas
19
19
.instanceFunction(" setTitle" , &SimpleFormClass::setTitle)
20
20
.instanceFunction(" setContent" , &SimpleFormClass::setContent)
21
21
.instanceFunction(" addButton" , &SimpleFormClass::addButton)
22
+ .instanceFunction(" addHeader" , &SimpleFormClass::addHeader)
23
+ .instanceFunction(" addLabel" , &SimpleFormClass::addLabel)
24
+ .instanceFunction(" addDivider" , &SimpleFormClass::addDivider)
22
25
.build();
23
26
24
27
ClassDefine<CustomFormClass> CustomFormClassBuilder =
25
28
defineClass<CustomFormClass>(" LLSE_CustomForm" )
26
29
.constructor(nullptr )
27
30
.instanceFunction(" setTitle" , &CustomFormClass::setTitle)
31
+ .instanceFunction(" addHeader" , &CustomFormClass::addHeader)
28
32
.instanceFunction(" addLabel" , &CustomFormClass::addLabel)
33
+ .instanceFunction(" addDivider" , &CustomFormClass::addDivider)
29
34
.instanceFunction(" addInput" , &CustomFormClass::addInput)
30
35
.instanceFunction(" addSwitch" , &CustomFormClass::addSwitch)
31
36
.instanceFunction(" addDropdown" , &CustomFormClass::addDropdown)
@@ -49,25 +54,29 @@ ll::form::SimpleForm* SimpleFormClass::extract(Local<Value> v) {
49
54
else return nullptr ;
50
55
}
51
56
52
- void SimpleFormClass::sendForm (ll::form::SimpleForm* form, Player* player, script::Local<Function>& callback) {
57
+ void SimpleFormClass::sendForm (
58
+ ll::form::SimpleForm* form,
59
+ Player* player,
60
+ script::Local<Function>& callback,
61
+ bool update
62
+ ) {
53
63
script::Global<Function> callbackFunc{callback};
54
- form->sendTo (
55
- *player,
56
- [engine{EngineScope::currentEngine ()},
57
- callback{std::move (callbackFunc)}](Player& pl, int chosen, FormCancelReason reason) {
58
- if ((ll::getGamingStatus () != ll::GamingStatus::Running)) return ;
59
- if (!EngineManager::isValid (engine)) return ;
60
- if (callback.isEmpty ()) return ;
61
-
62
- EngineScope scope (engine);
63
- try {
64
- auto reasonValue = reason.has_value () ? Number::newNumber ((uchar)reason.value ()) : Local<Value>();
65
- if (chosen < 0 ) callback.get ().call ({}, PlayerClass::newPlayer (&pl), reasonValue);
66
- else callback.get ().call ({}, PlayerClass::newPlayer (&pl), Number::newNumber (chosen), reasonValue);
67
- }
68
- CATCH_IN_CALLBACK (" sendForm" )
64
+ auto cb = [engine{EngineScope::currentEngine ()},
65
+ callback{std::move (callbackFunc)}](Player& pl, int chosen, FormCancelReason reason) {
66
+ if ((ll::getGamingStatus () != ll::GamingStatus::Running)) return ;
67
+ if (!EngineManager::isValid (engine)) return ;
68
+ if (callback.isEmpty ()) return ;
69
+
70
+ EngineScope scope (engine);
71
+ try {
72
+ auto reasonValue = reason.has_value () ? Number::newNumber ((uchar)reason.value ()) : Local<Value>();
73
+ if (chosen < 0 ) callback.get ().call ({}, PlayerClass::newPlayer (&pl), reasonValue);
74
+ else callback.get ().call ({}, PlayerClass::newPlayer (&pl), Number::newNumber (chosen), reasonValue);
69
75
}
70
- );
76
+ CATCH_IN_CALLBACK (" sendForm" )
77
+ };
78
+ if (update) form->sendUpdate (*player, std::move (cb));
79
+ else form->sendTo (*player, std::move (cb));
71
80
}
72
81
73
82
// 成员函数
@@ -107,6 +116,38 @@ Local<Value> SimpleFormClass::addButton(const Arguments& args) {
107
116
CATCH (" Fail in addButton!" )
108
117
}
109
118
119
+ Local<Value> SimpleFormClass::addHeader (const Arguments& args) {
120
+ CHECK_ARGS_COUNT (args, 1 );
121
+ CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
122
+
123
+ try {
124
+ form.appendLabel (args[0 ].asString ().toString ());
125
+ return this ->getScriptObject ();
126
+ }
127
+ CATCH (" Fail in addHeader!" )
128
+ }
129
+
130
+ Local<Value> SimpleFormClass::addLabel (const Arguments& args) {
131
+ CHECK_ARGS_COUNT (args, 1 );
132
+ CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
133
+
134
+ try {
135
+ form.appendLabel (args[0 ].asString ().toString ());
136
+ return this ->getScriptObject ();
137
+ }
138
+ CATCH (" Fail in addLabel!" )
139
+ }
140
+
141
+ Local<Value> SimpleFormClass::addDivider (const Arguments& args) {
142
+ CHECK_ARGS_COUNT (args, 0 );
143
+
144
+ try {
145
+ form.appendDivider ();
146
+ return this ->getScriptObject ();
147
+ }
148
+ CATCH (" Fail in addDivider!" )
149
+ }
150
+
110
151
// ////////////////// Custom Form ////////////////////
111
152
112
153
CustomFormClass::CustomFormClass () : ScriptClass(ScriptClass::ConstructFromCpp<CustomFormClass>{}), form(" " ) {}
@@ -124,29 +165,33 @@ lse::form::CustomFormWrapper* CustomFormClass::extract(Local<Value> v) {
124
165
}
125
166
126
167
// 成员函数
127
- void CustomFormClass::sendForm (lse::form::CustomFormWrapper* form, Player* player, script::Local<Function>& callback) {
168
+ void CustomFormClass::sendForm (
169
+ lse::form::CustomFormWrapper* form,
170
+ Player* player,
171
+ script::Local<Function>& callback,
172
+ bool update
173
+ ) {
128
174
script::Global<Function> callbackFunc{callback};
129
- form->sendTo (
130
- *player,
131
- [engine{EngineScope::currentEngine ()},
132
- callback{std::move (callbackFunc)
133
- }](Player& player, lse::form::CustomFormResult const & data, FormCancelReason reason) {
134
- if (ll::getGamingStatus () != ll::GamingStatus::Running) return ;
135
- if (!EngineManager::isValid (engine)) return ;
136
- if (callback.isEmpty ()) return ;
137
-
138
- EngineScope scope (engine);
139
- Local<Value> result;
140
- if (data) {
141
- result = JsonToValue (*data);
142
- }
143
- auto reasonVal = reason.has_value () ? Number::newNumber ((uchar)reason.value ()) : Local<Value>();
144
- try {
145
- callback.get ().call ({}, PlayerClass::newPlayer (&player), result, reasonVal);
146
- }
147
- CATCH_IN_CALLBACK (" sendForm" )
175
+ auto cb = [engine{EngineScope::currentEngine ()},
176
+ callback{std::move (callbackFunc)
177
+ }](Player& player, lse::form::CustomFormResult const & data, FormCancelReason reason) {
178
+ if (ll::getGamingStatus () != ll::GamingStatus::Running) return ;
179
+ if (!EngineManager::isValid (engine)) return ;
180
+ if (callback.isEmpty ()) return ;
181
+
182
+ EngineScope scope (engine);
183
+ Local<Value> result;
184
+ if (data) {
185
+ result = JsonToValue (*data);
186
+ }
187
+ auto reasonVal = reason.has_value () ? Number::newNumber ((uchar)reason.value ()) : Local<Value>();
188
+ try {
189
+ callback.get ().call ({}, PlayerClass::newPlayer (&player), result, reasonVal);
148
190
}
149
- );
191
+ CATCH_IN_CALLBACK (" sendForm" )
192
+ };
193
+ if (update) form->sendUpdate (*player, std::move (cb));
194
+ else form->sendTo (*player, std::move (cb));
150
195
}
151
196
152
197
Local<Value> CustomFormClass::setTitle (const Arguments& args) {
@@ -160,6 +205,17 @@ Local<Value> CustomFormClass::setTitle(const Arguments& args) {
160
205
CATCH (" Fail in setTitle!" )
161
206
}
162
207
208
+ Local<Value> CustomFormClass::addHeader (const Arguments& args) {
209
+ CHECK_ARGS_COUNT (args, 1 )
210
+ CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
211
+
212
+ try {
213
+ form.appendLabel (args[0 ].asString ().toString ());
214
+ return this ->getScriptObject ();
215
+ }
216
+ CATCH (" Fail in addHeader!" )
217
+ }
218
+
163
219
Local<Value> CustomFormClass::addLabel (const Arguments& args) {
164
220
CHECK_ARGS_COUNT (args, 1 )
165
221
CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
@@ -171,6 +227,16 @@ Local<Value> CustomFormClass::addLabel(const Arguments& args) {
171
227
CATCH (" Fail in addLabel!" )
172
228
}
173
229
230
+ Local<Value> CustomFormClass::addDivider (const Arguments& args) {
231
+ CHECK_ARGS_COUNT (args, 0 )
232
+
233
+ try {
234
+ form.appendDivider ();
235
+ return this ->getScriptObject ();
236
+ }
237
+ CATCH (" Fail in addDivider!" )
238
+ }
239
+
174
240
Local<Value> CustomFormClass::addInput (const Arguments& args) {
175
241
CHECK_ARGS_COUNT (args, 1 )
176
242
CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
0 commit comments