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

Add pregame timer support #5372

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions LuaRules/Gadgets/start_pregame_timer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function gadget:GetInfo()
return {
name = "Pregame Timer",
desc = "Listens to server pregame timekeeping messages",
author = "Sprung",
date = "2024",
license = "Public Domain",
layer = 0,
enabled = true,
}
end

if gadgetHandler:IsSyncedCode() then

function gadget:Initialize()
if Spring.GetGameFrame() > 0 then
gadgetHandler:RemoveGadget()
return
end
end

function gadget:GameStart()
Spring.SetGameRulesParam("pregame_timer_seconds", nil)
gadgetHandler:RemoveGadget()
end

function gadget:GotChatMsg (msg, senderID)
if string.find(msg, "pregame_timer_seconds") ~= 1 then
return
end

if senderID ~= 255 then -- autohost
return
end

local secondsUntilStart = tonumber(string.sub(msg, 23))
if not secondsUntilStart then
return
end

Spring.SetGameRulesParam("pregame_timer_seconds", secondsUntilStart)
SendToUnsynced("PreGameTimekeeping", secondsUntilStart)
end

else -- unsynced

function gadget:Initialize()
if Spring.GetGameFrame() > 0 then
gadgetHandler:RemoveGadget()
return
end

gadgetHandler:AddSyncAction("PreGameTimekeeping", function (_, secondsUntilStart)
if Script.LuaUI("PreGameTimekeeping") then
Script.LuaUI.PreGameTimekeeping(secondsUntilStart)
end
end)
end

function gadget:GameStart()
gadgetHandler:RemoveGadget()
end

function gadget:Shutdown()
gadgetHandler:RemoveSyncAction("PreGameTimekeeping")
end

end
6 changes: 6 additions & 0 deletions LuaUI/Widgets/gui_epicmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,12 @@ function widget:GameFrame(n)
end
end

function widget:PreGameTimekeeping(secondsUntilStart)
if lbl_gtime then
lbl_gtime:SetCaption("-"..GetTimeString(secondsUntilStart))
end
end

function widget:KeyPress(key, modifier, isRepeat, label)
if not get_key_bind_mod then
if key == KEYSYMS.LCTRL
Expand Down
8 changes: 8 additions & 0 deletions LuaUI/cawidgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ local flexCallIns = {
"UnitStructureMoved",
'MissileFired',
'MissileDestroyed',
"PreGameTimekeeping",
}
local flexCallInMap = {}
for _, ci in ipairs(flexCallIns) do
Expand Down Expand Up @@ -2657,6 +2658,13 @@ function widgetHandler:Load(zip)
end
end


function widgetHandler:PreGameTimekeeping(secondsUntilStart)
for _,w in r_ipairs(self.PreGameTimekeepingList) do
w:PreGameTimekeeping(secondsUntilStart)
end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Expand Down