@@ -33,6 +33,14 @@ local system = require("client.src.system")
3333local ModController = require (" client.src.mods.ModController" )
3434
3535local RichPresence = require (" client.lib.rich_presence.RichPresence" )
36+ local DebugSettings = require (" client.src.debug.DebugSettings" )
37+ local Button = require (" client.src.ui.Button" )
38+ local TextButton = require (" client.src.ui.TextButton" )
39+ local OverlayContainer = require (" client.src.ui.OverlayContainer" )
40+ local DebugMenu = require (" client.src.debug.DebugMenu" )
41+ local Label = require (" client.src.ui.Label" )
42+ local UIElement = require (" client.src.ui.UIElement" )
43+ local NavigationStack = require (" client.src.NavigationStack" )
3644
3745-- Provides a scale that is on .5 boundary to make sure it renders well.
3846-- Useful for creating new canvas with a solid DPI
@@ -106,12 +114,19 @@ local Game = class(
106114
107115 -- time in seconds, can be used by other elements to track the passing of time beyond dt
108116 self .timer = love .timer .getTime ()
117+
118+ self .debugOverlay = nil
119+ self .debugButton = nil
120+
121+ -- Root UI element that contains all UI (scenes + overlays + debug)
122+ self .uiRoot = UIElement ({x = 0 , y = 0 , width = consts .CANVAS_WIDTH , height = consts .CANVAS_HEIGHT })
109123 end
110124)
111125
112126Game .newCanvasSnappedScale = newCanvasSnappedScale
113127
114128function Game :load ()
129+ DebugSettings .init ()
115130 PuzzleLibrary .cleanupDefaultPuzzles (consts .PUZZLES_SAVE_DIRECTORY )
116131
117132 -- move to constructor
@@ -131,8 +146,11 @@ function Game:load()
131146 self .input :importConfigurations (user_input_conf )
132147 end
133148
134- self .navigationStack = require ( " client.src. NavigationStack" )
149+ self .navigationStack = NavigationStack ({} )
135150 self .navigationStack :push (StartUp ({setupRoutine = self .setupRoutine }))
151+
152+ -- Add navigation stack to root UI
153+ self .uiRoot :addChild (self .navigationStack )
136154 self .globalCanvas = love .graphics .newCanvas (consts .CANVAS_WIDTH , consts .CANVAS_HEIGHT , {dpiscale = GAME :newCanvasSnappedScale ()})
137155end
138156
@@ -253,6 +271,8 @@ function Game:setupRoutine()
253271
254272 self :initializeLocalPlayer ()
255273 ModController :loadModFor (characters [GAME .localPlayer .settings .characterId ], GAME .localPlayer , true )
274+
275+ self :initializeDebugOverlay ()
256276end
257277
258278-- GAME.localPlayer is the standard player for battleRooms that don't get started from replays/spectate
@@ -366,9 +386,9 @@ function Game:update(dt)
366386
367387 handleShortcuts ()
368388
369- prof .push (" navigationStack update" )
370- self .navigationStack :update (dt )
371- prof .pop (" navigationStack update" )
389+ prof .push (" uiRoot update" )
390+ self .uiRoot :update (dt )
391+ prof .pop (" uiRoot update" )
372392
373393 if self .backgroundImage then
374394 self .backgroundImage :update (dt )
@@ -386,7 +406,7 @@ function Game:draw()
386406 love .graphics .clear ()
387407
388408 -- With this, self.globalCanvas is clear and set as our active canvas everything is being drawn to
389- self .navigationStack :draw ()
409+ self .uiRoot :draw ()
390410
391411 self :drawFPS ()
392412 self :drawScaleInfo ()
@@ -402,8 +422,7 @@ function Game:draw()
402422end
403423
404424function Game :drawFPS ()
405- -- Draw the FPS if enabled
406- if self .config .show_fps then
425+ if self .config .show_fps or DebugSettings .forceFPS () then
407426 love .graphics .print (" FPS: " .. love .timer .getFPS (), 1 , 1 )
408427 end
409428end
@@ -666,4 +685,40 @@ function Game:setLanguage(lang_code)
666685 Localization :refresh_global_strings ()
667686end
668687
688+ function Game :initializeDebugOverlay ()
689+ if not DEBUG_ENABLED then
690+ return
691+ end
692+
693+ self .debugButton = TextButton ({
694+ x = consts .CANVAS_WIDTH - 50 ,
695+ y = consts .CANVAS_HEIGHT - 50 ,
696+ label = Label ({
697+ text = " Debug" ,
698+ translate = false ,
699+ hAlign = " center" ,
700+ vAlign = " center"
701+ }),
702+ width = 40 ,
703+ height = 40 ,
704+ onClick = function ()
705+ if self .debugOverlay then
706+ if not self .debugOverlay :isActive () then
707+ self .debugOverlay :open ()
708+ end
709+ end
710+ end
711+ })
712+
713+ local debugMenu = DebugMenu .makeDebugMenu ({height = consts .CANVAS_HEIGHT - 40 })
714+ self .debugOverlay = OverlayContainer ({
715+ content = debugMenu
716+ })
717+
718+ -- Add debug UI to root
719+ self .uiRoot :addChild (self .debugButton )
720+ self .uiRoot :addChild (self .debugOverlay )
721+ end
722+
723+
669724return Game
0 commit comments