2022-07-02 16:22:38 +02:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2022-12-29 19:26:00 +01:00
|
|
|
#include <hex/api/theme_manager.hpp>
|
2023-11-18 14:50:43 +01:00
|
|
|
#include <hex/api/shortcut_manager.hpp>
|
|
|
|
#include <hex/api/event_manager.hpp>
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2023-11-15 22:22:57 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2022-07-02 16:22:38 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <imgui.h>
|
2022-02-18 22:34:54 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
#include <fonts/codicons_font.h>
|
2021-08-29 14:18:45 +02:00
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2023-11-17 14:46:21 +01:00
|
|
|
#include <utility>
|
2023-12-06 13:49:58 +01:00
|
|
|
#include <hex/api/layout_manager.hpp>
|
2023-10-21 23:07:33 +02:00
|
|
|
#include <wolv/utils/string.hpp>
|
2022-07-14 11:38:23 +02:00
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
namespace {
|
2023-03-14 14:07:18 +01:00
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
/*
|
2023-10-21 23:07:33 +02:00
|
|
|
Values of this setting:
|
2023-06-20 11:55:56 +02:00
|
|
|
0 - do not check for updates on startup
|
|
|
|
1 - check for updates on startup
|
|
|
|
2 - default value - ask the user if he wants to check for updates. This value should only be encountered on the first startup.
|
|
|
|
*/
|
2023-10-21 23:07:33 +02:00
|
|
|
class ServerContactWidget : public ContentRegistry::Settings::Widgets::Widget {
|
|
|
|
public:
|
|
|
|
bool draw(const std::string &name) override {
|
|
|
|
bool enabled = this->m_value == 1;
|
2023-05-15 11:30:24 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
if (ImGui::Checkbox(name.data(), &enabled)) {
|
|
|
|
this->m_value = enabled ? 1 : 0;
|
|
|
|
return true;
|
2022-12-29 19:26:00 +01:00
|
|
|
}
|
2022-07-02 16:22:38 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
return false;
|
2021-02-10 18:17:09 +01:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void load(const nlohmann::json &data) override {
|
|
|
|
if (data.is_number())
|
|
|
|
this->m_value = data.get<int>();
|
|
|
|
}
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
nlohmann::json store() override {
|
|
|
|
return this->m_value;
|
|
|
|
}
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
private:
|
|
|
|
u32 m_value = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FPSWidget : public ContentRegistry::Settings::Widgets::Widget {
|
|
|
|
public:
|
|
|
|
bool draw(const std::string &name) override {
|
|
|
|
auto format = [this] -> std::string {
|
|
|
|
if (this->m_value > 200)
|
|
|
|
return "hex.builtin.setting.interface.fps.unlocked"_lang;
|
|
|
|
else if (this->m_value < 15)
|
|
|
|
return "hex.builtin.setting.interface.fps.native"_lang;
|
|
|
|
else
|
|
|
|
return "%d FPS";
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (ImGui::SliderInt(name.data(), &this->m_value, 14, 201, format.c_str(), ImGuiSliderFlags_AlwaysClamp)) {
|
2022-02-21 21:46:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-02-21 21:46:25 +01:00
|
|
|
return false;
|
2021-02-10 18:17:09 +01:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void load(const nlohmann::json &data) override {
|
|
|
|
if (data.is_number())
|
|
|
|
this->m_value = data.get<int>();
|
2022-05-22 23:26:46 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
nlohmann::json store() override {
|
|
|
|
return this->m_value;
|
2021-03-06 13:09:20 +01:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
private:
|
|
|
|
int m_value = 60;
|
|
|
|
};
|
2021-03-06 13:09:20 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
class UserFolderWidget : public ContentRegistry::Settings::Widgets::Widget {
|
|
|
|
public:
|
|
|
|
bool draw(const std::string &) override {
|
|
|
|
bool result = false;
|
2022-10-06 21:26:24 +02:00
|
|
|
|
2023-11-15 22:22:57 +01:00
|
|
|
if (!ImGui::BeginListBox("", ImVec2(-40_scaled, 280_scaled))) {
|
2023-10-21 23:07:33 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
for (size_t n = 0; n < this->m_paths.size(); n++) {
|
|
|
|
const bool isSelected = (this->m_itemIndex == n);
|
|
|
|
if (ImGui::Selectable(wolv::util::toUTF8String(this->m_paths[n]).c_str(), isSelected)) {
|
|
|
|
this->m_itemIndex = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSelected) {
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndListBox();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::BeginGroup();
|
2022-10-06 21:26:24 +02:00
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
if (ImGuiExt::IconButton(ICON_VS_NEW_FOLDER, ImGui::GetStyleColorVec4(ImGuiCol_Text), ImVec2(30, 30))) {
|
2023-10-21 23:07:33 +02:00
|
|
|
fs::openFileBrowser(fs::DialogMode::Folder, {}, [&](const std::fs::path &path) {
|
|
|
|
if (std::find(this->m_paths.begin(), this->m_paths.end(), path) == this->m_paths.end()) {
|
|
|
|
this->m_paths.emplace_back(path);
|
|
|
|
ImHexApi::System::setAdditionalFolderPaths(this->m_paths);
|
2022-10-06 21:26:24 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGuiExt::InfoTooltip("hex.builtin.setting.folders.add_folder"_lang);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
if (ImGuiExt::IconButton(ICON_VS_REMOVE_CLOSE, ImGui::GetStyleColorVec4(ImGuiCol_Text), ImVec2(30, 30))) {
|
2023-10-21 23:07:33 +02:00
|
|
|
if (!this->m_paths.empty()) {
|
|
|
|
this->m_paths.erase(std::next(this->m_paths.begin(), this->m_itemIndex));
|
|
|
|
ImHexApi::System::setAdditionalFolderPaths(this->m_paths);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGuiExt::InfoTooltip("hex.builtin.setting.folders.remove_folder"_lang);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ImGui::EndGroup();
|
2021-03-29 23:07:18 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
return result;
|
2021-03-29 23:07:18 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void load(const nlohmann::json &data) override {
|
|
|
|
if (data.is_array()) {
|
|
|
|
std::vector<std::string> pathStrings = data;
|
2022-09-18 16:22:08 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
for (const auto &pathString : pathStrings) {
|
|
|
|
this->m_paths.emplace_back(pathString);
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
nlohmann::json store() override {
|
|
|
|
std::vector<std::string> pathStrings;
|
2022-09-18 16:22:08 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
for (const auto &path : this->m_paths) {
|
|
|
|
pathStrings.push_back(wolv::util::toUTF8String(path));
|
|
|
|
}
|
2022-10-07 11:28:44 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
return pathStrings;
|
2022-10-07 11:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
private:
|
|
|
|
u32 m_itemIndex = 0;
|
|
|
|
std::vector<std::fs::path> m_paths;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScalingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
|
|
|
public:
|
|
|
|
bool draw(const std::string &name) override {
|
|
|
|
auto format = [this] -> std::string {
|
|
|
|
if (this->m_value == 0)
|
|
|
|
return "hex.builtin.setting.interface.scaling.native"_lang;
|
|
|
|
else
|
|
|
|
return "x%.1f";
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (ImGui::SliderFloat(name.data(), &this->m_value, 0, 10, format.c_str(), ImGuiSliderFlags_AlwaysClamp)) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-07 11:28:44 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
return false;
|
2022-10-07 11:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void load(const nlohmann::json &data) override {
|
|
|
|
if (data.is_number())
|
|
|
|
this->m_value = data.get<float>();
|
|
|
|
}
|
2023-07-31 11:17:37 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
nlohmann::json store() override {
|
|
|
|
return this->m_value;
|
2023-07-31 11:17:37 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
private:
|
|
|
|
float m_value = 0;
|
|
|
|
};
|
2023-07-31 11:17:37 +02:00
|
|
|
|
2023-11-17 14:46:21 +01:00
|
|
|
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
|
|
|
public:
|
2023-12-06 09:09:32 +01:00
|
|
|
KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_drawShortcut(shortcut), m_defaultShortcut(shortcut) {}
|
2023-11-17 14:46:21 +01:00
|
|
|
|
|
|
|
bool draw(const std::string &name) override {
|
|
|
|
std::string label;
|
|
|
|
|
|
|
|
if (!this->m_editing)
|
2023-12-06 09:09:32 +01:00
|
|
|
label = this->m_drawShortcut.toString();
|
2023-11-17 14:46:21 +01:00
|
|
|
else
|
|
|
|
label = "...";
|
|
|
|
|
|
|
|
if (label.empty())
|
|
|
|
label = "???";
|
|
|
|
|
2023-11-18 14:34:33 +01:00
|
|
|
|
|
|
|
if (this->m_hasDuplicate)
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError));
|
|
|
|
|
2023-11-17 14:46:21 +01:00
|
|
|
ImGui::PushID(this);
|
2023-11-18 14:34:33 +01:00
|
|
|
if (ImGui::Button(label.c_str(), ImVec2(250_scaled, 0))) {
|
2023-11-17 14:46:21 +01:00
|
|
|
this->m_editing = !this->m_editing;
|
|
|
|
|
|
|
|
if (this->m_editing)
|
|
|
|
ShortcutManager::pauseShortcuts();
|
|
|
|
else
|
|
|
|
ShortcutManager::resumeShortcuts();
|
|
|
|
}
|
2023-11-18 14:34:33 +01:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (this->m_hasDuplicate)
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
2023-11-19 18:22:57 +01:00
|
|
|
bool settingChanged = false;
|
|
|
|
|
2023-12-06 09:09:32 +01:00
|
|
|
ImGui::BeginDisabled(this->m_drawShortcut == this->m_defaultShortcut);
|
2023-11-18 14:34:33 +01:00
|
|
|
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
|
|
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, this->m_defaultShortcut, this->m_view);
|
2023-11-19 18:22:57 +01:00
|
|
|
|
2023-12-06 09:09:32 +01:00
|
|
|
this->m_drawShortcut = this->m_defaultShortcut;
|
|
|
|
if (!this->m_hasDuplicate) {
|
|
|
|
this->m_shortcut = this->m_defaultShortcut;
|
|
|
|
settingChanged = true;
|
|
|
|
}
|
|
|
|
|
2023-11-18 14:34:33 +01:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2023-11-17 14:46:21 +01:00
|
|
|
|
|
|
|
if (!ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
|
|
|
this->m_editing = false;
|
|
|
|
ShortcutManager::resumeShortcuts();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImGuiExt::TextFormatted("{}", name);
|
|
|
|
|
2023-11-18 14:34:33 +01:00
|
|
|
ImGui::PopID();
|
|
|
|
|
2023-11-17 14:46:21 +01:00
|
|
|
if (this->m_editing) {
|
|
|
|
if (this->detectShortcut()) {
|
|
|
|
this->m_editing = false;
|
|
|
|
ShortcutManager::resumeShortcuts();
|
|
|
|
|
2023-12-06 09:09:32 +01:00
|
|
|
settingChanged = true;
|
2023-12-06 11:05:13 +01:00
|
|
|
if (!this->m_hasDuplicate) {
|
2023-12-06 09:09:32 +01:00
|
|
|
}
|
2023-11-17 14:46:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-19 18:22:57 +01:00
|
|
|
return settingChanged;
|
2023-11-17 14:46:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override {
|
|
|
|
std::set<Key> keys;
|
|
|
|
|
|
|
|
for (const auto &key : data.get<std::vector<u32>>())
|
|
|
|
keys.insert(Key(Keys(key)));
|
|
|
|
|
|
|
|
if (keys.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto newShortcut = Shortcut(keys);
|
2023-11-18 14:34:33 +01:00
|
|
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
2023-11-17 14:46:21 +01:00
|
|
|
this->m_shortcut = std::move(newShortcut);
|
2023-12-06 09:09:32 +01:00
|
|
|
this->m_drawShortcut = this->m_shortcut;
|
2023-11-17 14:46:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json store() override {
|
|
|
|
std::vector<u32> keys;
|
|
|
|
|
|
|
|
for (const auto &key : this->m_shortcut.getKeys()) {
|
|
|
|
if (key != CurrentView)
|
|
|
|
keys.push_back(key.getKeyCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool detectShortcut() {
|
2023-11-24 20:17:01 +01:00
|
|
|
if (const auto &shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) {
|
2023-11-17 14:46:21 +01:00
|
|
|
auto keys = this->m_shortcut.getKeys();
|
|
|
|
std::erase_if(keys, [](Key key) {
|
|
|
|
return key != AllowWhileTyping && key != CurrentView;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto &key : shortcut->getKeys()) {
|
|
|
|
keys.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newShortcut = Shortcut(std::move(keys));
|
2023-11-18 14:34:33 +01:00
|
|
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
2023-12-06 09:09:32 +01:00
|
|
|
this->m_drawShortcut = std::move(newShortcut);
|
2023-11-17 14:46:21 +01:00
|
|
|
|
2023-11-24 20:17:01 +01:00
|
|
|
if (!this->m_hasDuplicate) {
|
2023-12-06 09:09:32 +01:00
|
|
|
this->m_shortcut = this->m_drawShortcut;
|
|
|
|
log::info("Changed shortcut to {}", shortcut->toString());
|
|
|
|
} else {
|
|
|
|
log::warn("Changing shortcut failed as it overlapped with another one", shortcut->toString());
|
2023-11-24 20:17:01 +01:00
|
|
|
}
|
2023-12-06 09:09:32 +01:00
|
|
|
|
|
|
|
return true;
|
2023-11-17 14:46:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
View *m_view = nullptr;
|
2023-12-06 09:09:32 +01:00
|
|
|
Shortcut m_shortcut, m_drawShortcut, m_defaultShortcut;
|
2023-11-17 14:46:21 +01:00
|
|
|
bool m_editing = false;
|
2023-11-18 14:34:33 +01:00
|
|
|
bool m_hasDuplicate = false;
|
2023-11-17 14:46:21 +01:00
|
|
|
};
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
}
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void registerSettings() {
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
/* General */
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
namespace Widgets = ContentRegistry::Settings::Widgets;
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-12-07 11:18:49 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.show_tips", false);
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.save_recent_providers", true);
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.auto_load_patterns", true);
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.sync_pattern_source", false);
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.network_interface", false);
|
|
|
|
ContentRegistry::Settings::add<ServerContactWidget>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.server_contact");
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.network", "hex.builtin.setting.general.upload_crash_logs", true);
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
/* Interface */
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
auto themeNames = ThemeManager::getThemeNames();
|
|
|
|
std::vector<nlohmann::json> themeJsons = { };
|
|
|
|
for (const auto &themeName : themeNames)
|
|
|
|
themeJsons.emplace_back(themeName);
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
themeNames.emplace(themeNames.begin(), ThemeManager::NativeTheme);
|
|
|
|
themeJsons.emplace(themeJsons.begin(), ThemeManager::NativeTheme);
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-11-25 13:42:51 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.color",
|
2023-10-21 23:07:33 +02:00
|
|
|
themeNames,
|
2023-10-22 17:31:53 +02:00
|
|
|
themeJsons,
|
|
|
|
"Dark").setChangedCallback([](auto &widget) {
|
2023-10-21 23:07:33 +02:00
|
|
|
auto dropDown = static_cast<Widgets::DropDown *>(&widget);
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
if (dropDown->getValue() == ThemeManager::NativeTheme)
|
|
|
|
ImHexApi::System::enableSystemThemeDetection(true);
|
|
|
|
else {
|
|
|
|
ImHexApi::System::enableSystemThemeDetection(false);
|
|
|
|
ThemeManager::changeTheme(dropDown->getValue());
|
|
|
|
}
|
|
|
|
});
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-11-25 13:42:51 +01:00
|
|
|
ContentRegistry::Settings::add<ScalingWidget>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.scaling").requiresRestart();
|
|
|
|
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.pattern_data_row_bg", false);
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
std::vector<std::string> languageNames;
|
|
|
|
std::vector<nlohmann::json> languageCodes;
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
for (auto &[languageCode, languageName] : LocalizationManager::getSupportedLanguages()) {
|
2023-10-21 23:07:33 +02:00
|
|
|
languageNames.emplace_back(languageName);
|
|
|
|
languageCodes.emplace_back(languageCode);
|
|
|
|
}
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-11-25 13:42:51 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "hex.builtin.setting.interface.language", languageNames, languageCodes, "en-US");
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-11-25 13:42:51 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::TextBox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "hex.builtin.setting.interface.wiki_explain_language", "en");
|
|
|
|
ContentRegistry::Settings::add<FPSWidget>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.fps");
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
#if defined (OS_LINUX)
|
|
|
|
constexpr static auto MultiWindowSupportEnabledDefault = 0;
|
|
|
|
#else
|
|
|
|
constexpr static auto MultiWindowSupportEnabledDefault = 1;
|
|
|
|
#endif
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-11-25 13:42:51 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.multi_windows", MultiWindowSupportEnabledDefault).requiresRestart();
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false);
|
2023-12-07 11:18:49 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.simplified_welcome_screen", false);
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60));
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false);
|
|
|
|
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.byte_padding", 0, 0, 50);
|
|
|
|
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.char_padding", 0, 0, 50);
|
2022-03-27 00:01:28 +01:00
|
|
|
|
2022-07-02 17:53:13 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
/* Fonts */
|
2022-07-02 17:53:13 +02:00
|
|
|
|
2023-11-28 13:53:08 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false)
|
|
|
|
.requiresRestart();
|
2023-11-23 23:15:42 +01:00
|
|
|
|
|
|
|
auto customFontEnabledSetting = ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_enable", false).requiresRestart();
|
|
|
|
|
2023-11-24 11:29:05 +01:00
|
|
|
const auto fontSettingsEnabled = [customFontEnabledSetting]{
|
|
|
|
auto &checkBox = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
|
|
|
|
|
|
|
|
return checkBox.isChecked();
|
|
|
|
};
|
|
|
|
|
2023-11-23 23:15:42 +01:00
|
|
|
ContentRegistry::Settings::add<Widgets::FilePicker>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path")
|
|
|
|
.requiresRestart()
|
2023-11-24 11:29:05 +01:00
|
|
|
.setEnabledCallback(fontSettingsEnabled);
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_size", 13, 0, 100)
|
|
|
|
.requiresRestart()
|
2023-11-24 11:29:05 +01:00
|
|
|
.setEnabledCallback(fontSettingsEnabled);
|
|
|
|
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_bold", false)
|
|
|
|
.requiresRestart()
|
|
|
|
.setEnabledCallback(fontSettingsEnabled);
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_italic", false)
|
|
|
|
.requiresRestart()
|
|
|
|
.setEnabledCallback(fontSettingsEnabled);
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_antialias", false)
|
|
|
|
.requiresRestart()
|
|
|
|
.setEnabledCallback(fontSettingsEnabled);
|
2022-07-14 11:38:23 +02:00
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2022-07-02 17:53:13 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
/* Folders */
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.folders", "hex.builtin.setting.folders.description");
|
|
|
|
ContentRegistry::Settings::add<UserFolderWidget>("hex.builtin.setting.folders", "", "hex.builtin.setting.folders.description");
|
2022-07-01 14:05:32 +02:00
|
|
|
|
|
|
|
/* Proxy */
|
|
|
|
|
2023-11-10 21:59:20 +01:00
|
|
|
HttpRequest::setProxyUrl(ContentRegistry::Settings::read("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.url", "").get<std::string>());
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.proxy", "hex.builtin.setting.proxy.description");
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
auto proxyEnabledSetting = ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.proxy", "", "hex.builtin.setting.proxy.enable", false).setChangedCallback([](Widgets::Widget &widget) {
|
|
|
|
auto checkBox = static_cast<Widgets::Checkbox *>(&widget);
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-11-10 21:59:20 +01:00
|
|
|
HttpRequest::setProxyState(checkBox->isChecked());
|
2023-10-21 23:07:33 +02:00
|
|
|
});
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::add<Widgets::TextBox>("hex.builtin.setting.proxy", "", "hex.builtin.setting.proxy.url", "")
|
|
|
|
.setEnabledCallback([proxyEnabledSetting] {
|
|
|
|
auto &checkBox = static_cast<Widgets::Checkbox &>(proxyEnabledSetting.getWidget());
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
return checkBox.isChecked();
|
|
|
|
})
|
|
|
|
.setChangedCallback([](Widgets::Widget &widget) {
|
|
|
|
auto textBox = static_cast<Widgets::TextBox *>(&widget);
|
2022-07-01 14:05:32 +02:00
|
|
|
|
2023-11-10 21:59:20 +01:00
|
|
|
HttpRequest::setProxyUrl(textBox->getValue());
|
2023-10-21 23:07:33 +02:00
|
|
|
});
|
2023-11-10 20:47:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Experiments */
|
|
|
|
ContentRegistry::Settings::setCategoryDescription("hex.builtin.setting.experiments", "hex.builtin.setting.experiments.description");
|
|
|
|
EventManager::subscribe<EventImHexStartupFinished>([]{
|
|
|
|
for (const auto &[name, experiment] : ContentRegistry::Experiments::impl::getExperiments()) {
|
|
|
|
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.experiments", "", experiment.unlocalizedName, false)
|
2023-11-21 14:38:01 +01:00
|
|
|
.setTooltip(Lang(experiment.unlocalizedDescription))
|
2023-11-10 20:47:08 +01:00
|
|
|
.setChangedCallback([name](Widgets::Widget &widget) {
|
|
|
|
auto checkBox = static_cast<Widgets::Checkbox *>(&widget);
|
|
|
|
|
|
|
|
ContentRegistry::Experiments::enableExperiement(name, checkBox->isChecked());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-17 14:46:21 +01:00
|
|
|
/* Shorcuts */
|
|
|
|
EventManager::subscribe<EventImHexStartupFinished>([]{
|
|
|
|
for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) {
|
|
|
|
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName, nullptr, shortcutEntry.shortcut);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &[viewName, view] : ContentRegistry::Views::impl::getEntries()) {
|
|
|
|
for (const auto &shortcutEntry : ShortcutManager::getViewShortcuts(view.get())) {
|
|
|
|
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", viewName, shortcutEntry.unlocalizedName, view.get(), shortcutEntry.shortcut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
|
|
|
|
2023-12-06 13:49:58 +01:00
|
|
|
static void loadLayoutSettings() {
|
|
|
|
const bool locked = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.layout_locked", false);
|
|
|
|
LayoutManager::lockLayout(locked);
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:22:38 +02:00
|
|
|
static void loadThemeSettings() {
|
2023-10-21 23:07:33 +02:00
|
|
|
auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>();
|
2022-07-02 16:22:38 +02:00
|
|
|
|
2023-03-23 20:35:16 +01:00
|
|
|
if (theme == ThemeManager::NativeTheme)
|
2022-12-29 19:26:00 +01:00
|
|
|
ImHexApi::System::enableSystemThemeDetection(true);
|
|
|
|
else {
|
|
|
|
ImHexApi::System::enableSystemThemeDetection(false);
|
2023-03-23 20:35:16 +01:00
|
|
|
ThemeManager::changeTheme(theme);
|
2022-12-29 19:26:00 +01:00
|
|
|
}
|
2022-07-02 16:22:38 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
static void loadFolderSettings() {
|
|
|
|
auto folderPathStrings = ContentRegistry::Settings::read("hex.builtin.setting.folders", "hex.builtin.setting.folders", std::vector<std::string> { });
|
|
|
|
|
|
|
|
std::vector<std::fs::path> paths;
|
|
|
|
for (const auto &pathString : folderPathStrings) {
|
|
|
|
paths.emplace_back(pathString);
|
|
|
|
}
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ImHexApi::System::setAdditionalFolderPaths(paths);
|
2022-07-14 11:38:23 +02:00
|
|
|
}
|
|
|
|
|
2022-07-02 16:22:38 +02:00
|
|
|
void loadSettings() {
|
2023-12-06 13:49:58 +01:00
|
|
|
loadLayoutSettings();
|
2022-07-02 16:22:38 +02:00
|
|
|
loadThemeSettings();
|
2023-10-21 23:07:33 +02:00
|
|
|
loadFolderSettings();
|
2022-07-02 16:22:38 +02:00
|
|
|
}
|
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
}
|