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") {
|
2022-02-01 18:09:40 +01:00
|
|
|
ImHexApi::Tasks::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
}
|
|
|
|
});
|
2022-01-23 02:28:38 +01:00
|
|
|
|
|
|
|
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.help", 2000, [&, this] {
|
|
|
|
if (ImGui::MenuItem("hex.builtin.view.settings.name"_lang)) {
|
2022-02-01 18:09:40 +01:00
|
|
|
ImHexApi::Tasks::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.settings.name").c_str()); });
|
2022-01-23 02:28:38 +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
|
|
|
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")) {
|
2022-02-18 22:34:54 +01:00
|
|
|
auto &entries = ContentRegistry::Settings::getEntries();
|
|
|
|
|
|
|
|
std::vector<std::decay_t<decltype(entries)>::const_iterator> sortedCategories;
|
|
|
|
|
|
|
|
for (auto it = entries.cbegin(); it != entries.cend(); it++) {
|
|
|
|
sortedCategories.emplace_back(std::move(it));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(sortedCategories.begin(), sortedCategories.end(), [](auto &item0, auto &item1) {
|
|
|
|
return item0->first.slot < item1->first.slot;
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto &descriptions = ContentRegistry::Settings::getCategoryDescriptions();
|
|
|
|
|
|
|
|
for (auto &it : sortedCategories) {
|
|
|
|
auto &[category, entries] = *it;
|
2021-09-20 23:40:36 +02:00
|
|
|
if (ImGui::BeginTabItem(LangEntry(category))) {
|
2022-02-18 22:34:54 +01:00
|
|
|
const std::string &categoryDesc = descriptions.count(category) ? descriptions.at(category) : category.name;
|
|
|
|
ImGui::TextUnformatted(LangEntry(categoryDesc));
|
2021-09-20 23:40:36 +02:00
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
for (auto &[name, callback] : entries) {
|
2022-02-18 22:34:54 +01:00
|
|
|
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category.name][name]))
|
2021-09-20 23:40:36 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
}
|