2022-03-23 11:40:28 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
|
|
Item {
|
|
|
|
property var cards: []
|
|
|
|
property int length: 0
|
|
|
|
property var pendingInput: []
|
|
|
|
property bool checkExisting: false
|
|
|
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
function add(inputs)
|
|
|
|
{
|
2022-03-30 06:14:40 +00:00
|
|
|
let card;
|
2022-03-23 11:40:28 +00:00
|
|
|
if (inputs instanceof Array) {
|
2022-03-30 06:14:40 +00:00
|
|
|
for (let i = 0; i < inputs.length; i++) {
|
2022-03-23 11:40:28 +00:00
|
|
|
card = inputs[i];
|
|
|
|
pendingInput.push(card);
|
|
|
|
cards.push(card.toData());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length += inputs.length;
|
|
|
|
} else {
|
|
|
|
pendingInput.push(inputs);
|
|
|
|
cards.push(inputs.toData());
|
|
|
|
|
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _contains(cid)
|
|
|
|
{
|
|
|
|
if (!checkExisting)
|
|
|
|
return true;
|
|
|
|
|
2022-03-30 06:14:40 +00:00
|
|
|
for (let i = 0; i < cards.length; i++)
|
2022-03-23 11:40:28 +00:00
|
|
|
{
|
|
|
|
if (cards[i].cid === cid)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
2022-03-30 06:14:40 +00:00
|
|
|
let component = Qt.createComponent("CardItem.qml");
|
2022-03-23 11:40:28 +00:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return [];
|
|
|
|
|
2022-03-30 06:14:40 +00:00
|
|
|
let parentPos = roomScene.mapFromItem(root, 0, 0);
|
|
|
|
let card;
|
|
|
|
let items = [];
|
2022-03-23 11:40:28 +00:00
|
|
|
for (let i = 0; i < outputs.length; i++) {
|
|
|
|
if (_contains(outputs[i])) {
|
|
|
|
let state = JSON.parse(Sanguosha.getCard4Qml(outputs[i]))
|
|
|
|
state.x = parentPos.x;
|
|
|
|
state.y = parentPos.y;
|
|
|
|
state.opacity = 0;
|
|
|
|
card = component.createObject(roomScene, state);
|
|
|
|
card.x -= card.width / 2;
|
|
|
|
card.x += (i - outputs.length / 2) * 15;
|
|
|
|
card.y -= card.height / 2;
|
|
|
|
items.push(card);
|
|
|
|
if (checkExisting) {
|
|
|
|
//@to-do: remove it from cards
|
|
|
|
cards.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length -= outputs.length;
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
2022-03-30 06:14:40 +00:00
|
|
|
let i, card;
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
if (animated) {
|
2022-03-30 06:14:40 +00:00
|
|
|
let parentPos = roomScene.mapFromItem(root, 0, 0);
|
2022-03-23 11:40:28 +00:00
|
|
|
for (i = 0; i < pendingInput.length; i++) {
|
|
|
|
card = pendingInput[i];
|
|
|
|
card.origX = parentPos.x - card.width / 2 + ((i - pendingInput.length / 2) * 15);
|
|
|
|
card.origY = parentPos.y - card.height / 2;
|
|
|
|
card.origOpacity = 0;
|
|
|
|
card.destroyOnStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pendingInput.length; i++)
|
|
|
|
pendingInput[i].goBack(true);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < pendingInput.length; i++) {
|
|
|
|
card = pendingInput[i];
|
|
|
|
card.x = parentPos.x - card.width / 2;
|
|
|
|
card.y = parentPos.y - card.height / 2;
|
|
|
|
card.opacity = 1;
|
|
|
|
card.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pendingInput = [];
|
|
|
|
}
|
|
|
|
}
|