From bebf91213166f41c91a02d1f75b0a4bd96752bc5 Mon Sep 17 00:00:00 2001 From: Yimura Date: Wed, 26 May 2021 13:17:19 +0200 Subject: [PATCH] feat(Windows): Added player window --- BigBaseV2/src/backend/backend.cpp | 5 ++ BigBaseV2/src/backend/looped/looped.hpp | 3 + .../src/backend/looped/system/screen_size.cpp | 14 ++++ .../looped/system/update_player_structs.cpp | 41 +++++++++ BigBaseV2/src/core/data/player_struct.hpp | 30 +++++++ BigBaseV2/src/core/globals.hpp | 14 ++++ BigBaseV2/src/gui/gui_main.cpp | 3 + BigBaseV2/src/gui/window.hpp | 2 + BigBaseV2/src/gui/window/window_player.cpp | 27 ++++++ BigBaseV2/src/gui/window/window_users.cpp | 84 +++++++++++++++++++ 10 files changed, 223 insertions(+) create mode 100644 BigBaseV2/src/backend/looped/system/screen_size.cpp create mode 100644 BigBaseV2/src/backend/looped/system/update_player_structs.cpp create mode 100644 BigBaseV2/src/core/data/player_struct.hpp create mode 100644 BigBaseV2/src/gui/window/window_player.cpp create mode 100644 BigBaseV2/src/gui/window/window_users.cpp diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index fc212172..5dd47f3d 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -8,6 +8,11 @@ namespace big void backend::loop() { g.attempt_save(); + QUEUE_JOB_BEGIN_CLAUSE() + { + looped::system_screen_size(); + looped::system_update_players(); + }QUEUE_JOB_END_CLAUSE QUEUE_JOB_BEGIN_CLAUSE() { diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index ddbae1c7..19d7cdf3 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -10,6 +10,9 @@ namespace big static void self_noclip(); static void self_no_ragdoll(); + static void system_update_players(); + static void system_screen_size(); + static void weapons_cage_gun(); static void weapons_delete_gun(); static void weapons_gravity_gun(); diff --git a/BigBaseV2/src/backend/looped/system/screen_size.cpp b/BigBaseV2/src/backend/looped/system/screen_size.cpp new file mode 100644 index 00000000..662fe785 --- /dev/null +++ b/BigBaseV2/src/backend/looped/system/screen_size.cpp @@ -0,0 +1,14 @@ +#include "backend/looped/looped.hpp" +#include "fiber_pool.hpp" +#include "natives.hpp" +#include "script.hpp" + +namespace big +{ + static bool bLastGodMode = false; + + void looped::system_screen_size() + { + GRAPHICS::_GET_ACTIVE_SCREEN_RESOLUTION(&g.window.x, &g.window.y); + } +} \ No newline at end of file diff --git a/BigBaseV2/src/backend/looped/system/update_player_structs.cpp b/BigBaseV2/src/backend/looped/system/update_player_structs.cpp new file mode 100644 index 00000000..c5cd60c5 --- /dev/null +++ b/BigBaseV2/src/backend/looped/system/update_player_structs.cpp @@ -0,0 +1,41 @@ +#include "backend/looped/looped.hpp" +#include "natives.hpp" +#include "script.hpp" + +namespace big +{ + static bool busy = false; + + void looped::system_update_players() + { + if (busy) return; + busy = true; + + for (Player i = 0; i < 32; i++) + { + if (NETWORK::NETWORK_IS_PLAYER_CONNECTED(i) && i != PLAYER::PLAYER_ID()) + { + // if (!g.players[i].is_online) // tell user player joined + + g.players[i].is_online = true; + + int iNetworkHandle[26]; + NETWORK::NETWORK_HANDLE_FROM_PLAYER(i, &iNetworkHandle[0], 13); + NETWORK::NETWORK_IS_HANDLE_VALID(&iNetworkHandle[0], 13) && NETWORK::NETWORK_IS_FRIEND(&iNetworkHandle[0]); + + g.players[i].is_friend = NETWORK::NETWORK_IS_HANDLE_VALID(iNetworkHandle, 13) && NETWORK::NETWORK_IS_FRIEND(iNetworkHandle); + + strcpy(g.players[i].name, PLAYER::GET_PLAYER_NAME(i)); + } + else + { + g.players[i].is_online = false; + g.players[i].is_friend = false; + } + + script::get_current()->yield(); + } + + busy = false; + } +} \ No newline at end of file diff --git a/BigBaseV2/src/core/data/player_struct.hpp b/BigBaseV2/src/core/data/player_struct.hpp new file mode 100644 index 00000000..4c89de01 --- /dev/null +++ b/BigBaseV2/src/core/data/player_struct.hpp @@ -0,0 +1,30 @@ +#pragma once + +#ifndef PLAYER_STRUCT +#define PLAYER_STRUCT + +namespace big +{ + struct CPlayer + { + char name[20]; + + bool is_friend = false; + bool is_online = false; + + bool operator < (const CPlayer& another) const + { + char temp[20], temp2[20]; + + for (uint8_t i = 0; i < 20; i++) + { + temp[i] = tolower(this->name[i]); + temp2[i] = tolower(another.name[i]); + } + + return strcmp(temp, temp2) < 0; + } + }; +} + +#endif \ No newline at end of file diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index f2636887..7af5df27 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -1,4 +1,5 @@ #pragma once +#include "data/player_struct.hpp" #include "enums.hpp" #ifndef GLOBALS_H @@ -9,6 +10,10 @@ struct globals { nlohmann::json default_options; nlohmann::json options; + struct player { + bool spectating = false; + }; + struct self { bool godmode = false; bool off_radar = false; @@ -29,8 +34,17 @@ struct globals { struct window { bool main = true; bool log = false; + bool users = false; + bool player = false; + + int x; + int y; }; + CPlayer players[32]; + CPlayer selected_player; + + player player{}; self self{}; vehicle vehicle{}; weapons weapons{}; diff --git a/BigBaseV2/src/gui/gui_main.cpp b/BigBaseV2/src/gui/gui_main.cpp index f0695d8b..a4e6931f 100644 --- a/BigBaseV2/src/gui/gui_main.cpp +++ b/BigBaseV2/src/gui/gui_main.cpp @@ -10,5 +10,8 @@ namespace big window::log(); window::main(); + + window::player(); + window::users(); } } \ No newline at end of file diff --git a/BigBaseV2/src/gui/window.hpp b/BigBaseV2/src/gui/window.hpp index 05186cdf..8e08a89b 100644 --- a/BigBaseV2/src/gui/window.hpp +++ b/BigBaseV2/src/gui/window.hpp @@ -7,5 +7,7 @@ namespace big static void top_bar(); static void log(); static void main(); + static void player(); + static void users(); }; } \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/window_player.cpp b/BigBaseV2/src/gui/window/window_player.cpp new file mode 100644 index 00000000..35c56c90 --- /dev/null +++ b/BigBaseV2/src/gui/window/window_player.cpp @@ -0,0 +1,27 @@ +#include "gui/window.hpp" +#include "imgui.h" + +namespace big +{ + void window::player() + { + if (!g.selected_player.is_online) return; + + char title[64]; + strcpy(title, "Player Options: "); + strcat(title, g.selected_player.name); + strcat(title, "###player_options"); + + ImGui::SetNextWindowSize({ 350.f, 300.f }, ImGuiCond_FirstUseEver); + if (g.window.player && ImGui::Begin(title, &g.window.player)) + { + /*ImGui::BeginTabBar("tabbar_player"); + + ImGui::EndTabBar();*/ + + ImGui::Checkbox("Spectate", &g.player.spectating); + + ImGui::End(); + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/window_users.cpp b/BigBaseV2/src/gui/window/window_users.cpp new file mode 100644 index 00000000..743779fc --- /dev/null +++ b/BigBaseV2/src/gui/window/window_users.cpp @@ -0,0 +1,84 @@ +#include "gui/window.hpp" +#include "imgui.h" + +namespace big +{ + void window::users() + { + static const float height_correction = 28.f; + static const float width = 170.f; + + ImGui::SetNextWindowSize({ width, (float)g.window.y - height_correction }, ImGuiCond_Always); + ImGui::SetNextWindowPos({ g.window.x - width, height_correction }, ImGuiCond_Always); + if (ImGui::Begin("###player_menu", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav)) + { + auto vecButtonWidth = ImVec2(ImGui::GetWindowSize().x - 30.f, 0.0f); + + //ImGui::TextColored({ 255,255,255,255 }, "YOU:"); + + //if (ImGui::Button(g_player.name, vecButtonWidth)) + //{ + // g_selectedPlayer = g_player; + // g_temp.windows.player = true; + //} + + //ImGui::Separator(); + + char title[64]; + sprintf(title, "Friends (%d)###friend_lists", 0); + if (ImGui::TreeNode(title)) + { + ImGui::Unindent(); + + bool friendInLobby = false; + + for (auto& player : g.players) + { + if (player.is_friend && player.is_online) + { + friendInLobby = true; + + if (ImGui::Button(player.name, vecButtonWidth)) + { + g.selected_player = player; + g.window.player = true; + } + } + } + + if (!friendInLobby) + { + ImGui::TextColored({ 180,180,180,255 }, "No friends in\ncurrent lobby."); + } + + ImGui::Indent(); + ImGui::TreePop(); + ImGui::Separator(); + } + + sprintf(title, "Players (%d)###player_lists", 0); + if (ImGui::TreeNode(title)) + { + ImGui::Unindent(); + + for (auto& player : g.players) + { + if (!player.is_friend && player.is_online) + { + if (ImGui::Button(player.name, vecButtonWidth)) + { + g.selected_player = player; + g.window.player = true; + } + } + } + + ImGui::Indent(); + ImGui::TreePop(); + } + + ImGui::End(); + } + + } +} \ No newline at end of file