From 4b090777286933ab9530aae5ed9400cf85823994 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Fri, 19 Feb 2021 13:41:50 +0600 Subject: [PATCH] Bug fixes, better scaling for high res --- .vscode/c_cpp_properties.json | 10 +--------- src/CheatMenu.cpp | 6 +----- src/Hook.cpp | 32 ++++++++++++++++++++++++-------- src/Hook.h | 2 +- src/Ui.cpp | 20 +++++++++++++++----- src/Vehicle.cpp | 2 +- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 084bd11..2b62a23 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,9 +8,7 @@ "${PLUGIN_SDK_DIR}/plugin_sa", "${PLUGIN_SDK_DIR}/plugin_sa/game_sa", "${PLUGIN_SDK_DIR}/shared", - "${PLUGIN_SDK_DIR}/shared/game", - "E:/plugin-sdk-master/plugin_sa/game_sa", - "E:/plugin-sdk-master/shared" + "${PLUGIN_SDK_DIR}/shared/game" ], "defines": [ "GTASA", @@ -20,12 +18,6 @@ "_CRT_SECURE_NO_WARNINGS", "_CRT_NON_CONFORMING_SWPRINTFS;", "GTASA;", - "GTAGAME_NAME=\"San Andreas\"", - "GTAGAME_ABBR=\"SA\"", - "GTAGAME_ABBRLOW=\"sa\"", - "GTAGAME_PROTAGONISTNAME=\"CJ\"", - "GTAGAME_CITYNAME=\"San Andreas\"", - "_LA_SUPPORT", "_DX9_SDK_INSTALLED", "PLUGIN_SGV_10US", "_MBCS", diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index 773ba17..465b872 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -46,7 +46,7 @@ void CheatMenu::ProcessWindow() CheatMenu::CheatMenu() { ApplyImGuiStyle(); - Hook::window_func = std::bind(&ProcessWindow); + Hook::window_callback = std::bind(&ProcessWindow); Events::initRwEvent += []() { @@ -113,16 +113,12 @@ void CheatMenu::ApplyImGuiStyle() style->GrabRounding = 1; style->WindowRounding = 1; style->ChildRounding = 1; - style->ScrollbarSize = 12; style->ScrollbarRounding = 1; style->GrabRounding = 1; style->FrameRounding = 0; style->TabRounding = 1.0; - style->IndentSpacing = 20; style->AntiAliasedLines = true; style->AntiAliasedFill = true; - style->ItemSpacing = ImVec2(8, 4); - style->FramePadding = ImVec2(5, 3); style->Alpha = 1; style->FrameBorderSize = 0; diff --git a/src/Hook.cpp b/src/Hook.cpp index f1da21c..b87a757 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -10,7 +10,7 @@ f_Reset Hook::oReset9 = NULL; bool Hook::mouse_visibility = false; bool Hook::show_mouse = false; -std::function Hook::window_func = NULL; +std::function Hook::window_callback = NULL; LRESULT Hook::WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -51,11 +51,11 @@ void Hook::Present(void *ptr) { Hook::ShowMouse(show_mouse); - // Change font size if the game resolution changes - if (Globals::screen_size.x != screen::GetScreenWidth() - && Globals::screen_size.y != screen::GetScreenHeight()) + // handle window scaling here + ImVec2 size(screen::GetScreenWidth(),screen::GetScreenHeight()); + if (Globals::screen_size.x != size.x && Globals::screen_size.y != size.y) { - int font_size = int(screen::GetScreenHeight() / 54.85); // manually tested + int font_size = int(size.y / 54.85f); // manually tested io.FontDefault = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/trebucbd.ttf", font_size); io.Fonts->Build(); @@ -65,7 +65,23 @@ void Hook::Present(void *ptr) else ImGui_ImplDX11_InvalidateDeviceObjects(); - Globals::screen_size = ImVec2(screen::GetScreenWidth(), screen::GetScreenHeight()); + if (Globals::screen_size.x != -1 && Globals::screen_size.y != -1) + { + Globals::menu_size.x += (size.x-Globals::screen_size.x) / 4.0f; + Globals::menu_size.y += (size.y-Globals::screen_size.y) / 1.2f; + } + + ImGuiStyle* style = &ImGui::GetStyle(); + float scale_x = size.x / 1366.0f; + float scale_y = size.y / 768.0f; + + style->FramePadding = ImVec2(5 * scale_x, 3 * scale_y); + style->ItemSpacing = ImVec2(8 * scale_x, 4 * scale_y); + style->ScrollbarSize = 12 * scale_x; + style->IndentSpacing = 20 * scale_x; + style->ItemInnerSpacing = ImVec2(4 * scale_x,4 * scale_y); + + Globals::screen_size = size; } ImGui_ImplWin32_NewFrame(); @@ -76,8 +92,8 @@ void Hook::Present(void *ptr) ImGui::NewFrame(); - if (window_func != NULL) - window_func(); + if (window_callback != NULL) + window_callback(); ImGui::EndFrame(); ImGui::Render(); diff --git a/src/Hook.h b/src/Hook.h index c3d0d4c..6dae06b 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -25,7 +25,7 @@ private: protected: static bool show_mouse; - static std::function window_func; + static std::function window_callback; Hook(); ~Hook(); diff --git a/src/Ui.cpp b/src/Ui.cpp index 0663946..63d4d40 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -465,6 +465,10 @@ void Ui::DrawImages(std::vector> &img_vec, ImV std::function get_name_func, std::function verify_func) { + // scale image size + image_size.x *= screen::GetScreenWidth() / 1366.0f; + image_size.y *= screen::GetScreenHeight() / 768.0f; + int images_in_row = static_cast(ImGui::GetWindowContentRegionWidth() / image_size.x); image_size.x = ImGui::GetWindowContentRegionWidth() / images_in_row - int(ImGuiStyleVar_ItemSpacing)*0.65f; @@ -536,7 +540,7 @@ void Ui::DrawImages(std::vector> &img_vec, ImV } if (images_count % images_in_row != 0) - ImGui::SameLine(0.0, 4.0); + ImGui::SameLine(0.0, ImGui::GetStyle().ItemInnerSpacing.x); images_count++; } @@ -826,16 +830,22 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) if (!active) current_hotkey = label; - if (active && (ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsItemClicked(ImGuiMouseButton_Right))) + if (active && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { current_hotkey = ""; state = true; } - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { - key_data.key1 = VK_NONE; - key_data.key2 = VK_NONE; + if (ImGui::IsItemHovered()) + { + key_data.key1 = VK_NONE; + key_data.key2 = VK_NONE; + } + else + current_hotkey = ""; + state = true; } diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index df3576d..0bc4b0e 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -992,7 +992,7 @@ void Vehicle::Main() ImGui::EndTabItem(); } - if (player && player->m_pVehicle) + if (player->m_pVehicle && player->m_nPedFlags.bInVehicle) { CVehicle *veh = FindPlayerPed()->m_pVehicle; int hveh = CPools::GetVehicleRef(veh);