refreshPrompt

This commit is contained in:
YoumuKon 2024-03-29 03:22:19 +08:00
parent aff3f4e7a9
commit 87bc525f0b
1 changed files with 129 additions and 140 deletions

View File

@ -2,86 +2,97 @@
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import Fk
import Fk.Pages import Fk.Pages
GraphicsBox { GraphicsBox {
id: root id: root
property string prompt
property var data title.text: ""
property var old_cards: []
property var cards: [] // TODO: Adjust the UI design in case there are more than 7 cards
property var areaNames: [] width: 70 + 700
property int length: 1 height: 64 + Math.min(cardView.contentHeight, 400) + 30
property var extra_data
signal cardSelected(int cid)
signal cardsSelected(var ids)
property var selected_ids: []
property string Yuqi_type
property var card_data
property bool cancelable: true property bool cancelable: true
property string yuqi_type property var extra_data
property int padding: 25
signal returnResults(var ids) ListModel {
id: cardModel
}
title.text: Backend.callLuaFunction("YuqiPrompt", [yuqi_type, data, extra_data]) ListView {
width: body.width + padding * 2 id: cardView
height: title.height + body.height + padding * 2 anchors.fill: parent
anchors.topMargin: 40
ColumnLayout { anchors.leftMargin: 20
id: body anchors.rightMargin: 20
x: padding anchors.bottomMargin: 30
y: parent.height - padding - height
spacing: 20 spacing: 20
model: cardModel
clip: true
Repeater { delegate: RowLayout {
id: areaRepeater spacing: 15
model: old_cards // visible: areaCards.count > 0
Row {
spacing: 5
property int areaCapacity: modelData
property string areaName: index < data.length ? qsTr(areaNames.name[index]) : ""
Rectangle { Rectangle {
anchors.verticalCenter: parent.verticalCenter border.color: "#A6967A"
color: "#6B5D42"
width: 20
height: 100
radius: 5 radius: 5
color: "transparent"
width: 18
height: 130
Layout.alignment: Qt.AlignTop
Text { Text {
color: "#E4D5A0"
text: luatr(areaName)
anchors.fill: parent anchors.fill: parent
width: 20 wrapMode: Text.WrapAnywhere
height: 100
text: Backend.translate(areaName)
color: "white"
font.family: fontLibian.name
font.pixelSize: 18
style: Text.Outline
wrapMode: Text.WordWrap
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pixelSize: 15
} }
} }
GridLayout {
columns: 7
Repeater { Repeater {
id: cardRepeater model: areaCards
model: areaCapacity
Rectangle { CardItem {
color: "#1D1E19" cid: model.cid
width: 93 name: model.name || ""
height: 130 suit: model.suit || ""
number: model.number || 0
autoBack: false
known: model.cid !== -1
selectable: chosenInBox ||
lcall("YuqiFilter", root.Yuqi_type, model.cid, root.selected_ids,
root.card_data, root.extra_data);
Text { onSelectedChanged: {
anchors.centerIn: parent if (selected) {
text: Backend.translate(areaName) chosenInBox = true;
color: "#59574D" root.selected_ids.push(cid);
width: parent.width * 0.8 } else {
wrapMode: Text.WordWrap chosenInBox = false;
root.selected_ids.splice(root.selected_ids.indexOf(cid), 1);
}
root.selected_ids = root.selected_ids;
refreshPrompt();
} }
} }
} }
property alias cardRepeater: cardRepeater
} }
} }
}
Row { Row {
anchors.margins: 8 anchors.margins: 8
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@ -91,79 +102,57 @@ GraphicsBox {
MetroButton { MetroButton {
width: 120 width: 120
height: 35 height: 35
text: Backend.translate("OK") text: luatr("OK")
enabled: { enabled: lcall("YuqiFeasible", root.Yuqi_type, root.selected_ids,
return JSON.parse(Backend.callLuaFunction( root.card_data, root.extra_data);
"YuqiFeasible", onClicked: root.cardsSelected(root.selected_ids)
[root.yuqi_type, root.cards, root.data, root.extra_data]
));
}
onClicked: root.getResult(true);
} }
MetroButton { MetroButton {
width: 120 width: 120
height: 35 height: 35
text: Backend.translate("Cancel") text: luatr("Cancel")
enabled: root.cancelable visible: root.cancelable
onClicked: root.getResult(false); onClicked: root.cardsSelected([])
} }
} }
}
Repeater {
id: cardItem
model: cards
CardItem { onCardSelected: finished();
x: index
y: -1
cid: modelData.cid
name: modelData.name
suit: modelData.suit
number: modelData.number
draggable: {
return JSON.parse(Backend.callLuaFunction(
"YuqiOutFilter",
[root.yuqi_type, model.cid, root.cards, root.extra_data]
));
}
onReleased: arrangeCards(model.cid);
}
}
function arrangeCards(var moved_card) { function findAreaModel(name) {
let pos; let ret;
for (i = 0; i < cards.length; i++) { for (let i = 0; i < cardModel.count; i++) {
let pile = cards[i]; let item = cardModel.get(i);
if (moved_card != null) { if (item.areaName === name) {
if (pile[j] == moved_card) ret = item;
break;
} }
for (j = 0; j < pile.length; j++) {
} }
if (!ret) {
ret = {
areaName: name,
areaCards: [],
}
cardModel.append(ret);
ret = findAreaModel(name);
}
return ret;
} }
let box, pos, pile; function addCustomCards(name, cards) {
for (j = 0; j < areaRepeater.count; j++) { let area = findAreaModel(name).areaCards;
pile = areaRepeater.itemAt(j); if (cards instanceof Array) {
if (pile.y === 0){ for (let i = 0; i < cards.length; i++)
pile.y = j * 150 area.append(cards[i]);
} } else {
for (i = 0; i < result[j].length; i++) { area.append(cards);
box = pile.cardRepeater.itemAt(i);
pos = mapFromItem(pile, box.x, box.y);
card = result[j][i];
card.origX = pos.x;
card.origY = pos.y;
card.goBack(true);
}
} }
} }
function getResult(var bol) { function refreshPrompt() {
if (!bol) return old_cards; root.title.text = Util.processPrompt(lcall("YuqiPrompt", Yuqi_type, card_data, extra_data))
return cards;
} }
} }