Skip to content

Commit

Permalink
Add API for advanced view settings options, including for sidebar ent…
Browse files Browse the repository at this point in the history
…ries
  • Loading branch information
narknon committed Dec 11, 2023
1 parent 51510a2 commit 8c7e201
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 140 deletions.
37 changes: 23 additions & 14 deletions src/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,11 @@ void Framework::draw_ui() {
ImGui::Text("(?)");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Allows mouse and keyboard inputs to register to the game while the UI is focused.");
ImGui::Checkbox("Show Advanced Options", &m_advanced_view_enabled);
ImGui::SameLine();
ImGui::Text("(?)");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Show additional options for greater control over various settings.");

if (m_mods_fully_initialized) {
if (ImGui::Button("Reset to Default Settings")) {
Expand All @@ -1180,7 +1185,7 @@ void Framework::draw_ui() {
ImGui::Columns(1);

// Mods:
std::vector<std::string> sidebar_entries{"About"};
sidebar_entries.insert(sidebar_entries.begin(), {"About", false});

if (ImGui::BeginTable("UEVRTable", 2, ImGuiTableFlags_::ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_::ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_::ImGuiTableFlags_SizingFixedFit)) {
ImGui::TableSetupColumn("UEVRLeftPaneColumn", ImGuiTableColumnFlags_WidthFixed, 150.0f);
Expand Down Expand Up @@ -1221,25 +1226,27 @@ void Framework::draw_ui() {
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());
sidebar_entries.push_back({mod->get_name().data(), mod->is_advanced_mod()} );
}
}

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 && !m_sidebar_state.initialized) {
m_sidebar_state.selected_entry = i;
m_sidebar_state.initialized = true;
ImGui::SetWindowFocus("UEVRRightPane");
}
if (m_advanced_view_enabled || !sidebar_entries[i].m_advanced_entry) {
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 && !m_sidebar_state.initialized) {
m_sidebar_state.selected_entry = i;
m_sidebar_state.initialized = true;
ImGui::SetWindowFocus("UEVRRightPane");
}

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

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

bool wants_focus_right = false;
Expand Down Expand Up @@ -1276,7 +1283,7 @@ void Framework::draw_ui() {
for (const auto& range : mod_sidebar_ranges) {
if (m_sidebar_state.selected_entry >= range.mn && m_sidebar_state.selected_entry < range.mx) {
if (range.has_sidebar_entries) {
range.mod->on_draw_sidebar_entry(sidebar_entries[m_sidebar_state.selected_entry]);
range.mod->on_draw_sidebar_entry(sidebar_entries[m_sidebar_state.selected_entry].m_label);
} else {
range.mod->on_draw_ui();
}
Expand Down Expand Up @@ -1341,6 +1348,8 @@ void Framework::draw_ui() {
if (m_last_draw_ui && !m_draw_ui) {
m_windows_message_hook->window_toggle_cursor(m_cursor_state);
}

sidebar_entries.clear();
}

void Framework::draw_about() {
Expand Down
30 changes: 28 additions & 2 deletions src/Framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class UEVRSharedMemory {
Data* m_data{};
};


struct SidebarEntryInfo {
std::string m_label{};
bool m_advanced_entry{false};
};

// Global facilitator
class Framework {
private:
Expand Down Expand Up @@ -190,7 +196,13 @@ class Framework {
if (delta < std::chrono::milliseconds(100)) {
return;
}
++m_sidebar_state.selected_entry;
int32_t selected_entry_local = m_sidebar_state.selected_entry + 1;
if (!m_advanced_view_enabled) {
while (sidebar_entries[selected_entry_local].m_advanced_entry) {
++selected_entry_local;
}
}
m_sidebar_state.selected_entry = selected_entry_local;

m_last_page_inc_time = now;
}
Expand All @@ -201,7 +213,13 @@ class Framework {
if (delta < std::chrono::milliseconds(100)) {
return;
}
--m_sidebar_state.selected_entry;
int32_t selected_entry_local = m_sidebar_state.selected_entry - 1;
if (!m_advanced_view_enabled) {
while (sidebar_entries[selected_entry_local].m_advanced_entry) {
--selected_entry_local;
}
}
m_sidebar_state.selected_entry = selected_entry_local;

m_last_page_dec_time = now;
}
Expand All @@ -211,6 +229,12 @@ class Framework {
void update_fonts();
void invalidate_device_objects();

public:
bool is_advanced_view_enabled() {
return m_advanced_view_enabled;
}

private:
void draw_ui();
void draw_about();

Expand Down Expand Up @@ -241,13 +265,15 @@ class Framework {
// UI
bool m_has_frame{false};
bool m_wants_device_object_cleanup{false};
bool m_advanced_view_enabled{false};
bool m_draw_ui{true};
bool m_last_draw_ui{m_draw_ui};
bool m_is_ui_focused{false};
bool m_cursor_state{false};
bool m_cursor_state_changed{true};
bool m_ui_option_transparent{true};
bool m_ui_passthrough{false};
std::vector<SidebarEntryInfo> sidebar_entries{};

ImVec2 m_last_window_pos{};
ImVec2 m_last_window_size{};
Expand Down
Loading

0 comments on commit 8c7e201

Please sign in to comment.