2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
// CardArea stores CardItem.
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
property var cards: []
|
|
|
|
property int length: 0
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
if (inputs instanceof Array) {
|
|
|
|
cards.push(...inputs);
|
|
|
|
} else {
|
|
|
|
cards.push(inputs);
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
length = cards.length;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function remove(outputs)
|
|
|
|
{
|
|
|
|
let result = [];
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
for (let j = 0; j < outputs.length; j++) {
|
|
|
|
if (outputs[j] === cards[i].cid) {
|
2023-06-09 09:23:02 +00:00
|
|
|
const state = JSON.parse(Backend.callLuaFunction("GetCardData", [cards[i].cid]));
|
2023-02-15 13:20:40 +00:00
|
|
|
cards[i].setData(state);
|
2022-04-30 07:27:56 +00:00
|
|
|
result.push(cards[i]);
|
|
|
|
cards.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
break;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
length = cards.length;
|
|
|
|
return result;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
let i, card;
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00: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 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (overflow) {
|
|
|
|
// TODO: Adjust cards in multiple lines if there are too many cards
|
2023-06-09 09:23:02 +00:00
|
|
|
const xLimit = root.width - card.width;
|
|
|
|
const spacing = xLimit / (cards.length - 1);
|
2022-04-30 07:27:56 +00:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX = i * spacing;
|
|
|
|
card.origY = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-06-09 09:23:02 +00:00
|
|
|
const parentPos = roomScene.mapFromItem(root, 0, 0);
|
2022-04-30 07:27:56 +00:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX += parentPos.x;
|
|
|
|
card.origY += parentPos.y;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (animated) {
|
|
|
|
for (i = 0; i < cards.length; i++)
|
|
|
|
cards[i].goBack(true);
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|