Skip to content

Commit

Permalink
Rework entire UI to be sidebar based
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 30, 2023
1 parent d80efd1 commit cf6e1f8
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 398 deletions.
125 changes: 113 additions & 12 deletions src/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,14 +1179,122 @@ void Framework::draw_ui() {
ImGui::Columns(1);

// Mods:
draw_about();
std::vector<std::string> sidebar_entries{"About"};
static int selected_sidebar_entry = 0;
static bool initialized_default_sidebar_entry = false;

ImGui::BeginTable("UEVRTable", 2, ImGuiTableFlags_::ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_::ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_::ImGuiTableFlags_SizingFixedFit);
ImGui::TableSetupColumn("UEVRLeftPane", ImGuiTableColumnFlags_WidthFixed, 150.0f);
ImGui::TableSetupColumn("UEVRRightPane", ImGuiTableColumnFlags_WidthStretch);

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); // Set to the first column

ImGui::BeginChild("UEVRLeftPane", ImVec2(0, 0), true);
auto dcs = [&](const char* label, uint32_t page_value) -> bool {
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.5f));
if (ImGui::Selectable(label, selected_sidebar_entry == page_value)) {
selected_sidebar_entry = page_value;
ImGui::PopStyleVar();
return true;
}
ImGui::PopStyleVar();
return false;
};

dcs("About", 0);

if (m_error.empty() && m_game_data_initialized) {
m_mods->on_draw_ui();
struct Info {
size_t mn{};
size_t mx{};
std::shared_ptr<Mod> mod{};
bool has_sidebar_entries{};
};

std::vector<Info> mod_sidebar_ranges{};

for (auto& mod : m_mods->get_mods()) {
auto entries = mod->get_sidebar_entries();

if (!entries.empty()) {
mod_sidebar_ranges.push_back(Info{sidebar_entries.size(), sidebar_entries.size() + entries.size(), mod, true});
sidebar_entries.insert(sidebar_entries.end(), entries.begin(), entries.end());
} else {
mod_sidebar_ranges.push_back(Info{sidebar_entries.size(), sidebar_entries.size() + 1, mod, false});
sidebar_entries.push_back(mod->get_name().data());
}
}

for (size_t i = 1; i < sidebar_entries.size(); ++i) {
for (const auto& range : mod_sidebar_ranges) {
if (i == range.mn) {
// Set first entry as default ("Runtime" entry of VR mod)
if (range.has_sidebar_entries && !initialized_default_sidebar_entry) {
selected_sidebar_entry = i;
initialized_default_sidebar_entry = true;
}

ImGui::Text(range.mod->get_name().data());
}
}

dcs(sidebar_entries[i].c_str(), i);
}

if (selected_sidebar_entry >= sidebar_entries.size()) {
selected_sidebar_entry = 0;
}

ImGui::EndChild();
ImGui::TableNextColumn(); // Move to the next column (right)

if (selected_sidebar_entry > 0) {
// Find the mod that owns this entry
for (const auto& range : mod_sidebar_ranges) {
if (selected_sidebar_entry >= range.mn && selected_sidebar_entry < range.mx) {
if (range.has_sidebar_entries) {
range.mod->on_draw_sidebar_entry(sidebar_entries[selected_sidebar_entry]);
} else {
range.mod->on_draw_ui();
}

break;
}
}
} else {
draw_about();
}

/*for (auto& mod : m_mods->get_mods()) {
mod->on_draw_ui();
}*/

//m_mods->on_draw_ui();

ImGui::EndTable();
} else if (!m_game_data_initialized) {
ImGui::EndChild();

if (selected_sidebar_entry == 0) {
ImGui::TableNextColumn();
draw_about();
}

ImGui::EndTable();

ImGui::TextWrapped("Framework is currently initializing...");
ImGui::TextWrapped("This menu will close after initialization if you have the remember option enabled.");
} else if (!m_error.empty()) {
ImGui::EndChild();

if (selected_sidebar_entry == 0) {
ImGui::TableNextColumn();
draw_about();
}

ImGui::EndTable();

ImGui::TextWrapped("Framework error: %s", m_error.c_str());
}

Expand All @@ -1213,12 +1321,6 @@ void Framework::draw_ui() {
}

