Skip to content

Commit 337512f

Browse files
committed
feat: add tooltip support for CustomFormBuilder
1 parent 929f896 commit 337512f

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

docs/apis/GuiAPI/FormBuilder.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ are called when there is player interaction, without fighting.
9393

9494
For a player object `pl`, using the function:
9595

96-
`pl.sendForm(fm,callback.forUpdating)`
96+
`pl.sendForm(fm,callback[,forUpdating])`
9797

9898
- Parameters:
9999
- fm : `SimpleForm`
@@ -176,7 +176,7 @@ For a specific form object `fm`, the following functions are available:
176176

177177
#### Add a Row of Input Boxes to the Form
178178

179-
`fm.addInput(title[,placeholder,default])`
179+
`fm.addInput(title[,placeholder,default,tooltip])`
180180

181181
- Parameters:
182182

@@ -185,25 +185,29 @@ For a specific form object `fm`, the following functions are available:
185185
- placeholder : `String`
186186
(Optional parameter) The default prompt in the input box.
187187
- default : `String`
188-
(Optional parameter) the default input in the input box.
188+
(Optional parameter) The default input in the input box.
189+
- tooltip : `String`
190+
(Optional parameter, added in 0.12.0) The text of tooltip
189191
- Return value: The processed form object (for other operations in the chain).
190192
- Return value type: `CustomForm`
191193

192194
#### Add a Row of Switch Options to the Form
193195

194-
`fm.addSwitch(title[,default])`
196+
`fm.addSwitch(title[,default,tooltip])`
195197

196198
- Parameters:
197199
- title : `String`
198200
Description text for a switch option.
199201
- default : `Boolean`
200202
(Optional parameter) Default state of the switch on/off.
203+
- tooltip : `String`
204+
(Optional parameter, added in 0.12.0) The text of tooltip
201205
- Return value: The processed form object (for other operations in the chain).
202206
- Return value type: `CustomForm`
203207

204208
#### Add a Drop-Down Menu to the Form
205209

206-
`fm.addDropdown(title,items[,default])`
210+
`fm.addDropdown(title,items[,default,tooltip])`
207211

208212
- Parameters:
209213

@@ -216,12 +220,15 @@ For a specific form object `fm`, the following functions are available:
216220
- default : `Integer`
217221
(Optional parameter) The number of the list item selected by default in the drop-down menu.
218222
The sequence number starts from 0. The default is 0, that is, the first item in the list is selected by default.
223+
224+
- tooltip : `String`
225+
(Optional parameter, added in 0.12.0) The text of tooltip
219226
- Return value: The processed form object (for other operations in the chain).
220227
- Return value type: `CustomForm`
221228

222229
#### Add a Row of Cursor Sliders to the Form
223230

224-
`fm.addSlider(title,min,max[,step,default])`
231+
`fm.addSlider(title,min,max[,step,default,tooltip])`
225232

226233
- Parameters:
227234
- title : `String`
@@ -236,12 +243,14 @@ For a specific form object `fm`, the following functions are available:
236243
(Optional parameter) The default initial grid number of the cursor slider, the value must be between the minimum
237244
and maximum grid number.
238245
Defaults to 0, i.e. the slider is at the beginning of the slider row.
246+
- tooltip : `String`
247+
(Optional parameter, added in 0.12.0) The text of tooltip
239248
- Return value: The processed form object (for other operations in the chain).
240249
- Return value type: `CustomForm`
241250

242251
#### Add a Row of Step Sliders to the Form
243252

244-
`fm.addStepSlider(title,items[,default])`
253+
`fm.addStepSlider(title,items[,default,tooltip])`
245254

246255
- Parameters:
247256
- title : `String`
@@ -253,6 +262,9 @@ For a specific form object `fm`, the following functions are available:
253262
- default : `Integer`
254263
(Optional parameter) Default initial options for step slider. Serial numbers start from 0.
255264
Defaults to 0, i.e. the slider is at the beginning of the slider row.
265+
266+
- tooltip : `String`
267+
(Optional parameter, added in 0.12.0) The text of tooltip
256268
- Return value: The processed form object (for other operations in the chain).
257269
- Return value type: `CustomForm`
258270

