Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow friends to join private battle directly #665

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1343,6 +1343,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 {
Expand All @@ -1358,17 +1379,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 @@ -1397,6 +1424,7 @@ function BattleListWindow:OpenHostWindow()
Spring.Echo("Got the password:", mypassword)
end
end


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