FreeKill/qml/Pages/RoomElement/SkillArea.qml
notify 9a951fdbfe
Spdx license (#109)
在所有代码中添加了许可证标记头
2023-04-09 13:35:35 +08:00

99 lines
2.1 KiB
QML

// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Layouts
Flickable {
id: root
property alias skill_buttons: skill_buttons
clip: true
contentWidth: panel.width
contentHeight: panel.height
contentX: contentWidth - width
width: Math.min(150, panel.width)
height: Math.min(180, panel.height)
flickableDirection: Flickable.AutoFlickIfNeeded
ListModel {
id: active_skills
}
ListModel {
id: not_active_skills
}
Item {
id: panel
width: Math.max(grid1.width, grid2.width)
height: grid1.height + grid2.height
Grid {
id: grid1
columns: 2
columnSpacing: 2
rowSpacing: 2
Repeater {
id: skill_buttons
model: active_skills
onItemAdded: parent.forceLayout()
SkillButton {
skill: model.skill
type: "active"
enabled: false
orig: model.orig_skill
onPressedChanged: {
if (enabled)
roomScene.activateSkill(orig, pressed);
}
}
}
}
Grid {
id: grid2
anchors.top: grid1.bottom
anchors.topMargin: 2
columns: 3
columnSpacing: 2
rowSpacing: 2
Repeater {
model: not_active_skills
onItemAdded: parent.forceLayout()
SkillButton {
skill: model.skill
orig: model.orig_skill
type: "notactive"
}
}
}
}
function addSkill(skill_name) {
let data = JSON.parse(Backend.callLuaFunction(
"GetSkillData",
[skill_name]
));
if (data.freq === "active") {
active_skills.append(data);
} else {
not_active_skills.append(data);
}
}
function loseSkill(skill_name) {
for (let i = 0; i < active_skills.count; i++) {
let item = active_skills.get(i);
if (item.orig_skill == skill_name) {
active_skills.remove(i);
}
}
for (let i = 0; i < not_active_skills.count; i++) {
let item = not_active_skills.get(i);
if (item.orig_skill == skill_name) {
not_active_skills.remove(i);
}
}
}
}