docs/apis/GuiAPI/FormBuilder.zh.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ reason可能会是`null`.
176176

177177
#### 向表单内增加一行输入框
178178

179-
`fm.addInput(title[,placeholder,default])`
179+
`fm.addInput(title[,placeholder,default,tooltip])`
180180

181181
- 参数:
182182

@@ -186,24 +186,28 @@ reason可能会是`null`.
186186
(可选参数)输入框内的提示字符
187187
- default : `String`
188188
(可选参数)输入框中默认存在的内容
189+
- tooltip : `String`
190+
(可选参数,在0.12.0中加入)提示文本
189191
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
190192
- 返回值类型:`CustomForm`
191193

192194
#### 向表单内增加一行开关选项
193195

194-
`fm.addSwitch(title[,default])`
196+
`fm.addSwitch(title[,default,tooltip])`
195197

196198
- 参数:
197199
- title : `String`
198200
开关选项描述文本
199201
- default : `Boolean`
200202
(可选参数)开关的默认状态 开 / 关
203+
- tooltip : `String`
204+
(可选参数,在0.12.0中加入)提示文本
201205
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
202206
- 返回值类型:`CustomForm`
203207

204208
#### 向表单内增加一行下拉菜单
205209

206-
`fm.addDropdown(title,items[,default])`
210+
`fm.addDropdown(title,items[,default,tooltip])`
207211

208212
- 参数:
209213

@@ -216,12 +220,15 @@ reason可能会是`null`.
216220
- default : `Integer`
217221
(可选参数)下拉菜单默认选中的列表项序号。
218222
序号从0开始编号。默认为0,即默认选中列表的第一项
223+
224+
- tooltip : `String`
225+
(可选参数,在0.12.0中加入)提示文本
219226
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
220227
- 返回值类型:`CustomForm`
221228

222229
#### 向表单内增加一行游标滑块
223230

224-
`fm.addSlider(title,min,max[,step,default])`
231+
`fm.addSlider(title,min,max[,step,default,tooltip])`
225232

226233
- 参数:
227234
- title : `String`
@@ -235,12 +242,14 @@ reason可能会是`null`.
235242
- default : `Integer`
236243
(可选参数)游标滑块默认初始格数,数值必须在最小和最大格数之间。
237244
默认为0,即滑块位于滑块行的开头
245+
- tooltip : `String`
246+
(可选参数,在0.12.0中加入)提示文本
238247
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
239248
- 返回值类型:`CustomForm`
240249

241250
#### 向表单内增加一行步进滑块
242251

243-
`fm.addStepSlider(title,items[,default])`
252+
`fm.addStepSlider(title,items[,default,tooltip])`
244253

245254
- 参数:
246255
- title : `String`
@@ -252,6 +261,9 @@ reason可能会是`null`.
252261
- default : `Integer`
253262
(可选参数)步进滑块默认初始选项。序号从0开始编号
254263
默认为0,即滑块位于滑块行的开头
264+
265+
- tooltip : `String`
266+
(可选参数,在0.12.0中加入)提示文本
255267
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
256268
- 返回值类型:`CustomForm`
257269

src/legacy/api/GuiAPI.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,14 @@ Local<Value> CustomFormClass::addInput(const Arguments& args) {
259259
CHECK_ARG_TYPE(args[0], ValueKind::kString)
260260
if (args.size() >= 2) CHECK_ARG_TYPE(args[1], ValueKind::kString);
261261
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kString);
262+
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);
262263

263264
try {
264265
std::string placeholder = args.size() >= 2 ? args[1].asString().toString() : "";
265266
std::string def = args.size() >= 3 ? args[2].asString().toString() : "";
267+
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";
266268

267-
form.appendInput("", args[0].asString().toString(), placeholder, def);
269+
form.appendInput("", args[0].asString().toString(), placeholder, def, tooltip);
268270
return this->getScriptObject();
269271
}
270272
CATCH("Fail in addInput!")
@@ -279,12 +281,14 @@ Local<Value> CustomFormClass::addSwitch(const Arguments& args) {
279281
return Local<Value>();
280282
}
281283
}
284+
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kString);
282285

