2023-04-09 05:35:35 +00:00
|
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-04-04 16:49:54 +00:00
|
|
|
|
-- 主动技/视为技用。
|
|
|
|
|
-- 能创造一个简单的组件供UI使用。
|
|
|
|
|
|
|
|
|
|
-- 前端的应答/修改最终会被保存到xxx.data中。
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 同时,这些应答也会被上传到服务器中。
|
2023-04-04 16:49:54 +00:00
|
|
|
|
|
|
|
|
|
local UI = {}
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- ComboBox: 一个按钮,点击后会显示类似askForChoice的框供选择
|
2023-04-04 16:49:54 +00:00
|
|
|
|
-- 可以赋值的属性有:
|
|
|
|
|
-- * choices: string[] 类型,保存着可选项,会被前端翻译
|
|
|
|
|
-- * default: string,默认的选项,默认为choices的第一个
|
2023-06-15 13:19:57 +00:00
|
|
|
|
-- * detailed: bool,为真的话送详细信息
|
2023-07-16 07:29:20 +00:00
|
|
|
|
-- * all_choices: string[] 类型,保存着所有选项,会被前端翻译
|
2023-04-04 16:49:54 +00:00
|
|
|
|
UI.ComboBox = function(spec)
|
2023-06-16 02:58:28 +00:00
|
|
|
|
-- assert(type(spec.choices) == "table", "Choices is not a table")
|
|
|
|
|
-- assert(#spec.choices > 0, "Choices is empty")
|
|
|
|
|
spec.choices = type(spec.choices) == "table" and spec.choices or Util.DummyTable
|
2023-04-04 16:49:54 +00:00
|
|
|
|
spec.default = spec.default or spec.choices[1]
|
2023-06-20 05:37:03 +00:00
|
|
|
|
spec.detailed = spec.detailed or false
|
2023-07-16 07:29:20 +00:00
|
|
|
|
spec.all_choices = type(spec.all_choices) == "table" and spec.all_choices or spec.choices
|
2023-04-04 16:49:54 +00:00
|
|
|
|
spec.type = "combo"
|
|
|
|
|
return spec
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-29 16:52:39 +00:00
|
|
|
|
-- Spin: 一个能用两侧加减号调整某些数值的组件,见于奇谋等技能
|
|
|
|
|
-- 可以赋值的属性有:
|
|
|
|
|
-- * from: 最小值
|
|
|
|
|
-- * to: 最大值
|
|
|
|
|
-- * default: 默认值 默认为最小的
|
|
|
|
|
UI.Spin = function(spec)
|
|
|
|
|
assert(spec.from <= spec.to)
|
|
|
|
|
spec.type = "spin"
|
|
|
|
|
return spec
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-04 16:49:54 +00:00
|
|
|
|
return UI
|