diff --git a/lua/ui-util.lua b/lua/ui-util.lua index dca8cd38..9e51d1db 100644 --- a/lua/ui-util.lua +++ b/lua/ui-util.lua @@ -20,4 +20,15 @@ UI.ComboBox = function(spec) return spec end +-- Spin: 一个能用两侧加减号调整某些数值的组件,见于奇谋等技能 +-- 可以赋值的属性有: +-- * from: 最小值 +-- * to: 最大值 +-- * default: 默认值 默认为最小的 +UI.Spin = function(spec) + assert(spec.from <= spec.to) + spec.type = "spin" + return spec +end + return UI diff --git a/packages/test/init.lua b/packages/test/init.lua index 80b7c558..30358fc6 100644 --- a/packages/test/init.lua +++ b/packages/test/init.lua @@ -71,14 +71,14 @@ local test_active = fk.CreateActiveSkill{ end, card_num = 2, target_filter = function() return true end, - interaction = function()return UI.ComboBox { - choices = Fk.package_names, + interaction = function()return UI.Spin { + --choices = Fk.package_names, + from=2,to=8, -- default = "guanyu", }end, on_use = function(self, room, effect) --room:doSuperLightBox("packages/test/qml/Test.qml") local from = room:getPlayerById(effect.from) - --print(self.interaction.data) local to = room:getPlayerById(effect.tos[1]) -- room:swapSeat(from, to) from:control(to) diff --git a/qml/Pages/Room.qml b/qml/Pages/Room.qml index f0ea10e3..0ffe7bc2 100644 --- a/qml/Pages/Room.qml +++ b/qml/Pages/Room.qml @@ -489,6 +489,13 @@ Item { skillInteraction.item.skill = skill_name; skillInteraction.item.default_choice = data["default"]; skillInteraction.item.choices = data.choices; + skillInteraction.item.clicked(); + break; + case "spin": + skillInteraction.source = "RoomElement/SkillInteraction/SkillSpin.qml"; + skillInteraction.item.skill = skill_name; + skillInteraction.item.from = data.from; + skillInteraction.item.to = data.to; break; default: skillInteraction.source = ""; diff --git a/qml/Pages/RoomElement/SkillInteraction/SkillSpin.qml b/qml/Pages/RoomElement/SkillInteraction/SkillSpin.qml new file mode 100644 index 00000000..6512d4ba --- /dev/null +++ b/qml/Pages/RoomElement/SkillInteraction/SkillSpin.qml @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +import QtQuick +import QtQuick.Controls + +SpinBox { + background: Rectangle { color: "#88EEEEEE" } + property int answer: value + property string skill + // from, to + + onValueChanged: { + Backend.callLuaFunction( + "SetInteractionDataOfSkill", + [skill, JSON.stringify(answer)] + ); + roomScene.dashboard.startPending(skill); + } + +} +