Skip to content

Commit

Permalink
(#117) UI: Add optional Long Press option menu toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jan 12, 2024
1 parent 3afaf8c commit 3a1e85c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/mods/FrameworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ void FrameworkConfig::draw_main() {
m_show_cursor_key->draw("Show Cursor Key");
m_remember_menu_state->draw("Remember Menu Open/Closed State");
m_enable_l3_r3_toggle->draw("Enable L3 + R3 Toggle");
ImGui::SameLine();
m_l3_r3_long_press->draw("L3 + R3 Long Press Menu Toggle");
m_always_show_cursor->draw("Always Show Cursor");
}

Expand Down
6 changes: 6 additions & 0 deletions src/mods/FrameworkConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class FrameworkConfig : public Mod {
return m_enable_l3_r3_toggle->value();
}

bool is_l3_r3_long_press() {
return m_l3_r3_long_press->value();
}

bool is_always_show_cursor() const {
return m_always_show_cursor->value();
}
Expand Down Expand Up @@ -83,6 +87,7 @@ class FrameworkConfig : public Mod {
ModToggle::Ptr m_menu_open{ ModToggle::create(generate_name("MenuOpen"), true) };
ModToggle::Ptr m_remember_menu_state{ ModToggle::create(generate_name("RememberMenuState"), false) };
ModToggle::Ptr m_enable_l3_r3_toggle{ ModToggle::create(generate_name("EnableL3R3Toggle"), true) };
ModToggle::Ptr m_l3_r3_long_press{ ModToggle::create(generate_name("L3R3LongPress"), false) };
ModToggle::Ptr m_always_show_cursor{ ModToggle::create(generate_name("AlwaysShowCursor"), false) };
ModToggle::Ptr m_advanced_mode{ ModToggle::create(generate_name("AdvancedMode"), false) };
ModCombo::Ptr m_imgui_theme{ ModCombo::create(generate_name("ImGuiTheme"), s_imgui_themes, Framework::ImGuiThemes::DEFAULT_DARK) };
Expand All @@ -95,6 +100,7 @@ class FrameworkConfig : public Mod {
*m_menu_open,
*m_remember_menu_state,
*m_enable_l3_r3_toggle,
*m_l3_r3_long_press,
*m_advanced_mode,
*m_imgui_theme,
*m_always_show_cursor,
Expand Down
32 changes: 24 additions & 8 deletions src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,16 +1064,30 @@ void VR::update_imgui_state_from_xinput_state(XINPUT_STATE& state, bool is_vr_co
return;
}

bool should_open = true;

const auto now = std::chrono::steady_clock::now();

if (now - m_last_xinput_l3_r3_menu_open >= std::chrono::seconds(1)) {
if (FrameworkConfig::get()->is_l3_r3_long_press() && !g_framework->is_drawing_ui()) {
if (!m_xinput_context.menu_longpress_begin_held) {
m_xinput_context.menu_longpress_begin = now;
}

m_xinput_context.menu_longpress_begin_held = true;
should_open = (now - m_xinput_context.menu_longpress_begin) >= std::chrono::seconds(1);
} else {
m_xinput_context.menu_longpress_begin_held = false;
}

if (should_open && now - m_last_xinput_l3_r3_menu_open >= std::chrono::seconds(1)) {
m_last_xinput_l3_r3_menu_open = std::chrono::steady_clock::now();
g_framework->set_draw_ui(!g_framework->is_drawing_ui());

state.Gamepad.wButtons &= ~(XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_RIGHT_THUMB); // so input doesn't go through to the game
}
} else if (is_using_this_controller) {
m_xinput_context.headlocked_begin_held = false;
m_xinput_context.menu_longpress_begin_held = false;
}

// We need to adjust the stick values based on the selected movement orientation value if the user wants to do this
Expand Down Expand Up @@ -1142,13 +1156,15 @@ void VR::update_imgui_state_from_xinput_state(XINPUT_STATE& state, bool is_vr_co
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;

// Headlocked aim toggle
if ((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0 && (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0) {
if (!m_xinput_context.headlocked_begin_held) {
m_xinput_context.headlocked_begin = std::chrono::steady_clock::now();
m_xinput_context.headlocked_begin_held = true;
if (!FrameworkConfig::get()->is_l3_r3_long_press()) {
if ((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0 && (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0) {
if (!m_xinput_context.headlocked_begin_held) {
m_xinput_context.headlocked_begin = std::chrono::steady_clock::now();
m_xinput_context.headlocked_begin_held = true;
}
} else {
m_xinput_context.headlocked_begin_held = false;
}
} else {
m_xinput_context.headlocked_begin_held = false;
}

// Now that we're drawing the UI, check for special button combos the user can use as shortcuts
Expand Down Expand Up @@ -1875,7 +1891,7 @@ void VR::on_frame() {
m_rt_modifier.draw = false;
}

if (is_allowed_draw_window && m_xinput_context.headlocked_begin_held) {
if (is_allowed_draw_window && m_xinput_context.headlocked_begin_held && !FrameworkConfig::get()->is_l3_r3_long_press()) {
const auto rt_size = g_framework->get_rt_size();

ImGui::Begin("AimMethod Notification", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav);
Expand Down
2 changes: 2 additions & 0 deletions src/mods/VR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,9 @@ class VR : public Mod {
}

bool headlocked_begin_held{false};
bool menu_longpress_begin_held{false};
std::chrono::steady_clock::time_point headlocked_begin{};
std::chrono::steady_clock::time_point menu_longpress_begin{};
} m_xinput_context{};

static std::string actions_json;
Expand Down

0 comments on commit 3a1e85c

Please sign in to comment.