ban generals (#146)

- 禁将功能
- 公告展示
This commit is contained in:
Ho-spair 2023-05-13 14:20:48 +08:00 committed by GitHub
parent a7e3ad0f19
commit 0033cd6c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 8 deletions

View File

@ -205,6 +205,7 @@ fk.client_callback["EnterRoom"] = function(jsonData)
local data = json.decode(jsonData)[3]
Fk.disabled_packs = data.disabledPack
Fk.disabled_generals = data.disabledGenerals
ClientInstance:notifyUI("EnterRoom", jsonData)
end

View File

@ -116,6 +116,8 @@ FreeKill使用的是libgit2的C API与此同时使用Git完成拓展包的下
["Cancel"] = "取消",
["End"] = "结束",
["Quit"] = "退出",
["BanGeneral"] = "禁将",
["ResumeGeneral"] = "解禁",
["$WelcomeToLobby"] = "欢迎进入FreeKill游戏大厅",

View File

@ -50,6 +50,7 @@ function Engine:initialize()
self.translations = {} -- srcText --> translated
self.game_modes = {}
self.disabled_packs = {}
self.disabled_generals = {}
self.kingdoms = {}
self:loadPackages()
@ -213,8 +214,9 @@ function Engine:getSameGenerals(name)
local tName = tmp[#tmp]
local ret = self.same_generals[tName] or {}
return table.filter(ret, function(g)
return g ~= name and self.generals[g] ~= nil and not
table.contains(self.disabled_packs, self.generals[g].package.name)
return g ~= name and self.generals[g] ~= nil and
not table.contains(self.disabled_packs, self.generals[g].package.name) and
not table.contains(self.disabled_generals, g)
end)
end
@ -334,7 +336,7 @@ function Engine:getAllGenerals(except)
local result = {}
for _, general in pairs(self.generals) do
if not (except and table.contains(except, general)) then
if not table.contains(self.disabled_packs, general.package.name) then
if not table.contains(self.disabled_packs, general.package.name) and not table.contains(self.disabled_generals, general.name) then
table.insert(result, general)
end
end

View File

@ -67,6 +67,7 @@ function Room:initialize(_room)
Room.initialize(self, _room) -- clear old data
self.settings = json.decode(_room:settings())
Fk.disabled_packs = self.settings.disabledPack
Fk.disabled_generals = self.settings.disabledGenerals
local main_co = coroutine.create(function()
self:run()
end)

View File

@ -22,6 +22,7 @@ QtObject {
property string ladyImg
property real bgmVolume
property bool disableMsgAudio
property var disabledGenerals: []
property int preferredTimeout
@ -59,6 +60,7 @@ QtObject {
bgmVolume = conf.bgmVolume ?? 50.;
disableMsgAudio = conf.disableMsgAudio ?? false;
preferredTimeout = conf.preferredTimeout ?? 15;
disabledGenerals = conf.disabledGenerals ?? [];
}
function saveConf() {
@ -81,6 +83,7 @@ QtObject {
conf.bgmVolume = bgmVolume;
conf.disableMsgAudio = disableMsgAudio;
conf.preferredTimeout = preferredTimeout;
conf.disabledGenerals = disabledGenerals;
Backend.saveConf(JSON.stringify(conf, undefined, 2));
}

View File

@ -67,6 +67,28 @@ Item {
generalDetail.updateGeneral();
// generalDetail.open();
}
Rectangle {
anchors.fill: parent
color: "black"
opacity: config.disabledGenerals.includes(modelData) ? 0.7 : 0
Behavior on opacity {
NumberAnimation {}
}
}
GlowText {
visible: config.disabledGenerals.includes(modelData)
text: '禁'
anchors.centerIn: parent
font.family: fontLi2.name
color: "#E4D5A0"
font.pixelSize: 36
font.weight: Font.Medium
glow.color: "black"
glow.spread: 0.3
glow.radius: 5
}
}
}
@ -172,11 +194,40 @@ Item {
}
}
ColumnLayout {
anchors.right: parent.right
Button {
text: Backend.translate("Quit")
anchors.right: parent.right
onClicked: {
mainStack.pop();
config.saveConf();
}
}
Button {
id: banButton
text: Backend.translate(config.disabledGenerals.includes(detailGeneralCard.name) ? 'ResumeGeneral' : 'BanGeneral')
visible: detailGeneralCard.name
onClicked: {
const { disabledGenerals } = config;
const { name } = detailGeneralCard;
if (banButton.text === Backend.translate('ResumeGeneral')) {
const deleteIndex = disabledGenerals.findIndex((general) => general === name);
if (deleteIndex === -1) {
return;
}
disabledGenerals.splice(deleteIndex, 1);
} else {
if (disabledGenerals.includes(name)) {
return;
}
disabledGenerals.push(name);
}
config.disabledGeneralsChanged();
}
}
}

View File

@ -11,6 +11,38 @@ import "Logic.js" as Logic
Item {
id: root
property alias roomModel: roomModel
Rectangle {
width: parent.width / 2 - roomListLayout.width / 2
height: parent.height * 0.7
anchors.top: exitButton.bottom
anchors.bottom: createRoomButton.top
anchors.right: parent.right
anchors.rightMargin: 20
color: "#88EEEEEE"
radius: 6
Flickable {
id: flickableContainer
ScrollBar.vertical: ScrollBar {}
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 10
flickableDirection: Flickable.VerticalFlick
width: parent.width - 10
height: parent.height - 10
contentWidth: flickableContainer.width
contentHeight: flickableContainer.height
clip: true
Text {
anchors.fill: parent
wrapMode: TextEdit.WrapAnywhere
text: '<h1>公告测试</h1><br>● 更新跳过觉醒(神郭嘉)、转换技概念(许攸)。<br>● 武将一览中增加禁将功能。'
}
}
}
Component {
id: roomDelegate
@ -81,6 +113,7 @@ Item {
}
RowLayout {
id: roomListLayout
anchors.centerIn: parent
width: childrenRect.width
height: parent.height
@ -113,6 +146,7 @@ Item {
}
Button {
id: createRoomButton
anchors.bottom: buttonRow.top
anchors.right: parent.right
width: 120
@ -162,6 +196,7 @@ Item {
}
Button {
id: exitButton
anchors.right: parent.right
text: Backend.translate("Exit Lobby")
display: AbstractButton.TextBesideIcon

View File

@ -116,6 +116,18 @@ ColumnLayout {
onClicked: {
root.finished();
mainWindow.busy = true;
let disabledGenerals = config.disabledGenerals.slice();
if (disabledGenerals.length) {
const availablePack = JSON.parse(Backend.callLuaFunction("GetAllGeneralPack", [])).
filter((pack) => !config.disabledPack.includes(pack));
disabledGenerals = disabledGenerals.filter((general) => {
return availablePack.find((pack) => JSON.parse(Backend.callLuaFunction("GetGenerals", [pack])).includes(general));
});
disabledGenerals = Array.from(new Set(disabledGenerals));
}
ClientInstance.notifyServer(
"CreateRoom",
JSON.stringify([roomName.text, playerNum.value, config.preferredTimeout, {
@ -124,6 +136,7 @@ ColumnLayout {
gameMode: config.preferedMode,
disabledPack: config.disabledPack,
generalNum: config.preferredGeneralNum,
disabledGenerals,
}])
);
}