From 9c5d399e183f71992f06fed60a3b22310b111702 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Tue, 16 Aug 2022 07:55:33 +0600 Subject: [PATCH] Refactor code --- src/cheatmenu.cpp | 212 +-------------------------------- src/cheatmenu.h | 34 +----- src/custom/animation.cpp | 2 +- src/custom/cutscene_sa.cpp | 2 +- src/custom/freecam_sa.cpp | 2 +- src/custom/neon_sa.cpp | 2 +- src/custom/particle_sa.cpp | 2 +- src/custom/randomcheats_sa.cpp | 2 +- src/custom/topdowncam_sa.cpp | 2 +- src/interface/icheat.hpp | 4 +- src/interface/ipage.cpp | 196 ++++++++++++++++++++++++++++++ src/interface/ipage.h | 72 +++++++++++ src/pages/menu.cpp | 2 +- src/pages/ped.cpp | 6 +- src/pages/weapon.cpp | 12 +- src/pages/weapon.h | 11 +- src/utils/overlay.cpp | 4 +- src/utils/rpc.cpp | 2 +- 18 files changed, 304 insertions(+), 265 deletions(-) create mode 100644 src/interface/ipage.cpp create mode 100644 src/interface/ipage.h diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index 60a4e9f..4ec85cd 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -105,134 +105,11 @@ void CheatMenu::DrawWindow() Overlay::Draw(); } -void CheatMenu::ProcessPages() -{ - static void* pCallback; - ImVec2 size = Widget::CalcSize(3, false); - ImGuiStyle &style = ImGui::GetStyle(); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - m_nMenuPage = Updater::IsUpdateAvailable() ? eMenuPages::UPDATE : m_nMenuPage; - - // Check once if it's anniversary day - static bool aniCheckDone; - if (!aniCheckDone) - { - SYSTEMTIME st; - GetSystemTime(&st); - - if (st.wMonth == 3 && st.wDay == 28) - { - /* - * We don't want to be annoying and - * show anniversary screen on every game start - */ - bool flag = gConfig.Get("Window.AnniversaryShown", false); - - if (!flag) - { - gConfig.Set("Window.AnniversaryShown", true); - m_nMenuPage = eMenuPages::ANNIVERSARY; - } - } - aniCheckDone = true; - } - - ImDrawList *pDrawList = ImGui::GetWindowDrawList(); - for (size_t i = 0; i < m_headerList.size(); ++i) - { - /* - * For welcome & update pages - * They don't need to add item in the header list - */ - if (m_headerList[i].skipHeader) - { - if (m_nMenuPage == m_headerList[i].page) - { - pCallback = m_headerList[i].pFunc; - } - - continue; - } - - const char* text = m_headerList[i].name.c_str(); - - ImVec4 color; - if (m_headerList[i].page == m_nMenuPage) - { - color = style.Colors[ImGuiCol_ButtonActive]; - pCallback = m_headerList[i].pFunc; - } - else - color = style.Colors[ImGuiCol_Button]; - - if (ImGui::InvisibleButton(text, size)) - { - m_nMenuPage = m_headerList[i].page; - size_t curPage = static_cast(m_headerList[i].page); - gConfig.Set("Window.CurrentPage", curPage); - pCallback = m_headerList[i].pFunc; - Updater::ResetUpdaterState(); - } - - if (ImGui::IsItemHovered()) - color = style.Colors[ImGuiCol_ButtonHovered]; - - /* - * Window rounding flags - * TODO: hardcoded atm - */ - ImDrawFlags flags = ImDrawFlags_RoundCornersNone; - if (i == 0) flags = ImDrawFlags_RoundCornersTopLeft; - if (i == 2) flags = ImDrawFlags_RoundCornersTopRight; - if (i == 6) flags = ImDrawFlags_RoundCornersBottomLeft; - if (i == 8) flags = ImDrawFlags_RoundCornersBottomRight; - - ImVec2 min = ImGui::GetItemRectMin(); - ImVec2 max = ImGui::GetItemRectMax(); - ImVec2 size = ImGui::CalcTextSize(text); - pDrawList->AddRectFilled(min, max, ImGui::GetColorU32(color), style.FrameRounding, flags); - ImGui::RenderTextClipped(min + style.FramePadding, max - style.FramePadding, text, NULL, &size, style.ButtonTextAlign); - - if (i % 3 != 2) - { - ImGui::SameLine(); - } - } - ImGui::PopStyleVar(); - ImGui::Dummy(ImVec2(0, 10)); - - if (pCallback != nullptr && ImGui::BeginChild("HEADERCONTENT")) - { - static_cast(pCallback)(); - ImGui::EndChild(); - } -} - -void CheatMenu::GenHeaderList() -{ - CheatMenu::m_headerList = - { - {TEXT_S("Window.TeleportPage"), &Teleport::ShowPage, eMenuPages::TELEPORT}, - {TEXT_S("Window.PlayerPage"), &Player::ShowPage, eMenuPages::PLAYER}, - {TEXT_S("Window.PedPage"), &Ped::ShowPage, eMenuPages::PED}, - {TEXT_S("Window.ScenePage"), &ScenePage::Draw, eMenuPages::SCENE}, - {TEXT_S("Window.VehiclePage"), &Vehicle::ShowPage, eMenuPages::VEHICLE}, - {TEXT_S("Window.WeaponPage"), &Weapon::ShowPage, eMenuPages::WEAPON}, - {TEXT_S("Window.GamePage"), &Game::ShowPage, eMenuPages::GAME}, - {TEXT_S("Window.VisualPage"), &Visual::ShowPage, eMenuPages::VISUAL}, - {TEXT_S("Window.MenuPage"), &Menu::ShowPage, eMenuPages::MENU}, - {"Welcome", &ShowWelcomePage, eMenuPages::WELCOME, true}, - {"Update", &ShowUpdatePage, eMenuPages::UPDATE, true}, - {"Anniversary", &ShowAnniversaryPage, eMenuPages::ANNIVERSARY, true} - }; -} - void CheatMenu::Init() { if (!std::filesystem::exists(PLUGIN_PATH((char*)FILE_NAME))) { - Log::Print(TEXT("Menu.CheatMenuNoDir")); + Log::Print("Failed to find CheatMenu directory!"); return; } @@ -259,7 +136,7 @@ void CheatMenu::Init() Teleport::Init(); Vehicle::Init(); Visual::Init(); - Weapon::Init(); + WeaponPage::Init(); Overlay::Init(); Events::processScriptsEvent += []() @@ -295,88 +172,7 @@ void CheatMenu::Init() }; } -void CheatMenu::ShowAnniversaryPage() -{ - Widget::TextCentered("Happy Anniversary!"); - ImGui::NewLine(); - - ImGui::TextWrapped("On this day, in 2019, the first public version of menu was released in MixMods Forum." - " It's been a blast working on it and I've learned a lot in the process.\n\nThanks to you and everyone who used or" - " contributed to the modification in any form or shape."); - - ImGui::NewLine(); - ImGui::TextWrapped("Feel free to star the GitHub repo or join the discord server and provide feedback, ideas, or suggestions."); - ImGui::NewLine(); - - if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(3)))) - { - OPEN_LINK(DISCORD_INVITE); - } - ImGui::SameLine(); - if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Widget::CalcSize(3)))) - { - OPEN_LINK(GITHUB_LINK); - } -} - -void CheatMenu::ShowWelcomePage() -{ - ImGui::NewLine(); - - Widget::TextCentered(TEXT("Menu.WelcomeMSG")); - Widget::TextCentered(std::format("{}: Grinch_",TEXT("Menu.Author"))); - - ImGui::NewLine(); - ImGui::TextWrapped(TEXT("Menu.EnsureLatest")); - if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(2)))) - { - OPEN_LINK(DISCORD_INVITE); - } - ImGui::SameLine(); - if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Widget::CalcSize(2)))) - { - OPEN_LINK(GITHUB_LINK); - } - ImGui::NewLine(); - ImGui::TextWrapped(TEXT("Menu.BugDisclaimer")); - ImGui::Dummy(ImVec2(0, 20)); - Widget::TextCentered(TEXT("Menu.PatreonText")); - if (ImGui::Button(TEXT("Menu.Patreon"), ImVec2(Widget::CalcSize(1)))) - { - OPEN_LINK("https://www.patreon.com/grinch_"); - } - ImGui::Dummy(ImVec2(0, 30)); - Widget::TextCentered(TEXT("Menu.CopyrightDisclaimer")); -} - -void CheatMenu::ShowUpdatePage() -{ - std::string ver = Updater::GetUpdateVersion(); - ImGui::Dummy(ImVec2(0, 20)); - Widget::TextCentered(TEXT("Menu.NewVersion")); - Widget::TextCentered(std::format("{}: {}", TEXT("Menu.CurrentVersion"), MENU_VERSION)); - Widget::TextCentered(TEXT("Menu.LatestVersion") + ver); - ImGui::Dummy(ImVec2(0, 10)); - ImGui::TextWrapped(TEXT("Menu.UpdaterInfo1")); - ImGui::Dummy(ImVec2(0, 10)); - ImGui::TextWrapped(TEXT("Menu.UpdaterInfo2")); - - ImGui::Dummy(ImVec2(0, 5)); - if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(2)))) - { - OPEN_LINK(DISCORD_INVITE); - } - - ImGui::SameLine(); - - if (ImGui::Button(TEXT("Menu.DownloadPage"), Widget::CalcSize(2))) - { - ShellExecute(NULL, "open", std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" + - ver).c_str(), NULL, NULL, SW_SHOWNORMAL); - } -} - -bool CheatMenu::IsMenuShown() +bool CheatMenu::IsBeingDrawn() { return m_bShowMenu; } @@ -447,7 +243,7 @@ void CheatMenu::ApplyStyle() style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f); } -void CheatMenu::ResetMenuSize() +void CheatMenu::ResetSize() { m_fMenuSize.x = screen::GetScreenWidth() / 4.0f; m_fMenuSize.y = screen::GetScreenHeight() / 1.2f; diff --git a/src/cheatmenu.h b/src/cheatmenu.h index 630684d..a445037 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -8,38 +8,16 @@ class CheatMenu { private: - enum class eMenuPages - { - ANNIVERSARY, GAME, MENU, NONE, PED, PLAYER, SCENE, TELEPORT, UPDATE, VEHICLE, VISUAL, WEAPON, WELCOME - }; - struct HeaderData - { - std::string name; - void *pFunc; - eMenuPages page; - bool skipHeader = false; - }; - - static inline eMenuPages m_nMenuPage = eMenuPages::WELCOME; // current visible menu page - static inline bool m_bShowMenu = false; // should the menu be drawn static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); - static inline bool m_bSizeChangedExternal = false; // Was menu size change requested - static inline std::vector m_headerList; + static inline bool m_bShowMenu = false; // should the menu be drawn + static inline bool m_bSizeChangedExternal = false; // Was menu size change requested // Applies imgui theme to the menu static void ApplyStyle(); // Draws the window ui each frame - // Also handles drawing info, overlay, command window static void DrawWindow(); - static void ShowAnniversaryPage(); - static void ShowUpdatePage(); - static void ShowWelcomePage(); - - // Does all the processing required to handle menu pages - static void ProcessPages(); - public: CheatMenu() = delete; CheatMenu(const CheatMenu&) = delete; @@ -48,12 +26,8 @@ public: static void Init(); // Returns true if the menu is being shown - static bool IsMenuShown(); + static bool IsBeingDrawn(); // Resets the menu height & width to default - static void ResetMenuSize(); - - // Generates menu headers - // Needs to be called after language change or adding new headers - static void GenHeaderList(); + static void ResetSize(); }; diff --git a/src/custom/animation.cpp b/src/custom/animation.cpp index bdee3de..c474e38 100644 --- a/src/custom/animation.cpp +++ b/src/custom/animation.cpp @@ -16,7 +16,7 @@ #include #endif -AnimationMgr& Animation = *AnimationMgr::Get(); +AnimationMgr& Animation = AnimationMgr::Get(); #ifdef GTAVC // Thanks to codenulls(https://github.com/codenulls/) diff --git a/src/custom/cutscene_sa.cpp b/src/custom/cutscene_sa.cpp index 4a23eaa..891f8ce 100644 --- a/src/custom/cutscene_sa.cpp +++ b/src/custom/cutscene_sa.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "cutscene_sa.h" -CutsceneMgr& Cutscene = *CutsceneMgr::Get(); +CutsceneMgr& Cutscene = CutsceneMgr::Get(); CutsceneMgr::CutsceneMgr() { static CdeclEvent , PRIORITY_AFTER, ArgPickNone, void()> skipCutsceneEvent; diff --git a/src/custom/freecam_sa.cpp b/src/custom/freecam_sa.cpp index ab5921c..18d55f6 100644 --- a/src/custom/freecam_sa.cpp +++ b/src/custom/freecam_sa.cpp @@ -2,7 +2,7 @@ #include "freecam_sa.h" static CVector gTotalMouse; -FreecamMgr& Freecam = *FreecamMgr::Get(); +FreecamMgr& Freecam = FreecamMgr::Get(); void FreecamMgr::Enable() { diff --git a/src/custom/neon_sa.cpp b/src/custom/neon_sa.cpp index ae2bc03..3d96c88 100644 --- a/src/custom/neon_sa.cpp +++ b/src/custom/neon_sa.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "neon_sa.h" -NeonMgr& Neon = *NeonMgr::Get(); +NeonMgr& Neon = NeonMgr::Get(); // Neon sprite const unsigned char neon_mask[1689] = diff --git a/src/custom/particle_sa.cpp b/src/custom/particle_sa.cpp index dbb3835..c9badd1 100644 --- a/src/custom/particle_sa.cpp +++ b/src/custom/particle_sa.cpp @@ -2,7 +2,7 @@ #include "particle_sa.h" #include "utils/widget.h" -ParticleMgr& Particle = *ParticleMgr::Get(); +ParticleMgr& Particle = ParticleMgr::Get(); void ParticleMgr::Play(std::string& cat, std::string& name, std::string& particle) { CPlayerPed* pPlayer = FindPlayerPed(); diff --git a/src/custom/randomcheats_sa.cpp b/src/custom/randomcheats_sa.cpp index 146b188..3f252be 100644 --- a/src/custom/randomcheats_sa.cpp +++ b/src/custom/randomcheats_sa.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "randomcheats_sa.h" -RandomCheatsMgr& RandomCheats = *RandomCheatsMgr::Get(); +RandomCheatsMgr& RandomCheats = RandomCheatsMgr::Get(); void RandomCheatsMgr::Process() { diff --git a/src/custom/topdowncam_sa.cpp b/src/custom/topdowncam_sa.cpp index 5203a86..574d7e1 100644 --- a/src/custom/topdowncam_sa.cpp +++ b/src/custom/topdowncam_sa.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "topdowncam_sa.h" -TopDownCamera& TopDownCam = *TopDownCamera::Get(); +TopDownCamera& TopDownCam = TopDownCamera::Get(); TopDownCamera::TopDownCamera() { diff --git a/src/interface/icheat.hpp b/src/interface/icheat.hpp index 240f57c..631fb93 100644 --- a/src/interface/icheat.hpp +++ b/src/interface/icheat.hpp @@ -20,10 +20,10 @@ public: m_bEnabled = true; } - static T *Get() + static T &Get() { static T _instance; - return &_instance; + return _instance; } // Returns the current stae of the cheat diff --git a/src/interface/ipage.cpp b/src/interface/ipage.cpp new file mode 100644 index 0000000..595cd35 --- /dev/null +++ b/src/interface/ipage.cpp @@ -0,0 +1,196 @@ +#include "pch.h" +#include "ipage.h" +#include "utils/updater.h" +#include "utils/widget.h" + +static void DrawAnniversaryPage() +{ + Widget::TextCentered("Happy Anniversary!"); + ImGui::NewLine(); + + ImGui::TextWrapped("On this day, in 2019, the first public version of menu was released in MixMods Forum." + " It's been a blast working on it and I've learned a lot in the process.\n\nThanks to you and everyone who used or" + " contributed to the modification in any form or shape."); + + ImGui::NewLine(); + ImGui::TextWrapped("Feel free to star the GitHub repo or join the discord server and provide feedback, ideas, or suggestions."); + ImGui::NewLine(); + + if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(3)))) + { + OPEN_LINK(DISCORD_INVITE); + } + ImGui::SameLine(); + if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Widget::CalcSize(3)))) + { + OPEN_LINK(GITHUB_LINK); + } +} + +static void DrawWelcomePage() +{ + ImGui::NewLine(); + + Widget::TextCentered(TEXT("Menu.WelcomeMSG")); + Widget::TextCentered(std::format("{}: Grinch_",TEXT("Menu.Author"))); + + ImGui::NewLine(); + ImGui::TextWrapped(TEXT("Menu.EnsureLatest")); + if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(2)))) + { + OPEN_LINK(DISCORD_INVITE); + } + ImGui::SameLine(); + if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Widget::CalcSize(2)))) + { + OPEN_LINK(GITHUB_LINK); + } + ImGui::NewLine(); + ImGui::TextWrapped(TEXT("Menu.BugDisclaimer")); + ImGui::Dummy(ImVec2(0, 20)); + Widget::TextCentered(TEXT("Menu.PatreonText")); + if (ImGui::Button(TEXT("Menu.Patreon"), ImVec2(Widget::CalcSize(1)))) + { + OPEN_LINK("https://www.patreon.com/grinch_"); + } + ImGui::Dummy(ImVec2(0, 30)); + Widget::TextCentered(TEXT("Menu.CopyrightDisclaimer")); +} + +static void DrawUpdatePage() +{ + std::string ver = Updater::GetUpdateVersion(); + ImGui::Dummy(ImVec2(0, 20)); + Widget::TextCentered(TEXT("Menu.NewVersion")); + Widget::TextCentered(std::format("{}: {}", TEXT("Menu.CurrentVersion"), MENU_VERSION)); + Widget::TextCentered(TEXT("Menu.LatestVersion") + ver); + ImGui::Dummy(ImVec2(0, 10)); + ImGui::TextWrapped(TEXT("Menu.UpdaterInfo1")); + ImGui::Dummy(ImVec2(0, 10)); + ImGui::TextWrapped(TEXT("Menu.UpdaterInfo2")); + + ImGui::Dummy(ImVec2(0, 5)); + if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Widget::CalcSize(2)))) + { + OPEN_LINK(DISCORD_INVITE); + } + + ImGui::SameLine(); + + if (ImGui::Button(TEXT("Menu.DownloadPage"), Widget::CalcSize(2))) + { + ShellExecute(NULL, "open", std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" + + ver).c_str(), NULL, NULL, SW_SHOWNORMAL); + } +} + +template +void IPage::Process() +{ + ImVec2 size = Widget::CalcSize(3, false); + ImGuiStyle &style = ImGui::GetStyle(); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + if (Updater::IsUpdateAvailable()) + { + m_nCurrentPage = eMenuPage::Update; + } + + // Check once if it's anniversary day + static bool aniCheckDone; + if (!aniCheckDone) + { + SYSTEMTIME st; + GetSystemTime(&st); + + if (st.wMonth == 3 && st.wDay == 28) + { + /* + * We don't want to be annoying and + * show anniversary screen on every game start + */ + bool flag = gConfig.Get("Window.AnniversaryShown", false); + + if (!flag) + { + gConfig.Set("Window.AnniversaryShown", true); + m_nMenuPage = eMenuPages::ANNIVERSARY; + } + } + aniCheckDone = true; + } + + ImDrawList *pDrawList = ImGui::GetWindowDrawList(); + for (size_t i = 0; i < m_headerList.size(); ++i) + { + /* + * For welcome & update pages + * They don't need to add item in the header list + */ + if (m_headerList[i].skipHeader) + { + if (m_nMenuPage == m_headerList[i].page) + { + pCallback = m_headerList[i].pFunc; + } + + continue; + } + + const char* text = m_headerList[i].name.c_str(); + + ImVec4 color; + if (m_headerList[i].page == m_nMenuPage) + { + color = style.Colors[ImGuiCol_ButtonActive]; + pCallback = m_headerList[i].pFunc; + } + else + { + color = style.Colors[ImGuiCol_Button]; + } + + if (ImGui::InvisibleButton(text, size)) + { + m_nMenuPage = m_headerList[i].page; + size_t curPage = static_cast(m_headerList[i].page); + gConfig.Set("Window.CurrentPage", curPage); + pCallback = m_headerList[i].pFunc; + Updater::ResetUpdaterState(); + } + + if (ImGui::IsItemHovered()) + { + color = style.Colors[ImGuiCol_ButtonHovered]; + } + + /* + * Window rounding flags + * TODO: hardcoded atm + */ + ImDrawFlags flags = ImDrawFlags_RoundCornersNone; + if (i == 0) flags = ImDrawFlags_RoundCornersTopLeft; + if (i == 2) flags = ImDrawFlags_RoundCornersTopRight; + if (i == 6) flags = ImDrawFlags_RoundCornersBottomLeft; + if (i == 8) flags = ImDrawFlags_RoundCornersBottomRight; + + ImVec2 min = ImGui::GetItemRectMin(); + ImVec2 max = ImGui::GetItemRectMax(); + ImVec2 size = ImGui::CalcTextSize(text); + pDrawList->AddRectFilled(min, max, ImGui::GetColorU32(color), style.FrameRounding, flags); + ImGui::RenderTextClipped(min + style.FramePadding, max - style.FramePadding, text, NULL, &size, style.ButtonTextAlign); + + if (i % 3 != 2) + { + ImGui::SameLine(); + } + } + ImGui::PopStyleVar(); + ImGui::Dummy(ImVec2(0, 10)); + + if (m_pCurrentPage != nullptr && ImGui::BeginChild("HEADERCONTENT")) + { + m_pCurrentPage->Draw(); + ImGui::EndChild(); + } +} \ No newline at end of file diff --git a/src/interface/ipage.h b/src/interface/ipage.h new file mode 100644 index 0000000..f69062e --- /dev/null +++ b/src/interface/ipage.h @@ -0,0 +1,72 @@ +#pragma once +#include + +enum class eMenuPage +{ + Anniversary, + Game, + Menu, + None, + Ped, + Player, + Scene, + Teleport, + Update, + Vehicle, + Visual, + Weapon, + Welcome +}; + +/* + Interface class for pages + Every page must inherit this +*/ +template +class IPage +{ +private: + eMenuPage m_ePage; // Menu page ID + bool m_bHasHeader; // Does the page has a header button + std::string m_NameKey; // A key to the page name string + +public: + static inline std::vector m_nPageList; // Contains list of the created pages + static inline IPage* m_pCurrentPage = nullptr; // Currently visible menu page + + IPage(m_ePage page, std::string&& key, bool header = true) + : m_ePage(page), m_NameKey(key), m_bHasHeader(header) + { + m_nPageList.push_back(this); + } + + // Page drawing code goes here + virtual void Draw() = 0; + + static T *Get() final + { + static T _instance; + return &_instance; + } + + // Returns the ID of the page + eMenuPage GetPageID() final + { + return m_ePage; + } + + // Returns true if the page has a visible header button + bool HasHeaderButton() final + { + return m_bHasHeader; + } + + // Returns the page name key + std::string GetKey() final + { + return m_NameKey; + } + + // Process the menu pages & draw them + static void Process() final; +}; \ No newline at end of file diff --git a/src/pages/menu.cpp b/src/pages/menu.cpp index 8c185d9..b471182 100644 --- a/src/pages/menu.cpp +++ b/src/pages/menu.cpp @@ -56,7 +56,7 @@ void Menu::ShowPage() ImGui::Spacing(); if (ImGui::Button(TEXT("Menu.ResetSize"), ImVec2(Widget::CalcSize(2)))) { - CheatMenu::ResetMenuSize(); + CheatMenu::ResetSize(); } ImGui::SameLine(); if (ImGui::Button(TEXT("Menu.ReloadFonts"), ImVec2(Widget::CalcSize(2)))) diff --git a/src/pages/ped.cpp b/src/pages/ped.cpp index c984657..497c6dd 100644 --- a/src/pages/ped.cpp +++ b/src/pages/ped.cpp @@ -380,15 +380,15 @@ void Ped::ShowPage() ImGui::Text(TEXT("Ped.SelectedWeapon"), weaponName.c_str()); ImGui::Spacing(); #ifdef GTASA - Widget::ImageList(Weapon::m_WeaponData, + Widget::ImageList(WeaponPage::m_WeaponData, [](std::string& str) { Spawner::m_nWeaponId = std::stoi(str); - weaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); + weaponName = WeaponPage::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); }, [](std::string& str) { - return Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); + return WeaponPage::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); }, [](std::string& str) { diff --git a/src/pages/weapon.cpp b/src/pages/weapon.cpp index d5d9869..dc2a018 100644 --- a/src/pages/weapon.cpp +++ b/src/pages/weapon.cpp @@ -4,7 +4,7 @@ #include "utils/util.h" #include -void Weapon::Init() +void WeaponPage::Init() { Events::processScriptsEvent += [] { @@ -94,7 +94,7 @@ void Weapon::Init() } #ifdef GTASA -void Weapon::SetGangWeapon(std::string& weapon_type) +void WeaponPage::SetGangWeapon(std::string& weapon_type) { m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon] = std::stoi(weapon_type); CGangs::SetGangWeapons(m_nSelectedGang, m_nGangWeaponList[m_nSelectedGang][0], m_nGangWeaponList[m_nSelectedGang][1], @@ -162,7 +162,7 @@ static eWeaponType GetWeaponTypeFromModel(int model) #endif #ifdef GTASA -void Weapon::GiveWeaponToPlayer(std::string& weapon_type) +void WeaponPage::GiveWeaponToPlayer(std::string& weapon_type) { CPlayerPed* player = FindPlayerPed(); int hplayer = CPools::GetPedRef(player); @@ -223,7 +223,7 @@ void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::st } #endif -void Weapon::AddWeapon() +void WeaponPage::AddNew() { static char name[INPUT_BUFFER_SIZE]; static int model = 0; @@ -240,7 +240,7 @@ void Weapon::AddWeapon() } } -void Weapon::ShowPage() +void WeaponPage::Draw() { CPlayerPed* pPlayer = FindPlayerPed(); uint hplayer = CPools::GetPedRef(pPlayer); @@ -384,7 +384,7 @@ void Weapon::ShowPage() [](std::string& str) { return str != "0"; /*Unarmed*/ - }, AddWeapon); + }, AddNew); #else Widget::DataList(m_WeaponData, GiveWeaponToPlayer, AddWeapon); #endif diff --git a/src/pages/weapon.h b/src/pages/weapon.h index c0c0817..f635834 100644 --- a/src/pages/weapon.h +++ b/src/pages/weapon.h @@ -1,7 +1,7 @@ #pragma once #include "pch.h" -class Weapon +class WeaponPage { private: static inline bool m_bFastReload; @@ -37,13 +37,14 @@ private: #endif public: - Weapon() = delete; - Weapon(const Weapon&) = delete; + WeaponPage() = delete; + WeaponPage(const WeaponPage&) = delete; static void Init(); - static void ShowPage(); + + static void Draw(); - static void AddWeapon(); + static void AddNew(); #ifdef GTASA static inline ResourceStore m_WeaponData { "weapons", eResourceType::TYPE_IMAGE_TEXT, ImVec2(65, 65) }; diff --git a/src/utils/overlay.cpp b/src/utils/overlay.cpp index bf3cd33..bfcb3c0 100644 --- a/src/utils/overlay.cpp +++ b/src/utils/overlay.cpp @@ -326,7 +326,7 @@ void Overlay::ProcessCommands(std::string&& str) if (wep_name == "jetpack") { std::string weapon = "-1"; - Weapon::GiveWeaponToPlayer(weapon); + WeaponPage::GiveWeaponToPlayer(weapon); Util::SetMessage(TEXT("Menu.WeaponSpawned")); } else @@ -337,7 +337,7 @@ void Overlay::ProcessCommands(std::string&& str) if (wep_name != "" && pweaponinfo->m_nModelId1 != -1) { - Weapon::GiveWeaponToPlayer(weapon_name); + WeaponPage::GiveWeaponToPlayer(weapon_name); Util::SetMessage(TEXT("Menu.WeaponSpawned")); } else diff --git a/src/utils/rpc.cpp b/src/utils/rpc.cpp index 3df41ca..24e3173 100644 --- a/src/utils/rpc.cpp +++ b/src/utils/rpc.cpp @@ -133,7 +133,7 @@ void RPC::Process() } - if (CheatMenu::IsMenuShown()) + if (CheatMenu::IsBeingDrawn()) { stateText = TEXT("RPC.BrowsingCheatMenu"); }