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
|
2023-05-19 02:08:36 +00:00
|
|
|
|
import Fk
|
|
|
|
|
import Fk.Pages
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
|
|
|
|
GraphicsBox {
|
2022-04-30 07:27:56 +00:00
|
|
|
|
property alias generalList: generalList
|
|
|
|
|
// property var generalList: []
|
|
|
|
|
property int choiceNum: 1
|
|
|
|
|
property var choices: []
|
|
|
|
|
property var selectedItem: []
|
|
|
|
|
property bool loaded: false
|
2023-08-24 13:37:06 +00:00
|
|
|
|
property bool convertDisabled: false
|
2024-04-06 16:45:55 +00:00
|
|
|
|
property bool hegemony: false
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
|
id: generalList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id: root
|
2024-01-24 19:23:29 +00:00
|
|
|
|
title.text: luatr("$ChooseGeneral").arg(choiceNum) +
|
|
|
|
|
(config.enableFreeAssign ? "(" + luatr("Enable free assign") + ")" : "")
|
2022-04-30 07:27:56 +00:00
|
|
|
|
width: generalArea.width + body.anchors.leftMargin + body.anchors.rightMargin
|
2024-01-24 19:23:29 +00:00
|
|
|
|
height: body.implicitHeight + body.anchors.topMargin +
|
|
|
|
|
body.anchors.bottomMargin
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
id: body
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: 40
|
|
|
|
|
anchors.bottomMargin: 20
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: generalArea
|
2024-01-24 19:23:29 +00:00
|
|
|
|
width: (generalList.count > 8 ? Math.ceil(generalList.count / 2)
|
|
|
|
|
: Math.max(3, generalList.count)) * 97
|
2023-03-20 06:53:56 +00:00
|
|
|
|
height: generalList.count > 8 ? 290 : 150
|
2022-04-30 07:27:56 +00:00
|
|
|
|
z: 1
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
id: generalMagnetList
|
|
|
|
|
model: generalList.count
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
|
width: 93
|
|
|
|
|
height: 130
|
2024-01-24 19:23:29 +00:00
|
|
|
|
x: {
|
|
|
|
|
const count = generalList.count;
|
|
|
|
|
let columns = generalList.count;
|
|
|
|
|
if (columns > 8) {
|
|
|
|
|
columns = Math.ceil(columns / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ret = (index % columns) * 98;
|
|
|
|
|
if (count > 8 && index > count / 2 && count % 2 == 1)
|
|
|
|
|
ret += 50;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
y: {
|
|
|
|
|
if (generalList.count <= 8)
|
|
|
|
|
return 0;
|
|
|
|
|
return index < generalList.count / 2 ? 0 : 135;
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: splitLine
|
|
|
|
|
width: parent.width - 80
|
|
|
|
|
height: 6
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
clip: true
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
Item {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: 165
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
id: resultArea
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
spacing: 10
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
id: resultList
|
|
|
|
|
model: choiceNum
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
color: "#1D1E19"
|
|
|
|
|
radius: 3
|
|
|
|
|
width: 93
|
|
|
|
|
height: 130
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: buttonArea
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: 40
|
|
|
|
|
|
2023-03-18 18:21:45 +00:00
|
|
|
|
Row {
|
2022-04-30 07:27:56 +00:00
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.bottom: parent.bottom
|
2023-03-18 18:21:45 +00:00
|
|
|
|
spacing: 8
|
|
|
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
|
id: convertBtn
|
2023-08-24 13:37:06 +00:00
|
|
|
|
visible: !convertDisabled
|
2024-01-24 19:23:29 +00:00
|
|
|
|
text: luatr("Same General Convert")
|
|
|
|
|
onClicked: {
|
2024-06-10 06:58:48 +00:00
|
|
|
|
roomScene.startCheat("SameConvert", { cards: generalList, choices: choices });
|
2024-01-24 19:23:29 +00:00
|
|
|
|
}
|
2023-03-18 18:21:45 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-03-18 18:21:45 +00:00
|
|
|
|
MetroButton {
|
|
|
|
|
id: fightButton
|
2024-01-24 19:23:29 +00:00
|
|
|
|
text: luatr("Fight")
|
2023-03-18 18:21:45 +00:00
|
|
|
|
width: 120
|
|
|
|
|
height: 35
|
|
|
|
|
enabled: false
|
|
|
|
|
|
|
|
|
|
onClicked: close();
|
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
|
id: detailBtn
|
|
|
|
|
enabled: choices.length > 0
|
2024-01-24 19:23:29 +00:00
|
|
|
|
text: luatr("Show General Detail")
|
2023-05-18 23:45:21 +00:00
|
|
|
|
onClicked: roomScene.startCheat(
|
2023-05-19 02:08:36 +00:00
|
|
|
|
"GeneralDetail",
|
2023-05-18 23:45:21 +00:00
|
|
|
|
{ generals: choices }
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
id: generalCardList
|
|
|
|
|
model: generalList
|
|
|
|
|
|
|
|
|
|
GeneralCardItem {
|
|
|
|
|
name: model.name
|
2023-04-23 13:10:07 +00:00
|
|
|
|
//enabled: //!(choices[0] && choices[0].kingdom !== this.kingdom)
|
|
|
|
|
selectable: !(selectedItem[0] && selectedItem[0].kingdom !== kingdom)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
draggable: true
|
|
|
|
|
|
|
|
|
|
onClicked: {
|
2023-04-23 13:10:07 +00:00
|
|
|
|
if (!selectable) return;
|
2022-04-30 07:27:56 +00:00
|
|
|
|
let toSelect = true;
|
|
|
|
|
for (let i = 0; i < selectedItem.length; i++) {
|
|
|
|
|
if (selectedItem[i] === this) {
|
|
|
|
|
toSelect = false;
|
|
|
|
|
selectedItem.splice(i, 1);
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if (toSelect && selectedItem.length < choiceNum)
|
|
|
|
|
selectedItem.push(this);
|
|
|
|
|
updatePosition();
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
|
onRightClicked: {
|
|
|
|
|
if (selectedItem.indexOf(this) === -1 && config.enableFreeAssign)
|
2023-05-19 02:08:36 +00:00
|
|
|
|
roomScene.startCheat("FreeAssign", { card: this });
|
2023-02-15 11:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
onReleased: {
|
2023-03-18 07:34:42 +00:00
|
|
|
|
arrangeCards();
|
2022-04-30 07:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
function arrangeCards()
|
|
|
|
|
{
|
|
|
|
|
let item, i;
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
selectedItem = [];
|
|
|
|
|
for (i = 0; i < generalList.count; i++) {
|
|
|
|
|
item = generalCardList.itemAt(i);
|
2023-04-23 13:10:07 +00:00
|
|
|
|
if (item.y > splitLine.y && item.selectable)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
selectedItem.push(item);
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
selectedItem.sort((a, b) => a.x - b.x);
|
|
|
|
|
|
|
|
|
|
if (selectedItem.length > choiceNum)
|
|
|
|
|
selectedItem.splice(choiceNum, selectedItem.length - choiceNum);
|
|
|
|
|
|
|
|
|
|
updatePosition();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 14:16:09 +00:00
|
|
|
|
/*
|
|
|
|
|
主副将的主势力和副势力至少有一个相同;
|
|
|
|
|
副将不可野 主将可野
|
|
|
|
|
*/
|
|
|
|
|
function isHegPair(gcard1, gcard2) {
|
|
|
|
|
if (!gcard1 || gcard1 === gcard2) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gcard2.kingdom == "wild") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gcard1.kingdom == "wild") {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const k1 = gcard1.kingdom;
|
|
|
|
|
const k2 = gcard2.kingdom;
|
|
|
|
|
const sub1 = gcard1.subkingdom;
|
|
|
|
|
const sub2 = gcard2.subkingdom;
|
|
|
|
|
|
|
|
|
|
if (k1 == k2) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sub1 && (sub1 == k2 || sub1 == sub2)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sub2 && sub2 == k1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-06 16:45:55 +00:00
|
|
|
|
function updateCompanion(gcard1, gcard2, overwrite) {
|
|
|
|
|
if (lcall("IsCompanionWith", gcard1.name, gcard2.name)) {
|
|
|
|
|
gcard1.hasCompanions = true;
|
|
|
|
|
} else if (overwrite) {
|
|
|
|
|
gcard1.hasCompanions = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
function updatePosition()
|
|
|
|
|
{
|
|
|
|
|
choices = [];
|
|
|
|
|
let item, magnet, pos, i;
|
|
|
|
|
for (i = 0; i < selectedItem.length && i < resultList.count; i++) {
|
|
|
|
|
item = selectedItem[i];
|
|
|
|
|
choices.push(item.name);
|
|
|
|
|
magnet = resultList.itemAt(i);
|
|
|
|
|
pos = root.mapFromItem(resultArea, magnet.x, magnet.y);
|
|
|
|
|
if (item.origX !== pos.x || item.origY !== item.y) {
|
|
|
|
|
item.origX = pos.x;
|
|
|
|
|
item.origY = pos.y;
|
|
|
|
|
item.goBack(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
root.choicesChanged();
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2023-12-28 04:11:24 +00:00
|
|
|
|
fightButton.enabled = (choices.length == choiceNum) &&
|
2024-04-06 16:45:55 +00:00
|
|
|
|
(hegemony ? isHegPair(selectedItem[0], selectedItem[1]) : true);
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
for (i = 0; i < generalCardList.count; i++) {
|
|
|
|
|
item = generalCardList.itemAt(i);
|
2024-04-06 16:45:55 +00:00
|
|
|
|
item.selectable = hegemony ? isHegPair(selectedItem[0], item)
|
2024-01-24 19:23:29 +00:00
|
|
|
|
: true;
|
2024-04-06 16:45:55 +00:00
|
|
|
|
if (hegemony) {
|
2024-06-10 06:58:48 +00:00
|
|
|
|
item.inPosition = 0;
|
2024-04-06 16:45:55 +00:00
|
|
|
|
if (selectedItem[0]) {
|
|
|
|
|
if (selectedItem[1]) {
|
|
|
|
|
if (selectedItem[0] === item) {
|
|
|
|
|
updateCompanion(item, selectedItem[1], true);
|
|
|
|
|
} else if (selectedItem[1] === item) {
|
|
|
|
|
updateCompanion(item, selectedItem[0], true);
|
|
|
|
|
} else {
|
|
|
|
|
item.hasCompanions = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (selectedItem[0] !== item) {
|
|
|
|
|
updateCompanion(item, selectedItem[0], true);
|
|
|
|
|
} else {
|
|
|
|
|
for (let j = 0; j < generalList.count; j++) {
|
|
|
|
|
updateCompanion(item, generalList.get(j), false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (let j = 0; j < generalList.count; j++) {
|
|
|
|
|
updateCompanion(item, generalList.get(j), false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if (selectedItem.indexOf(item) != -1)
|
|
|
|
|
continue;
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
magnet = generalMagnetList.itemAt(i);
|
|
|
|
|
pos = root.mapFromItem(generalMagnetList.parent, magnet.x, magnet.y);
|
|
|
|
|
if (item.origX !== pos.x || item.origY !== item.y) {
|
|
|
|
|
item.origX = pos.x;
|
|
|
|
|
item.origY = pos.y;
|
|
|
|
|
item.goBack(true);
|
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|
2023-03-18 18:21:45 +00:00
|
|
|
|
|
2024-06-10 06:58:48 +00:00
|
|
|
|
if (hegemony) {
|
|
|
|
|
if (selectedItem[0]) {
|
|
|
|
|
if (selectedItem[0].mainMaxHp < 0) {
|
|
|
|
|
selectedItem[0].inPosition = 1;
|
|
|
|
|
} else if (selectedItem[0].deputyMaxHp < 0) {
|
|
|
|
|
selectedItem[0].inPosition = -1;
|
|
|
|
|
}
|
|
|
|
|
if (selectedItem[1]) {
|
|
|
|
|
if (selectedItem[1].mainMaxHp < 0) {
|
|
|
|
|
selectedItem[1].inPosition = -1;
|
|
|
|
|
} else if (selectedItem[1].deputyMaxHp < 0) {
|
|
|
|
|
selectedItem[1].inPosition = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-18 18:21:45 +00:00
|
|
|
|
for (let i = 0; i < generalList.count; i++) {
|
2024-01-24 19:23:29 +00:00
|
|
|
|
if (lcall("GetSameGenerals", generalList.get(i).name).length > 0) {
|
2023-05-18 23:45:21 +00:00
|
|
|
|
convertBtn.enabled = true;
|
2023-03-18 18:21:45 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
convertBtn.enabled = false;
|
2022-04-30 07:27:56 +00:00
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
}
|