2023-09-19 06:27:54 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import Fk.Pages
|
|
|
|
|
|
|
|
GraphicsBox {
|
|
|
|
id: root
|
|
|
|
|
2023-11-07 04:57:00 +00:00
|
|
|
title.text: Backend.callLuaFunction("PoxiPrompt", [poxi_type, card_data, extra_data])
|
2023-09-19 06:27:54 +00:00
|
|
|
|
|
|
|
// TODO: Adjust the UI design in case there are more than 7 cards
|
|
|
|
width: 70 + 700
|
2023-10-27 14:19:30 +00:00
|
|
|
height: 64 + Math.min(cardView.contentHeight, 400) + 30
|
2023-09-19 06:27:54 +00:00
|
|
|
|
|
|
|
signal cardSelected(int cid)
|
|
|
|
signal cardsSelected(var ids)
|
|
|
|
property var selected_ids: []
|
|
|
|
property string poxi_type
|
|
|
|
property var card_data
|
2023-10-27 14:19:30 +00:00
|
|
|
property bool cancelable: true
|
|
|
|
property var extra_data
|
2023-09-19 06:27:54 +00:00
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: cardModel
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: cardView
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: 40
|
|
|
|
anchors.leftMargin: 20
|
|
|
|
anchors.rightMargin: 20
|
2023-10-27 14:19:30 +00:00
|
|
|
anchors.bottomMargin: 30
|
2023-09-19 06:27:54 +00:00
|
|
|
spacing: 20
|
|
|
|
model: cardModel
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
delegate: RowLayout {
|
|
|
|
spacing: 15
|
2023-10-27 14:19:30 +00:00
|
|
|
// visible: areaCards.count > 0
|
2023-09-19 06:27:54 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
border.color: "#A6967A"
|
|
|
|
radius: 5
|
|
|
|
color: "transparent"
|
|
|
|
width: 18
|
|
|
|
height: 130
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
|
|
|
|
Text {
|
|
|
|
color: "#E4D5A0"
|
|
|
|
text: Backend.translate(areaName)
|
|
|
|
anchors.fill: parent
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
columns: 7
|
|
|
|
Repeater {
|
|
|
|
model: areaCards
|
|
|
|
|
|
|
|
CardItem {
|
|
|
|
cid: model.cid
|
|
|
|
name: model.name || ""
|
|
|
|
suit: model.suit || ""
|
|
|
|
number: model.number || 0
|
|
|
|
autoBack: false
|
|
|
|
known: model.cid !== -1
|
|
|
|
selectable: {
|
|
|
|
return root.selected_ids.includes(model.cid) || JSON.parse(Backend.callLuaFunction(
|
|
|
|
"PoxiFilter",
|
2023-10-27 14:19:30 +00:00
|
|
|
[root.poxi_type, model.cid, root.selected_ids, root.card_data, root.extra_data]
|
2023-09-19 06:27:54 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
onSelectedChanged: {
|
|
|
|
if (selected) {
|
|
|
|
chosenInBox = true;
|
|
|
|
root.selected_ids.push(cid);
|
|
|
|
} else {
|
|
|
|
chosenInBox = false;
|
|
|
|
root.selected_ids.splice(root.selected_ids.indexOf(cid), 1);
|
|
|
|
}
|
|
|
|
root.selected_ids = root.selected_ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 14:19:30 +00:00
|
|
|
Row {
|
|
|
|
anchors.margins: 8
|
2023-09-19 06:27:54 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2023-10-27 14:19:30 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
spacing: 32
|
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
width: 120
|
|
|
|
height: 35
|
|
|
|
text: Backend.translate("OK")
|
|
|
|
enabled: {
|
|
|
|
return JSON.parse(Backend.callLuaFunction(
|
|
|
|
"PoxiFeasible",
|
|
|
|
[root.poxi_type, root.selected_ids, root.card_data, root.extra_data]
|
|
|
|
));
|
|
|
|
}
|
|
|
|
onClicked: root.cardsSelected(root.selected_ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
width: 120
|
|
|
|
height: 35
|
|
|
|
text: Backend.translate("Cancel")
|
2023-11-07 04:57:00 +00:00
|
|
|
visible: root.cancelable
|
2023-10-27 14:19:30 +00:00
|
|
|
onClicked: root.cardsSelected([])
|
2023-09-19 06:27:54 +00:00
|
|
|
}
|
2023-10-27 14:19:30 +00:00
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
}
|
|
|
|
|
2023-10-27 14:19:30 +00:00
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
onCardSelected: finished();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
ret = {
|
|
|
|
areaName: name,
|
|
|
|
areaCards: [],
|
|
|
|
}
|
|
|
|
cardModel.append(ret);
|
|
|
|
ret = findAreaModel(name);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|