From 9c2d5439e05b0c184cbf4772f65d47722b3017b4 Mon Sep 17 00:00:00 2001 From: jere0500 Date: Tue, 23 Apr 2024 14:41:01 +0200 Subject: [PATCH 1/2] Allow friends to join private battle directly Added checkbox, Setting the gatekeeper to friends. Try to directly join, on lobby with a password (could be open for friends) --- .../components/battle/battle_list_window.lua | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index 01c636600..22b926719 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -1405,6 +1405,27 @@ function BattleListWindow:OpenHostWindow() parent = hostBattleWindow, } + local friendCheckbox = Checkbox:New { + x = 15, + width = 300, + y = 225, + height = 35, + boxalign = "left", + boxsize = 20, + caption = "Allow friends to join directly", + checked = false, + objectOverrideFont = WG.Chobby.Configuration:GetFont(2), + OnChange = { + function (obj, newState) + allowFriendsToJoin = newState + + end + }, + parent = hostBattleWindow, + tooltip = "If you have a private battle, allow friends to join without entering a password.", + } + friendCheckbox:Hide() + local userWantsPrivateBattle = false --if lobby:GetMyIsAdmin() then -- TODO: remove this when feature goes live local privateCheckbox = Checkbox:New { @@ -1420,17 +1441,23 @@ function BattleListWindow:OpenHostWindow() OnChange = { function (obj, newState) userWantsPrivateBattle = newState + if newState then + friendCheckbox:Show() + else + friendCheckbox:Hide() + end end }, parent = hostBattleWindow, tooltip = "If you want a passworded battleroom, please be patient while we spin up a room for you. You will be PM-ed a 4 character password you can share with your friends.", } + --end local errorLabel = Label:New { x = 15, width = 200, - y = 235, + y = 245, align = "left", height = 35, caption = "",-- i18n("game_type") .. ":", @@ -1462,6 +1489,7 @@ function BattleListWindow:OpenHostWindow() Spring.Echo("Got the password:", mypassword) end end + lobby:AddListener("OnSaidPrivate", listenForPrivateBattle) lobby:SayPrivate(targetCluster, "!privatehost") @@ -1499,8 +1527,20 @@ function BattleListWindow:OpenHostWindow() lobby:JoinBattle(myprivatebattleID, mypassword, _, true) -- forcePlayer = true lobby:RemoveListener("OnSaidPrivate", listenForPrivateBattle) + local function listenForBoss(listener, userName, message, msgDate) + if string.find(userName, targetCluster, nil, true) and string.find(message, "* Boss mode enabled for", nil, true) then + Spring.Echo(userName) + lobby:SayBattle("$gatekeeper friends") + lobby:RemoveListener("OnSaidBattleEx", listenForBoss) + end + end + local function bossSelf() local myplayername = lobby:GetMyUserName() or '' + if allowFriendsToJoin then + -- sets the gatekeeper after being set to boss + lobby:AddListener("OnSaidBattleEx", listenForBoss) + end lobby:SayBattle("Password is: " .. mypassword) lobby:SayBattle("!boss " .. myplayername) end @@ -1740,7 +1780,9 @@ function BattleListWindow:JoinBattle(battle, _, _, joinAsPlayer) lobby:AddListener("OnJoinBattleFailed", onJoinBattleFailed) lobby:AddListener("OnJoinBattle", onJoinBattle) - + + -- try to join first without a password, succeeds when lobby is open to friends + tryJoin() local popupHolder = PriorityPopup(passwordWindow, CancelFunc, tryJoin) screen0:FocusControl(ebPassword) end From 43f50e41b5054a453986ed41eee1aac41d9f697a Mon Sep 17 00:00:00 2001 From: Moose <124457076+AntlerForce@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:35:43 -0700 Subject: [PATCH 2/2] Change language around gatekeeper setting This dialog still isn't great looking. --- .../widgets/chobby/components/battle/battle_list_window.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua index 22b926719..91910121f 100644 --- a/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua +++ b/LuaMenu/widgets/chobby/components/battle/battle_list_window.lua @@ -1412,7 +1412,7 @@ function BattleListWindow:OpenHostWindow() height = 35, boxalign = "left", boxsize = 20, - caption = "Allow friends to join directly", + caption = "Friends only", checked = false, objectOverrideFont = WG.Chobby.Configuration:GetFont(2), OnChange = { @@ -1422,7 +1422,7 @@ function BattleListWindow:OpenHostWindow() end }, parent = hostBattleWindow, - tooltip = "If you have a private battle, allow friends to join without entering a password.", + tooltip = "Only friends can join your battle, but they can do so without the password.", } friendCheckbox:Hide()