2021-01-11 20:31:40 +01:00
|
|
|
#include "views/view_settings.hpp"
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
ViewSettings::ViewSettings() : View("hex.view.settings.name") {
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::subscribe<RequestOpenWindow>(this, [this](const std::string &name) {
|
2021-04-18 20:24:42 +02:00
|
|
|
if (name == "Settings") {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.view.settings.name").c_str()); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
}
|
|
|
|
});
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewSettings::~ViewSettings() {
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::unsubscribe<RequestOpenWindow>(this);
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawContent() {
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX));
|
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
if (ImGui::BeginPopupModal(View::toWindowName("hex.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
|
2021-01-11 20:31:40 +01:00
|
|
|
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
2021-02-13 15:15:32 +01:00
|
|
|
ImGui::TextUnformatted(LangEntry(category));
|
2021-01-11 20:31:40 +01:00
|
|
|
ImGui::Separator();
|
|
|
|
for (auto &[name, callback] : entries) {
|
2021-02-13 15:15:32 +01:00
|
|
|
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category][name]))
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<EventSettingsChanged>();
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
ImGui::NewLine();
|
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
2021-01-27 14:26:24 +01:00
|
|
|
} else
|
|
|
|
this->getWindowOpenState() = false;
|
2021-01-11 20:31:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawMenu() {
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
|
2021-02-21 13:49:03 +01:00
|
|
|
if (ImGui::MenuItem("hex.view.settings.name"_lang)) {
|
2021-03-03 22:26:17 +01:00
|
|
|
View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.view.settings.name").c_str()); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|