From ef3decba532c0351ac55d5e2045da21bab1645ee Mon Sep 17 00:00:00 2001 From: Johann <76482511+Primexz@users.noreply.github.com> Date: Tue, 31 Jan 2023 00:21:29 +0100 Subject: [PATCH] feat(ui): add ingame overlay (#910) * feat(overlay): add current time * feat(overlay): add customization options * fix(overlay): use local time zone * fix(overlay): enable by default * feat(overlay): add position modification --- src/core/globals.hpp | 16 ++++++- src/gui.cpp | 3 +- src/views/core/view_overlay.cpp | 54 ++++++++++++++++++++++++ src/views/settings/view_gui_settings.cpp | 20 +++++++++ src/views/view.hpp | 1 + 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/views/core/view_overlay.cpp diff --git a/src/core/globals.hpp b/src/core/globals.hpp index 679bd0c1..819666a5 100644 --- a/src/core/globals.hpp +++ b/src/core/globals.hpp @@ -621,7 +621,21 @@ namespace big bool switched_view = true; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(window, color, gui_scale, switched_view) + struct ingame_overlay + { + bool opened = true; + bool show_with_menu_opened = false; + + bool show_fps = true; + bool show_players = true; + bool show_time = true; + bool show_replay_interface = true; + bool show_game_versions = true; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(ingame_overlay, opened, show_with_menu_opened, show_fps, show_players, show_time, show_replay_interface, show_game_versions) + } ingame_overlay{}; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(window, color, gui_scale, switched_view, ingame_overlay) } window{}; struct context_menu diff --git a/src/gui.cpp b/src/gui.cpp index 15151421..4db30d40 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -15,10 +15,11 @@ namespace big { g_renderer->add_dx_callback(view::gta_data, -1); // -1 highest priority of drawing g_renderer->add_dx_callback(view::notifications, -2); // second highest priority + g_renderer->add_dx_callback(view::overlay, -3); // 3rd highest priority g_renderer->add_dx_callback([this] { dx_on_tick(); - }, -3); // 3rd highest priority + }, -4); // 4th highest priority g_renderer->add_wndproc_callback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { diff --git a/src/views/core/view_overlay.cpp b/src/views/core/view_overlay.cpp new file mode 100644 index 00000000..0fef5390 --- /dev/null +++ b/src/views/core/view_overlay.cpp @@ -0,0 +1,54 @@ +#include "views/view.hpp" +#include "pointers.hpp" +#include "gta_util.hpp" +#include "gui.hpp" + +namespace big +{ + void view::overlay() + { + if (!g.window.ingame_overlay.opened || (g_gui->is_open() && !g.window.ingame_overlay.show_with_menu_opened)) + return; + + ImGui::SetNextWindowPos(ImVec2(10.0f, 10.0f), ImGuiCond_FirstUseEver, ImVec2(0.0f, 0.0f)); + ImGui::SetNextWindowBgAlpha(0.3f); + + if (ImGui::Begin("overlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) + { + ImGui::Text("YimMenu"); + + ImGui::Separator(); + + if (g.window.ingame_overlay.show_fps) + ImGui::Text("%.0f FPS", ImGui::GetIO().Framerate / 2); + + if (CNetworkPlayerMgr *network_player_mgr = gta_util::get_network_player_mgr(); g.window.ingame_overlay.show_players) + ImGui::Text(std::format("Players: {}/{}", network_player_mgr->m_player_count, network_player_mgr->m_player_limit).c_str()); + + if (g.window.ingame_overlay.show_time) + ImGui::Text(std::format("Time: {:%d-%m-%Y %H:%M:%OS}", std::chrono::current_zone()->to_local(std::chrono::system_clock::now())).c_str()); + + if (auto replay_interface = *g_pointers->m_replay_interface; g.window.ingame_overlay.show_replay_interface) + { + ImGui::Separator(); + + if(replay_interface->m_ped_interface) + ImGui::Text(std::format("Ped Pool: {}/{}", replay_interface->m_ped_interface->m_cur_peds, replay_interface->m_ped_interface->m_max_peds).c_str()); + + if(replay_interface->m_vehicle_interface) + ImGui::Text(std::format("Vehicle Pool: {}/{}", replay_interface->m_vehicle_interface->m_cur_vehicles, replay_interface->m_vehicle_interface->m_max_vehicles).c_str()); + + if(replay_interface->m_object_interface) + ImGui::Text(std::format("Object Pool: {}/{}", replay_interface->m_object_interface->m_cur_objects, replay_interface->m_object_interface->m_max_objects).c_str()); + } + + if (g.window.ingame_overlay.show_game_versions) + { + ImGui::Separator(); + ImGui::Text(std::format("Game Version: {}", g_pointers->m_game_version).c_str()); + ImGui::Text(std::format("Online Version: {}", g_pointers->m_online_version).c_str()); + } + } + ImGui::End(); + } +} \ No newline at end of file diff --git a/src/views/settings/view_gui_settings.cpp b/src/views/settings/view_gui_settings.cpp index c9156306..c944579d 100644 --- a/src/views/settings/view_gui_settings.cpp +++ b/src/views/settings/view_gui_settings.cpp @@ -19,6 +19,26 @@ namespace big { g.window.color = ImGui::ColorConvertFloat4ToU32(col_gui); } + + components::sub_title("Ingame Overlay"); + ImGui::Checkbox("Show Overlay", &g.window.ingame_overlay.opened); + ImGui::SameLine(); + ImGui::Checkbox("Show when Menu opened", &g.window.ingame_overlay.show_with_menu_opened); + + ImGui::BeginGroup(); + + ImGui::Checkbox("Show FPS", &g.window.ingame_overlay.show_fps); + ImGui::Checkbox("Show Players", &g.window.ingame_overlay.show_players); + ImGui::Checkbox("Show Time", &g.window.ingame_overlay.show_time); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::Checkbox("Show Replay Interface", &g.window.ingame_overlay.show_replay_interface); + ImGui::Checkbox("Show Game Version", &g.window.ingame_overlay.show_game_versions); + + ImGui::EndGroup(); } } \ No newline at end of file diff --git a/src/views/view.hpp b/src/views/view.hpp index 05f06097..ac6835ae 100644 --- a/src/views/view.hpp +++ b/src/views/view.hpp @@ -27,6 +27,7 @@ namespace big static void mobile(); static void navigation(); static void notifications(); + static void overlay(); static void root(); static void self(); static void session();