From 78fb8804d8085f182bd966136b1a433846a5991e Mon Sep 17 00:00:00 2001 From: Ashleigh Adams Date: Wed, 3 Sep 2025 22:06:54 +0100 Subject: [PATCH] Prevent flicker Prevent flickering of the HTML menu, and close it instantly when the menu is closed --- src/SharpModMenu/PlayerMenuState.cs | 12 ++++++++++++ src/SharpModMenu/SharpModMenu.cs | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/SharpModMenu/PlayerMenuState.cs b/src/SharpModMenu/PlayerMenuState.cs index fd2759d..f025b40 100644 --- a/src/SharpModMenu/PlayerMenuState.cs +++ b/src/SharpModMenu/PlayerMenuState.cs @@ -142,7 +142,15 @@ private bool MenuActive if (value) Driver.ActiveMenuStates.Add(this); else + { Driver.ActiveMenuStates.Remove(this); + if (ShowingHtmlContent) + { + ShowingHtmlContent = false; + Player.PrintToCenterHtml(HtmlContent ?? "", 0); + HtmlContent = null; + } + } } } @@ -609,13 +617,17 @@ private void BuildMenuStrings(Menu currentMenu, Action(OnTick); RegisterListener(OnCheckTransmit); + RegisterListener(OnMapStartHandler); } public override void Unload(bool hotReload) @@ -67,8 +70,28 @@ public override void Unload(bool hotReload) ProcessUserCmdsFunc?.Unhook(ProcessUserCmds, HookMode.Pre); } + // thanks to Deana for this snippet + private CCSGameRules? GameRulesEnt { get; set; } + private bool LoadedGameRules { get; set; } + + private void OnMapStartHandler(string map) + { + GameRulesEnt = null; + LoadedGameRules = false; + } + private void OnTick() { + if (!LoadedGameRules) + { + LoadedGameRules = true; + GameRulesEnt = Utilities.FindAllEntitiesByDesignerName("cs_gamerules").FirstOrDefault()?.GameRules; + } + else if (GameRulesEnt is not null) + { + GameRulesEnt.GameRestart = GameRulesEnt.RestartRoundTime < Server.CurrentTime; + } + if (UseFallbackWasdInputMethod) { for (int i = 0; i < DriverInstance!.ActiveMenuStates.Count; i++)