|
8 | 8 | #include "SohImGuiImpl.h" |
9 | 9 | #include "TextureMod.h" |
10 | 10 | #include "Lib/ImGui/imgui_internal.h" |
| 11 | +#include "Utils/StringHelper.h" |
11 | 12 |
|
12 | 13 | void Ship::GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) { |
13 | 14 | ImGuiIO& io = ImGui::GetIO(); |
@@ -50,10 +51,21 @@ void Ship::GameOverlay::TextDrawNotification(float duration, bool shadow, const |
50 | 51 | vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); |
51 | 52 | buf[IM_ARRAYSIZE(buf) - 1] = 0; |
52 | 53 | va_end(args); |
53 | | - |
54 | | - this->RegisteredOverlays[fmt] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration }); |
| 54 | + this->RegisteredOverlays[StringHelper::Sprintf("NotificationID:%d%d", rand(), this->RegisteredOverlays.size())] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration }); |
| 55 | + NeedsCleanup = true; |
55 | 56 | } |
56 | 57 |
|
| 58 | +void Ship::GameOverlay::CleanupNotifications() { |
| 59 | + if(!NeedsCleanup) return; |
| 60 | + for (auto it = this->RegisteredOverlays.begin(); it != this->RegisteredOverlays.end(); ) { |
| 61 | + if (it->second->type == OverlayType::NOTIFICATION && it->second->duration <= 0.0f) { |
| 62 | + it = this->RegisteredOverlays.erase(it); |
| 63 | + } else { |
| 64 | + ++it; |
| 65 | + } |
| 66 | + } |
| 67 | + NeedsCleanup = false; |
| 68 | +} |
57 | 69 |
|
58 | 70 | float Ship::GameOverlay::GetScreenWidth() { |
59 | 71 | const ImGuiViewport* viewport = ImGui::GetMainViewport(); |
@@ -137,6 +149,8 @@ void Ship::GameOverlay::Draw() { |
137 | 149 | ImGui::Begin("SoHOverlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | |
138 | 150 | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs); |
139 | 151 |
|
| 152 | + this->CleanupNotifications(); |
| 153 | + |
140 | 154 | float textY = 50; |
141 | 155 | float notY = 0; |
142 | 156 |
|
|
0 commit comments