diff --git a/include/window.hpp b/include/window.hpp index 502db7a71..75b7a398d 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -63,6 +63,9 @@ namespace hex { std::string m_availableUpdate; + bool m_showTipOfTheDay; + std::string m_tipOfTheDay; + ImGui::Texture m_bannerTexture; ImGui::Texture m_logoTexture; diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 6b95eacc1..3b4704115 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -4,6 +4,21 @@ namespace hex::plugin::builtin { void registerSettings() { + /* General */ + + ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) { + static bool enabled = setting.is_number() ? static_cast(setting) : 1; + + if (ImGui::Checkbox(name.data(), &enabled)) { + setting = static_cast(enabled); + return true; + } + + return false; + }); + + /* Interface */ + ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) { static int selection = setting.is_number() ? static_cast(setting) : 0; diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 70ad22218..4a6aae78d 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -49,12 +49,14 @@ namespace hex::plugin::builtin { { "hex.welcome.learn.plugins.desc", "Erweitere ImHex mit neuen Funktionen mit Plugins" }, { "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.welcome.header.various", "Verschiedenes" }, + { "hex.welcome.tip_of_the_day", "Tipp des Tages" }, { "hex.safety_backup.title", "Verlorene Daten wiederherstellen" }, { "hex.safety_backup.desc", "Oh nein, ImHex ist letztes mal abgestürtzt.\nWillst du das verherige Projekt wiederherstellen?"}, { "hex.safety_backup.restore", "Ja, Wiederherstellen" }, { "hex.safety_backup.delete", "Nein, Entfernen" }, + { "hex.common.little_endian", "Little Endian" }, { "hex.common.big_endian", "Big Endian" }, { "hex.common.decimal", "Dezimal" }, @@ -72,6 +74,8 @@ namespace hex::plugin::builtin { { "hex.common.load", "Laden" }, { "hex.common.cancel", "Abbrechen" }, { "hex.common.set", "Setzen" }, + { "hex.common.close", "Schliessen" }, + { "hex.common.dont_show_again", "Nicht mehr anzeigen" }, { "hex.view.bookmarks.name", "Lesezeichen" }, { "hex.view.bookmarks.default_title", "Lesezeichen [0x{0:X} - 0x{1:X}]" }, @@ -535,6 +539,8 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Kürzlich geöffnete Dateien" }, + { "hex.builtin.setting.general", "Allgemein" }, + { "hex.builtin.setting.general.show_tips", "Tipps beim start anzeigen" }, { "hex.builtin.setting.interface", "Aussehen" }, { "hex.builtin.setting.interface.color", "Farbthema" }, { "hex.builtin.setting.interface.color.dark", "Dunkel" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index e9c7fdb4e..15227c625 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -49,6 +49,7 @@ namespace hex::plugin::builtin { { "hex.welcome.learn.plugins.desc", "Extend ImHex with additional features using plugins" }, { "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.welcome.header.various", "Various" }, + { "hex.welcome.tip_of_the_day", "Tip of the Day" }, { "hex.safety_backup.title", "Restore lost data" }, { "hex.safety_backup.desc", "Oh no, ImHex crashed last time.\nDo you want to restore your past work?"}, @@ -73,6 +74,8 @@ namespace hex::plugin::builtin { { "hex.common.load", "Load" }, { "hex.common.cancel", "Cancel" }, { "hex.common.set", "Set" }, + { "hex.common.close", "Close" }, + { "hex.common.dont_show_again", "Don't show again" }, { "hex.view.bookmarks.name", "Bookmarks" }, { "hex.view.bookmarks.default_title", "Bookmark [0x{0:X} - 0x{1:X}]" }, @@ -536,6 +539,8 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Recent Files" }, + { "hex.builtin.setting.general", "General" }, + { "hex.builtin.setting.general.show_tips", "Show tips on startup" }, { "hex.builtin.setting.interface", "Interface" }, { "hex.builtin.setting.interface.color", "Color theme" }, { "hex.builtin.setting.interface.color.dark", "Dark" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index d74657b3b..8ea2f855d 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -49,6 +49,7 @@ namespace hex::plugin::builtin { { "hex.welcome.learn.plugins.desc", "Espandi l'utilizzo di ImHex con i Plugin" }, { "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.welcome.header.various", "Varie" }, + //{ "hex.welcome.tip_of_the_day", "Tip of the Day" }, //{ "hex.safety_backup.title", "Restore lost data" }, //{ "hex.safety_backup.desc", "Oh no, ImHex crashed last time.\nDo you want to restore your past work?"}, @@ -72,6 +73,8 @@ namespace hex::plugin::builtin { { "hex.common.load", "Carica" }, { "hex.common.cancel", "Cancella" }, { "hex.common.set", "Imposta" }, + //{ "hex.common.close", "Close" }, + //{ "hex.common.dont_show_again", "Don't show again" }, { "hex.view.bookmarks.name", "Segnalibri" }, { "hex.view.bookmarks.default_title", "Segnalibro [0x{0:X} - 0x{1:X}]" }, @@ -535,6 +538,8 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "File recenti" }, + //{ "hex.builtin.setting.general", "General" }, + //{ "hex.builtin.setting.general.show_tips", "Show tips on startup" }, { "hex.builtin.setting.interface", "Interfaccia" }, { "hex.builtin.setting.interface.color", "Colore del Tema" }, { "hex.builtin.setting.interface.color.dark", "Scuro" }, diff --git a/source/init/tasks.cpp b/source/init/tasks.cpp index 5c2f1a15e..8b566d066 100644 --- a/source/init/tasks.cpp +++ b/source/init/tasks.cpp @@ -47,6 +47,18 @@ namespace hex::init { return true; } + static bool downloadInformation() { + hex::Net net; + + auto tip = net.getString("https://api.werwolv.net/imhex/tip"); + if (tip.code != 200) + return false; + + getInitArguments().push_back({ "tip-of-the-day", tip.response }); + + return true; + } + bool createDirectories() { bool result = true; @@ -185,6 +197,7 @@ namespace hex::init { std::vector getInitTasks() { return { { "Checking for updates...", checkForUpdates }, + { "Downloading information...", downloadInformation }, { "Creating directories...", createDirectories }, { "Loading default views...", loadDefaultViews }, { "Loading plugins...", loadPlugins }, diff --git a/source/window/window.cpp b/source/window/window.cpp index 8c53bc692..646e1df39 100644 --- a/source/window/window.cpp +++ b/source/window/window.cpp @@ -68,6 +68,12 @@ namespace hex { this->m_availableUpdate = value; } else if (argument == "no-plugins") { View::doLater([]{ ImGui::OpenPopup("No Plugins"); }); + } else if (argument == "tip-of-the-day") { + this->m_tipOfTheDay = value; + + this->m_showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1); + if (this->m_showTipOfTheDay) + View::doLater([]{ ImGui::OpenPopup("hex.welcome.tip_of_the_day"_lang); }); } } } @@ -455,6 +461,24 @@ namespace hex { ImGui::End(); ImGui::PopStyleVar(2); + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); + ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size / 3, ImGuiCond_Appearing); + if (ImGui::BeginPopup("hex.welcome.tip_of_the_day"_lang)) { + ImGui::Header("hex.welcome.tip_of_the_day"_lang, true); + + ImGui::TextWrapped("%s", this->m_tipOfTheDay.c_str()); + ImGui::NewLine(); + + if (ImGui::Checkbox("hex.common.dont_show_again"_lang, &this->m_showTipOfTheDay)) + ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", this->m_showTipOfTheDay); + + ImGui::SameLine((ImGui::GetMainViewport()->Size / 3 - ImGui::CalcTextSize("hex.common.close"_lang) - ImGui::GetStyle().FramePadding).x); + + if (ImGui::Button("hex.common.close"_lang)) + ImGui::CloseCurrentPopup(); + + ImGui::EndPopup(); + } ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); if (ImGui::BeginPopupModal("No Plugins", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) {