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
|
2022-09-14 13:01:10 +08:00
|
|
|
width: 70 + Math.min(7, Math.max(1, handcards.count, equips.count, delayedTricks.count)) * 100
|
|
|
|
height: 50 + (handcards.count > 0 ? 150 : 0) + (equips.count > 0 ? 150 : 0) + (delayedTricks.count > 0 ? 150 : 0)
|
|
|
|
|
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 {
|
|
|
|
id: handcards
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: equips
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: delayedTricks
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: 40
|
|
|
|
anchors.leftMargin: 20
|
|
|
|
anchors.rightMargin: 20
|
|
|
|
anchors.bottomMargin: 20
|
|
|
|
|
|
|
|
Row {
|
|
|
|
height: 130
|
|
|
|
spacing: 15
|
|
|
|
visible: handcards.count > 0
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
border.color: "#A6967A"
|
|
|
|
radius: 5
|
|
|
|
color: "transparent"
|
|
|
|
width: 18
|
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
Text {
|
|
|
|
color: "#E4D5A0"
|
|
|
|
text: Backend.translate("$Hand")
|
|
|
|
anchors.fill: parent
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
spacing: 7
|
|
|
|
Repeater {
|
|
|
|
model: handcards
|
|
|
|
|
|
|
|
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) {
|
|
|
|
origY = origY - 20;
|
|
|
|
root.selected_ids.push(cid);
|
|
|
|
} else {
|
|
|
|
origY = origY + 20;
|
|
|
|
root.selected_ids.splice(root.selected_ids.indexOf(cid), 1);
|
|
|
|
}
|
|
|
|
origX = x;
|
|
|
|
goBack(true);
|
|
|
|
root.selected_ids = root.selected_ids;
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
height: 130
|
|
|
|
spacing: 15
|
|
|
|
visible: equips.count > 0
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
border.color: "#A6967A"
|
|
|
|
radius: 5
|
|
|
|
color: "transparent"
|
|
|
|
width: 18
|
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
Text {
|
|
|
|
color: "#E4D5A0"
|
|
|
|
text: Backend.translate("$Equip")
|
|
|
|
anchors.fill: parent
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
spacing: 7
|
|
|
|
Repeater {
|
|
|
|
model: equips
|
|
|
|
|
|
|
|
CardItem {
|
|
|
|
cid: model.cid
|
|
|
|
name: model.name
|
|
|
|
suit: model.suit
|
|
|
|
number: model.number
|
|
|
|
autoBack: false
|
|
|
|
selectable: true
|
2023-03-01 21:41:16 +08:00
|
|
|
onClicked: {
|
|
|
|
if (!root.multiChoose) {
|
|
|
|
root.cardSelected(cid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSelectedChanged: {
|
|
|
|
if (selected) {
|
|
|
|
origY = origY - 20;
|
|
|
|
root.selected_ids.push(cid);
|
|
|
|
} else {
|
|
|
|
origY = origY + 20;
|
|
|
|
root.selected_ids.splice(root.selected_ids.indexOf(cid));
|
|
|
|
}
|
|
|
|
origX = x;
|
|
|
|
goBack(true);
|
|
|
|
root.selected_ids = root.selected_ids;
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
height: 130
|
|
|
|
spacing: 15
|
|
|
|
visible: delayedTricks.count > 0
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
border.color: "#A6967A"
|
|
|
|
radius: 5
|
|
|
|
color: "transparent"
|
|
|
|
width: 18
|
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
Text {
|
|
|
|
color: "#E4D5A0"
|
|
|
|
text: Backend.translate("$Judge")
|
|
|
|
anchors.fill: parent
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
spacing: 7
|
|
|
|
Repeater {
|
|
|
|
model: delayedTricks
|
|
|
|
|
|
|
|
CardItem {
|
|
|
|
cid: model.cid
|
|
|
|
name: model.name
|
|
|
|
suit: model.suit
|
|
|
|
number: model.number
|
|
|
|
autoBack: false
|
|
|
|
selectable: true
|
2023-03-01 21:41:16 +08:00
|
|
|
onClicked: {
|
|
|
|
if (!root.multiChoose) {
|
|
|
|
root.cardSelected(cid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSelectedChanged: {
|
|
|
|
if (selected) {
|
|
|
|
origY = origY - 20;
|
|
|
|
root.selected_ids.push(cid);
|
|
|
|
} else {
|
|
|
|
origY = origY + 20;
|
|
|
|
root.selected_ids.splice(root.selected_ids.indexOf(cid));
|
|
|
|
}
|
|
|
|
origX = x;
|
|
|
|
goBack(true);
|
|
|
|
root.selected_ids = root.selected_ids;
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 21:41:16 +08:00
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
onCardSelected: finished();
|
|
|
|
|
|
|
|
function addHandcards(cards)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|