From 61bf2879ab65cbc730bb162c25819617d390f225 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 4 Oct 2026 10:03:33 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20Debug=20HUD=20toggle=20is=20now=20LIVE?= =?UTF-8?q?=20=E2=80=94=20flipping=20the=20checkbox=20mid-session=20recrea?= =?UTF-8?q?tes=20the=20player=20HUD=20on=20the=20spot=20(NumericUI=20recre?= =?UTF-8?q?ate=5Fhud=20pattern,=20pcall-guarded,=200.5s=20debounce);=20UIH?= =?UTF-8?q?ud:init=20hook=20also=20strips=20the=20element=20when=20setting?= =?UTF-8?q?=20is=20off=20so=20recreate=20removes=20it;=20inject=20log=20no?= =?UTF-8?q?w=20reports=20ADDED?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/mods/AutoMark/ui/debug_hud.lua | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/AutoMark/scripts/mods/AutoMark/ui/debug_hud.lua b/AutoMark/scripts/mods/AutoMark/ui/debug_hud.lua index 2304ed3..f467741 100644 --- a/AutoMark/scripts/mods/AutoMark/ui/debug_hud.lua +++ b/AutoMark/scripts/mods/AutoMark/ui/debug_hud.lua @@ -18,33 +18,82 @@ mod:add_require_path(ELEMENT_FILENAME) mod:hook("UIHud", "init", function(func, self, elements, visibility_groups, params) - if mod_settings.debug_hud and elements then - local already = false + if elements then + local idx = nil for i = 1, #elements do if elements[i].class_name == ELEMENT_CLASS_NAME then - already = true + idx = i break end end - if not already then + if mod_settings.debug_hud and not idx then elements[#elements + 1] = { class_name = ELEMENT_CLASS_NAME, filename = ELEMENT_FILENAME, use_hud_scale = true, visibility_groups = { "alive", "dead" }, } + if not mod.debug_hud_inject_logged then + mod.debug_hud_inject_logged = true + mod:diag("OMNI-HUD inject: ADDED") + end + elseif not mod_settings.debug_hud and idx then + table.remove(elements, idx) end - if not mod.debug_hud_inject_logged then - mod.debug_hud_inject_logged = true - mod:diag("OMNI-HUD inject: setting=on already=", tostring(already)) - end - elseif not mod.debug_hud_inject_logged then - mod.debug_hud_inject_logged = true - mod:diag("OMNI-HUD inject: setting=off, skipped") end return func(self, elements, visibility_groups, params) end) +-- live toggling: UIHud init only runs on HUD creation, so when the setting flips we +-- rebuild the HUD on the spot (pattern borrowed from NumericUI's recreate_hud) +local recreate_timer = 0 +local last_debug_hud = nil + +mod.update = function (dt) + local want = mod_settings.debug_hud and true or false + if last_debug_hud == nil then + last_debug_hud = want + return + end + + if want ~= last_debug_hud then + last_debug_hud = want + recreate_timer = 0.5 + return + end + + if recreate_timer <= 0 then + return + end + + recreate_timer = recreate_timer - dt + if recreate_timer > 0 then + return + end + + local ok, err = pcall(function() + local ui_manager = Managers.ui + local hud = ui_manager and ui_manager._hud + if not hud or not hud._element_definitions or not hud._visibility_groups then + return + end + + local player = Managers.player and Managers.player:local_player(1) + if not player then + return + end + + local elements = hud._element_definitions + local visibility_groups = hud._visibility_groups + hud:destroy() + ui_manager:create_player_hud(player:peer_id(), player:local_player_id(), elements, visibility_groups) + mod:diag("OMNI-HUD: live recreate, debug_hud ->", tostring(want)) + end) + if not ok then + mod:diag("OMNI-HUD: live recreate FAILED:", tostring(err)) + end +end + local function unit_breed_name(unit) if not unit then return "-"