FreeKill/Fk/RoomElement/HandcardArea.qml
notify d0eb3ba2e3
Dev2 (#323)
- CardItem一律可长按,除了卡牌一览
- Qml Mark在QML中可获得主人的id
- Qml Mark可实现某某视角完全不可见
- 隐藏#开头的pile
- 可自定义interaction了
- LogMessage新增toast成员
- 修复投降杀人bug
2024-02-27 02:28:13 +08:00

138 lines
2.8 KiB
QML

// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import Fk
Item {
property alias cards: cardArea.cards
property alias length: cardArea.length
property var selectedCards: []
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);
}
}
function filterInputCard(card)
{
card.autoBack = true;
card.draggable = true;
card.selectable = false;
card.clicked.connect(adjustCards);
}
function remove(outputs)
{
const result = cardArea.remove(outputs);
let card;
for (let i = 0; i < result.length; i++) {
card = result[i];
card.draggable = false;
card.selectable = false;
card.selectedChanged.disconnect(adjustCards);
card.prohibitReason = "";
}
return result;
}
function enableCards(cardIds)
{
let card, i;
cards.forEach(card => {
card.selectable = cardIds.includes(card.cid);
if (!card.selectable) {
card.selected = false;
unselectCard(card);
}
});
updateCardPosition(true);
}
function updateCardPosition(animated)
{
cardArea.updateCardPosition(false);
cards.forEach(card => {
if (card.selected) {
card.origY -= 20;
}
if (!card.selectable) {
if (config.hideUseless) {
card.origY += 60;
}
}
});
if (animated) {
cards.forEach(card => card.goBack(true));
}
}
function adjustCards()
{
area.updateCardPosition(true);
for (let i = 0; i < cards.length; i++) {
const card = cards[i];
if (card.selected) {
if (!selectedCards.includes(card))
selectCard(card);
} else {
if (selectedCards.includes(card))
unselectCard(card);
}
}
}
function selectCard(card)
{
selectedCards.push(card);
cardSelected(card.cid, true);
}
function unselectCard(card)
{
for (let i = 0; i < selectedCards.length; i++) {
if (selectedCards[i] === card) {
selectedCards.splice(i, 1);
cardSelected(card.cid, false);
break;
}
}
}
function unselectAll(exceptId) {
let card = undefined;
for (let i = 0; i < selectedCards.length; i++) {
if (selectedCards[i].cid !== exceptId) {
selectedCards[i].selected = false;
} else {
card = selectedCards[i];
card.selected = true;
}
}
if (card === undefined) {
selectedCards = [];
} else {
selectedCards = [card];
}
updateCardPosition(true);
}
}