FreeKill/qml/Pages/RoomElement/ChooseGeneralBox.qml
notify cc271bcdf8 Standard equips (#50)
* support fkp

* get default setting in qml

* correct zixing

* mark

* TODO: parse fkp in c++

* scale the drawer

* free assign

* fix free assign bug

* add submodule for official generals

* generate fkp in cpp code

* use UTF-8 in windows conhost

* use onUse for regular skill

* active skill for fkp

* add fkp function; change data for DMG and Heal

* add cancelable to askForDiscard

* don't let generals naked

* config bg and bgm

* fix exists for win

* bugfix: rewardandpunish

* fkp: vs skill

* room config

* observe

* god_salavation

* fkp: judge

* add read storage permission for android build

* remove submodule fk_official

* remove include/

* use a submodule as include directory

* libgit2

* remove debugging 'downloadNewPack'

* libgit2.dll for Windows

* rewrite system_enum, disable dangerous function

* fix bug in trigger()

* filter skill

* filter judgement card

* add about page for git2

* very basic general detail

* FKP: status skill

* libgit: android test

* libgit: build for android

* 1

* libgit2.dll

* android: load qm file after copy asset

* filter skill: if no filter skill then remove filtered card

* allow warning and critical to show a popup, and fix warnings from QML

* resource: move general audio/image to packages/

* move assets of cards

* FKP: modify

* use sqlite db to manage packages

* packman cli

* packman gui

* use Popup for error dialog

* android full screen note

* fix android ssl problem
2023-02-15 19:54:35 +08:00

183 lines
4.3 KiB
QML

import QtQuick
import ".."
import "../skin-bank.js" as SkinBank
GraphicsBox {
property alias generalList: generalList
// property var generalList: []
property int choiceNum: 1
property var choices: []
property var selectedItem: []
property bool loaded: false
ListModel {
id: generalList
}
id: root
title.text: Backend.translate("$ChooseGeneral").arg(choiceNum)
width: generalArea.width + body.anchors.leftMargin + body.anchors.rightMargin
height: body.implicitHeight + body.anchors.topMargin + body.anchors.bottomMargin
Column {
id: body
anchors.fill: parent
anchors.margins: 40
anchors.bottomMargin: 20
Item {
id: generalArea
width: (generalList.count >= 5 ? Math.ceil(generalList.count / 2) : Math.max(3, generalList.count)) * 97
height: generalList.count >= 5 ? 290 : 150
z: 1
Repeater {
id: generalMagnetList
model: generalList.count
Item {
width: 93
height: 130
x: (index % Math.ceil(generalList.count / (generalList.count >= 5 ? 2 : 1))) * 98 + (generalList.count >= 5 && index > generalList.count / 2 && generalList.count % 2 == 1 ? 50 : 0)
y: generalList.count < 5 ? 0 : (index < generalList.count / 2 ? 0 : 135)
}
}
}
Item {
id: splitLine
width: parent.width - 80
height: 6
anchors.horizontalCenter: parent.horizontalCenter
clip: true
}
Item {
width: parent.width
height: 165
Row {
id: resultArea
anchors.centerIn: parent
spacing: 10
Repeater {
id: resultList
model: choiceNum
Rectangle {
color: "#1D1E19"
radius: 3
width: 93
height: 130
}
}
}
}
Item {
id: buttonArea
width: parent.width
height: 40
MetroButton {
id: fightButton
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
text: Backend.translate("Fight")
width: 120
height: 35
enabled: false
onClicked: close();
}
}
}
Repeater {
id: generalCardList
model: generalList
GeneralCardItem {
name: model.name
selectable: true
draggable: true
onClicked: {
let toSelect = true;
for (let i = 0; i < selectedItem.length; i++) {
if (selectedItem[i] === this) {
toSelect = false;
selectedItem.splice(i, 1);
}
}
if (toSelect && selectedItem.length < choiceNum)
selectedItem.push(this);
updatePosition();
}
onRightClicked: {
if (selectedItem.indexOf(this) === -1 && config.enableFreeAssign)
roomScene.startCheat("RoomElement/Cheat/FreeAssign.qml", { card: this });
}
onReleased: {
if (!isClicked)
arrangeCards();
}
}
}
function arrangeCards()
{
let item, i;
selectedItem = [];
for (i = 0; i < generalList.count; i++) {
item = generalCardList.itemAt(i);
if (item.y > splitLine.y)
selectedItem.push(item);
}
selectedItem.sort((a, b) => a.x - b.x);
if (selectedItem.length > choiceNum)
selectedItem.splice(choiceNum, selectedItem.length - choiceNum);
updatePosition();
}
function updatePosition()
{
choices = [];
let item, magnet, pos, i;
for (i = 0; i < selectedItem.length && i < resultList.count; i++) {
item = selectedItem[i];
choices.push(item.name);
magnet = resultList.itemAt(i);
pos = root.mapFromItem(resultArea, magnet.x, magnet.y);
if (item.origX !== pos.x || item.origY !== item.y) {
item.origX = pos.x;
item.origY = pos.y;
item.goBack(true);
}
}
fightButton.enabled = (choices.length == choiceNum);
for (i = 0; i < generalCardList.count; i++) {
item = generalCardList.itemAt(i);
if (selectedItem.indexOf(item) != -1)
continue;
magnet = generalMagnetList.itemAt(i);
pos = root.mapFromItem(generalMagnetList.parent, magnet.x, magnet.y);
if (item.origX !== pos.x || item.origY !== item.y) {
item.origX = pos.x;
item.origY = pos.y;
item.goBack(true);
}
}
}
}