2022-09-14 13:01:10 +08:00
|
|
|
import QtQuick
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 15:27:56 +08:00
|
|
|
property var discardedCards: []
|
|
|
|
property alias cards: area.cards
|
|
|
|
property bool toVanish: false
|
|
|
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
CardArea {
|
|
|
|
id: area
|
|
|
|
}
|
|
|
|
|
|
|
|
InvisibleCardArea {
|
|
|
|
id: invisibleArea
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: vanishTimer
|
|
|
|
interval: 1500
|
|
|
|
repeat: true
|
|
|
|
running: true
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered: {
|
|
|
|
let i, card;
|
|
|
|
if (toVanish) {
|
|
|
|
for (i = 0; i < discardedCards.length; i++) {
|
|
|
|
card = discardedCards[i];
|
2023-01-29 18:11:41 +08:00
|
|
|
if (card.busy) {
|
|
|
|
discardedCards.splice(i, 1);
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
card.origOpacity = 0;
|
|
|
|
card.goBack(true);
|
|
|
|
card.destroyOnStop()
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
cards = cards.filter((c) => discardedCards.indexOf(c) === -1);
|
2022-04-30 15:27:56 +08:00
|
|
|
updateCardPosition(true);
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
discardedCards = [];
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
if (cards[i].busy)
|
|
|
|
continue;
|
|
|
|
discardedCards.push(cards[i]);
|
|
|
|
}
|
|
|
|
toVanish = false;
|
2022-04-30 15:27:56 +08:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < discardedCards.length; i++) {
|
2023-01-29 18:11:41 +08:00
|
|
|
discardedCards[i].selectable = false;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
toVanish = true
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
area.add(inputs);
|
|
|
|
// if (!inputs instanceof Array)
|
|
|
|
for (let i = 0; i < inputs.length; i++) {
|
2023-01-29 18:11:41 +08:00
|
|
|
let c = inputs[i];
|
|
|
|
c.footnoteVisible = true;
|
|
|
|
c.selectable = true;
|
|
|
|
c.height = c.height * 0.8;
|
|
|
|
c.width = c.width * 0.8;
|
|
|
|
c.rotation = (Math.random() - 0.5) * 5;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
|
|
|
let i, j;
|
|
|
|
|
|
|
|
let result = area.remove(outputs);
|
2023-01-29 18:11:41 +08:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
let c = result[i];
|
|
|
|
c.footnoteVisible = false;
|
|
|
|
c.selectable = false;
|
|
|
|
c.height = c.height / 0.8;
|
|
|
|
c.width = c.width / 0.8;
|
|
|
|
c.rotation = 0;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
let vanished = [];
|
|
|
|
if (result.length < outputs.length) {
|
|
|
|
for (i = 0; i < outputs.length; i++) {
|
|
|
|
let exists = false;
|
|
|
|
for (j = 0; j < result.length; j++) {
|
|
|
|
if (result[j].cid === outputs[i]) {
|
|
|
|
exists = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
if (!exists)
|
|
|
|
vanished.push(outputs[i]);
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
result = result.concat(invisibleArea.remove(vanished));
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
for (i = 0; i < result.length; i++) {
|
|
|
|
for (j = 0; j < discardedCards.length; j++) {
|
|
|
|
if (result[i].cid === discardedCards[j].cid) {
|
|
|
|
discardedCards.splice(j, 1);
|
|
|
|
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
|
|
|
updateCardPosition(true);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
if (cards.length <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let i, card;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
//@to-do: Adjust cards in multiple lines if there are too many cards
|
|
|
|
let xLimit = root.width - card.width;
|
|
|
|
let spacing = xLimit / (cards.length - 1);
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX = i * spacing;
|
|
|
|
card.origY = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
let offsetX = Math.max(0, (root.width - cards.length * card.width) / 2);
|
|
|
|
let parentPos = roomScene.mapFromItem(root, 0, 0);
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.origX += parentPos.x + offsetX;
|
|
|
|
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
|
|
|
}
|