2021-12-07 22:47:41 +01:00
|
|
|
#include "content/views/view_settings.hpp"
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
ViewSettings::ViewSettings() : View("hex.builtin.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") {
|
2021-12-07 22:47:41 +01:00
|
|
|
View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.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() {
|
|
|
|
|
2021-12-12 13:35:23 +01:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(500, 300) * SharedData::globalScale, ImGuiCond_Always);
|
|
|
|
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) {
|
2021-09-20 23:40:36 +02:00
|
|
|
if (ImGui::BeginTabBar("settings")) {
|
|
|
|
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
|
|
|
if (ImGui::BeginTabItem(LangEntry(category))) {
|
|
|
|
ImGui::TextUnformatted(LangEntry(category));
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
for (auto &[name, callback] : entries) {
|
|
|
|
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category][name]))
|
|
|
|
EventManager::post<EventSettingsChanged>();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
2021-09-20 23:40:36 +02:00
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
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-12-12 13:35:23 +01:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::MenuItem("hex.builtin.view.settings.name"_lang)) {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
2021-08-18 23:12:27 +02:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|