1
0
mirror of synced 2024-11-13 18:50:53 +01:00

ui: Add tips of the day

This commit is contained in:
WerWolv 2021-08-22 21:11:01 +02:00
parent 2362e7a11f
commit c84c106b17
7 changed files with 71 additions and 0 deletions

View File

@ -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;

View File

@ -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<int>(setting) : 1;
if (ImGui::Checkbox(name.data(), &enabled)) {
setting = static_cast<int>(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<int>(setting) : 0;

View File

@ -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" },

View File

@ -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" },

View File

@ -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" },

View File

@ -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<Task> getInitTasks() {
return {
{ "Checking for updates...", checkForUpdates },
{ "Downloading information...", downloadInformation },
{ "Creating directories...", createDirectories },
{ "Loading default views...", loadDefaultViews },
{ "Loading plugins...", loadPlugins },

View File

@ -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)) {