parent
496598623d
commit
36fa1de360
|
@ -42,6 +42,10 @@ function GetGeneralDetail(name)
|
|||
return json.encode(ret)
|
||||
end
|
||||
|
||||
function GetSameGenerals(name)
|
||||
return json.encode(Fk:getSameGenerals(name))
|
||||
end
|
||||
|
||||
local cardSubtypeStrings = {
|
||||
[Card.SubtypeNone] = "none",
|
||||
[Card.SubtypeDelayedTrick] = "delayed_trick",
|
||||
|
|
|
@ -72,6 +72,7 @@ Fk:loadTranslationTable{
|
|||
["$EnterRoom"] = "成功加入房间。",
|
||||
["$Choice"] = "%1:请选择",
|
||||
["$ChooseGeneral"] = "请选择 %1 名武将",
|
||||
["Same General Convert"] = "替换武将",
|
||||
["Fight"] = "出战",
|
||||
|
||||
["#PlayCard"] = "出牌阶段,请使用一张牌",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
---@field global_trigger TriggerSkill[]
|
||||
---@field global_status_skill table<class, Skill[]>
|
||||
---@field generals table<string, General>
|
||||
---@field same_generals table<string, string[]>
|
||||
---@field lords string[]
|
||||
---@field cards Card[]
|
||||
---@field translations table<string, table<string, string>>
|
||||
|
@ -29,6 +30,7 @@ function Engine:initialize()
|
|||
self.global_trigger = {}
|
||||
self.global_status_skill = {}
|
||||
self.generals = {} -- name --> General
|
||||
self.same_generals = {}
|
||||
self.lords = {} -- lordName[]
|
||||
self.cards = {} -- Card[]
|
||||
self.translations = {} -- srcText --> translated
|
||||
|
@ -141,6 +143,12 @@ function Engine:addGeneral(general)
|
|||
error(string.format("Duplicate general %s detected", general.name))
|
||||
end
|
||||
self.generals[general.name] = general
|
||||
|
||||
if general.name ~= general.trueName then
|
||||
local tName = general.trueName
|
||||
self.same_generals[tName] = self.same_generals[tName] or { tName }
|
||||
table.insert(self.same_generals[tName], general.name)
|
||||
end
|
||||
end
|
||||
|
||||
---@param generals General[]
|
||||
|
@ -151,6 +159,16 @@ function Engine:addGenerals(generals)
|
|||
end
|
||||
end
|
||||
|
||||
---@param name string
|
||||
function Engine:getSameGenerals(name)
|
||||
local tmp = name:split("__")
|
||||
local tName = tmp[#tmp]
|
||||
local ret = self.same_generals[tName] or {}
|
||||
return table.filter(ret, function(g)
|
||||
return self.generals[g] ~= nil
|
||||
end)
|
||||
end
|
||||
|
||||
local cardId = 1
|
||||
local _card_name_table = {}
|
||||
---@param card Card
|
||||
|
@ -218,7 +236,11 @@ function Engine:getGeneralsRandomly(num, generalPool, except, filter)
|
|||
local availableGenerals = {}
|
||||
for _, general in pairs(generalPool) do
|
||||
if not table.contains(except, general.name) and not (filter and filter(general)) then
|
||||
table.insert(availableGenerals, general)
|
||||
if #table.filter(availableGenerals, function(g)
|
||||
return g.trueName == general.trueName
|
||||
end) == 0 then
|
||||
table.insert(availableGenerals, general)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---@class General : Object
|
||||
---@field package Package
|
||||
---@field name string
|
||||
---@field trueName string
|
||||
---@field kingdom string
|
||||
---@field hp integer
|
||||
---@field maxHp integer
|
||||
|
@ -17,6 +18,9 @@ General.Female = 2
|
|||
function General:initialize(package, name, kingdom, hp, maxHp, gender)
|
||||
self.package = package
|
||||
self.name = name
|
||||
local name_splited = name:split("__")
|
||||
self.trueName = name_splited[#name_splited]
|
||||
|
||||
self.kingdom = kingdom
|
||||
self.hp = hp
|
||||
self.maxHp = maxHp or hp
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import ".."
|
||||
|
||||
Item {
|
||||
id: root
|
||||
anchors.fill: parent
|
||||
property var extra_data: ({})
|
||||
|
||||
signal finish()
|
||||
|
||||
Flickable {
|
||||
height: parent.height
|
||||
width: generalButtons.width
|
||||
anchors.centerIn: parent
|
||||
contentHeight: generalButtons.height
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
ColumnLayout {
|
||||
id: generalButtons
|
||||
Repeater {
|
||||
model: ListModel {
|
||||
id: glist
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Text { text: Backend.translate(gname) }
|
||||
GridLayout {
|
||||
columns: 3
|
||||
|
||||
Repeater {
|
||||
model: JSON.parse(Backend.callLuaFunction("GetSameGenerals", [gname]))
|
||||
|
||||
GeneralCardItem {
|
||||
name: modelData
|
||||
selectable: true
|
||||
|
||||
onClicked: {
|
||||
let idx = 0;
|
||||
for (; idx < extra_data.cards.count; idx++) {
|
||||
if (extra_data.cards.get(idx).name === gname)
|
||||
break;
|
||||
}
|
||||
|
||||
if (idx < extra_data.cards.count) {
|
||||
extra_data.cards.set(idx, { name: modelData });
|
||||
}
|
||||
root.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onExtra_dataChanged: {
|
||||
if (!extra_data.cards) return;
|
||||
for (let i = 0; i < extra_data.cards.count; i++) {
|
||||
glist.set(i, { gname: extra_data.cards.get(i).name });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -80,16 +80,29 @@ GraphicsBox {
|
|||
width: parent.width
|
||||
height: 40
|
||||
|
||||
MetroButton {
|
||||
id: fightButton
|
||||
Row {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
text: Backend.translate("Fight")
|
||||
width: 120
|
||||
height: 35
|
||||
enabled: false
|
||||
spacing: 8
|
||||
|
||||
onClicked: close();
|
||||
MetroButton {
|
||||
id: convertBtn
|
||||
text: Backend.translate("Same General Convert")
|
||||
onClicked: roomScene.startCheat(
|
||||
"RoomElement/Cheat/SameConvert.qml",
|
||||
{ cards: generalList }
|
||||
);
|
||||
}
|
||||
|
||||
MetroButton {
|
||||
id: fightButton
|
||||
text: Backend.translate("Fight")
|
||||
width: 120
|
||||
height: 35
|
||||
enabled: false
|
||||
|
||||
onClicked: close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,5 +190,15 @@ GraphicsBox {
|
|||
item.goBack(true);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < generalList.count; i++) {
|
||||
if (JSON.parse(Backend.callLuaFunction(
|
||||
"GetSameGenerals", [generalList.get(i).name])
|
||||
).length > 0) {
|
||||
convertBtn.visible = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
convertBtn.visible = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ CardItem {
|
|||
property string kingdom
|
||||
property int hp
|
||||
property int maxHp
|
||||
property string pkgName: ""
|
||||
name: ""
|
||||
// description: Sanguosha.getGeneralDescription(name)
|
||||
suit: ""
|
||||
|
@ -81,10 +82,42 @@ CardItem {
|
|||
style: Text.Outline
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
visible: pkgName !== ""
|
||||
height: 16
|
||||
width: childrenRect.width + 4
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 4
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
|
||||
color: "#3C3229"
|
||||
opacity: 0.8
|
||||
radius: 4
|
||||
border.color: "white"
|
||||
border.width: 1
|
||||
Text {
|
||||
text: Backend.translate(pkgName)
|
||||
x: 2; y: 1
|
||||
font.family: fontLibian.name
|
||||
font.pixelSize: 14
|
||||
color: "white"
|
||||
style: Text.Outline
|
||||
textFormat: Text.RichText
|
||||
}
|
||||
}
|
||||
|
||||
onNameChanged: {
|
||||
let data = JSON.parse(Backend.callLuaFunction("GetGeneralData", [name]));
|
||||
kingdom = data.kingdom;
|
||||
hp = data.hp;
|
||||
maxHp = data.maxHp;
|
||||
|
||||
let splited = name.split("__");
|
||||
if (splited.length > 1) {
|
||||
pkgName = splited[0];
|
||||
} else {
|
||||
pkgName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue