2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
2023-05-19 02:08:36 +00:00
|
|
|
import Fk.Pages
|
2023-01-29 10:11:41 +00:00
|
|
|
|
|
|
|
GraphicsBox {
|
|
|
|
id: root
|
2023-06-18 16:20:50 +00:00
|
|
|
property string prompt
|
2023-01-29 10:11:41 +00:00
|
|
|
property var cards: []
|
|
|
|
property var result: []
|
|
|
|
property var areaCapacities: []
|
2023-04-25 11:02:17 +00:00
|
|
|
property var areaLimits: []
|
2023-01-29 10:11:41 +00:00
|
|
|
property var areaNames: []
|
|
|
|
property int padding: 25
|
|
|
|
|
2023-06-18 16:20:50 +00:00
|
|
|
title.text: Backend.translate(prompt !== "" ? prompt : "Please arrange cards")
|
2023-01-29 10:11:41 +00:00
|
|
|
width: body.width + padding * 2
|
|
|
|
height: title.height + body.height + padding * 2
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: body
|
|
|
|
x: padding
|
|
|
|
y: parent.height - padding - height
|
|
|
|
spacing: 20
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: areaRepeater
|
|
|
|
model: areaCapacities
|
|
|
|
|
|
|
|
Row {
|
|
|
|
spacing: 5
|
|
|
|
|
|
|
|
property int areaCapacity: modelData
|
|
|
|
property string areaName: index < areaNames.length ? qsTr(areaNames[index]) : ""
|
|
|
|
|
2023-06-11 08:22:11 +00:00
|
|
|
Rectangle {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
color: "#6B5D42"
|
|
|
|
width: 20
|
|
|
|
height: 100
|
|
|
|
radius: 5
|
|
|
|
|
|
|
|
Text {
|
|
|
|
anchors.fill: parent
|
|
|
|
width: 20
|
|
|
|
height: 100
|
|
|
|
text: areaName
|
|
|
|
color: "white"
|
|
|
|
font.family: fontLibian.name
|
|
|
|
font.pixelSize: 18
|
|
|
|
style: Text.Outline
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
Repeater {
|
|
|
|
id: cardRepeater
|
|
|
|
model: areaCapacity
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
color: "#1D1E19"
|
|
|
|
width: 93
|
|
|
|
height: 130
|
|
|
|
|
|
|
|
Text {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: areaName
|
|
|
|
color: "#59574D"
|
|
|
|
width: parent.width * 0.8
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
property alias cardRepeater: cardRepeater
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2023-04-25 11:02:17 +00:00
|
|
|
id: buttonConfirm
|
2023-01-29 10:11:41 +00:00
|
|
|
text: Backend.translate("OK")
|
|
|
|
width: 120
|
|
|
|
height: 35
|
|
|
|
|
|
|
|
onClicked: close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: cardItem
|
|
|
|
model: cards
|
|
|
|
|
|
|
|
CardItem {
|
|
|
|
x: index
|
|
|
|
y: -1
|
|
|
|
cid: modelData.cid
|
|
|
|
name: modelData.name
|
|
|
|
suit: modelData.suit
|
|
|
|
number: modelData.number
|
2023-11-07 13:14:51 +00:00
|
|
|
mark: modelData.mark
|
2023-01-29 10:11:41 +00:00
|
|
|
draggable: true
|
|
|
|
onReleased: arrangeCards();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function arrangeCards() {
|
|
|
|
result = new Array(areaCapacities.length);
|
|
|
|
let i;
|
2023-04-25 11:02:17 +00:00
|
|
|
for (i = 0; i < result.length; i++){
|
2023-01-29 10:11:41 +00:00
|
|
|
result[i] = [];
|
2023-04-25 11:02:17 +00:00
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
|
|
|
|
let card, j, area, cards, stay;
|
|
|
|
for (i = 0; i < cardItem.count; i++) {
|
|
|
|
card = cardItem.itemAt(i);
|
|
|
|
|
|
|
|
stay = true;
|
|
|
|
for (j = areaRepeater.count - 1; j >= 0; j--) {
|
|
|
|
area = areaRepeater.itemAt(j);
|
|
|
|
cards = result[j];
|
|
|
|
if (cards.length < areaCapacities[j] && card.y >= area.y) {
|
|
|
|
cards.push(card);
|
|
|
|
stay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 11:02:17 +00:00
|
|
|
if (stay) {
|
2023-06-07 05:02:53 +00:00
|
|
|
for (j = 0; j < areaRepeater.count; j++) {
|
|
|
|
if (result[j].length < areaCapacities[j]) {
|
|
|
|
result[j].push(card);
|
|
|
|
break;
|
|
|
|
}
|
2023-04-25 11:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < result.length; i++)
|
|
|
|
result[i].sort((a, b) => a.x - b.x);
|
|
|
|
|
2023-04-25 11:02:17 +00:00
|
|
|
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
let box, pos, pile;
|
|
|
|
for (j = 0; j < areaRepeater.count; j++) {
|
|
|
|
pile = areaRepeater.itemAt(j);
|
2023-04-25 11:02:17 +00:00
|
|
|
if (pile.y === 0){
|
|
|
|
pile.y = j * 150
|
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
for (i = 0; i < result[j].length; i++) {
|
|
|
|
box = pile.cardRepeater.itemAt(i);
|
|
|
|
pos = mapFromItem(pile, box.x, box.y);
|
|
|
|
card = result[j][i];
|
|
|
|
card.origX = pos.x;
|
|
|
|
card.origY = pos.y;
|
|
|
|
card.goBack(true);
|
|
|
|
}
|
|
|
|
}
|
2023-04-25 11:02:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < areaRepeater.count; i++) {
|
|
|
|
if (result[i].length < areaLimits[i]) {
|
|
|
|
buttonConfirm.enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buttonConfirm.enabled = true;
|
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getResult() {
|
2023-06-09 09:23:02 +00:00
|
|
|
const ret = [];
|
2023-01-29 10:11:41 +00:00
|
|
|
result.forEach(t => {
|
2023-06-09 09:23:02 +00:00
|
|
|
const t2 = [];
|
2023-01-29 10:11:41 +00:00
|
|
|
t.forEach(v => t2.push(v.cid));
|
|
|
|
ret.push(t2);
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|