Skip to content

Commit

Permalink
Merge pull request #665 from jere0500/friendjoin-merge
Browse files Browse the repository at this point in the history
Allow friends to join private battle directly
  • Loading branch information
AntlerForce authored Nov 8, 2024
2 parents 740e3f5 + 43f50e4 commit 5541fa3
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions LuaMenu/widgets/chobby/components/battle/battle_list_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "Friends only",
checked = false,
objectOverrideFont = WG.Chobby.Configuration:GetFont(2),
OnChange = {
function (obj, newState)
allowFriendsToJoin = newState

end
},
parent = hostBattleWindow,
tooltip = "Only friends can join your battle, but they can do so without the password.",
}
friendCheckbox:Hide()

local userWantsPrivateBattle = false
--if lobby:GetMyIsAdmin() then -- TODO: remove this when feature goes live
local privateCheckbox = Checkbox:New {
Expand All @@ -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") .. ":",
Expand Down Expand Up @@ -1462,6 +1489,7 @@ function BattleListWindow:OpenHostWindow()
Spring.Echo("Got the password:", mypassword)
end
end


lobby:AddListener("OnSaidPrivate", listenForPrivateBattle)
lobby:SayPrivate(targetCluster, "!privatehost")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5541fa3

Please sign in to comment.