Skip to content

Commit 3d421c6

Browse files
Merge pull request #19 from CSGALS/prevent-flicker
Prevent flicker
2 parents d0eae3e + 78fb880 commit 3d421c6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/SharpModMenu/PlayerMenuState.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,15 @@ private bool MenuActive
142142
if (value)
143143
Driver.ActiveMenuStates.Add(this);
144144
else
145+
{
145146
Driver.ActiveMenuStates.Remove(this);
147+
if (ShowingHtmlContent)
148+
{
149+
ShowingHtmlContent = false;
150+
Player.PrintToCenterHtml(HtmlContent ?? "<font></font>", 0);
151+
HtmlContent = null;
152+
}
153+
}
146154
}
147155
}
148156

@@ -609,13 +617,17 @@ private void BuildMenuStrings(Menu currentMenu, Action<string, TextStyling, int?
609617
}
610618

611619
public bool ForceRefresh = true;
620+
public bool ShowingHtmlContent;
612621
public void Tick()
613622
{
614623
if (CurrentMenu is null)
615624
return;
616625

617626
if (PresentingHtml && HtmlContent is not null)
627+
{
628+
ShowingHtmlContent = true;
618629
Player.PrintToCenterHtml(HtmlContent);
630+
}
619631

620632
var observerInfo = Player.GetObserverInfo();
621633

src/SharpModMenu/SharpModMenu.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.Linq;
45
using System.Runtime.InteropServices;
56
using System.Text;
67

@@ -13,6 +14,7 @@
1314
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
1415

1516
using CSSUniversalMenuAPI;
17+
1618
using static CounterStrikeSharp.API.Core.Listeners;
1719

1820
namespace SharpModMenu;
@@ -58,6 +60,7 @@ public override void Load(bool hotReload)
5860

5961
RegisterListener<OnTick>(OnTick);
6062
RegisterListener<CheckTransmit>(OnCheckTransmit);
63+
RegisterListener<OnMapStart>(OnMapStartHandler);
6164
}
6265

6366
public override void Unload(bool hotReload)
@@ -67,8 +70,28 @@ public override void Unload(bool hotReload)
6770
ProcessUserCmdsFunc?.Unhook(ProcessUserCmds, HookMode.Pre);
6871
}
6972

73+
// thanks to Deana for this snippet
74+
private CCSGameRules? GameRulesEnt { get; set; }
75+
private bool LoadedGameRules { get; set; }
76+
77+
private void OnMapStartHandler(string map)
78+
{
79+
GameRulesEnt = null;
80+
LoadedGameRules = false;
81+
}
82+
7083
private void OnTick()
7184
{
85+
if (!LoadedGameRules)
86+
{
87+
LoadedGameRules = true;
88+
GameRulesEnt = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").FirstOrDefault()?.GameRules;
89+
}
90+
else if (GameRulesEnt is not null)
91+
{
92+
GameRulesEnt.GameRestart = GameRulesEnt.RestartRoundTime < Server.CurrentTime;
93+
}
94+
7295
if (UseFallbackWasdInputMethod)
7396
{
7497
for (int i = 0; i < DriverInstance!.ActiveMenuStates.Count; i++)

0 commit comments

Comments
 (0)