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