283286
try {
284287
bool def =
285288
args.size() >= 2 ? args[1].isBoolean() ? args[1].asBoolean().value() : args[1].asNumber().toInt32() : false;
289+
std::string tooltip = args.size() >= 3 ? args[2].asString().toString() : "";
286290

287-
form.appendToggle("", args[0].asString().toString(), def);
291+
form.appendToggle("", args[0].asString().toString(), def, tooltip);
288292
return this->getScriptObject();
289293
}
290294
CATCH("Fail in addSwitch!")
@@ -295,6 +299,7 @@ Local<Value> CustomFormClass::addDropdown(const Arguments& args) {
295299
CHECK_ARG_TYPE(args[0], ValueKind::kString)
296300
CHECK_ARG_TYPE(args[1], ValueKind::kArray);
297301
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
302+
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);
298303

299304
try {
300305
auto optionsArr = args[1].asArray();
@@ -304,9 +309,10 @@ Local<Value> CustomFormClass::addDropdown(const Arguments& args) {
304309
options.emplace_back(optionsArr.get(i).asString().toString());
305310
}
306311

307-
int def = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
312+
int def = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
313+
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";
308314

309-
form.appendDropdown("", args[0].asString().toString(), options, def);
315+
form.appendDropdown("", args[0].asString().toString(), options, def, tooltip);
310316
return this->getScriptObject();
311317
}
312318
CATCH("Fail in addDropdown!")
@@ -319,6 +325,7 @@ Local<Value> CustomFormClass::addSlider(const Arguments& args) {
319325
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
320326
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kNumber);
321327
if (args.size() >= 5) CHECK_ARG_TYPE(args[4], ValueKind::kNumber);
328+
if (args.size() >= 6) CHECK_ARG_TYPE(args[5], ValueKind::kString);
322329

323330
try {
324331
int minValue = args[1].asNumber().toInt32();
@@ -328,8 +335,9 @@ Local<Value> CustomFormClass::addSlider(const Arguments& args) {
328335
int step = args.size() >= 4 ? args[3].asNumber().toInt32() : 1;
329336
int defValue = args.size() >= 5 ? args[4].asNumber().toInt32() : minValue;
330337
if (defValue < minValue || defValue > maxValue) defValue = minValue;
338+
std::string tooltip = args.size() >= 6 ? args[5].asString().toString() : "";
331339

332-
form.appendSlider("", args[0].asString().toString(), minValue, maxValue, step, defValue);
340+
form.appendSlider("", args[0].asString().toString(), minValue, maxValue, step, defValue, tooltip);
333341
return this->getScriptObject();
334342
}
335343
CATCH("Fail in addSlider!")
@@ -340,16 +348,18 @@ Local<Value> CustomFormClass::addStepSlider(const Arguments& args) {
340348
CHECK_ARG_TYPE(args[0], ValueKind::kString)
341349
CHECK_ARG_TYPE(args[1], ValueKind::kArray);
342350
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
351+
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);
343352

344353
try {
345354
auto stepsArr = args[1].asArray();
346355
std::vector<std::string> steps;
347356
steps.reserve(stepsArr.size());
348357
for (size_t i = 0; i < stepsArr.size(); ++i) steps.push_back(stepsArr.get(i).asString().toString());
349358

350-
int defIndex = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
359+
int defIndex = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
360+
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";
351361

352-
form.appendStepSlider("", args[0].asString().toString(), steps, defIndex);
362+
form.appendStepSlider("", args[0].asString().toString(), steps, defIndex, tooltip);
353363
return this->getScriptObject();
354364
}
355365
CATCH("Fail in addStepSlider!")

0 commit comments

Comments
 (0)