fix: ImHex no longer behaves weirdly or crashes when no plugins are loaded
This commit is contained in:
parent
64e35886b7
commit
d177d69724
@ -42,7 +42,7 @@ namespace hex {
|
||||
|
||||
float m_globalScale = 1.0f, m_fontScale = 1.0f;
|
||||
bool m_fpsVisible = false;
|
||||
double m_targetFps;
|
||||
double m_targetFps = 60.0;
|
||||
bool m_demoWindowOpen = false;
|
||||
bool m_layoutConfigured = false;
|
||||
|
||||
|
@ -38,8 +38,8 @@ namespace hex {
|
||||
|
||||
if (!json.contains(unlocalizedCategory.data()))
|
||||
json[unlocalizedCategory.data()] = nlohmann::json::object();
|
||||
if (!json[unlocalizedCategory.data()].contains(unlocalizedName.data()))
|
||||
json[unlocalizedCategory.data()][unlocalizedName.data()] = defaultValue;
|
||||
if (!json[unlocalizedCategory.data()].contains(unlocalizedName.data()) || !json[unlocalizedCategory.data()][unlocalizedName.data()].is_number())
|
||||
json[unlocalizedCategory.data()][unlocalizedName.data()] = int(defaultValue);
|
||||
}
|
||||
|
||||
void ContentRegistry::Settings::add(std::string_view unlocalizedCategory, std::string_view unlocalizedName, std::string_view defaultValue, const std::function<bool(std::string_view, nlohmann::json&)> &callback) {
|
||||
@ -49,8 +49,8 @@ namespace hex {
|
||||
|
||||
if (!json.contains(unlocalizedCategory.data()))
|
||||
json[unlocalizedCategory.data()] = nlohmann::json::object();
|
||||
if (!json[unlocalizedCategory.data()].contains(unlocalizedName.data()))
|
||||
json[unlocalizedCategory.data()][unlocalizedName.data()] = defaultValue;
|
||||
if (!json[unlocalizedCategory.data()].contains(unlocalizedName.data()) || !json[unlocalizedCategory.data()][unlocalizedName.data()].is_string())
|
||||
json[unlocalizedCategory.data()][unlocalizedName.data()] = std::string(defaultValue);
|
||||
}
|
||||
|
||||
void ContentRegistry::Settings::write(std::string_view unlocalizedCategory, std::string_view unlocalizedName, s64 value) {
|
||||
|
@ -187,7 +187,8 @@ namespace hex {
|
||||
EventManager::subscribe<EventSettingsChanged>(this, [this] {
|
||||
auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
|
||||
|
||||
this->m_highlightAlpha = alpha;
|
||||
if (alpha.is_number())
|
||||
this->m_highlightAlpha = alpha;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,7 @@ namespace hex {
|
||||
if (argument == "update-available") {
|
||||
this->m_availableUpdate = value;
|
||||
} else if (argument == "no-plugins") {
|
||||
View::showErrorPopup("No plugins are loaded, including the built-in functions plugin!\n"
|
||||
"Make sure you got at least builtin.hexplug in your plugins folder.");
|
||||
View::doLater([]{ ImGui::OpenPopup("No Plugins"); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -351,12 +350,15 @@ namespace hex {
|
||||
}
|
||||
|
||||
if (this->m_fpsVisible) {
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - 3 * ImGui::GetFontSize());
|
||||
ImGui::Text("%.1f FPS", ImGui::GetIO().Framerate);
|
||||
std::string fps = hex::format("{:.1f} FPS ", ImGui::GetIO().Framerate);
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - fps.length() * ImGui::GetFontSize());
|
||||
ImGui::TextUnformatted(fps.c_str());
|
||||
} else {
|
||||
#if defined(DEBUG)
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetCursorPosX());
|
||||
ImGui::Text(ICON_FA_BUG, ImGui::GetIO().Framerate);
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 2 * ImGui::GetFontSize());
|
||||
ImGui::TextUnformatted(ICON_FA_BUG);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -382,6 +384,15 @@ namespace hex {
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// Popup for when no plugins were loaded. Intentionally left untranslated because localization isn't available
|
||||
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
|
||||
if (ImGui::BeginPopupModal("No Plugins", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) {
|
||||
ImGui::TextUnformatted("No ImHex plugins loaded (including the built-in plugin)!");
|
||||
ImGui::TextUnformatted("Make sure you at least got the builtin plugin in your plugins folder.");
|
||||
ImGui::TextUnformatted("To find out where your plugin folder is, check ImHex' Readme.");
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::frameEnd() {
|
||||
@ -463,12 +474,7 @@ namespace hex {
|
||||
{
|
||||
const auto &plugins = PluginManager::getPlugins();
|
||||
|
||||
if (plugins.empty()) {
|
||||
// Intentionally left untranslated so it will be readable even if no plugin with translations is loaded
|
||||
ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F),
|
||||
"No plugins loaded! To use ImHex properly, "
|
||||
"make sure at least the builtin plugin is in the /plugins folder next to the executable");
|
||||
} else {
|
||||
if (!plugins.empty()) {
|
||||
if (ImGui::BeginTable("plugins", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2((ImGui::GetContentRegionAvail().x * 5) / 6, ImGui::GetTextLineHeightWithSpacing() * 5))) {
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
ImGui::TableSetupColumn("hex.welcome.plugins.plugin"_lang);
|
||||
|
Loading…
x
Reference in New Issue
Block a user