diff options
| author | KiritoDev <36680385+KiritoDv@users.noreply.github.com> | 2022-05-12 19:44:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-12 20:44:50 -0400 |
| commit | b3d19eee3a50fb563cff3fb93e754c4b52f759bf (patch) | |
| tree | 2f393c73145fa458410233c62aaa731fb4464570 | |
| parent | 3bc0564d9abb481749277fab54e5fa449ac57f10 (diff) | |
Fixed id and cleanup on finish of notifications (#304)
Co-authored-by: KiritoDv <nohomoboi01@gmail.com>
| -rw-r--r-- | libultraship/libultraship/GameOverlay.cpp | 18 | ||||
| -rw-r--r-- | libultraship/libultraship/GameOverlay.h | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/libultraship/libultraship/GameOverlay.cpp b/libultraship/libultraship/GameOverlay.cpp index 02e089366..042ff980c 100644 --- a/libultraship/libultraship/GameOverlay.cpp +++ b/libultraship/libultraship/GameOverlay.cpp @@ -8,6 +8,7 @@ #include "SohImGuiImpl.h" #include "TextureMod.h" #include "Lib/ImGui/imgui_internal.h" +#include "Utils/StringHelper.h" void Ship::GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) { ImGuiIO& io = ImGui::GetIO(); @@ -50,10 +51,21 @@ void Ship::GameOverlay::TextDrawNotification(float duration, bool shadow, const vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); buf[IM_ARRAYSIZE(buf) - 1] = 0; va_end(args); - - this->RegisteredOverlays[fmt] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration }); + this->RegisteredOverlays[StringHelper::Sprintf("NotificationID:%d%d", rand(), this->RegisteredOverlays.size())] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration }); + NeedsCleanup = true; } +void Ship::GameOverlay::CleanupNotifications() { + if(!NeedsCleanup) return; + for (auto it = this->RegisteredOverlays.begin(); it != this->RegisteredOverlays.end(); ) { + if (it->second->type == OverlayType::NOTIFICATION && it->second->duration <= 0.0f) { + it = this->RegisteredOverlays.erase(it); + } else { + ++it; + } + } + NeedsCleanup = false; +} float Ship::GameOverlay::GetScreenWidth() { const ImGuiViewport* viewport = ImGui::GetMainViewport(); @@ -137,6 +149,8 @@ void Ship::GameOverlay::Draw() { ImGui::Begin("SoHOverlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs); + this->CleanupNotifications(); + float textY = 50; float notY = 0; diff --git a/libultraship/libultraship/GameOverlay.h b/libultraship/libultraship/GameOverlay.h index e3161bca3..605cd5898 100644 --- a/libultraship/libultraship/GameOverlay.h +++ b/libultraship/libultraship/GameOverlay.h @@ -33,6 +33,8 @@ namespace Ship { void TextDraw(float x, float y, bool shadow, ImVec4 color, const char* text, ...); void TextDrawNotification(float duration, bool shadow, const char* fmt, ...); private: + bool NeedsCleanup = false; + void CleanupNotifications(); void LoadFont(const std::string& name, const std::string& path, float fontSize); }; |
