2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
2023-05-19 10:08:36 +08:00
|
|
|
import Fk.Pages
|
2022-09-14 13:01:10 +08:00
|
|
|
|
|
|
|
GraphicsBox {
|
|
|
|
id: root
|
2023-07-16 15:29:20 +08:00
|
|
|
|
|
|
|
title.text: root.multiChoose ? Backend.translate("$ChooseCards").arg(root.min).arg(root.max) : Backend.translate("$ChooseCard")
|
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
// TODO: Adjust the UI design in case there are more than 7 cards
|
2023-08-24 21:37:24 +08:00
|
|
|
width: 70 + 700
|
2023-08-27 21:22:03 +08:00
|
|
|
height: 64 + Math.min(cardView.contentHeight, 400) + (multiChoose ? 20 : 0)
|
2022-09-14 13:01:10 +08:00
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
signal cardSelected(int cid)
|
|
|
|
signal cardsSelected(var ids)
|
|
|
|
property bool multiChoose: false
|
|
|
|
property int min: 0
|
|
|
|
property int max: 1
|
|
|
|
property var selected_ids: []
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
ListModel {
|
2023-08-24 21:37:24 +08:00
|
|
|
id: cardModel
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
ListView {
|
|
|
|
id: cardView
|
2022-09-14 13:01:10 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: 40
|
|
|
|
anchors.leftMargin: 20
|
|
|
|
anchors.rightMargin: 20
|
|
|
|
anchors.bottomMargin: 20
|
2023-08-24 21:37:24 +08:00
|
|
|
spacing: 20
|
|
|
|
model: cardModel
|
|
|
|
clip: true
|
2022-09-14 13:01:10 +08:00
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
delegate: RowLayout {
|
2022-09-14 13:01:10 +08:00
|
|
|
spacing: 15
|
2023-08-24 21:37:24 +08:00
|
|
|
visible: areaCards.count > 0
|
2022-09-14 13:01:10 +08:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
border.color: "#A6967A"
|
|
|
|
radius: 5
|
|
|
|
color: "transparent"
|
|
|
|
width: 18
|
2023-08-24 21:37:24 +08:00
|
|
|
height: 130
|
|
|
|
Layout.alignment: Qt.AlignTop
|
2022-09-14 13:01:10 +08:00
|
|
|
|
|
|
|
Text {
|
|
|
|
color: "#E4D5A0"
|
2023-08-24 21:37:24 +08:00
|
|
|
text: Backend.translate(areaName)
|
2022-09-14 13:01:10 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
GridLayout {
|
|
|
|
columns: 7
|
2022-09-14 13:01:10 +08:00
|
|
|
Repeater {
|
2023-08-24 21:37:24 +08:00
|
|
|
model: areaCards
|
2022-09-14 13:01:10 +08:00
|
|
|
|
|
|
|
CardItem {
|
2023-03-05 01:28:59 +08:00
|
|
|
cid: model.cid
|
|
|
|
name: model.name || ""
|
|
|
|
suit: model.suit || ""
|
|
|
|
number: model.number || 0
|
2022-09-14 13:01:10 +08:00
|
|
|
autoBack: false
|
2023-03-05 01:28:59 +08:00
|
|
|
known: model.cid !== -1
|
2022-09-14 13:01:10 +08:00
|
|
|
selectable: true
|
2023-03-01 21:41:16 +08:00
|
|
|
onClicked: {
|
|
|
|
if (!root.multiChoose) {
|
|
|
|
root.cardSelected(cid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSelectedChanged: {
|
|
|
|
if (selected) {
|
2023-08-24 21:37:24 +08:00
|
|
|
virt_name = "$Selected";
|
2023-08-26 07:37:04 +08:00
|
|
|
root.selected_ids.push(cid);
|
2023-03-01 21:41:16 +08:00
|
|
|
} else {
|
2023-08-24 21:37:24 +08:00
|
|
|
virt_name = "";
|
2023-08-26 07:37:04 +08:00
|
|
|
root.selected_ids.splice(root.selected_ids.indexOf(cid), 1);
|
2023-03-01 21:41:16 +08:00
|
|
|
}
|
|
|
|
root.selected_ids = root.selected_ids;
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
MetroButton {
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
text: Backend.translate("OK")
|
|
|
|
visible: root.multiChoose
|
|
|
|
enabled: root.selected_ids.length <= root.max && root.selected_ids.length >= root.min
|
|
|
|
onClicked: root.cardsSelected(root.selected_ids)
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
onCardSelected: finished();
|
2022-09-14 13:01:10 +08:00
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
function findAreaModel(name) {
|
|
|
|
let ret;
|
|
|
|
for (let i = 0; i < cardModel.count; i++) {
|
|
|
|
let item = cardModel.get(i);
|
|
|
|
if (item.areaName == name) {
|
|
|
|
ret = item;
|
|
|
|
break;
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
if (!ret) {
|
|
|
|
ret = {
|
|
|
|
areaName: name,
|
|
|
|
areaCards: [],
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
cardModel.append(ret);
|
|
|
|
ret = findAreaModel(name);
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
return ret;
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
function addHandcards(cards) {
|
|
|
|
let handcards = findAreaModel('$Hand').areaCards;
|
2022-09-14 13:01:10 +08:00
|
|
|
if (cards instanceof Array) {
|
2023-03-05 01:28:59 +08:00
|
|
|
for (let i = 0; i < cards.length; i++)
|
2022-09-14 13:01:10 +08:00
|
|
|
handcards.append(cards[i]);
|
|
|
|
} else {
|
|
|
|
handcards.append(cards);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addEquips(cards)
|
|
|
|
{
|
2023-08-24 21:37:24 +08:00
|
|
|
let equips = findAreaModel('$Equip').areaCards;
|
2022-09-14 13:01:10 +08:00
|
|
|
if (cards instanceof Array) {
|
2023-03-05 01:28:59 +08:00
|
|
|
for (let i = 0; i < cards.length; i++)
|
2022-09-14 13:01:10 +08:00
|
|
|
equips.append(cards[i]);
|
|
|
|
} else {
|
|
|
|
equips.append(cards);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDelayedTricks(cards)
|
|
|
|
{
|
2023-08-24 21:37:24 +08:00
|
|
|
let delayedTricks = findAreaModel('$Judge').areaCards;
|
2022-09-14 13:01:10 +08:00
|
|
|
if (cards instanceof Array) {
|
2023-03-05 01:28:59 +08:00
|
|
|
for (let i = 0; i < cards.length; i++)
|
2022-09-14 13:01:10 +08:00
|
|
|
delayedTricks.append(cards[i]);
|
|
|
|
} else {
|
|
|
|
delayedTricks.append(cards);
|
|
|
|
}
|
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
function addCustomCards(name, cards) {
|
|
|
|
let area = findAreaModel(name).areaCards;
|
|
|
|
if (cards instanceof Array) {
|
|
|
|
for (let i = 0; i < cards.length; i++)
|
|
|
|
area.append(cards[i]);
|
|
|
|
} else {
|
|
|
|
area.append(cards);
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|