void Framework::draw_about() {
if (!ImGui::CollapsingHeader("About")) {
return;
}

ImGui::TreePush("About");

ImGui::Text("Author: praydog");
ImGui::Text("Unreal Engine VR");
ImGui::Text("https://github.com/praydog/UEVR");
Expand All @@ -1232,15 +1334,16 @@ void Framework::draw_about() {
std::string text;
};

static std::array<License, 8> licenses{
static std::array<License, 9> licenses{
License{ "glm", license::glm },
License{ "imgui", license::imgui },
License{ "safetyhook", license::safetyhook },
License{ "spdlog", license::spdlog },
License{ "json", license::json },
License{ "bddisasm", utility::narrow(license::bddisasm) },
License{ "directxtk", license::directxtk },
License{ "directxtk12", license::directxtk }
License{ "directxtk12", license::directxtk },
License{ "openvr", license::openvr },
};

for (const auto& license : licenses) {
Expand All @@ -1253,8 +1356,6 @@ void Framework::draw_about() {
}

ImGui::Separator();

ImGui::TreePop();
}

void Framework::set_imgui_style() noexcept {
Expand Down
3 changes: 3 additions & 0 deletions src/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ class Mod {
virtual std::optional<std::string> on_initialize() { return std::nullopt; };
virtual std::optional<std::string> on_initialize_d3d_thread() { return std::nullopt; };

virtual std::vector<std::string> get_sidebar_entries() { return {}; };

// This gets called after updating stuff like keyboard/mouse input to imgui
// can be used to override these inputs e.g. with a custom input system
// like VR controllers
Expand All @@ -389,6 +391,7 @@ class Mod {
virtual void on_post_frame() {}; // after imgui rendering is done
virtual void on_post_present() {}; // actually after present gets called
virtual void on_draw_ui() {};
virtual void on_draw_sidebar_entry(std::string_view in_entry) {};
virtual void on_device_reset() {};
virtual bool on_message(HWND wnd, UINT message, WPARAM w_param, LPARAM l_param) { return true; };
virtual void on_xinput_get_state(uint32_t* retval, uint32_t user_index, XINPUT_STATE* state) {};
Expand Down
8 changes: 0 additions & 8 deletions src/mods/FrameworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ std::optional<std::string> FrameworkConfig::on_initialize() {
}

void FrameworkConfig::on_draw_ui() {
if (!ImGui::CollapsingHeader("Configuration")) {
return;
}

ImGui::TreePush("Configuration");

m_menu_key->draw("Menu Key");
m_show_cursor_key->draw("Show Cursor Key");
m_remember_menu_state->draw("Remember Menu Open/Closed State");
Expand All @@ -27,8 +21,6 @@ void FrameworkConfig::on_draw_ui() {
if (m_font_size->draw("Font Size")) {
g_framework->set_font_size(m_font_size->value());
}

ImGui::TreePop();
}

void FrameworkConfig::on_frame() {
Expand Down
56 changes: 26 additions & 30 deletions src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,44 +914,40 @@ void PluginLoader::reload_plugins() {
}

void PluginLoader::on_draw_ui() {
ImGui::SetNextItemOpen(false, ImGuiCond_Once);

if (ImGui::CollapsingHeader(get_name().data())) {
std::scoped_lock _{m_mux};
std::scoped_lock _{m_mux};

if (ImGui::Button("Attempt Unload Plugins")) {
attempt_unload_plugins();
}
if (ImGui::Button("Attempt Unload Plugins")) {
attempt_unload_plugins();
}

if (ImGui::Button("Reload Plugins")) {
attempt_unload_plugins();
reload_plugins();
}
if (ImGui::Button("Reload Plugins")) {
attempt_unload_plugins();
reload_plugins();
}

if (!m_plugins.empty()) {
ImGui::Text("Loaded plugins:");
if (!m_plugins.empty()) {
ImGui::Text("Loaded plugins:");

for (auto&& [name, _] : m_plugins) {
ImGui::Text(name.c_str());
}
} else {
ImGui::Text("No plugins loaded.");
for (auto&& [name, _] : m_plugins) {
ImGui::Text(name.c_str());
}
} else {
ImGui::Text("No plugins loaded.");
}

if (!m_plugin_load_errors.empty()) {
ImGui::Spacing();
ImGui::Text("Errors:");
for (auto&& [name, error] : m_plugin_load_errors) {
ImGui::Text("%s - %s", name.c_str(), error.c_str());
}
if (!m_plugin_load_errors.empty()) {
ImGui::Spacing();
ImGui::Text("Errors:");
for (auto&& [name, error] : m_plugin_load_errors) {
ImGui::Text("%s - %s", name.c_str(), error.c_str());
}
}

if (!m_plugin_load_warnings.empty()) {
ImGui::Spacing();
ImGui::Text("Warnings:");
for (auto&& [name, warning] : m_plugin_load_warnings) {
ImGui::Text("%s - %s", name.c_str(), warning.c_str());
}
if (!m_plugin_load_warnings.empty()) {
ImGui::Spacing();
ImGui::Text("Warnings:");
for (auto&& [name, warning] : m_plugin_load_warnings) {
ImGui::Text("%s - %s", name.c_str(), warning.c_str());
}
}
}
Expand Down
Loading

0 comments on commit cf6e1f8

Please sign in to comment.