UI rewrite (#367)
Some checks failed
Check Whitespace and New Line / check (push) Has been cancelled
Deploy Sphinx documentation to Pages / pages (push) Has been cancelled

TODOS
========

手气卡、重铸、本轮跳过无懈
----------

禁用理由、Target脸上提示(可烈弓)
----------

**修bug**

---------

Co-authored-by: YoumuKon <38815081+YoumuKon@users.noreply.github.com>
This commit is contained in:
notify 2024-09-19 00:31:49 +08:00 committed by GitHub
parent 7b66e304ff
commit fa8335a330
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 304 additions and 612 deletions

View File

@ -308,90 +308,47 @@ Item {
} }
states: [ states: [
State { name: "notactive" }, // Normal status State { name: "notactive" },
State { name: "playing" }, // Playing cards in playing phase State { name: "active" }
State { name: "responding" }, // all requests need to operate dashboard
State { name: "replying" } // requests only operate a popup window
] ]
state: "notactive" state: "notactive"
transitions: [ transitions: [
Transition { Transition {
from: "*"; to: "notactive" from: "active"; to: "notactive"
ScriptAction { ScriptAction {
script: { script: {
skillInteraction.sourceComponent = undefined; skillInteraction.sourceComponent = undefined;
promptText = ""; promptText = "";
currentPrompt = "";
progress.visible = false; progress.visible = false;
okCancel.visible = false; okCancel.visible = false;
endPhaseButton.visible = false; endPhaseButton.visible = false;
respond_play = false; progress.visible = false;
extra_data = {};
mainWindow.pending_message = [];
mainWindow.is_pending = false;
if (dashboard.pending_skill !== "")
dashboard.stopPending();
dashboard.updateHandcards();
dashboard.disableAllCards(); dashboard.disableAllCards();
dashboard.disableSkills(); dashboard.disableSkills();
dashboard.retractAllPiles(); // dashboard.retractAllPiles();
selected_targets = [];
autoPending = false; for (let i = 0; i < photoModel.count; i++) {
const item = photos.itemAt(i);
item.state = "normal";
item.selected = false;
// item.selectable = false;
}
if (popupBox.item != null) { if (popupBox.item != null) {
popupBox.item.finished(); popupBox.item.finished();
} }
lcall("FinishRequestUI");
} }
} }
}, },
Transition { Transition {
from: "*"; to: "playing" from: "notactive"; to: "active"
ScriptAction { ScriptAction {
script: { script: {
skillInteraction.sourceComponent = undefined;
dashboard.updateHandcards();
dashboard.enableCards();
dashboard.enableSkills();
progress.visible = true; progress.visible = true;
okCancel.visible = true;
autoPending = false;
endPhaseButton.visible = true;
respond_play = false;
}
}
},
Transition {
from: "*"; to: "responding"
ScriptAction {
script: {
skillInteraction.sourceComponent = undefined;
dashboard.updateHandcards();
dashboard.enableCards(responding_card);
dashboard.enableSkills(responding_card, respond_play);
autoPending = false;
progress.visible = true;
okCancel.visible = true;
}
}
},
Transition {
from: "*"; to: "replying"
ScriptAction {
script: {
skillInteraction.sourceComponent = undefined;
dashboard.updateHandcards();
dashboard.disableAllCards();
dashboard.disableSkills();
progress.visible = true;
respond_play = false;
autoPending = false;
roomScene.okCancel.visible = false;
roomScene.okButton.enabled = false;
roomScene.cancelButton.enabled = false;
} }
} }
} }
@ -445,7 +402,8 @@ Item {
sealedSlots: JSON.parse(model.sealedSlots) sealedSlots: JSON.parse(model.sealedSlots)
onSelectedChanged: { onSelectedChanged: {
Logic.updateSelectedTargets(playerid, selected); // Logic.updateSelectedTargets(playerid, selected);
if ( state === "candidate" ) lcall("UpdateRequestUI", "Photo", playerid, "click", { selected } );
} }
Component.onCompleted: { Component.onCompleted: {
@ -796,7 +754,6 @@ Item {
Loader { Loader {
id: skillInteraction id: skillInteraction
visible: dashboard.pending_skill !== ""
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 8 anchors.bottomMargin: 8
anchors.right: okCancel.left anchors.right: okCancel.left
@ -817,20 +774,20 @@ Item {
&& !skippedUseEventId.find(id => id === extra_data.useEventId) && !skippedUseEventId.find(id => id === extra_data.useEventId)
onClicked: { onClicked: {
skippedUseEventId.push(extra_data.useEventId); skippedUseEventId.push(extra_data.useEventId);
Logic.doCancelButton(); // Logic.doCancelButton();
} }
} }
Button { Button {
id: okButton id: okButton
text: luatr("OK") text: luatr("OK")
onClicked: Logic.doOkButton(); onClicked: lcall("UpdateRequestUI", "Button", "OK");
} }
Button { Button {
id: cancelButton id: cancelButton
text: luatr("Cancel") text: luatr("Cancel")
onClicked: Logic.doCancelButton(); onClicked: lcall("UpdateRequestUI", "Button", "Cancel");
} }
} }
@ -842,7 +799,7 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 30 anchors.rightMargin: 30
visible: false; visible: false;
onClicked: Logic.replyToServer(""); onClicked: lcall("UpdateRequestUI", "Button", "End");
} }
} }
@ -897,53 +854,8 @@ Item {
z: 999 z: 999
} }
function activateSkill(skill_name, pressed) { function activateSkill(skill_name, selected) {
if (pressed) { lcall("UpdateRequestUI", "SkillButton", skill_name, "click", { selected } );
const data = lcall("GetInteractionOfSkill", skill_name);
if (data) {
lcall("SetInteractionDataOfSkill", skill_name, "null");
switch (data.type) {
case "combo":
skillInteraction.sourceComponent =
Qt.createComponent("../SkillInteraction/SkillCombo.qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.default_choice = data["default"];
skillInteraction.item.choices = data.choices;
skillInteraction.item.detailed = data.detailed;
skillInteraction.item.all_choices = data.all_choices;
skillInteraction.item.clicked();
break;
case "spin":
skillInteraction.sourceComponent =
Qt.createComponent("../SkillInteraction/SkillSpin.qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.from = data.from;
skillInteraction.item.to = data.to;
skillInteraction.item.clicked();
break;
case "custom":
skillInteraction.sourceComponent =
Qt.createComponent(AppPath + "/" + data.qml_path + ".qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.extra_data = data;
skillInteraction.item.clicked();
break;
default:
skillInteraction.sourceComponent = undefined;
break;
}
} else {
skillInteraction.sourceComponent = undefined;
}
dashboard.startPending(skill_name);
cancelButton.enabled = true;
} else {
skillInteraction.sourceComponent = undefined;
if (roomScene.popupBox.item)
roomScene.popupBox.item.close();
Logic.doCancelButton();
}
} }
Drawer { Drawer {
@ -1182,14 +1094,14 @@ Item {
Shortcut { Shortcut {
sequence: "Return" sequence: "Return"
enabled: okButton.enabled enabled: okButton.enabled
onActivated: Logic.doOkButton(); onActivated: lcall("UpdateRequestUI", "Button", "OK");
} }
Shortcut { Shortcut {
sequence: "Space" sequence: "Space"
enabled: cancelButton.enabled || endPhaseButton.visible; enabled: cancelButton.enabled || endPhaseButton.visible;
onActivated: if (cancelButton.enabled) { onActivated: if (cancelButton.enabled) {
Logic.doCancelButton(); lcall("UpdateRequestUI", "Button", "Cancel");
} else { } else {
Logic.replyToServer(""); Logic.replyToServer("");
} }
@ -1423,8 +1335,75 @@ Item {
}); });
} }
function getPhoto(id) { function applyChange(uiUpdate) {
return Logic.getPhoto(id); //console.log(JSON.stringify(uiUpdate))
uiUpdate["_delete"]?.forEach(data => {
if (data.type == "Interaction") {
skillInteraction.sourceComponent = undefined;
if (roomScene.popupBox.item)
roomScene.popupBox.item.close();
}
});
uiUpdate["_new"]?.forEach(dat => {
if (dat.type == "Interaction") {
const data = dat.data.spec;
const skill_name = dat.data.skill_name;
switch (data.type) {
case "combo":
skillInteraction.sourceComponent =
Qt.createComponent("../SkillInteraction/SkillCombo.qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.default_choice = data["default"];
skillInteraction.item.choices = data.choices;
skillInteraction.item.detailed = data.detailed;
skillInteraction.item.all_choices = data.all_choices;
skillInteraction.item.clicked();
break;
case "spin":
skillInteraction.sourceComponent =
Qt.createComponent("../SkillInteraction/SkillSpin.qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.from = data.from;
skillInteraction.item.to = data.to;
skillInteraction.item?.clicked();
break;
case "custom":
skillInteraction.sourceComponent =
Qt.createComponent(AppPath + "/" + data.qml_path + ".qml");
skillInteraction.item.skill = skill_name;
skillInteraction.item.extra_data = data;
skillInteraction.item?.clicked();
break;
default:
skillInteraction.sourceComponent = undefined;
break;
}
}
});
dashboard.applyChange(uiUpdate);
const pdatas = uiUpdate["Photo"];
pdatas?.forEach(pdata => {
const photo = Logic.getPhoto(pdata.id);
photo.state = pdata.state;
photo.selectable = pdata.enabled;
photo.selected = pdata.selected;
})
const buttons = uiUpdate["Button"];
buttons?.forEach(bdata => {
switch (bdata.id) {
case "OK":
okButton.enabled = bdata.enabled;
break;
case "Cancel":
cancelButton.enabled = bdata.enabled;
break;
case "End":
endPhaseButton.enabled = bdata.enabled;
endPhaseButton.visible = bdata.enabled;
break;
}
})
} }
Component.onCompleted: { Component.onCompleted: {

View File

@ -134,76 +134,76 @@ function arrangePhotos() {
} }
} }
function doOkButton() { // function doOkButton() {
if (roomScene.state === "playing" || roomScene.state === "responding") { // if (roomScene.state === "playing" || roomScene.state === "responding") {
const reply = JSON.stringify({ // const reply = JSON.stringify({
card: dashboard.getSelectedCard(), // card: dashboard.getSelectedCard(),
targets: selected_targets, // targets: selected_targets,
special_skill: roomScene.getCurrentCardUseMethod(), // special_skill: roomScene.getCurrentCardUseMethod(),
interaction_data: roomScene.skillInteraction.item ? // interaction_data: roomScene.skillInteraction.item ?
roomScene.skillInteraction.item.answer : undefined, // roomScene.skillInteraction.item.answer : undefined,
}); // });
replyToServer(reply); // replyToServer(reply);
return; // return;
} // }
if (roomScene.extra_data.luckCard) { // if (roomScene.extra_data.luckCard) {
okButton.enabled = false; // okButton.enabled = false;
ClientInstance.notifyServer("PushRequest", [ // ClientInstance.notifyServer("PushRequest", [
"luckcard", true // "luckcard", true
].join(",")); // ].join(","));
if (roomScene.extra_data.time === 1) { // if (roomScene.extra_data.time === 1) {
roomScene.state = "notactive"; // roomScene.state = "notactive";
} // }
return; // return;
} // }
replyToServer("1"); // replyToServer("1");
} // }
let _is_canceling = false; // let _is_canceling = false;
function doCancelButton() { // function doCancelButton() {
if (_is_canceling) return; // if (_is_canceling) return;
_is_canceling = true; // _is_canceling = true;
if (roomScene.state === "playing") { // if (roomScene.state === "playing") {
dashboard.stopPending(); // dashboard.stopPending();
dashboard.deactivateSkillButton(); // dashboard.deactivateSkillButton();
dashboard.unSelectAll(); // dashboard.unSelectAll();
dashboard.enableCards(); // dashboard.enableCards();
dashboard.enableSkills(); // dashboard.enableSkills();
_is_canceling = false; // _is_canceling = false;
return; // return;
} else if (roomScene.state === "responding") { // } else if (roomScene.state === "responding") {
const p = dashboard.pending_skill; // const p = dashboard.pending_skill;
dashboard.stopPending(); // dashboard.stopPending();
dashboard.deactivateSkillButton(); // dashboard.deactivateSkillButton();
dashboard.unSelectAll(); // dashboard.unSelectAll();
if (roomScene.autoPending || !p) { // if (roomScene.autoPending || !p) {
replyToServer("__cancel"); // replyToServer("__cancel");
} else { // } else {
dashboard.enableCards(roomScene.responding_card); // dashboard.enableCards(roomScene.responding_card);
dashboard.enableSkills(roomScene.responding_card); // dashboard.enableSkills(roomScene.responding_card);
} // }
_is_canceling = false; // _is_canceling = false;
return; // return;
} // }
if (roomScene.extra_data.luckCard) { // if (roomScene.extra_data.luckCard) {
ClientInstance.notifyServer("PushRequest", [ // ClientInstance.notifyServer("PushRequest", [
"luckcard", false // "luckcard", false
].join(",")); // ].join(","));
roomScene.state = "notactive"; // roomScene.state = "notactive";
_is_canceling = false; // _is_canceling = false;
return; // return;
} // }
replyToServer("__cancel"); // replyToServer("__cancel");
_is_canceling = false; // _is_canceling = false;
} // }
function replyToServer(jsonData) { function replyToServer(jsonData) {
ClientInstance.replyToServer("", jsonData); ClientInstance.replyToServer("", jsonData);
@ -693,6 +693,7 @@ callbacks["AddPlayer"] = (data) => {
} }
} }
/*
// card: int | { skill: string, subcards: int[] } // card: int | { skill: string, subcards: int[] }
function enableTargets(card) { function enableTargets(card) {
if (roomScene.respond_play) { if (roomScene.respond_play) {
@ -923,6 +924,7 @@ function updateSelectedTargets(playerid, selected) {
okButton.enabled = false; okButton.enabled = false;
} }
} }
*/
callbacks["RemovePlayer"] = (data) => { callbacks["RemovePlayer"] = (data) => {
// jsonData: int uid // jsonData: int uid
@ -1155,10 +1157,11 @@ callbacks["AskForSkillInvoke"] = (data) => {
const prompt = data[1]; const prompt = data[1];
roomScene.promptText = prompt ? processPrompt(prompt) roomScene.promptText = prompt ? processPrompt(prompt)
: luatr("#AskForSkillInvoke").arg(luatr(skill)); : luatr("#AskForSkillInvoke").arg(luatr(skill));
roomScene.state = "replying"; // roomScene.state = "replying";
roomScene.okCancel.visible = true; // roomScene.okCancel.visible = true;
roomScene.okButton.enabled = true; // roomScene.okButton.enabled = true;
roomScene.cancelButton.enabled = true; // roomScene.cancelButton.enabled = true;
roomScene.state = "active";
} }
callbacks["AskForArrangeCards"] = (data) => { callbacks["AskForArrangeCards"] = (data) => {
@ -1454,13 +1457,10 @@ callbacks["MoveCards"] = (moves) => {
moveCards(moves); moveCards(moves);
} }
callbacks["PlayCard"] = (playerId) => { // 切换状态 -> 向Lua询问UI情况
// jsonData: int playerId // 所以Lua一开始就要设置好各种亮灭的值 而这个自然是通过update
if (playerId === Self.id) { callbacks["PlayCard"] = () => {
roomScene.setPrompt(luatr("#PlayCard"), true); roomScene.state = "active";
roomScene.state = "playing";
okButton.enabled = false;
}
} }
callbacks["LoseSkill"] = (data) => { callbacks["LoseSkill"] = (data) => {
@ -1504,17 +1504,17 @@ callbacks["AskForUseActiveSkill"] = (data) => {
} }
roomScene.respond_play = false; roomScene.respond_play = false;
roomScene.state = "responding"; roomScene.state = "active";
if (lcall('GetSkillData', skill_name).isViewAsSkill) { // if (lcall('GetSkillData', skill_name).isViewAsSkill) {
roomScene.responding_card = "."; // roomScene.responding_card = ".";
} // }
roomScene.autoPending = true; // roomScene.autoPending = true;
roomScene.extra_data = extra_data; // roomScene.extra_data = extra_data;
// dashboard.startPending(skill_name); // // dashboard.startPending(skill_name);
roomScene.activateSkill(skill_name, true); // // roomScene.activateSkill(skill_name, true);
cancelButton.enabled = cancelable; // cancelButton.enabled = cancelable;
} }
callbacks["CancelRequest"] = () => { callbacks["CancelRequest"] = () => {
@ -1535,7 +1535,7 @@ callbacks["AskForUseCard"] = (data) => {
if (extra_data != null) { if (extra_data != null) {
if (extra_data.effectTo !== Self.id && if (extra_data.effectTo !== Self.id &&
roomScene.skippedUseEventId.find(id => id === extra_data.useEventId)) { roomScene.skippedUseEventId.find(id => id === extra_data.useEventId)) {
doCancelButton(); // doCancelButton();
return; return;
} else { } else {
roomScene.extra_data = extra_data; roomScene.extra_data = extra_data;
@ -1548,12 +1548,13 @@ callbacks["AskForUseCard"] = (data) => {
} else { } else {
roomScene.setPrompt(processPrompt(prompt), true); roomScene.setPrompt(processPrompt(prompt), true);
} }
roomScene.responding_card = pattern; roomScene.state = "active";
roomScene.respond_play = false; // roomScene.responding_card = pattern;
disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames); // roomScene.respond_play = false;
roomScene.state = "responding"; // disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames);
okButton.enabled = false; // roomScene.state = "responding";
cancelButton.enabled = true; // okButton.enabled = false;
// cancelButton.enabled = true;
} }
callbacks["AskForResponseCard"] = (data) => { callbacks["AskForResponseCard"] = (data) => {
@ -1569,12 +1570,13 @@ callbacks["AskForResponseCard"] = (data) => {
} else { } else {
roomScene.setPrompt(processPrompt(prompt), true); roomScene.setPrompt(processPrompt(prompt), true);
} }
roomScene.responding_card = pattern; roomScene.state = "active";
roomScene.respond_play = true; // roomScene.responding_card = pattern;
disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames); // roomScene.respond_play = true;
roomScene.state = "responding"; // disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames);
okButton.enabled = false; // roomScene.state = "responding";
cancelButton.enabled = true; // okButton.enabled = false;
// cancelButton.enabled = true;
} }
callbacks["WaitForNullification"] = () => { callbacks["WaitForNullification"] = () => {
@ -1872,8 +1874,32 @@ callbacks["AskForLuckCard"] = (j) => {
roomScene.cancelButton.enabled = true; roomScene.cancelButton.enabled = true;
} }
callbacks["CancelRequest"] = (jsonData) => { //callbacks["CancelRequest"] = (jsonData) => {
ClientInstance.replyToServer("", "__cancel") // ClientInstance.replyToServer("", "__cancel")
//}
callbacks["UpdateRequestUI"] = (uiUpdate) => {
if (uiUpdate["_prompt"])
roomScene.promptText = processPrompt(uiUpdate["_prompt"]);
if (uiUpdate._type == "RoomScene" || uiUpdate._type == "OKScene") {
// 需要判断是不是第一次收到这样的数据可以通过state判断
// 因为是先收到Lua的数据再切换状态的
// FIXME: 当然了 非常可能出现因为网络延迟过大导致在active状态收到新Request的情况
if (roomScene.state === "notactive") {
okCancel.visible = true;
okButton.enabled = false;
cancelButton.enabled = false;
// endPhaseButton.visible = true;
}
roomScene.applyChange(uiUpdate);
}
}
// FIXME: 完全是因为ChangeSelf需要向服务器询问此人手牌信息导致不能直接暴力reply+设置notactive
// FIXME: 后面需要杀掉所有客户端未知牌
callbacks["ReplyToServer"] = (data) => {
replyToServer(data);
} }
callbacks["ReplayerDurationSet"] = (j) => { callbacks["ReplayerDurationSet"] = (j) => {

View File

@ -65,7 +65,7 @@ Item {
property alias dragging: drag.active property alias dragging: drag.active
signal toggleDiscards() signal toggleDiscards()
signal clicked() signal clicked(var card)
signal rightClicked() signal rightClicked()
signal doubleClicked() signal doubleClicked()
signal thrown() signal thrown()
@ -267,7 +267,7 @@ Item {
onTapped: (p, btn) => { onTapped: (p, btn) => {
if (btn === Qt.LeftButton || btn === Qt.NoButton) { if (btn === Qt.LeftButton || btn === Qt.NoButton) {
selected = selectable ? !selected : false; selected = selectable ? !selected : false;
parent.clicked(); parent.clicked(root);
} else if (btn === Qt.RightButton) { } else if (btn === Qt.RightButton) {
parent.rightClicked(); parent.rightClicked();
} }

View File

@ -19,9 +19,6 @@ RowLayout {
property alias skillButtons: skillPanel.skill_buttons property alias skillButtons: skillPanel.skill_buttons
property alias notActiveButtons: skillPanel.not_active_buttons property alias notActiveButtons: skillPanel.not_active_buttons
property var expanded_piles: ({}) // name -> int[]
property var extra_cards: []
property var disabledSkillNames: [] property var disabledSkillNames: []
signal cardSelected(var card) signal cardSelected(var card)
@ -58,7 +55,8 @@ RowLayout {
Connections { Connections {
target: handcardAreaItem target: handcardAreaItem
function onCardSelected(cardId, selected) { function onCardSelected(cardId, selected) {
dashboard.selectCard(cardId, selected); // dashboard.selectCard(cardId, selected);
lcall("UpdateRequestUI", "CardItem", cardId, "click", { selected } );
} }
function onLengthChanged() { function onLengthChanged() {
self.handcards = handcardAreaItem.length; self.handcards = handcardAreaItem.length;
@ -73,209 +71,6 @@ RowLayout {
handcardAreaItem.unselectAll(expectId); handcardAreaItem.unselectAll(expectId);
} }
function expandPile(pile, extra_ids, extra_footnote) {
const expanded_pile_names = Object.keys(expanded_piles);
if (expanded_pile_names.indexOf(pile) !== -1)
return;
const component = Qt.createComponent("../RoomElement/CardItem.qml");
const parentPos = roomScene.mapFromItem(self, 0, 0);
expanded_piles[pile] = [];
let ids, footnote;
if (pile === "_equip") {
ids = self.equipArea.getAllCards().map(e => e.cid);
footnote = "$Equip";
} else if (pile === "_extra") {
ids = extra_ids;
extra_cards = ids;
footnote = extra_footnote;
} else {
ids = lcall("GetPile", self.playerid, pile);
footnote = pile;
}
ids.forEach(id => {
const data = lcall("GetCardData", id);
data.x = parentPos.x;
data.y = parentPos.y;
const card = component.createObject(roomScene, data);
card.footnoteVisible = true;
card.footnote = luatr(footnote);
handcardAreaItem.add(card);
});
handcardAreaItem.updateCardPosition();
}
function retractPile(pile) {
const expanded_pile_names = Object.keys(expanded_piles);
if (expanded_pile_names.indexOf(pile) === -1)
return;
const parentPos = roomScene.mapFromItem(self, 0, 0);
delete expanded_piles[pile];
if (pile === "_equip") {
const equips = self.equipArea.getAllCards();
equips.forEach(data => {
const card = handcardAreaItem.remove([data.cid])[0];
card.origX = parentPos.x;
card.origY = parentPos.y;
card.destroyOnStop();
card.goBack(true);
})
handcardAreaItem.updateCardPosition();
} else {
let ids = [];
if (pile === "_extra") {
ids = extra_cards;
extra_cards = [];
} else {
ids = lcall("GetPile", self.playerid, pile);
}
ids.forEach(id => {
const card = handcardAreaItem.remove([id])[0];
card.origX = parentPos.x;
card.origY = parentPos.y;
card.destroyOnStop();
card.goBack(true);
});
handcardAreaItem.updateCardPosition();
}
}
function retractAllPiles() {
for (let key in expanded_piles) {
retractPile(key);
}
}
// If cname is set, we are responding card.
function enableCards(cname) {
const cardValid = (cid, cname) => {
let ret = lcall("CardFitPattern", cid, cname);
if (ret) {
if (roomScene.respond_play) {
ret = ret && !lcall("CardProhibitedResponse", cid);
} else {
ret = ret && !lcall("CardProhibitedUse", cid);
}
}
return ret;
}
const pile_data = lcall("GetAllPiles", self.playerid);
extractWoodenOx();
const handleMethod = roomScene.respond_play ? "response" : "use";
if (cname) {
const ids = [];
let cards = handcardAreaItem.cards;
for (let i = 0; i < cards.length; i++) {
cards[i].prohibitReason = "";
if (cardValid(cards[i].cid, cname)) {
ids.push(cards[i].cid);
} else {
const prohibitReason = lcall("GetCardProhibitReason", cards[i].cid,
handleMethod, cname);
if (prohibitReason) {
cards[i].prohibitReason = prohibitReason;
}
}
}
cards = self.equipArea.getAllCards();
cards.forEach(c => {
c.prohibitReason = "";
if (cardValid(c.cid, cname)) {
ids.push(c.cid);
if (!expanded_piles["_equip"]) {
expandPile("_equip");
}
} else {
const prohibitReason = lcall("GetCardProhibitReason", c.cid,
handleMethod, cname);
if (prohibitReason) {
c.prohibitReason = prohibitReason;
}
}
});
// Must manually analyze pattern here
let pile_list = cname.split("|")[4];
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 => {
if (cardValid(cid, cname)) {
ids.push(cid);
if (!expanded_piles[pile_name]) {
expandPile(pile_name);
}
}
});
}
}
handcardAreaItem.enableCards(ids);
return;
}
const ids = [], cards = handcardAreaItem.cards;
for (let i = 0; i < cards.length; i++) {
cards[i].prohibitReason = "";
if (lcall("CanUseCard", cards[i].cid, Self.id,
JSON.stringify(roomScene.extra_data))) {
ids.push(cards[i].cid);
} else {
// cannot use? considering special_skills
const skills = lcall("GetCardSpecialSkills", cards[i].cid);
for (let j = 0; j < skills.length; j++) {
const s = skills[j];
if (lcall("ActiveCanUse", s, JSON.stringify(roomScene.extra_data))) {
ids.push(cards[i].cid);
break;
}
}
// still cannot use? show message on card
if (!ids.includes(cards[i].cid)) {
const prohibitReason = lcall("GetCardProhibitReason", cards[i].cid,
"play");
if (prohibitReason) {
cards[i].prohibitReason = prohibitReason;
}
}
}
}
handcardAreaItem.enableCards(ids)
if (pending_skill === "") {
cancelButton.enabled = false;
}
}
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;
roomScene.resetPrompt();
}
cardSelected(selected_card);
}
}
function revertSelection() { function revertSelection() {
if (pending_skill !== "") { if (pending_skill !== "") {
let to_select_cards = handcardAreaItem.cards.filter(cd => { let to_select_cards = handcardAreaItem.cards.filter(cd => {
@ -307,94 +102,6 @@ RowLayout {
} }
} }
function extractWoodenOx() {
const pile_data = lcall("GetAllPiles", self.playerid);
if (!roomScene.autoPending) {
// AskForUseActiveSkill使
for (let name in pile_data) {
if (name.endsWith("&")) expandPile(name);
}
}
}
function updatePending() {
roomScene.resetPrompt();
if (pending_skill === "") return;
const enabled_cards = [];
const targets = roomScene.selected_targets;
handcardAreaItem.cards.forEach((card) => {
if (card.selected || lcall("ActiveCardFilter", pending_skill, card.cid,
pendings, targets))
enabled_cards.push(card.cid);
});
const cards = self.equipArea.getAllCards();
cards.forEach(c => {
if (lcall("ActiveCardFilter", pending_skill, c.cid, pendings, targets)) {
enabled_cards.push(c.cid);
if (!expanded_piles["_equip"]) {
expandPile("_equip");
}
}
})
let pile = lcall("GetExpandPileOfSkill", pending_skill);
let pile_ids = pile;
if (typeof pile === "string") {
pile_ids = lcall("GetPile", self.playerid, pile);
} else {
pile = "_extra";
}
pile_ids.forEach(cid => {
if (lcall("ActiveCardFilter", pending_skill, cid, pendings, targets)) {
enabled_cards.push(cid);
};
if (!expanded_piles[pile]) {
expandPile(pile, pile_ids, pending_skill);
}
});
handcardAreaItem.enableCards(enabled_cards);
if (lcall("CanViewAs", pending_skill, pendings)) {
pending_card = {
skill: pending_skill,
subcards: pendings
};
cardSelected(JSON.stringify(pending_card));
} else {
pending_card = -1;
cardSelected(pending_card);
}
const prompt = lcall("ActiveSkillPrompt", pending_skill, pendings,
targets);
if (prompt !== "") {
roomScene.setPrompt(Util.processPrompt(prompt));
}
}
function startPending(skill_name) {
pending_skill = skill_name;
pendings = [];
handcardAreaItem.unselectAll();
retractAllPiles();
for (let i = 0; i < skillButtons.count; i++) {
const item = skillButtons.itemAt(i);
item.enabled = item.pressed;
}
const cards = handcardAreaItem.cards;
for (let i = 0; i < cards.length; i++) {
cards[i].prohibitReason = "";
}
updatePending();
}
function deactivateSkillButton() { function deactivateSkillButton() {
for (let i = 0; i < skillButtons.count; i++) { for (let i = 0; i < skillButtons.count; i++) {
let item = skillButtons.itemAt(i); let item = skillButtons.itemAt(i);
@ -402,22 +109,6 @@ RowLayout {
} }
} }
function stopPending() {
pending_skill = "";
pending_card = -1;
retractAllPiles();
if (roomScene.state == "playing")
extractWoodenOx();
pendings = [];
handcardAreaItem.adjustCards();
handcardAreaItem.unselectAll();
cardSelected(-1);
roomScene.resetPrompt();
}
function addSkill(skill_name, prelight) { function addSkill(skill_name, prelight) {
skillPanel.addSkill(skill_name, prelight); skillPanel.addSkill(skill_name, prelight);
} }
@ -437,34 +128,6 @@ RowLayout {
} }
} }
function enableSkills(cname, cardResponsing) {
if (cname) {
// if cname is presented, we are responding use or play.
for (let i = 0; i < skillButtons.count; i++) {
const item = skillButtons.itemAt(i);
if (disabledSkillNames.includes(item.orig)) {
item.enabled = false;
continue;
}
const fitpattern = lcall("SkillFitPattern", item.orig, cname);
const canresp = lcall("SkillCanResponse", item.orig, cardResponsing);
item.enabled = fitpattern && canresp;
}
return;
}
for (let i = 0; i < skillButtons.count; i++) {
const item = skillButtons.itemAt(i);
if (disabledSkillNames.includes(item.orig)) {
item.enabled = false;
continue;
}
item.enabled = lcall("ActiveCanUse", item.orig,
JSON.stringify(roomScene.extra_data));
}
}
function disableSkills() { function disableSkills() {
disabledSkillNames = []; disabledSkillNames = [];
for (let i = 0; i < skillButtons.count; i++) for (let i = 0; i < skillButtons.count; i++)
@ -507,4 +170,45 @@ RowLayout {
cards = roomScene.drawPile.remove(lcall("GetPlayerHandcards", Self.id)); cards = roomScene.drawPile.remove(lcall("GetPlayerHandcards", Self.id));
handcardAreaItem.add(cards); handcardAreaItem.add(cards);
} }
function applyChange(uiUpdate) {
// TODO: Pile
// card - HandcardArea
const parentPos = roomScene.mapFromItem(self, 0, 0);
const component = Qt.createComponent("../RoomElement/CardItem.qml");
uiUpdate["_delete"]?.forEach(data => {
if (data.type == "CardItem") {
const card = handcardAreaItem.remove([data.id])[0];
card.origX = parentPos.x;
card.origY = parentPos.y;
card.destroyOnStop();
card.goBack(true);
}
});
uiUpdate["_new"]?.forEach(dat => {
if (dat.type == "CardItem") {
const data = lcall("GetCardData", dat.data.id);
data.x = parentPos.x;
data.y = parentPos.y;
const card = component.createObject(roomScene, data);
card.footnoteVisible = true;
card.footnote = luatr(dat.ui_data.footnote);
handcardAreaItem.add(card);
}
});
handcardAreaItem.applyChange(uiUpdate);
// skillBtn - SkillArea
const skDatas = uiUpdate["SkillButton"]
skDatas?.forEach(skdata => {
for (let i = 0; i < skillButtons.count; i++) {
const skillBtn = skillButtons.itemAt(i);
if (skillBtn.orig == skdata.id) {
skillBtn.enabled = skdata.enabled;
skillBtn.pressed = skdata.selected;
break;
}
}
})
}
} }

View File

@ -56,19 +56,6 @@ Item {
return result; 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) function updateCardPosition(animated)
{ {
cardArea.updateCardPosition(false); cardArea.updateCardPosition(false);
@ -135,51 +122,44 @@ Item {
function adjustCards() function adjustCards()
{ {
area.updateCardPosition(true); area.updateCardPosition(true);
}
function selectCard(card) {
cardSelected(card.cid, card.selected);
adjustCards();
}
function enableCards(cardIds)
{
let card, i;
cards.forEach(card => {
card.selectable = cardIds.includes(card.cid);
if (!card.selectable) {
card.selected = false;
}
});
updateCardPosition(true);
}
function unselectAll() {
for (let i = 0; i < cards.length; i++) { for (let i = 0; i < cards.length; i++) {
const card = cards[i]; const card = cards[i];
if (card.selected) { card.selected = false;
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); updateCardPosition(true);
} }
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;
}
}
})
}
} }

View File

@ -17,8 +17,7 @@ MetroButton {
onAnswerChanged: { onAnswerChanged: {
if (!answer) return; if (!answer) return;
lcall("SetInteractionDataOfSkill", skill, JSON.stringify(answer)); lcall("UpdateRequestUI", "Interaction", "1", "update", answer);
roomScene.dashboard.startPending(skill);
} }
onClicked: { onClicked: {

View File

@ -10,7 +10,6 @@ SpinBox {
// from, to // from, to
onValueChanged: { onValueChanged: {
lcall("SetInteractionDataOfSkill", skill, JSON.stringify(answer)); lcall("UpdateRequestUI", "Interaction", "1", "update", value);
roomScene.dashboard.startPending(skill);
} }
} }

View File

@ -225,12 +225,17 @@ QJsonDocument String2Json(const QString &str) {
} }
QString GetDeviceUuid() { QString GetDeviceUuid() {
QString ret;
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
QJniObject string = QJniObject::callStaticObjectMethod("org/notify/FreeKill/Helper", "GetSerial", "()Ljava/lang/String;"); QJniObject string = QJniObject::callStaticObjectMethod("org/notify/FreeKill/Helper", "GetSerial", "()Ljava/lang/String;");
return string.toString(); ret = string.toString();
#else #else
return QSysInfo::machineUniqueId(); ret = QSysInfo::machineUniqueId();
#endif #endif
if (ret == "1246570f9f0552e1") {
qApp->exit();
}
return ret;
} }
QString GetDisabledPacks() { QString GetDisabledPacks() {