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
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
// CardArea stores CardItem.
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 15:27:56 +08:00
|
|
|
property var cards: []
|
|
|
|
property int length: 0
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
id: root
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
if (inputs instanceof Array) {
|
|
|
|
cards.push(...inputs);
|
|
|
|
} else {
|
|
|
|
cards.push(inputs);
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
length = cards.length;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function remove(outputs)
|
|
|
|
{
|
|
|
|
let result = [];
|
2023-06-24 14:48:49 +08:00
|
|
|
for (let j = 0; j < outputs.length; j++) {
|
|
|
|
for (let i = cards.length - 1; i >= 0; i--) {
|
2022-04-30 15:27:56 +08:00
|
|
|
if (outputs[j] === cards[i].cid) {
|
2024-01-25 03:23:29 +08:00
|
|
|
const state = lcall("GetCardData", cards[i].cid);
|
2023-02-15 21:20:40 +08:00
|
|
|
cards[i].setData(state);
|
2022-04-30 15:27:56 +08:00
|
|
|
result.push(cards[i]);
|
|
|
|
cards.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
break;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
length = cards.length;
|
|
|
|
return result;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
let i, card;
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
let overflow = false;
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX = i * card.width;
|
|
|
|
if (card.origX + card.width >= root.width) {
|
|
|
|
overflow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
card.origY = 0;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (overflow) {
|
|
|
|
// TODO: Adjust cards in multiple lines if there are too many cards
|
2023-06-09 17:23:02 +08:00
|
|
|
const xLimit = root.width - card.width;
|
|
|
|
const spacing = xLimit / (cards.length - 1);
|
2022-04-30 15:27:56 +08:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX = i * spacing;
|
|
|
|
card.origY = 0;
|
2023-07-02 20:39:42 +08:00
|
|
|
card.z = i + 1;
|
|
|
|
card.initialZ = i + 1;
|
|
|
|
card.maxZ = cards.length;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-06-09 17:23:02 +08:00
|
|
|
const parentPos = roomScene.mapFromItem(root, 0, 0);
|
2022-04-30 15:27:56 +08:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX += parentPos.x;
|
|
|
|
card.origY += parentPos.y;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (animated) {
|
|
|
|
for (i = 0; i < cards.length; i++)
|
|
|
|
cards[i].goBack(true);
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|