From e4ee4c507d9769b7205c4a2754cd74bd679d5725 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Wed, 10 Feb 2021 20:47:35 +0600 Subject: [PATCH] Improve hotkeys --- src/Game.cpp | 6 ++---- src/Game.h | 2 -- src/Menu.cpp | 5 ++++- src/Menu.h | 1 + src/Ui.cpp | 23 ++++++++++------------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 295d4cf..88107aa 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -50,7 +50,6 @@ bool Game::solid_water = false; bool Game::ss_shortcut = false; bool Game::sync_time = false; -uint Game::ss_shotcut_timer = 0; uint Game::sync_time_timer = 0; uint Game::solid_water_object = 0; @@ -107,11 +106,10 @@ Game::Game() if (ss_shortcut) { - if (Ui::HotKeyPressed(Menu::hotkeys::quick_ss) && timer - ss_shotcut_timer > 1000) + if (Ui::HotKeyPressed(Menu::hotkeys::quick_ss)) { Command(); CHud::SetHelpMessage("Screenshot taken", false, false, false); - ss_shotcut_timer = timer; } } @@ -262,7 +260,7 @@ void Game::FreeCam() if (freecam::tmouseY < -150) freecam::tmouseY = -150; - if (KeyPressed(VK_RETURN)) + if (Ui::HotKeyPressed(Menu::hotkeys::free_cam_tp_player)) { CPlayerPed *player = FindPlayerPed(-1); CVector pos = freecam::ped->GetPosition(); diff --git a/src/Game.h b/src/Game.h index 0fe6e15..b126b44 100644 --- a/src/Game.h +++ b/src/Game.h @@ -48,8 +48,6 @@ public: static bool solid_water; static bool ss_shortcut; static bool sync_time; - - static uint ss_shotcut_timer; static uint sync_time_timer; static uint solid_water_object; diff --git a/src/Menu.cpp b/src/Menu.cpp index 6a6fdc4..5bffd8d 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -23,6 +23,7 @@ HotKeyData Menu::hotkeys::freecam{}; HotKeyData Menu::hotkeys::command_window{}; HotKeyData Menu::hotkeys::flip_veh{}; HotKeyData Menu::hotkeys::fix_veh{}; +HotKeyData Menu::hotkeys::free_cam_tp_player{VK_RETURN,VK_RETURN}; HotKeyData Menu::hotkeys::god_mode{}; HotKeyData Menu::hotkeys::menu_open{}; HotKeyData Menu::hotkeys::quick_ss{}; @@ -341,7 +342,9 @@ void Menu::Main() if (ImGui::BeginTabItem("Hotkeys")) { ImGui::Spacing(); - ImGui::TextWrapped("Right clicking will set hotkey to none. Some are set to none by default. Choose keys for them if you want to use them."); + ImGui::Text("Usage"); + Ui::ShowTooltip("Left-click selects hotkey.\nLeft clicking outside deselects." +"\nRight click disables hotkey."); ImGui::Spacing(); ImGui::BeginChild("Hotkeys"); if (Ui::HotKey("Open/ close cheat menu", hotkeys::menu_open)) diff --git a/src/Menu.h b/src/Menu.h index c292ebc..094fbd9 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -24,6 +24,7 @@ public: static HotKeyData command_window; static HotKeyData fix_veh; static HotKeyData flip_veh; + static HotKeyData free_cam_tp_player; static HotKeyData god_mode; static HotKeyData menu_open; static HotKeyData quick_ss; diff --git a/src/Ui.cpp b/src/Ui.cpp index c81d1ed..961d8c6 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -790,6 +790,7 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) if (active) { ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); for (int key = 3; key != 135; ++key) { @@ -820,19 +821,18 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) if (key_data.key1 != key_data.key2) text += (" + " + key_names[key_data.key2-1]); + + if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(), ImVec2(ImGui::GetWindowContentRegionWidth() / 3.5, ImGui::GetFrameHeight()))) + if (!active) + current_hotkey = label; - if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(), ImVec2(ImGui::GetWindowContentRegionWidth() / 3, ImGui::GetFrameHeight()))) + if (active && (ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsItemClicked(ImGuiMouseButton_Left))) { - if (active) - { - current_hotkey = ""; - state = true; - } - else - current_hotkey = label;; + current_hotkey = ""; + state = true; } - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) // right click + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { key_data.key1 = VK_NONE; key_data.key2 = VK_NONE; @@ -843,10 +843,7 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) ImGui::Text(label); if (active) - ImGui::PopStyleColor(); - - if (!(ImGui::IsWindowFocused() || ImGui::IsItemVisible())) - current_hotkey = ""; + ImGui::PopStyleColor(2); return state; }