refreshPrompt
This commit is contained in:
parent
aff3f4e7a9
commit
87bc525f0b
|
@ -2,168 +2,157 @@
|
||||||
|
|
||||||
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 {
|
Rectangle {
|
||||||
spacing: 5
|
border.color: "#A6967A"
|
||||||
|
radius: 5
|
||||||
|
color: "transparent"
|
||||||
|
width: 18
|
||||||
|
height: 130
|
||||||
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
property int areaCapacity: modelData
|
Text {
|
||||||
property string areaName: index < data.length ? qsTr(areaNames.name[index]) : ""
|
color: "#E4D5A0"
|
||||||
|
text: luatr(areaName)
|
||||||
Rectangle {
|
anchors.fill: parent
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
wrapMode: Text.WrapAnywhere
|
||||||
color: "#6B5D42"
|
verticalAlignment: Text.AlignVCenter
|
||||||
width: 20
|
horizontalAlignment: Text.AlignHCenter
|
||||||
height: 100
|
font.pixelSize: 15
|
||||||
radius: 5
|
|
||||||
|
|
||||||
Text {
|
|
||||||
anchors.fill: parent
|
|
||||||
width: 20
|
|
||||||
height: 100
|
|
||||||
text: Backend.translate(areaName)
|
|
||||||
color: "white"
|
|
||||||
font.family: fontLibian.name
|
|
||||||
font.pixelSize: 18
|
|
||||||
style: Text.Outline
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
|
||||||
anchors.margins: 8
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
spacing: 32
|
|
||||||
|
|
||||||
MetroButton {
|
|
||||||
width: 120
|
|
||||||
height: 35
|
|
||||||
text: Backend.translate("OK")
|
|
||||||
enabled: {
|
|
||||||
return JSON.parse(Backend.callLuaFunction(
|
|
||||||
"YuqiFeasible",
|
|
||||||
[root.yuqi_type, root.cards, root.data, root.extra_data]
|
|
||||||
));
|
|
||||||
}
|
|
||||||
onClicked: root.getResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
MetroButton {
|
|
||||||
width: 120
|
|
||||||
height: 35
|
|
||||||
text: Backend.translate("Cancel")
|
|
||||||
enabled: root.cancelable
|
|
||||||
onClicked: root.getResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Repeater {
|
|
||||||
id: cardItem
|
|
||||||
model: cards
|
|
||||||
|
|
||||||
CardItem {
|
|
||||||
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) {
|
|
||||||
let pos;
|
|
||||||
for (i = 0; i < cards.length; i++) {
|
|
||||||
let pile = cards[i];
|
|
||||||
if (moved_card != null) {
|
|
||||||
if (pile[j] == moved_card)
|
|
||||||
}
|
|
||||||
for (j = 0; j < pile.length; j++) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
let box, pos, pile;
|
|
||||||
for (j = 0; j < areaRepeater.count; j++) {
|
|
||||||
pile = areaRepeater.itemAt(j);
|
|
||||||
if (pile.y === 0){
|
|
||||||
pile.y = j * 150
|
|
||||||
}
|
|
||||||
for (i = 0; i < result[j].length; i++) {
|
|
||||||
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) {
|
Row {
|
||||||
if (!bol) return old_cards;
|
anchors.margins: 8
|
||||||
return cards;
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
spacing: 32
|
||||||
|
|
||||||
|
MetroButton {
|
||||||
|
width: 120
|
||||||
|
height: 35
|
||||||
|
text: luatr("OK")
|
||||||
|
enabled: lcall("YuqiFeasible", root.Yuqi_type, root.selected_ids,
|
||||||
|
root.card_data, root.extra_data);
|
||||||
|
onClicked: root.cardsSelected(root.selected_ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
MetroButton {
|
||||||
|
width: 120
|
||||||
|
height: 35
|
||||||
|
text: luatr("Cancel")
|
||||||
|
visible: root.cancelable
|
||||||
|
onClicked: root.cardsSelected([])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
onCardSelected: finished();
|
||||||
|
|
||||||
|
function findAreaModel(name) {
|
||||||
|
let ret;
|
||||||
|
for (let i = 0; i < cardModel.count; i++) {
|
||||||
|
let item = cardModel.get(i);
|
||||||
|
if (item.areaName === name) {
|
||||||
|
ret = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ret) {
|
||||||
|
ret = {
|
||||||
|
areaName: name,
|
||||||
|
areaCards: [],
|
||||||
|
}
|
||||||
|
cardModel.append(ret);
|
||||||
|
ret = findAreaModel(name);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addCustomCards(name, cards) {
|
||||||
|
let area = findAreaModel(name).areaCards;
|
||||||
|
if (cards instanceof Array) {
|
||||||
|
for (let i = 0; i < cards.length; i++)
|
||||||
|
area.append(cards[i]);
|
||||||
|
} else {
|
||||||
|
area.append(cards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshPrompt() {
|
||||||
|
root.title.text = Util.processPrompt(lcall("YuqiPrompt", Yuqi_type, card_data, extra_data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue