@@ -19,13 +19,18 @@ ClassDefine<SimpleFormClass> SimpleFormClassBuilder = defineClass<SimpleFormClas
1919 .instanceFunction(" setTitle" , &SimpleFormClass::setTitle)
2020 .instanceFunction(" setContent" , &SimpleFormClass::setContent)
2121 .instanceFunction(" addButton" , &SimpleFormClass::addButton)
22+ .instanceFunction(" addHeader" , &SimpleFormClass::addHeader)
23+ .instanceFunction(" addLabel" , &SimpleFormClass::addLabel)
24+ .instanceFunction(" addDivider" , &SimpleFormClass::addDivider)
2225 .build();
2326
2427ClassDefine<CustomFormClass> CustomFormClassBuilder =
2528 defineClass<CustomFormClass>(" LLSE_CustomForm" )
2629 .constructor(nullptr )
2730 .instanceFunction(" setTitle" , &CustomFormClass::setTitle)
31+ .instanceFunction(" addHeader" , &CustomFormClass::addHeader)
2832 .instanceFunction(" addLabel" , &CustomFormClass::addLabel)
33+ .instanceFunction(" addDivider" , &CustomFormClass::addDivider)
2934 .instanceFunction(" addInput" , &CustomFormClass::addInput)
3035 .instanceFunction(" addSwitch" , &CustomFormClass::addSwitch)
3136 .instanceFunction(" addDropdown" , &CustomFormClass::addDropdown)
@@ -49,25 +54,29 @@ ll::form::SimpleForm* SimpleFormClass::extract(Local<Value> v) {
4954 else return nullptr ;
5055}
5156
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+ ) {
5363 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);
6975 }
70- );
76+ CATCH_IN_CALLBACK (" sendForm" )
77+ };
78+ if (update) form->sendUpdate (*player, std::move (cb));
79+ else form->sendTo (*player, std::move (cb));
7180}
7281
7382// 成员函数
@@ -107,6 +116,38 @@ Local<Value> SimpleFormClass::addButton(const Arguments& args) {
107116 CATCH (" Fail in addButton!" )
108117}
109118
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+
110151// ////////////////// Custom Form ////////////////////
111152
112153CustomFormClass::CustomFormClass () : ScriptClass(ScriptClass::ConstructFromCpp<CustomFormClass>{}), form(" " ) {}
@@ -124,29 +165,33 @@ lse::form::CustomFormWrapper* CustomFormClass::extract(Local<Value> v) {
124165}
125166
126167// 成员函数
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+ ) {
128174 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);
148190 }
149- );
191+ CATCH_IN_CALLBACK (" sendForm" )
192+ };
193+ if (update) form->sendUpdate (*player, std::move (cb));
194+ else form->sendTo (*player, std::move (cb));
150195}
151196
152197Local<Value> CustomFormClass::setTitle (const Arguments& args) {
@@ -160,6 +205,17 @@ Local<Value> CustomFormClass::setTitle(const Arguments& args) {
160205 CATCH (" Fail in setTitle!" )
161206}
162207
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+
163219Local<Value> CustomFormClass::addLabel (const Arguments& args) {
164220 CHECK_ARGS_COUNT (args, 1 )
165221 CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
@@ -171,6 +227,16 @@ Local<Value> CustomFormClass::addLabel(const Arguments& args) {
171227 CATCH (" Fail in addLabel!" )
172228}
173229
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+
174240Local<Value> CustomFormClass::addInput (const Arguments& args) {
175241 CHECK_ARGS_COUNT (args, 1 )
176242 CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
0 commit comments