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
|
2023-05-19 10:08:36 +08:00
|
|
|
import Fk
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 15:27:56 +08:00
|
|
|
property alias cards: cardArea.cards
|
|
|
|
property alias length: cardArea.length
|
|
|
|
property var selectedCards: []
|
2024-09-18 23:53:38 +08:00
|
|
|
property var movepos
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
signal cardSelected(int cardId, bool selected)
|
|
|
|
|
|
|
|
id: area
|
|
|
|
|
|
|
|
CardArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
id: cardArea
|
|
|
|
onLengthChanged: area.updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
cardArea.add(inputs);
|
|
|
|
if (inputs instanceof Array) {
|
|
|
|
for (let i = 0; i < inputs.length; i++)
|
|
|
|
filterInputCard(inputs[i]);
|
|
|
|
} else {
|
|
|
|
filterInputCard(inputs);
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterInputCard(card)
|
|
|
|
{
|
|
|
|
card.autoBack = true;
|
2024-09-18 23:53:38 +08:00
|
|
|
card.draggable = lcall("CanSortHandcards", Self.id);
|
2022-04-30 15:27:56 +08:00
|
|
|
card.selectable = false;
|
2024-10-13 10:38:55 +08:00
|
|
|
card.clicked.connect(selectCard);
|
2022-04-30 15:27:56 +08:00
|
|
|
card.clicked.connect(adjustCards);
|
2024-09-18 23:53:38 +08:00
|
|
|
card.released.connect(updateCardReleased);
|
|
|
|
card.xChanged.connect(updateCardDragging);
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
2023-06-09 17:23:02 +08:00
|
|
|
const result = cardArea.remove(outputs);
|
2022-04-30 15:27:56 +08:00
|
|
|
let card;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
card = result[i];
|
|
|
|
card.draggable = false;
|
|
|
|
card.selectable = false;
|
2024-10-25 23:13:05 +08:00
|
|
|
card.clicked.disconnect(selectCard);
|
2022-04-30 15:27:56 +08:00
|
|
|
card.selectedChanged.disconnect(adjustCards);
|
2024-09-18 23:53:38 +08:00
|
|
|
card.released.disconnect(updateCardReleased);
|
|
|
|
card.xChanged.disconnect(updateCardDragging);
|
2023-09-19 14:27:54 +08:00
|
|
|
card.prohibitReason = "";
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
cardArea.updateCardPosition(false);
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-06-24 14:48:49 +08:00
|
|
|
cards.forEach(card => {
|
|
|
|
if (card.selected) {
|
2022-04-30 15:27:56 +08:00
|
|
|
card.origY -= 20;
|
2023-06-24 14:48:49 +08:00
|
|
|
}
|
|
|
|
if (!card.selectable) {
|
|
|
|
if (config.hideUseless) {
|
|
|
|
card.origY += 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (animated) {
|
2023-06-24 14:48:49 +08:00
|
|
|
cards.forEach(card => card.goBack(true));
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
2024-09-18 23:53:38 +08:00
|
|
|
function updateCardDragging()
|
|
|
|
{
|
|
|
|
let _card, c;
|
|
|
|
let index;
|
|
|
|
for (index = 0; index < cards.length; index++) {
|
|
|
|
c = cards[index];
|
|
|
|
if (c.dragging) {
|
|
|
|
_card = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_card) return;
|
|
|
|
_card.goBackAnim.stop();
|
|
|
|
_card.opacity = 0.8
|
|
|
|
|
|
|
|
let card;
|
|
|
|
movepos = null;
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
if (card.dragging) continue;
|
|
|
|
|
|
|
|
if (card.x > _card.x) {
|
|
|
|
movepos = i - (index < i ? 1 : 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (movepos == null) { // 最右
|
|
|
|
movepos = cards.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCardReleased(_card)
|
|
|
|
{
|
|
|
|
let i;
|
|
|
|
if (movepos != null) {
|
|
|
|
i = cards.indexOf(_card);
|
|
|
|
cards.splice(i, 1);
|
|
|
|
cards.splice(movepos, 0, _card);
|
|
|
|
movepos = null;
|
|
|
|
}
|
|
|
|
updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function adjustCards()
|
|
|
|
{
|
|
|
|
area.updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
2024-09-19 00:31:49 +08:00
|
|
|
function selectCard(card) {
|
2024-10-13 10:38:55 +08:00
|
|
|
if (card.selectable) cardSelected(card.cid, card.selected);
|
2024-09-19 00:31:49 +08:00
|
|
|
adjustCards();
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
2024-09-19 00:31:49 +08:00
|
|
|
function enableCards(cardIds)
|
2022-04-30 15:27:56 +08:00
|
|
|
{
|
2024-09-19 00:31:49 +08:00
|
|
|
let card, i;
|
|
|
|
cards.forEach(card => {
|
|
|
|
card.selectable = cardIds.includes(card.cid);
|
|
|
|
if (!card.selectable) {
|
|
|
|
card.selected = false;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2024-09-19 00:31:49 +08:00
|
|
|
});
|
|
|
|
updateCardPosition(true);
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
2024-09-19 00:31:49 +08:00
|
|
|
function unselectAll() {
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
const card = cards[i];
|
|
|
|
card.selected = false;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
updateCardPosition(true);
|
|
|
|
}
|
2024-09-19 00:31:49 +08:00
|
|
|
|
|
|
|
function applyChange(uiUpdate) {
|
|
|
|
uiUpdate["CardItem"]?.forEach(cdata => {
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
const card = cards[i];
|
|
|
|
if (card.cid === cdata.id) {
|
|
|
|
card.selectable = cdata.enabled;
|
|
|
|
card.selected = cdata.selected;
|
|
|
|
updateCardPosition(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-11-09 19:27:41 +08:00
|
|
|
});
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
const card = cards[i];
|
|
|
|
if (!card.selectable) {
|
|
|
|
const reason = lcall("GetCardProhibitReason", card.cid);
|
|
|
|
card.prohibitReason = reason;
|
|
|
|
}
|
|
|
|
}
|
2024-09-19 00:31:49 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|