From 3a6a4011d089fccb863b0c7d3bbede3005281376 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 15 Feb 2025 11:15:56 +0100 Subject: [PATCH] feat: Added nag banners for donations --- .../builtin/source/content/welcome_screen.cpp | 17 +++++++++++++++++ plugins/ui/include/banners/banner_button.hpp | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index b7539b49b..645d06b86 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -37,6 +37,8 @@ #include #include +#include +#include namespace hex::plugin::builtin { @@ -765,6 +767,21 @@ namespace hex::plugin::builtin { TaskManager::doLater([]{ AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.crash.name"); }); + } else { + std::random_device rd; + if (!ImHexApi::System::isCorporateEnvironment()) { + if (rd() % 25 == 0) { + ui::BannerButton::open(ICON_VS_HEART, "Using ImHex for professional work? Ask your boss to sponsor us!", ImColor(0x68, 0xA7, 0x70), "Donate Now!", [] { + hex::openWebpage("https://imhex.werwolv.net/donate_work"); + }); + } + } else { + if (rd() % 75 == 0) { + ui::BannerButton::open(ICON_VS_HEART, "ImHex needs your help to stay alive! Donate now to fund infrastructure and further development", ImColor(0x68, 0xA7, 0x70), "Donate Now!", [] { + hex::openWebpage("https://github.com/sponsors/WerWolv"); + }); + } + } } // Load info banner texture either locally or from the server diff --git a/plugins/ui/include/banners/banner_button.hpp b/plugins/ui/include/banners/banner_button.hpp index 680b1118e..44e010cc6 100644 --- a/plugins/ui/include/banners/banner_button.hpp +++ b/plugins/ui/include/banners/banner_button.hpp @@ -13,7 +13,7 @@ namespace hex::ui { : Banner(color), m_icon(icon), m_message(std::move(message)), m_buttonText(std::move(buttonText)), m_buttonCallback(std::move(buttonCallback)) { } void drawContent() override { - const std::string buttonText = Lang(m_buttonText); + const std::string buttonText = hex::format(" {} ", Lang(m_buttonText).get()); const auto buttonSize = ImGui::CalcTextSize(buttonText.c_str()); const auto iconSize = ImGui::CalcTextSize(m_icon); const auto textHeight = std::max(ImGui::CalcTextSize(Lang(m_message)).y, iconSize.y); @@ -37,11 +37,14 @@ namespace hex::ui { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - buttonSize.x - 20_scaled); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 2_scaled); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1_scaled); + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_Tab)); if (ImGui::SmallButton(buttonText.c_str())) { m_buttonCallback(); this->close(); } - ImGui::PopStyleVar(1); + ImGui::PopStyleColor(); + ImGui::PopStyleVar(2); } private: