mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-15 19:22:25 +08:00
General & Cards overview (#18)
* adjust room list of the lobby * add client lua func * overviews Co-authored-by: Notify-ctrl <notify-ctrl@qq.com>
This commit is contained in:
parent
af4924c260
commit
fd2d7b4d10
|
@ -6,7 +6,9 @@ function GetGeneralData(name)
|
|||
local general = Fk.generals[name]
|
||||
if general == nil then general = Fk.generals["diaochan"] end
|
||||
return json.encode {
|
||||
general.kingdom
|
||||
kingdom = general.kingdom,
|
||||
hp = general.hp,
|
||||
maxHp = general.maxHp
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -24,3 +26,39 @@ function GetCardData(id)
|
|||
color = card.color,
|
||||
}
|
||||
end
|
||||
|
||||
function GetAllGeneralPack()
|
||||
local ret = {}
|
||||
for _, name in ipairs(Fk.package_names) do
|
||||
if Fk.packages[name].type == Package.GeneralPack then
|
||||
table.insert(ret, name)
|
||||
end
|
||||
end
|
||||
return json.encode(ret)
|
||||
end
|
||||
|
||||
function GetGenerals(pack_name)
|
||||
local ret = {}
|
||||
for _, g in ipairs(Fk.packages[pack_name].generals) do
|
||||
table.insert(ret, g.name)
|
||||
end
|
||||
return json.encode(ret)
|
||||
end
|
||||
|
||||
function GetAllCardPack()
|
||||
local ret = {}
|
||||
for _, name in ipairs(Fk.package_names) do
|
||||
if Fk.packages[name].type == Package.CardPack then
|
||||
table.insert(ret, name)
|
||||
end
|
||||
end
|
||||
return json.encode(ret)
|
||||
end
|
||||
|
||||
function GetCards(pack_name)
|
||||
local ret = {}
|
||||
for _, c in ipairs(Fk.packages[pack_name].cards) do
|
||||
table.insert(ret, c.id)
|
||||
end
|
||||
return json.encode(ret)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---@class Engine : Object
|
||||
---@field packages table<string, Package>
|
||||
---@field package_names string[]
|
||||
---@field skills table<string, Skill>
|
||||
---@field related_skills table<string, Skill[]>
|
||||
---@field global_trigger TriggerSkill[]
|
||||
|
@ -19,6 +20,7 @@ function Engine:initialize()
|
|||
Fk = self
|
||||
|
||||
self.packages = {} -- name --> Package
|
||||
self.package_names = {}
|
||||
self.skills = {} -- name --> Skill
|
||||
self.related_skills = {} -- skillName --> relatedSkill[]
|
||||
self.global_trigger = {}
|
||||
|
@ -37,6 +39,7 @@ function Engine:loadPackage(pack)
|
|||
error(string.format("Duplicate package %s detected", pack.name))
|
||||
end
|
||||
self.packages[pack.name] = pack
|
||||
table.insert(self.package_names, pack.name)
|
||||
|
||||
-- add cards, generals and skills to Engine
|
||||
if pack.type == Package.CardPack then
|
||||
|
@ -48,9 +51,26 @@ function Engine:loadPackage(pack)
|
|||
end
|
||||
|
||||
function Engine:loadPackages()
|
||||
for _, dir in ipairs(FileIO.ls("packages")) do
|
||||
local directories = FileIO.ls("packages")
|
||||
|
||||
-- load standard & standard_cards first
|
||||
self:loadPackage(require("packages.standard"))
|
||||
self:loadPackage(require("packages.standard_cards"))
|
||||
table.removeOne(directories, "standard")
|
||||
table.removeOne(directories, "standard_cards")
|
||||
|
||||
for _, dir in ipairs(directories) do
|
||||
if FileIO.isDir("packages/" .. dir) then
|
||||
self:loadPackage(require(string.format("packages.%s", dir)))
|
||||
local pack = require(string.format("packages.%s", dir))
|
||||
-- Note that instance of Package is a table too
|
||||
-- so dont use type(pack) == "table" here
|
||||
if pack[1] ~= nil then
|
||||
for _, p in ipairs(pack) do
|
||||
self:loadPackage(p)
|
||||
end
|
||||
else
|
||||
self:loadPackage(pack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ extension.metadata = require "packages.standard.metadata"
|
|||
dofile "packages/standard/game_rule.lua"
|
||||
|
||||
Fk:loadTranslationTable{
|
||||
["standard"] = "标准包",
|
||||
["wei"] = "魏",
|
||||
["shu"] = "蜀",
|
||||
["wu"] = "吴",
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
local extension = Package:new("standard_cards", Package.CardPack)
|
||||
extension.metadata = require "packages.standard_cards.metadata"
|
||||
|
||||
Fk:loadTranslationTable{
|
||||
["standard_cards"] = "标+EX"
|
||||
}
|
||||
|
||||
local slash = fk.CreateBasicCard{
|
||||
name = "slash",
|
||||
number = 7,
|
||||
|
@ -278,6 +282,7 @@ Fk:loadTranslationTable{
|
|||
extension:addCards({
|
||||
indulgence,
|
||||
indulgence:clone(Card.Club, 6),
|
||||
indulgence:clone(Card.Heart, 6),
|
||||
})
|
||||
|
||||
local crossbow = fk.CreateWeapon{
|
||||
|
|
52
qml/Pages/CardsOverview.qml
Normal file
52
qml/Pages/CardsOverview.qml
Normal file
|
@ -0,0 +1,52 @@
|
|||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Controls 2.0
|
||||
import "RoomElement"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property bool loaded: false
|
||||
|
||||
ListView {
|
||||
width: Math.floor(root.width / 98) * 98
|
||||
height: parent.height
|
||||
anchors.centerIn: parent
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
model: ListModel {
|
||||
id: packages
|
||||
}
|
||||
|
||||
delegate: ColumnLayout {
|
||||
Text { text: Backend.translate(name) }
|
||||
GridLayout {
|
||||
columns: root.width / 98
|
||||
Repeater {
|
||||
model: JSON.parse(Backend.getCards(name))
|
||||
CardItem {
|
||||
autoBack: false
|
||||
Component.onCompleted: {
|
||||
let data = JSON.parse(Backend.getCardData(modelData));
|
||||
setData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Quit"
|
||||
anchors.right: parent.right
|
||||
onClicked: {
|
||||
mainStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
function loadPackages() {
|
||||
if (loaded) return;
|
||||
let packs = JSON.parse(Backend.getAllCardPack());
|
||||
packs.forEach((name) => packages.append({ name: name }));
|
||||
loaded = true;
|
||||
}
|
||||
}
|
53
qml/Pages/GeneralsOverview.qml
Normal file
53
qml/Pages/GeneralsOverview.qml
Normal file
|
@ -0,0 +1,53 @@
|
|||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Controls 2.0
|
||||
import "RoomElement"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property bool loaded: false
|
||||
|
||||
ListView {
|
||||
width: Math.floor(root.width / 98) * 98
|
||||
height: parent.height
|
||||
anchors.centerIn: parent
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
model: ListModel {
|
||||
id: packages
|
||||
}
|
||||
|
||||
delegate: ColumnLayout {
|
||||
Text { text: Backend.translate(name) }
|
||||
GridLayout {
|
||||
columns: root.width / 98
|
||||
Repeater {
|
||||
model: JSON.parse(Backend.getGenerals(name))
|
||||
GeneralCardItem {
|
||||
autoBack: false
|
||||
Component.onCompleted: {
|
||||
let data = JSON.parse(Backend.getGeneralData(modelData));
|
||||
name = modelData;
|
||||
kingdom = data.kingdom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Quit"
|
||||
anchors.right: parent.right
|
||||
onClicked: {
|
||||
mainStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
function loadPackages() {
|
||||
if (loaded) return;
|
||||
let packs = JSON.parse(Backend.getAllGeneralPack());
|
||||
packs.forEach((name) => packages.append({ name: name }));
|
||||
loaded = true;
|
||||
}
|
||||
}
|
|
@ -10,27 +10,26 @@ Item {
|
|||
Component {
|
||||
id: roomDelegate
|
||||
|
||||
Row {
|
||||
spacing: 24
|
||||
RowLayout {
|
||||
width: roomList.width * 0.9
|
||||
spacing: 16
|
||||
Text {
|
||||
width: 40
|
||||
text: String(roomId)
|
||||
text: roomId
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 40
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
text: roomName
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 20
|
||||
text: gameMode
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 10
|
||||
color: (playerNum == capacity) ? "red" : "black"
|
||||
text: String(playerNum) + "/" + String(capacity)
|
||||
text: playerNum + "/" + capacity
|
||||
}
|
||||
|
||||
Text {
|
||||
|
@ -60,30 +59,25 @@ Item {
|
|||
RowLayout {
|
||||
anchors.fill: parent
|
||||
Rectangle {
|
||||
width: root.width * 0.7
|
||||
height: root.height
|
||||
Layout.preferredWidth: root.width * 0.7
|
||||
Layout.fillHeight: true
|
||||
color: "#e2e2e1"
|
||||
radius: 4
|
||||
Text {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: "Room List"
|
||||
}
|
||||
ListView {
|
||||
height: parent.height * 0.9
|
||||
width: parent.width * 0.95
|
||||
contentHeight: roomDelegate.height * count
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
anchors.centerIn: parent
|
||||
id: roomList
|
||||
delegate: roomDelegate
|
||||
model: roomModel
|
||||
}
|
||||
Rectangle {
|
||||
id: scrollbar
|
||||
anchors.right: roomList.right
|
||||
y: roomList.visibleArea.yPosition * roomList.height
|
||||
width: 10
|
||||
radius: 4
|
||||
height: roomList.visibleArea.heightRatio * roomList.height
|
||||
color: "#a89da8"
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
|
@ -103,9 +97,17 @@ Item {
|
|||
}
|
||||
Button {
|
||||
text: "Generals Overview"
|
||||
onClicked: {
|
||||
mainStack.push(generalsOverview);
|
||||
mainStack.currentItem.loadPackages();
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "Cards Overview"
|
||||
onClicked: {
|
||||
mainStack.push(cardsOverview);
|
||||
mainStack.currentItem.loadPackages();
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "Scenarios Overview"
|
||||
|
|
|
@ -308,6 +308,6 @@ Item {
|
|||
if (!roomScene.isStarted) return;
|
||||
generalName.text = Backend.translate(general);
|
||||
let data = JSON.parse(Backend.getGeneralData(general));
|
||||
kingdom = data[0];
|
||||
kingdom = data.kingdom;
|
||||
}
|
||||
}
|
||||
|
|
19
qml/main.qml
19
qml/main.qml
|
@ -18,20 +18,11 @@ Window {
|
|||
anchors.fill: parent
|
||||
}
|
||||
|
||||
Component {
|
||||
id: init
|
||||
Init {}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: lobby
|
||||
Lobby {}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: room
|
||||
Room {}
|
||||
}
|
||||
Component { id: init; Init {} }
|
||||
Component { id: lobby; Lobby {} }
|
||||
Component { id: generalsOverview; GeneralsOverview {} }
|
||||
Component { id: cardsOverview; CardsOverview {} }
|
||||
Component { id: room; Room {} }
|
||||
|
||||
property bool busy: false
|
||||
BusyIndicator {
|
||||
|
|
|
@ -119,4 +119,36 @@ QString QmlBackend::getCardData(int id) {
|
|||
CALLFUNC
|
||||
}
|
||||
|
||||
QString QmlBackend::getAllGeneralPack() {
|
||||
lua_State *L = ClientInstance->getLuaState();
|
||||
lua_getglobal(L, "GetAllGeneralPack");
|
||||
lua_pushinteger(L, 0);
|
||||
|
||||
CALLFUNC
|
||||
}
|
||||
|
||||
QString QmlBackend::getGenerals(const QString &pack_name) {
|
||||
lua_State *L = ClientInstance->getLuaState();
|
||||
lua_getglobal(L, "GetGenerals");
|
||||
lua_pushstring(L, pack_name.toUtf8().data());
|
||||
|
||||
CALLFUNC
|
||||
}
|
||||
|
||||
QString QmlBackend::getAllCardPack() {
|
||||
lua_State *L = ClientInstance->getLuaState();
|
||||
lua_getglobal(L, "GetAllCardPack");
|
||||
lua_pushinteger(L, 0);
|
||||
|
||||
CALLFUNC
|
||||
}
|
||||
|
||||
QString QmlBackend::getCards(const QString &pack_name) {
|
||||
lua_State *L = ClientInstance->getLuaState();
|
||||
lua_getglobal(L, "GetCards");
|
||||
lua_pushstring(L, pack_name.toUtf8().data());
|
||||
|
||||
CALLFUNC
|
||||
}
|
||||
|
||||
#undef CALLFUNC
|
||||
|
|
|
@ -29,6 +29,10 @@ public:
|
|||
Q_INVOKABLE QString translate(const QString &src);
|
||||
Q_INVOKABLE QString getGeneralData(const QString &general_name);
|
||||
Q_INVOKABLE QString getCardData(int id);
|
||||
Q_INVOKABLE QString getAllGeneralPack();
|
||||
Q_INVOKABLE QString getGenerals(const QString &pack_name);
|
||||
Q_INVOKABLE QString getAllCardPack();
|
||||
Q_INVOKABLE QString getCards(const QString &pack_name);
|
||||
|
||||
signals:
|
||||
void notifyUI(const QString &command, const QString &jsonData);
|
||||
|
|
Loading…
Reference in New Issue
Block a user