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
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import Qt5Compat.GraphicalEffects
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
RowLayout {
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
property var self
|
2022-04-30 07:27:56 +00:00
|
|
|
property alias handcardArea: handcardAreaItem
|
|
|
|
|
|
|
|
property string pending_skill: ""
|
|
|
|
property var pending_card
|
|
|
|
property var pendings: [] // int[], store cid
|
|
|
|
property int selected_card: -1
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
property alias skillButtons: skillPanel.skill_buttons
|
|
|
|
|
|
|
|
property var expanded_piles: ({}) // name -> int[]
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
signal cardSelected(var card)
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
Item { width: 5 }
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
HandcardArea {
|
|
|
|
id: handcardAreaItem
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 130
|
2022-09-14 05:01:10 +00:00
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
Layout.bottomMargin: 24
|
|
|
|
onWidthChanged: updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkillArea {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.maximumWidth: width
|
|
|
|
Layout.maximumHeight: height
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
Layout.bottomMargin: 32
|
|
|
|
Layout.rightMargin: -16
|
|
|
|
id: skillPanel
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
Item {
|
|
|
|
width: 175
|
|
|
|
height: 233
|
2022-09-14 05:01:10 +00:00
|
|
|
Layout.rightMargin: -175 / 8 + (roomArea.width - 175 * 0.75 * 7) / 8
|
2023-04-27 06:15:08 +00:00
|
|
|
// handcards: handcardAreaItem.length
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: handcardAreaItem
|
|
|
|
function onCardSelected(cardId, selected) {
|
|
|
|
dashboard.selectCard(cardId, selected);
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2023-04-27 06:15:08 +00:00
|
|
|
function onLengthChanged() {
|
|
|
|
self.handcards = handcardAreaItem.length;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disableAllCards() {
|
|
|
|
handcardAreaItem.enableCards([]);
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function unSelectAll(expectId) {
|
|
|
|
handcardAreaItem.unselectAll(expectId);
|
|
|
|
}
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
function expandPile(pile) {
|
|
|
|
let expanded_pile_names = Object.keys(expanded_piles);
|
|
|
|
if (expanded_pile_names.indexOf(pile) !== -1)
|
|
|
|
return;
|
|
|
|
|
2023-05-20 08:00:03 +00:00
|
|
|
let component = Qt.createComponent("../RoomElement/CardItem.qml");
|
2023-04-27 06:15:08 +00:00
|
|
|
let parentPos = roomScene.mapFromItem(self, 0, 0);
|
2022-09-14 05:01:10 +00:00
|
|
|
|
|
|
|
expanded_piles[pile] = [];
|
|
|
|
if (pile === "_equip") {
|
2023-04-27 06:15:08 +00:00
|
|
|
let equips = self.equipArea.getAllCards();
|
2022-09-14 05:01:10 +00:00
|
|
|
equips.forEach(data => {
|
|
|
|
data.x = parentPos.x;
|
|
|
|
data.y = parentPos.y;
|
|
|
|
let card = component.createObject(roomScene, data);
|
2023-01-29 10:11:41 +00:00
|
|
|
card.footnoteVisible = true;
|
|
|
|
card.footnote = Backend.translate("$Equip");
|
2022-09-14 05:01:10 +00:00
|
|
|
handcardAreaItem.add(card);
|
|
|
|
})
|
|
|
|
handcardAreaItem.updateCardPosition();
|
2023-03-04 17:28:59 +00:00
|
|
|
} else {
|
2023-04-27 06:15:08 +00:00
|
|
|
let ids = JSON.parse(Backend.callLuaFunction("GetPile", [self.playerid, pile]));
|
2023-03-04 17:28:59 +00:00
|
|
|
ids.forEach(id => {
|
|
|
|
let data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
data.x = parentPos.x;
|
|
|
|
data.y = parentPos.y;
|
|
|
|
let card = component.createObject(roomScene, data);
|
|
|
|
card.footnoteVisible = true;
|
|
|
|
card.footnote = Backend.translate(pile);
|
|
|
|
handcardAreaItem.add(card);
|
|
|
|
});
|
|
|
|
handcardAreaItem.updateCardPosition();
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function retractPile(pile) {
|
|
|
|
let expanded_pile_names = Object.keys(expanded_piles);
|
|
|
|
if (expanded_pile_names.indexOf(pile) === -1)
|
|
|
|
return;
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
let parentPos = roomScene.mapFromItem(self, 0, 0);
|
2022-09-14 05:01:10 +00:00
|
|
|
|
|
|
|
delete expanded_piles[pile];
|
|
|
|
if (pile === "_equip") {
|
2023-04-27 06:15:08 +00:00
|
|
|
let equips = self.equipArea.getAllCards();
|
2022-09-14 05:01:10 +00:00
|
|
|
equips.forEach(data => {
|
|
|
|
let card = handcardAreaItem.remove([data.cid])[0];
|
|
|
|
card.origX = parentPos.x;
|
|
|
|
card.origY = parentPos.y;
|
|
|
|
card.destroyOnStop();
|
|
|
|
card.goBack(true);
|
|
|
|
})
|
|
|
|
handcardAreaItem.updateCardPosition();
|
2023-03-04 17:28:59 +00:00
|
|
|
} else {
|
2023-04-27 06:15:08 +00:00
|
|
|
let ids = JSON.parse(Backend.callLuaFunction("GetPile", [self.playerid, pile]));
|
2023-03-04 17:28:59 +00:00
|
|
|
ids.forEach(id => {
|
|
|
|
let card = handcardAreaItem.remove([id])[0];
|
|
|
|
card.origX = parentPos.x;
|
|
|
|
card.origY = parentPos.y;
|
|
|
|
card.destroyOnStop();
|
|
|
|
card.goBack(true);
|
|
|
|
});
|
|
|
|
handcardAreaItem.updateCardPosition();
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
function retractAllPiles() {
|
|
|
|
for (let key in expanded_piles) {
|
|
|
|
retractPile(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
// If cname is set, we are responding card.
|
|
|
|
function enableCards(cname) {
|
2023-04-10 07:55:06 +00:00
|
|
|
const cardValid = (cid, cname) => {
|
|
|
|
let ret = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFitPattern", [cid, cname]));
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
if (roomScene.respond_play) {
|
|
|
|
ret = ret && !JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardProhibitedResponse", [cid]));
|
|
|
|
} else {
|
|
|
|
ret = ret && !JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardProhibitedUse", [cid]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
if (cname) {
|
|
|
|
let ids = [], cards = handcardAreaItem.cards;
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
2023-04-10 07:55:06 +00:00
|
|
|
if (cardValid(cards[i].cid, cname)) {
|
2022-12-18 13:19:35 +00:00
|
|
|
ids.push(cards[i].cid);
|
2023-04-10 07:55:06 +00:00
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
}
|
2023-04-27 06:15:08 +00:00
|
|
|
cards = self.equipArea.getAllCards();
|
2023-01-29 10:11:41 +00:00
|
|
|
cards.forEach(c => {
|
2023-04-10 07:55:06 +00:00
|
|
|
if (cardValid(c.cid, cname)) {
|
2023-01-29 10:11:41 +00:00
|
|
|
ids.push(c.cid);
|
|
|
|
if (!expanded_piles["_equip"]) {
|
|
|
|
expandPile("_equip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-07 02:21:56 +00:00
|
|
|
// Must manually analyze pattern here
|
|
|
|
let pile_list = cname.split("|")[4];
|
2023-04-27 06:15:08 +00:00
|
|
|
let pile_data = JSON.parse(Backend.callLuaFunction("GetAllPiles", [self.playerid]));
|
2023-03-07 02:21:56 +00:00
|
|
|
if (pile_list && pile_list !== "." && !(pile_data instanceof Array)) {
|
|
|
|
pile_list = pile_list.split(",");
|
|
|
|
for (let pile_name of pile_list) {
|
|
|
|
pile_data[pile_name] && pile_data[pile_name].forEach(cid => {
|
2023-04-10 07:55:06 +00:00
|
|
|
if (cardValid(cid, cname)) {
|
2023-03-04 17:28:59 +00:00
|
|
|
ids.push(cid);
|
|
|
|
if (!expanded_piles[pile_name]) {
|
|
|
|
expandPile(pile_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
handcardAreaItem.enableCards(ids);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-07 02:21:56 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
let ids = [], cards = handcardAreaItem.cards;
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
2023-05-28 04:22:43 +00:00
|
|
|
if (JSON.parse(Backend.callLuaFunction("CanUseCard", [cards[i].cid, Self.id]))) {
|
2022-04-30 07:27:56 +00:00
|
|
|
ids.push(cards[i].cid);
|
2023-05-28 04:22:43 +00:00
|
|
|
} else {
|
|
|
|
// cannot use? considering special_skills
|
|
|
|
let skills = JSON.parse(Backend.callLuaFunction("GetCardSpecialSkills", [cards[i].cid]));
|
|
|
|
for (let j = 0; j < skills.length; j++) {
|
|
|
|
let s = skills[j];
|
|
|
|
if (JSON.parse(Backend.callLuaFunction("ActiveCanUse", [s]))) {
|
|
|
|
ids.push(cards[i].cid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
handcardAreaItem.enableCards(ids)
|
2022-09-14 05:01:10 +00:00
|
|
|
if (pending_skill === "") {
|
|
|
|
cancelButton.enabled = false;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectCard(cardId, selected) {
|
|
|
|
if (pending_skill !== "") {
|
|
|
|
if (selected) {
|
|
|
|
pendings.push(cardId);
|
|
|
|
} else {
|
|
|
|
pendings.splice(pendings.indexOf(cardId), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePending();
|
|
|
|
} else {
|
|
|
|
if (selected) {
|
|
|
|
handcardAreaItem.unselectAll(cardId);
|
|
|
|
selected_card = cardId;
|
|
|
|
} else {
|
|
|
|
handcardAreaItem.unselectAll();
|
|
|
|
selected_card = -1;
|
|
|
|
}
|
|
|
|
cardSelected(selected_card);
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedCard() {
|
|
|
|
if (pending_skill !== "") {
|
|
|
|
return JSON.stringify({
|
|
|
|
skill: pending_skill,
|
|
|
|
subcards: pendings
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return selected_card;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePending() {
|
|
|
|
if (pending_skill === "") return;
|
|
|
|
|
|
|
|
let enabled_cards = [];
|
2022-09-14 05:01:10 +00:00
|
|
|
let targets = roomScene.selected_targets;
|
2022-04-30 07:27:56 +00:00
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
handcardAreaItem.cards.forEach((card) => {
|
|
|
|
if (card.selected || JSON.parse(Backend.callLuaFunction(
|
|
|
|
"ActiveCardFilter",
|
|
|
|
[pending_skill, card.cid, pendings, targets]
|
|
|
|
)))
|
2022-04-30 07:27:56 +00:00
|
|
|
enabled_cards.push(card.cid);
|
|
|
|
});
|
2023-01-29 10:11:41 +00:00
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
let cards = self.equipArea.getAllCards();
|
2023-01-29 10:11:41 +00:00
|
|
|
cards.forEach(c => {
|
|
|
|
if (JSON.parse(Backend.callLuaFunction(
|
|
|
|
"ActiveCardFilter",
|
|
|
|
[pending_skill, c.cid, pendings, targets]
|
|
|
|
))) {
|
|
|
|
enabled_cards.push(c.cid);
|
|
|
|
if (!expanded_piles["_equip"]) {
|
|
|
|
expandPile("_equip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2023-03-04 17:28:59 +00:00
|
|
|
|
2023-03-07 02:21:56 +00:00
|
|
|
let pile = Backend.callLuaFunction("GetExpandPileOfSkill", [pending_skill]);
|
2023-04-27 06:15:08 +00:00
|
|
|
let pile_ids = JSON.parse(Backend.callLuaFunction("GetPile", [self.playerid, pile]));
|
2023-03-07 02:21:56 +00:00
|
|
|
pile_ids.forEach(cid => {
|
|
|
|
if (JSON.parse(Backend.callLuaFunction(
|
|
|
|
"ActiveCardFilter",
|
|
|
|
[pending_skill, cid, pendings, targets]
|
|
|
|
))) {
|
|
|
|
enabled_cards.push(cid);
|
2023-04-04 08:25:37 +00:00
|
|
|
if (!expanded_piles[pile]) {
|
|
|
|
expandPile(pile);
|
2023-03-07 02:21:56 +00:00
|
|
|
}
|
2023-03-04 17:28:59 +00:00
|
|
|
}
|
2023-03-07 02:21:56 +00:00
|
|
|
});
|
2023-03-04 17:28:59 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
handcardAreaItem.enableCards(enabled_cards);
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
if (JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CanViewAs",
|
|
|
|
[pending_skill, pendings]
|
|
|
|
))) {
|
2022-04-30 07:27:56 +00:00
|
|
|
pending_card = {
|
|
|
|
skill: pending_skill,
|
|
|
|
subcards: pendings
|
|
|
|
};
|
|
|
|
cardSelected(JSON.stringify(pending_card));
|
|
|
|
} else {
|
|
|
|
pending_card = -1;
|
|
|
|
cardSelected(pending_card);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function startPending(skill_name) {
|
|
|
|
pending_skill = skill_name;
|
|
|
|
pendings = [];
|
|
|
|
handcardAreaItem.unselectAll();
|
2022-09-15 03:17:13 +00:00
|
|
|
for (let i = 0; i < skillButtons.count; i++) {
|
|
|
|
let item = skillButtons.itemAt(i);
|
|
|
|
item.enabled = item.pressed;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
updatePending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deactivateSkillButton() {
|
2022-09-14 05:01:10 +00:00
|
|
|
for (let i = 0; i < skillButtons.count; i++) {
|
|
|
|
skillButtons.itemAt(i).pressed = false;
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopPending() {
|
|
|
|
pending_skill = "";
|
|
|
|
pending_card = -1;
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
retractAllPiles();
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
pendings = [];
|
|
|
|
handcardAreaItem.adjustCards();
|
2022-09-14 05:01:10 +00:00
|
|
|
handcardAreaItem.unselectAll();
|
2022-04-30 07:27:56 +00:00
|
|
|
cardSelected(-1);
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
|
2023-04-23 13:10:07 +00:00
|
|
|
function addSkill(skill_name, prelight) {
|
|
|
|
skillPanel.addSkill(skill_name, prelight);
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 13:10:07 +00:00
|
|
|
function loseSkill(skill_name, prelight) {
|
|
|
|
skillPanel.loseSkill(skill_name, prelight);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prelightSkill(skill_name, prelight) {
|
|
|
|
let btns = skillPanel.prelight_buttons;
|
|
|
|
for (let i = 0; i < btns.count; i++) {
|
|
|
|
let btn = btns.itemAt(i);
|
|
|
|
if (btn.orig === skill_name) {
|
|
|
|
btn.prelighted = prelight;
|
|
|
|
btn.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-30 10:55:59 +00:00
|
|
|
function enableSkills(cname, cardResponsing) {
|
2022-12-18 13:19:35 +00:00
|
|
|
if (cname) {
|
2023-01-29 10:11:41 +00:00
|
|
|
// if cname is presented, we are responding use or play.
|
2023-01-16 11:13:07 +00:00
|
|
|
for (let i = 0; i < skillButtons.count; i++) {
|
|
|
|
let item = skillButtons.itemAt(i);
|
2023-01-29 10:11:41 +00:00
|
|
|
let fitpattern = JSON.parse(Backend.callLuaFunction("SkillFitPattern", [item.orig, cname]));
|
2023-04-30 10:55:59 +00:00
|
|
|
let canresp = JSON.parse(Backend.callLuaFunction("SkillCanResponse", [item.orig, cardResponsing]));
|
2023-01-29 10:11:41 +00:00
|
|
|
item.enabled = fitpattern && canresp;
|
2023-01-16 11:13:07 +00:00
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
for (let i = 0; i < skillButtons.count; i++) {
|
|
|
|
let item = skillButtons.itemAt(i);
|
|
|
|
item.enabled = JSON.parse(Backend.callLuaFunction("ActiveCanUse", [item.orig]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableSkills() {
|
|
|
|
for (let i = 0; i < skillButtons.count; i++)
|
|
|
|
skillButtons.itemAt(i).enabled = false;
|
|
|
|
}
|
2022-12-20 04:51:54 +00:00
|
|
|
|
|
|
|
function tremble() {
|
2023-04-27 06:15:08 +00:00
|
|
|
self.tremble();
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
unSelectAll();
|
|
|
|
disableSkills();
|
|
|
|
|
|
|
|
let cards = handcardAreaItem.cards;
|
|
|
|
let toRemove = [];
|
|
|
|
for (let c of cards) {
|
|
|
|
toRemove.push(c.cid);
|
|
|
|
c.origY += 30;
|
|
|
|
c.origOpacity = 0
|
|
|
|
c.goBack(true);
|
|
|
|
c.destroyOnStop();
|
|
|
|
}
|
|
|
|
handcardAreaItem.remove(toRemove);
|
|
|
|
|
|
|
|
skillPanel.clearSkills();
|
|
|
|
|
|
|
|
let skills = JSON.parse(Backend.callLuaFunction("GetPlayerSkills", [Self.id]));
|
|
|
|
for (let s of skills) {
|
|
|
|
addSkill(s.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
cards = roomScene.drawPile.remove(JSON.parse(Backend.callLuaFunction("GetPlayerHandcards", [Self.id])));
|
|
|
|
handcardAreaItem.add(cards);
|
2022-12-20 04:51:54 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|