From 347f33fb2dc23f851bc25a256478a12f4e787a18 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sun, 17 Sep 2023 16:23:26 -0400 Subject: [PATCH] Disable input when typing into a text field. (#2140) Closes #2139 --- src/backend/backend.cpp | 1 + src/backend/looped/hud/hud_disable_input.cpp | 14 ++++++++++++++ src/backend/looped/looped.hpp | 1 + src/core/settings.hpp | 2 ++ src/gui/components/input_text.cpp | 4 +--- src/gui/components/input_text_with_hint.cpp | 12 ++---------- src/services/hotkey/hotkey_service.cpp | 2 +- src/views/debug/view_debug_globals.cpp | 2 ++ src/views/network/view_player_database.cpp | 4 ++++ src/views/self/view_outfit_editor.cpp | 2 ++ src/views/self/view_outfit_slots.cpp | 2 ++ src/views/self/view_weapons.cpp | 6 +----- src/views/vehicle/spawn/view_persist_car.cpp | 4 ++++ src/views/world/view_model_swapper.cpp | 4 ++++ 14 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 src/backend/looped/hud/hud_disable_input.cpp diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index 84a77fae..ae3775d0 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -117,6 +117,7 @@ namespace big while (g_running) { looped::hud_transition_state(); + looped::hud_disable_input(); looped::session_pop_multiplier_areas(); looped::session_force_thunder(); looped::session_randomize_ceo_colors(); diff --git a/src/backend/looped/hud/hud_disable_input.cpp b/src/backend/looped/hud/hud_disable_input.cpp new file mode 100644 index 00000000..b89df382 --- /dev/null +++ b/src/backend/looped/hud/hud_disable_input.cpp @@ -0,0 +1,14 @@ +#include "backend/looped/looped.hpp" +#include "natives.hpp" + +namespace big +{ + void looped::hud_disable_input() + { + if (g.self.hud.typing) + { + PAD::DISABLE_ALL_CONTROL_ACTIONS(0); + g.self.hud.typing--; + } + } +} \ No newline at end of file diff --git a/src/backend/looped/looped.hpp b/src/backend/looped/looped.hpp index 4c70337d..0ef170c5 100644 --- a/src/backend/looped/looped.hpp +++ b/src/backend/looped/looped.hpp @@ -18,6 +18,7 @@ namespace big { public: static void hud_transition_state(); + static void hud_disable_input(); static void player_good_options(); static void player_toxic_options(); diff --git a/src/core/settings.hpp b/src/core/settings.hpp index 8680e83a..b099657d 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -15,6 +15,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include +#define TYPING_TICKS 3 class CNetGamePlayer; enum class eNetObjType; @@ -363,6 +364,7 @@ namespace big std::array hud_components_states = {false}; bool force_show_hud_element = false; bool force_show_hud = false; + std::atomic_uint_fast8_t typing = 0; NLOHMANN_DEFINE_TYPE_INTRUSIVE(hud, color_override, color_override_initialized, hud_color_overrides, hide_radar, hide_ammo, selected_hud_component, hud_components_states, force_show_hud_element, force_show_hud) } hud{}; diff --git a/src/gui/components/input_text.cpp b/src/gui/components/input_text.cpp index ba7ff410..12fb7370 100644 --- a/src/gui/components/input_text.cpp +++ b/src/gui/components/input_text.cpp @@ -11,8 +11,6 @@ namespace big g_fiber_pool->queue_job(std::move(cb)); if (ImGui::IsItemActive()) - g_fiber_pool->queue_job([] { - PAD::DISABLE_ALL_CONTROL_ACTIONS(0); - }); + g.self.hud.typing = TYPING_TICKS; } } \ No newline at end of file diff --git a/src/gui/components/input_text_with_hint.cpp b/src/gui/components/input_text_with_hint.cpp index d59eaece..fcaf8ad4 100644 --- a/src/gui/components/input_text_with_hint.cpp +++ b/src/gui/components/input_text_with_hint.cpp @@ -12,11 +12,7 @@ namespace big g_fiber_pool->queue_job(std::move(cb)); if (ImGui::IsItemActive()) - { - g_fiber_pool->queue_job([] { - PAD::DISABLE_ALL_CONTROL_ACTIONS(0); - }); - } + g.self.hud.typing = TYPING_TICKS; return returned; } @@ -27,11 +23,7 @@ namespace big g_fiber_pool->queue_job(std::move(cb)); if (ImGui::IsItemActive()) - { - g_fiber_pool->queue_job([] { - PAD::DISABLE_ALL_CONTROL_ACTIONS(0); - }); - } + g.self.hud.typing = TYPING_TICKS; return returned; } } \ No newline at end of file diff --git a/src/services/hotkey/hotkey_service.cpp b/src/services/hotkey/hotkey_service.cpp index 0de1632c..ae9f2889 100644 --- a/src/services/hotkey/hotkey_service.cpp +++ b/src/services/hotkey/hotkey_service.cpp @@ -88,7 +88,7 @@ namespace big if (g.cmd_executor.enabled) return; - if (g_gui->is_open()) + if (g_gui->is_open() || HUD::IS_PAUSE_MENU_ACTIVE() || SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(RAGE_JOAAT("cellphone_flashhand")) > 0 || HUD::IS_MP_TEXT_CHAT_TYPING()) return; if (state == eKeyState::RELEASE || state == eKeyState::DOWN) diff --git a/src/views/debug/view_debug_globals.cpp b/src/views/debug/view_debug_globals.cpp index 92ab79ca..4855317b 100644 --- a/src/views/debug/view_debug_globals.cpp +++ b/src/views/debug/view_debug_globals.cpp @@ -219,6 +219,8 @@ namespace big static char global_name[50]{}; ImGui::SetNextItemWidth(200.f); ImGui::InputText("##GlobalName", global_name, IM_ARRAYSIZE(global_name)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; if (ImGui::Button("Save Global")) { save_global(global_name, global_test); diff --git a/src/views/network/view_player_database.cpp b/src/views/network/view_player_database.cpp index b9427791..fea45e85 100644 --- a/src/views/network/view_player_database.cpp +++ b/src/views/network/view_player_database.cpp @@ -120,6 +120,8 @@ namespace big { current_player->name = name_buf; } + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; if (ImGui::InputScalar("RID"_T.data(), ImGuiDataType_S64, ¤t_player->rockstar_id) || ImGui::Checkbox("IS_MODDER"_T.data(), ¤t_player->is_modder) @@ -189,6 +191,8 @@ namespace big current_player->notes = note_buffer; notes_dirty = true; } + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; ImGui::Checkbox("Join Redirect", ¤t_player->join_redirect); if (ImGui::IsItemHovered()) diff --git a/src/views/self/view_outfit_editor.cpp b/src/views/self/view_outfit_editor.cpp index 70f9216d..bdbb70cf 100644 --- a/src/views/self/view_outfit_editor.cpp +++ b/src/views/self/view_outfit_editor.cpp @@ -182,6 +182,8 @@ namespace big ImGui::SetNextItemWidth(300); ImGui::InputText("##outfit_name", outfit_name, sizeof(outfit_name)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; ImGui::SameLine(); components::button("OUTFIT_SAVE_CURRENT"_T, [] { diff --git a/src/views/self/view_outfit_slots.cpp b/src/views/self/view_outfit_slots.cpp index 263a1832..b197803f 100644 --- a/src/views/self/view_outfit_slots.cpp +++ b/src/views/self/view_outfit_slots.cpp @@ -21,6 +21,8 @@ namespace big ImGui::SetNextItemWidth(300); ImGui::InputText("OUTFIT_NAME"_T.data(), outfit::get_slot_name_address(slot), 16); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; static outfit::components_t components; static outfit::props_t props; diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index cc3e989e..62aaca9a 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -141,11 +141,7 @@ namespace big g.weapons.vehicle_gun_model = vehicle_gun; } if (ImGui::IsItemActive()) - { - g_fiber_pool->queue_job([] { - PAD::DISABLE_ALL_CONTROL_ACTIONS(0); - }); - } + g.self.hud.typing = TYPING_TICKS; break; case CustomWeapon::PAINT_GUN: diff --git a/src/views/vehicle/spawn/view_persist_car.cpp b/src/views/vehicle/spawn/view_persist_car.cpp index 9da2e85b..864839d0 100644 --- a/src/views/vehicle/spawn/view_persist_car.cpp +++ b/src/views/vehicle/spawn/view_persist_car.cpp @@ -132,6 +132,8 @@ namespace big components::small_text("VEHICLE_FILE_NAME"_T); ImGui::SetNextItemWidth(250); ImGui::InputText("##vehiclefilename", vehicle_file_name_input, IM_ARRAYSIZE(vehicle_file_name_input)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; if (ImGui::IsItemHovered()) ImGui::SetTooltip("VEHICLE_FILE_NAME_EXAMPLE"_T.data()); @@ -139,6 +141,8 @@ namespace big components::small_text("VEHICLE_FOLDER_NAME"_T); ImGui::SetNextItemWidth(250); ImGui::InputText("##foldername", save_folder, IM_ARRAYSIZE(save_folder)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; if (ImGui::IsItemHovered()) ImGui::SetTooltip("VEHICLE_FOLDER_NAME_EXAMPLE"_T.data()); diff --git a/src/views/world/view_model_swapper.cpp b/src/views/world/view_model_swapper.cpp index 9d9f0a85..fef9f635 100644 --- a/src/views/world/view_model_swapper.cpp +++ b/src/views/world/view_model_swapper.cpp @@ -16,9 +16,13 @@ namespace big ImGui::SetNextItemWidth(width); ImGui::InputText("Dst", dst_text, IM_ARRAYSIZE(dst_text)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; ImGui::SameLine(); ImGui::SetNextItemWidth(width); ImGui::InputText("Src", src_text, IM_ARRAYSIZE(src_text)); + if (ImGui::IsItemActive()) + g.self.hud.typing = TYPING_TICKS; ImGui::SameLine(); if (ImGui::Button("Add/Change"))