Skip to content

Commit 318af3b

Browse files
committed
Overlay: move font scale to "UI Settings" window, add GlobalOpacity setting
also added toggle to disable notifications entirely mow tries forcing cursor to be hidden or to show too, hopefully better chance of cursor showing properly
1 parent 39e4679 commit 318af3b

File tree

5 files changed

+176
-69
lines changed

5 files changed

+176
-69
lines changed

src/overlay/chatroom.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class ChatRoom : public OverlayWindow
2929
char inputBuffer[256] = "";
3030
std::deque<ChatMessage> messages;
3131
static constexpr size_t MAX_MESSAGES = 100;
32-
static constexpr float MESSAGE_DISPLAY_DURATION = 5.0f; // seconds
33-
static constexpr float MESSAGE_VERYRECENT_DURATION = 2.f;
32+
static constexpr float MESSAGE_DISPLAY_SECONDS = 5.0f;
33+
static constexpr float MESSAGE_VERYRECENT_SECONDS = 2.0f;
3434

3535
std::mutex mtx;
3636

@@ -119,13 +119,17 @@ class ChatRoom : public OverlayWindow
119119
auto duration = std::chrono::duration_cast<std::chrono::seconds>(
120120
currentTime - msg.timestamp).count();
121121

122-
if (duration < MESSAGE_VERYRECENT_DURATION)
122+
if (duration < MESSAGE_VERYRECENT_SECONDS)
123123
{
124124
hasVeryRecentMessages = true;
125125
hasRecentMessages = true;
126+
break;
126127
}
127-
else if (duration < MESSAGE_DISPLAY_DURATION)
128+
if (duration < MESSAGE_DISPLAY_SECONDS)
129+
{
128130
hasRecentMessages = true;
131+
break;
132+
}
129133
}
130134
}
131135

src/overlay/hooks_overlay.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,16 @@ class D3DHooks : public Hook
7272

7373
CreateLetterboxVertex();
7474

75-
if (!Settings::OverlayEnabled)
76-
return;
77-
78-
// Setup Dear ImGui context
79-
IMGUI_CHECKVERSION();
80-
ImGui::CreateContext();
81-
ImGuiIO& io = ImGui::GetIO(); (void)io;
82-
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
83-
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
84-
io.FontGlobalScale = Overlay::GlobalFontScale;
85-
86-
// Setup Dear ImGui style
87-
ImGui::StyleColorsDark();
88-
//ImGui::StyleColorsLight();
89-
90-
// Setup Platform/Renderer backends
91-
ImGui_ImplWin32_Init(Game::GameHwnd());
92-
ImGui_ImplDX9_Init(Game::D3DDevice());
93-
94-
overlayInited = true;
75+
if (Settings::OverlayEnabled)
76+
{
77+
Overlay::init_imgui();
78+
79+
// Setup Platform/Renderer backends
80+
ImGui_ImplWin32_Init(Game::GameHwnd());
81+
ImGui_ImplDX9_Init(Game::D3DDevice());
82+
83+
overlayInited = true;
84+
}
9585
}
9686

9787
inline static SafetyHookMid midhook_d3dendscene{};

src/overlay/notifications.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Notifications
7070
return;
7171
}
7272

73+
if (!Overlay::NotifyEnable)
74+
return;
75+
7376
ImVec2 screenSize = ImGui::GetIO().DisplaySize;
7477

7578
// Calculate starting position for the latest notification

src/overlay/overlay.cpp

Lines changed: 152 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,6 @@ class GlobalsWindow : public OverlayWindow
3333

