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

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