custom cfc_disconnect_interface
intentionally out-of-tree to avoid custom interface being under GPLv3
This commit is contained in:
parent
eda2fe0db0
commit
3a4c9c373f
@ -0,0 +1,139 @@
|
|||||||
|
include( "cfc_disconnect_interface/client/cl_api.lua" )
|
||||||
|
|
||||||
|
local TIME_TO_RESTART = GetConVar( "cfc_disconnect_interface_restart_time" ):GetInt()
|
||||||
|
|
||||||
|
local apiState
|
||||||
|
|
||||||
|
--Auto Reconnect by Extra Mental
|
||||||
|
|
||||||
|
surface.CreateFont( "ARFontTitle",{
|
||||||
|
font = "Trebuchet",
|
||||||
|
size = ScrH()/1.5/18
|
||||||
|
})
|
||||||
|
|
||||||
|
surface.CreateFont( "ARFontBody",{
|
||||||
|
font = "Trebuchet",
|
||||||
|
size = ScrH()/1.5/15
|
||||||
|
})
|
||||||
|
|
||||||
|
surface.CreateFont( "ARFontButton",{
|
||||||
|
font = "Trebuchet",
|
||||||
|
size = ScrH()/1.5/12
|
||||||
|
})
|
||||||
|
|
||||||
|
local Menu
|
||||||
|
local WaitMsg = ""
|
||||||
|
local Cancelled = false
|
||||||
|
local MenuOpen = false
|
||||||
|
local CountDown = TIME_TO_RESTART
|
||||||
|
local CountDownActive = false
|
||||||
|
|
||||||
|
--Safely close the menu without error.
|
||||||
|
local function CloseMenu()
|
||||||
|
if MenuOpen then
|
||||||
|
MenuOpen = false
|
||||||
|
CountDownActive = false
|
||||||
|
CountDown = TIME_TO_RESTART
|
||||||
|
Menu:Close()
|
||||||
|
if dTimer.Exists("CountDownRetry") then dTimer.Remove("CountDownRetry") end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Open the menu
|
||||||
|
local function OpenMenu()
|
||||||
|
if MenuOpen or Cancelled then return end--Dont want to open more than 1 or when cancelled
|
||||||
|
|
||||||
|
MenuOpen = true
|
||||||
|
WaitMsg = "Waiting for server response..."
|
||||||
|
|
||||||
|
Menu = vgui.Create("DFrame")
|
||||||
|
Menu:SetSize(ScrW()/2.5,ScrH()/5)
|
||||||
|
Menu:SetTitle("")
|
||||||
|
Menu:CenterHorizontal(0.5)
|
||||||
|
Menu:CenterVertical(0.1)
|
||||||
|
Menu:ShowCloseButton(false)
|
||||||
|
Menu:MakePopup()
|
||||||
|
|
||||||
|
Menu.Paint = function(self, W, H)
|
||||||
|
draw.RoundedBox(0, 0, 0, W, H, Color(50,50,50,255))--Background
|
||||||
|
draw.RoundedBox(0, 0, 0, W, H/4.8, Color(255,0,0,255))--TitleBar
|
||||||
|
|
||||||
|
draw.SimpleText("Connection Lost D:", "ARFontTitle", W/2, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER)
|
||||||
|
draw.SimpleText(WaitMsg, "ARFontBody", W/2, H/3.3, Color(255, 255, 255), TEXT_ALIGN_CENTER)
|
||||||
|
end
|
||||||
|
|
||||||
|
local CancelBtn = vgui.Create("DButton")
|
||||||
|
CancelBtn:SetParent(Menu)
|
||||||
|
CancelBtn:SetText("")
|
||||||
|
CancelBtn:SetSize(Menu:GetWide()/2,Menu:GetTall()/3)
|
||||||
|
CancelBtn:SetPos(0,Menu:GetTall()-(Menu:GetTall()/3))
|
||||||
|
CancelBtn.Paint = function( self, W, H )
|
||||||
|
draw.RoundedBox(0, W*0.02/2, H*0.08/2, W/1.02, H/1.08, Color(255,255,255,255))
|
||||||
|
draw.DrawText("Cancel", "ARFontButton", W/2, 2, Color(0,0,0,255), TEXT_ALIGN_CENTER)
|
||||||
|
end
|
||||||
|
|
||||||
|
local DiscBtn = vgui.Create("DButton")
|
||||||
|
DiscBtn:SetParent(Menu)
|
||||||
|
DiscBtn:SetText("")
|
||||||
|
DiscBtn:SetSize(Menu:GetWide()/2,Menu:GetTall()/3)
|
||||||
|
DiscBtn:SetPos(Menu:GetWide()/2,Menu:GetTall()-(Menu:GetTall()/3))
|
||||||
|
DiscBtn.Paint = function( self, W, H )
|
||||||
|
draw.RoundedBox(0, W*0.02/2, H*0.08/2, W/1.02, H/1.08, Color(255,255,255,255))
|
||||||
|
draw.DrawText("Disconnect", "ARFontButton", W/2, 2, Color(0,0,0,255), TEXT_ALIGN_CENTER)
|
||||||
|
end
|
||||||
|
|
||||||
|
CancelBtn.DoClick = function()
|
||||||
|
Cancelled = true
|
||||||
|
CountDownActive = false
|
||||||
|
CloseMenu()
|
||||||
|
end
|
||||||
|
DiscBtn.DoClick = function()
|
||||||
|
RunConsoleCommand("disconnect")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Menu:Think()
|
||||||
|
if apiState == CFCCrashAPI.INACTIVE or apiState == nil then
|
||||||
|
CloseMenu()
|
||||||
|
else
|
||||||
|
CountDownActive = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not dTimer.Exists("CountDownRetry") then
|
||||||
|
dTimer.Create("CountDownRetry", 1, CountDown + 1, function()
|
||||||
|
if CountDownActive then
|
||||||
|
if CountDown <= 0 then
|
||||||
|
LocalPlayer():ConCommand("retry")
|
||||||
|
end
|
||||||
|
CountDown = CountDown - 1
|
||||||
|
WaitMsg = "Auto reconnecting in " .. CountDown .. " seconds."
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
hook.Add( "ShutDown", "CFC_DisconnectInterface_Shutdown", function()
|
||||||
|
if MenuOpen then
|
||||||
|
CloseMenu()
|
||||||
|
end
|
||||||
|
end )
|
||||||
|
|
||||||
|
hook.Add( "CFC_CrashTick", "CFC_DisconnectInterface_InterfaceUpdate", function( isCrashing, _timeDown, _apiState )
|
||||||
|
if _apiState ~= CFCCrashAPI.PINGING_API then
|
||||||
|
apiState = _apiState
|
||||||
|
end
|
||||||
|
if isCrashing then
|
||||||
|
-- Open interface if server is crashing, API has responded, interface isn't already open, and interface has not yet been opened
|
||||||
|
if _apiState == CFCCrashAPI.PINGING_API or _apiState == CFCCrashAPI.SERVER_UP then return end
|
||||||
|
if MenuOpen then return end
|
||||||
|
OpenMenu()
|
||||||
|
else
|
||||||
|
-- Close menu if server stops crashing
|
||||||
|
if MenuOpen then
|
||||||
|
CloseMenu()
|
||||||
|
else
|
||||||
|
Cancelled = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end )
|
Loading…
Reference in New Issue
Block a user