3434
ImGui::Begin("Globals", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
3535

36-
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.51f, 0.00f, 0.14f, 0.00f));
37-
if (ImGui::Button("-"))
38-
{
39-
if (Overlay::GlobalFontScale > 1.0f)
40-
{
41-
Overlay::GlobalFontScale -= 0.05f;
42-
settingsChanged = true;
43-
}
44-
45-
ImGui::GetIO().FontGlobalScale = Overlay::GlobalFontScale;
46-
}
47-
48-
ImGui::SameLine();
49-
50-
if (ImGui::Button("+"))
51-
{
52-
if (Overlay::GlobalFontScale < 4.0f)
53-
{
54-
Overlay::GlobalFontScale += 0.05f;
55-
settingsChanged = true;
56-
}
57-
58-
ImGui::GetIO().FontGlobalScale = Overlay::GlobalFontScale;
59-
}
60-
61-
ImGui::PopStyleColor();
62-
ImGui::SameLine();
63-
ImGui::Text("Overlay Font Size");
64-
65-
ImGui::Separator();
6636
ImGui::Text("Info");
6737
EVWORK_CAR* car = Game::pl_car();
6838
ImGui::Text("game_mode: %d", *Game::game_mode);
@@ -139,22 +109,81 @@ class UISettingsWindow : public OverlayWindow
139109
{
140110
bool settingsChanged = false;
141111

142-
ImGui::Begin("Notification Settings", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
143-
ImGui::SetWindowPos(ImVec2(startX, curY), ImGuiCond_FirstUseEver);
144-
145-
settingsChanged |= ImGui::SliderInt("Display Time", &Overlay::NotifyDisplayTime, 0, 60);
146-
settingsChanged |= ImGui::Checkbox("Enable Online Lobby Notifications", &Overlay::NotifyOnlineEnable);
147-
settingsChanged |= ImGui::SliderInt("Online Update Time", &Overlay::NotifyOnlineUpdateTime, 10, 60);
148-
149-
static const char* items[]{ "Never Hide", "Online Race", "Any Race" };
150-
settingsChanged |= ImGui::Combo("Hide During", &Overlay::NotifyHideMode, items, IM_ARRAYSIZE(items));
151-
152-
settingsChanged |= ImGui::Checkbox("Hide Chat Background", &Overlay::ChatHideBackground);
153-
154-
ImGui::End();
112+
if (ImGui::Begin("UI Settings", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
113+
{
114+
ImGui::SetWindowPos(ImVec2(startX, curY), ImGuiCond_FirstUseEver);
115+
116+
if (ImGui::TreeNodeEx("Global", ImGuiTreeNodeFlags_DefaultOpen))
117+
{
118+
static bool fontScaleChanged = false;
119+
if (ImGui::SliderFloat("Font Scale", &Overlay::GlobalFontScale, 0.5f, 2.5f))
120+
fontScaleChanged |= true;
121+
122+
if (fontScaleChanged)
123+
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left))
124+
{
125+
settingsChanged |= true;
126+
fontScaleChanged = false;
127+
}
128+
129+
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.51f, 0.00f, 0.14f, 0.00f));
130+
if (ImGui::Button("-"))
131+
{
132+
if (Overlay::GlobalFontScale > 1.0f)
133+
{
134+
Overlay::GlobalFontScale -= 0.05f;
135+
settingsChanged = true;
136+
}
137+
}
138+
139+
ImGui::SameLine();
140+
141+
if (ImGui::Button("+"))
142+
{
143+
if (Overlay::GlobalFontScale < 5.0f)
144+
{
145+
Overlay::GlobalFontScale += 0.05f;
146+
settingsChanged = true;
147+
}
148+
}
149+
150+
ImGui::PopStyleColor();
151+
152+
settingsChanged |= ImGui::SliderFloat("Overlay Opacity", &Overlay::GlobalOpacity, 0.1f, 5.0f);
153+
154+
ImGui::TreePop();
155+
}
156+
157+
if (ImGui::TreeNodeEx("Notifications", ImGuiTreeNodeFlags_DefaultOpen))
158+
{
159+
settingsChanged |= ImGui::Checkbox("Enable Notifications", &Overlay::NotifyEnable);
160+
settingsChanged |= ImGui::SliderInt("Display Time", &Overlay::NotifyDisplayTime, 0, 60);
161+
settingsChanged |= ImGui::Checkbox("Enable Online Lobby Notifications", &Overlay::NotifyOnlineEnable);
162+
settingsChanged |= ImGui::SliderInt("Online Update Time", &Overlay::NotifyOnlineUpdateTime, 10, 60);
163+
164+
static const char* items[]{ "Never Hide", "Online Race", "Any Race" };
165+
settingsChanged |= ImGui::Combo("Hide During", &Overlay::NotifyHideMode, items, IM_ARRAYSIZE(items));
166+
167+
ImGui::TreePop();
168+
}
169+
170+
if (ImGui::TreeNodeEx("Chat", ImGuiTreeNodeFlags_DefaultOpen))
171+
{
172+
settingsChanged |= ImGui::Checkbox("Hide Chat Background", &Overlay::ChatHideBackground);
173+
174+
ImGui::TreePop();
175+
}
176+
177+
ImGui::End();
178+
}
155179

156180
if (settingsChanged)
181+
{
182+
ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w = Overlay::GlobalOpacity;
183+
ImGui::GetIO().FontGlobalScale = Overlay::GlobalFontScale;
184+
157185
Overlay::settings_write();
186+
}
158187
}
159188
}
160189
static UISettingsWindow instance;
@@ -181,6 +210,33 @@ void Overlay::init()
181210
UpdateCheck_Init();
182211
}
183212

