From a4a055eb36cdfe9582c30903676fdf033c9851d5 Mon Sep 17 00:00:00 2001 From: Cvolton Date: Thu, 15 Aug 2024 15:45:10 +0200 Subject: [PATCH] dont show rate limit notifications in editor or playlayer --- src/hooks/GJBaseGameLayer.cpp | 16 ++++++++++++++++ src/utils.cpp | 16 ++++++++++++++++ src/utils.hpp | 3 +++ src/utils/ServerUtils.cpp | 4 ++-- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/hooks/GJBaseGameLayer.cpp diff --git a/src/hooks/GJBaseGameLayer.cpp b/src/hooks/GJBaseGameLayer.cpp new file mode 100644 index 0000000..d6a315e --- /dev/null +++ b/src/hooks/GJBaseGameLayer.cpp @@ -0,0 +1,16 @@ +#include +#include +#include "../utils.hpp" + +using namespace geode::prelude; + + +class BI_DLL $modify(BIGJBaseGameLayer, GJBaseGameLayer) { + bool init() { + if (!GJBaseGameLayer::init()) return false; + + BetterInfo::cancelUnimportantNotifications(); + + return true; + } +}; \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 1af443e..35c3db2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -885,4 +885,20 @@ long long BetterInfo::strtol(std::string_view str) { long long result = 0; std::from_chars(str.data(), str.data() + str.size(), result); return result; +} + +static std::vector> notifications; +void BetterInfo::showUnimportantNotification(const std::string& content, NotificationIcon icon, float time) { + if(GJBaseGameLayer::get()) return; + + auto notif = Notification::create(content, icon, time); + notifications.push_back(notif); + notif->show(); +} + +void BetterInfo::cancelUnimportantNotifications() { + for(auto& notification : notifications) { + notification->cancel(); + } + notifications.clear(); } \ No newline at end of file diff --git a/src/utils.hpp b/src/utils.hpp index 9ecec24..7161b06 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -91,4 +91,7 @@ namespace BetterInfo { BI_DLL int stoi(std::string_view str); BI_DLL float stof(std::string_view str); BI_DLL long long strtol(std::string_view str); + + BI_DLL void showUnimportantNotification(const std::string& content, NotificationIcon icon, float time = 5.f); + BI_DLL void cancelUnimportantNotifications(); } \ No newline at end of file diff --git a/src/utils/ServerUtils.cpp b/src/utils/ServerUtils.cpp index 483354f..8b002a4 100644 --- a/src/utils/ServerUtils.cpp +++ b/src/utils/ServerUtils.cpp @@ -346,13 +346,13 @@ bool ServerUtils::showCFError(const std::string& data) { message = fmt::format(" A server error has occurred.\n (error code: {})", error); break; } - Notification::create(message, NotificationIcon::Error, 5.f)->show(); + BetterInfo::showUnimportantNotification(message, NotificationIcon::Error, 5.f); return true; } return false; } bool ServerUtils::showRateLimitError(int seconds) { - Notification::create(fmt::format(" Rate limited by RobTop's server\n Try again in {}", GameToolbox::getTimeString(seconds, false)), NotificationIcon::Warning, 5.f)->show(); + BetterInfo::showUnimportantNotification(fmt::format(" Rate limited by RobTop's server\n Try again in {}", GameToolbox::getTimeString(seconds, false)), NotificationIcon::Warning, 5.f); return true; } \ No newline at end of file