213+
void Overlay::init_imgui()
214+
{
215+
// Setup Dear ImGui context
216+
IMGUI_CHECKVERSION();
217+
ImGui::CreateContext();
218+
ImGuiIO& io = ImGui::GetIO(); (void)io;
219+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
220+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
221+
io.FontGlobalScale = Overlay::GlobalFontScale;
222+
223+
// Setup Dear ImGui style
224+
ImGui::StyleColorsDark();
225+
//ImGui::StyleColorsLight();
226+
227+
ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w = Overlay::GlobalOpacity;
228+
ImGui::GetIO().FontGlobalScale = Overlay::GlobalFontScale;
229+
}
230+
231+
void ForceShowCursor(bool show) {
232+
int counter = 0;
233+
234+
// Adjust the counter until the cursor visibility matches the desired state
235+
do {
236+
counter = ShowCursor(show);
237+
} while ((show && counter < 0) || (!show && counter >= 0));
238+
}
239+
184240
bool Overlay::render()
185241
{
186242
IsActive = false;
@@ -196,9 +252,9 @@ bool Overlay::render()
196252
{
197253
overlay_visible = !overlay_visible;
198254
if (overlay_visible)
199-
ShowCursor(true);
255+
ForceShowCursor(true);
200256
else
201-
ShowCursor(false);
257+
ForceShowCursor(false);
202258
}
203259

204260
// Start the Dear ImGui frame
@@ -207,6 +263,53 @@ bool Overlay::render()
207263
// Notifications are rendered before any other window
208264
Notifications::instance.render();
209265

266+
if (overlay_visible)
267+
{
268+
if (ImGui::BeginMainMenuBar()) {
269+
if (ImGui::BeginMenu("File")) {
270+
if (ImGui::MenuItem("Open", "Ctrl+O")) {
271+
// Handle Open action
272+
}
273+
if (ImGui::MenuItem("Save", "Ctrl+S")) {
274+
// Handle Save action
275+
}
276+
if (ImGui::MenuItem("Exit")) {
277+
// Handle Exit action
278+
}
279+
ImGui::EndMenu();
280+
}
281+
282+
if (ImGui::BeginMenu("Edit")) {
283+
if (ImGui::MenuItem("Undo", "Ctrl+Z")) {
284+
// Handle Undo action
285+
}
286+
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, false)) {
287+
// Disabled menu item (not clickable)
288+
}
289+
ImGui::Separator(); // Adds a separator line
290+
if (ImGui::MenuItem("Cut", "Ctrl+X")) {
291+
// Handle Cut action
292+
}
293+
if (ImGui::MenuItem("Copy", "Ctrl+C")) {
294+
// Handle Copy action
295+
}
296+
if (ImGui::MenuItem("Paste", "Ctrl+V")) {
297+
// Handle Paste action
298+
}
299+
ImGui::EndMenu();
300+
}
301+
302+
if (ImGui::BeginMenu("Help")) {
303+
if (ImGui::MenuItem("About")) {
304+
// Handle About action
305+
}
306+
ImGui::EndMenu();
307+
}
308+
309+
ImGui::EndMainMenuBar();
310+
}
311+
}
312+
210313
for (const auto& wnd : s_windows)
211314
wnd->render(overlay_visible);
212315

@@ -234,7 +337,9 @@ bool Overlay::settings_read()
234337
}
235338

236339
GlobalFontScale = ini.Get("Overlay", "FontScale", GlobalFontScale);
340+
GlobalOpacity = ini.Get("Overlay", "Opacity", GlobalOpacity);
237341

342+
NotifyEnable = ini.Get("Notifications", "Enable", NotifyEnable);
238343
NotifyDisplayTime = ini.Get("Notifications", "DisplayTime", NotifyDisplayTime);
239344
NotifyOnlineEnable = ini.Get("Notifications", "OnlineEnable", NotifyOnlineEnable);
240345
NotifyOnlineUpdateTime = ini.Get("Notifications", "OnlineUpdateTime", NotifyOnlineUpdateTime);
@@ -255,7 +360,9 @@ bool Overlay::settings_write()
255360
{
256361
inih::INIReader ini;
257362
ini.Set("Overlay", "FontScale", GlobalFontScale);
363+
ini.Set("Overlay", "Opacity", GlobalOpacity);
258364

365+
ini.Set("Notifications", "Enable", NotifyEnable);
259366
ini.Set("Notifications", "DisplayTime", NotifyDisplayTime);
260367
ini.Set("Notifications", "OnlineEnable", NotifyOnlineEnable);
261368
ini.Set("Notifications", "OnlineUpdateTime", NotifyOnlineUpdateTime);

src/overlay/overlay.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Overlay
1313
{
1414
public:
1515
inline static float GlobalFontScale = 1.5f;
16+
inline static float GlobalOpacity = 0.8f;
1617

18+
inline static bool NotifyEnable = true;
1719
inline static int NotifyDisplayTime = 7;
1820
inline static bool NotifyOnlineEnable = true;
1921
inline static int NotifyOnlineUpdateTime = 20;
@@ -40,6 +42,7 @@ class Overlay
4042

4143
public:
4244
static void init();
45+
static void init_imgui();
4346

4447
static bool settings_read();
4548
static bool settings_write();

0 commit comments

Comments
 (0)