From 3242328ce5b8fb4f317d04134952298356b696fa Mon Sep 17 00:00:00 2001 From: PringlesGang Date: Wed, 18 Sep 2024 00:32:22 +0200 Subject: [PATCH] Refactored backlog menu --- CMakeLists.txt | 2 + src/games/cc/backlogmenu.cpp | 68 +++++++++++++++++++++++++ src/games/cc/backlogmenu.h | 18 +++---- src/games/mo6tw/backlogmenu.cpp | 30 +++++++++++ src/games/mo6tw/backlogmenu.h | 16 ++++++ src/profile/games/cc/backlogmenu.cpp | 3 +- src/profile/games/mo6tw/backlogmenu.cpp | 3 +- src/ui/backlogmenu.cpp | 59 +-------------------- src/ui/backlogmenu.h | 10 ++-- 9 files changed, 133 insertions(+), 76 deletions(-) create mode 100644 src/games/mo6tw/backlogmenu.cpp create mode 100644 src/games/mo6tw/backlogmenu.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d3dda9f24..ad4c7eacd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,7 @@ set(Impacto_Src src/games/chlcc/trophymenuentry.cpp src/games/chlcc/delusiontrigger.cpp + src/games/cc/backlogmenu.cpp src/games/cc/dialoguebox.cpp src/games/cc/titlemenu.cpp src/games/cc/sysmesbox.cpp @@ -183,6 +184,7 @@ set(Impacto_Src src/games/cclcc/savesystem.cpp src/games/cclcc/systemmenu.cpp + src/games/mo6tw/backlogmenu.cpp src/games/mo6tw/dialoguebox.cpp src/games/mo6tw/sysmesbox.cpp src/games/mo6tw/systemmenu.cpp diff --git a/src/games/cc/backlogmenu.cpp b/src/games/cc/backlogmenu.cpp index e69de29bb..ee5194ab7 100644 --- a/src/games/cc/backlogmenu.cpp +++ b/src/games/cc/backlogmenu.cpp @@ -0,0 +1,68 @@ +#include "backlogmenu.h" + +#include "../../profile/game.h" +#include "../../ui/backlogmenu.h" +#include "../../profile/ui/systemmenu.h" +#include "../../profile/ui/backlogmenu.h" +#include "../../profile/games/cc/backlogmenu.h" +#include "../../profile/games/cclcc/systemmenu.h" + +namespace Impacto { +namespace UI { +namespace CC { + +using namespace Impacto::UI::CC; +using namespace Impacto::Profile::BacklogMenu; +using namespace Impacto::Profile::CC::BacklogMenu; + +BacklogMenu::BacklogMenu() : UI::BacklogMenu::BacklogMenu() { + switch (Impacto::Profile::SystemMenu::Type) { + default: + MaskSprite = nullptr; + break; + case UI::SystemMenuType::CCLCC: + MaskSprite = &Profile::CCLCC::SystemMenu::MenuMask; + break; + /* Enable once CC system menu is properly seperated + case UI::SystemMenuType::CC: + MaskSprite = &Profile::CC::SystemMenu::MenuMask; + break; + */ + } +} + +void BacklogMenu::Render() { + if (State == Hidden) return; + + glm::vec4 transition(1.0f, 1.0f, 1.0f, FadeAnimation.Progress); + glm::vec4 maskTint = glm::vec4(1.0f); + maskTint.a = 0.50 * FadeAnimation.Progress; + + MainItems->Tint = transition; + + int repeatHeight = BacklogBackgroundRepeatHeight; + float backgroundY = + fmod(PageY - EntryYPadding - RenderingBounds.Y, repeatHeight); + Renderer->DrawSprite(BacklogBackground, glm::vec2(0.0f, backgroundY), + transition); + Renderer->DrawSprite(BacklogBackground, + glm::vec2(0.0f, backgroundY + repeatHeight), transition); + + RenderHighlight(); + Renderer->DrawSprite(BacklogHeaderSprite, BacklogHeaderPosition, transition); + MainItems->Render(); + MainScrollbar->Render(); + + if (MaskSprite != nullptr) + Renderer->DrawSprite( + *MaskSprite, + RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight), + maskTint); + + Renderer->DrawSprite(BacklogControlsSprite, BacklogControlsPosition, + transition); +} + +} // namespace CC +} // namespace UI +} // namespace Impacto \ No newline at end of file diff --git a/src/games/cc/backlogmenu.h b/src/games/cc/backlogmenu.h index 188585918..ef9270330 100644 --- a/src/games/cc/backlogmenu.h +++ b/src/games/cc/backlogmenu.h @@ -1,6 +1,7 @@ #pragma once #include "../../ui/backlogmenu.h" +#include "../../spritesheet.h" namespace Impacto { namespace UI { @@ -10,17 +11,12 @@ class BacklogMenu : public UI::BacklogMenu { public: BacklogMenu(); - void Init(); - - void Show(); - void Hide(); - void UpdateInput(); - void Update(float dt); void Render(); -}; - + private: + const Sprite* MaskSprite; +}; -} // namespace CC -} // namespace UI -} // namespace Impacto \ No newline at end of file +} // namespace CC +} // namespace UI +} // namespace Impacto \ No newline at end of file diff --git a/src/games/mo6tw/backlogmenu.cpp b/src/games/mo6tw/backlogmenu.cpp new file mode 100644 index 000000000..56216054d --- /dev/null +++ b/src/games/mo6tw/backlogmenu.cpp @@ -0,0 +1,30 @@ +#include "backlogmenu.h" + +#include "../../ui/backlogmenu.h" +#include "../../profile/ui/backlogmenu.h" +#include "../../profile/games/mo6tw/backlogmenu.h" +#include "../../profile/games/mo6tw/systemmenu.h" + +namespace Impacto { +namespace UI { +namespace MO6TW { + +using namespace Impacto::UI::MO6TW; +using namespace Impacto::Profile::BacklogMenu; +using namespace Impacto::Profile::MO6TW::BacklogMenu; + +void BacklogMenu::Render() { + if (State == Hidden) return; + + glm::vec4 col(1.0f, 1.0f, 1.0f, FadeAnimation.Progress); + MainItems->Tint = col; + + Renderer->DrawSprite(BacklogBackground, glm::vec2(0.0f), col); + RenderHighlight(); + MainItems->Render(); + MainScrollbar->Render(); +} + +} // namespace MO6TW +} // namespace UI +} // namespace Impacto diff --git a/src/games/mo6tw/backlogmenu.h b/src/games/mo6tw/backlogmenu.h new file mode 100644 index 000000000..3a5c48f21 --- /dev/null +++ b/src/games/mo6tw/backlogmenu.h @@ -0,0 +1,16 @@ +#pragma once + +#include "../../ui/backlogmenu.h" + +namespace Impacto { +namespace UI { +namespace MO6TW { + +class BacklogMenu : public UI::BacklogMenu { + public: + void Render(); +}; + +} // namespace MO6TW +} // namespace UI +} // namespace Impacto diff --git a/src/profile/games/cc/backlogmenu.cpp b/src/profile/games/cc/backlogmenu.cpp index 052f18d0b..e3852eb10 100644 --- a/src/profile/games/cc/backlogmenu.cpp +++ b/src/profile/games/cc/backlogmenu.cpp @@ -1,6 +1,7 @@ #include "backlogmenu.h" #include "../../profile_internal.h" #include "../../../ui/ui.h" +#include "../../../games/cc/backlogmenu.h" namespace Impacto { namespace Profile { @@ -22,7 +23,7 @@ void Configure() { auto drawType = Game::DrawComponentType::_from_integral_unchecked( EnsureGetMemberInt("DrawType")); - UI::BacklogMenuPtr = new UI::BacklogMenu(); + UI::BacklogMenuPtr = new UI::CC::BacklogMenu(); UI::Menus[drawType].push_back(UI::BacklogMenuPtr); } diff --git a/src/profile/games/mo6tw/backlogmenu.cpp b/src/profile/games/mo6tw/backlogmenu.cpp index d27f71981..55059f064 100644 --- a/src/profile/games/mo6tw/backlogmenu.cpp +++ b/src/profile/games/mo6tw/backlogmenu.cpp @@ -1,6 +1,7 @@ #include "backlogmenu.h" #include "../../profile_internal.h" #include "../../../ui/ui.h" +#include "../../../games/mo6tw/backlogmenu.h" namespace Impacto { namespace Profile { @@ -11,7 +12,7 @@ void Configure() { auto drawType = Game::DrawComponentType::_from_integral_unchecked( EnsureGetMemberInt("DrawType")); - UI::BacklogMenuPtr = new UI::BacklogMenu(); + UI::BacklogMenuPtr = new UI::MO6TW::BacklogMenu(); UI::Menus[drawType].push_back(UI::BacklogMenuPtr); } diff --git a/src/ui/backlogmenu.cpp b/src/ui/backlogmenu.cpp index ba84e8a8d..f2fec15c8 100644 --- a/src/ui/backlogmenu.cpp +++ b/src/ui/backlogmenu.cpp @@ -157,64 +157,7 @@ void BacklogMenu::RenderHighlight() const { } } -void BacklogMenu::Render() { - if (State == Hidden || Type == +BacklogMenuType::None) return; - - switch (Type) { - case BacklogMenuType::MO6TW: { - glm::vec4 col(1.0f, 1.0f, 1.0f, FadeAnimation.Progress); - MainItems->Tint = col; - - Renderer->DrawSprite(BacklogBackground, glm::vec2(0.0f), col); - RenderHighlight(); - MainItems->Render(); - MainScrollbar->Render(); - } - case BacklogMenuType::CC: { - using namespace Impacto::Profile::CC::BacklogMenu; - glm::vec4 transition(1.0f, 1.0f, 1.0f, FadeAnimation.Progress); - glm::vec4 maskTint = glm::vec4(1.0f); - maskTint.a = 0.85f * FadeAnimation.Progress; - - Sprite* menuMask = nullptr; - switch (Impacto::Profile::SystemMenu::Type) { - default: - break; - // TODO: implement for CC - case UI::SystemMenuType::CCLCC: - menuMask = &Profile::CCLCC::SystemMenu::MenuMask; - break; - } - - MainItems->Tint = transition; - - int repeatHeight = - Profile::CC::BacklogMenu::BacklogBackgroundRepeatHeight; - float backgroundY = - fmod(PageY - EntryYPadding - RenderingBounds.Y, repeatHeight); - Renderer->DrawSprite(BacklogBackground, glm::vec2(0.0f, backgroundY), - transition); - Renderer->DrawSprite(BacklogBackground, - glm::vec2(0.0f, backgroundY + repeatHeight), - transition); - - RenderHighlight(); - Renderer->DrawSprite(BacklogHeaderSprite, BacklogHeaderPosition, - transition); - MainItems->Render(); - MainScrollbar->Render(); - - if (menuMask != nullptr) - Renderer->DrawSprite( - *menuMask, - RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight), - maskTint); - - Renderer->DrawSprite(BacklogControlsSprite, BacklogControlsPosition, - transition); - } - } -} +void BacklogMenu::Render() {} void BacklogMenu::AddMessage(uint8_t* str, int audioId) { if (!GetFlag(SF_REVADDDISABLE) || ScrWork[SW_MESWIN0TYPE] == 0) { diff --git a/src/ui/backlogmenu.h b/src/ui/backlogmenu.h index 692b0125f..5521c7082 100644 --- a/src/ui/backlogmenu.h +++ b/src/ui/backlogmenu.h @@ -12,10 +12,10 @@ class BacklogMenu : public Menu { public: BacklogMenu(); - void Show(); - void Hide(); - void Update(float dt); - void Render(); + virtual void Show(); + virtual void Hide(); + virtual void Update(float dt); + virtual void Render(); void AddMessage(uint8_t* str, int audioId = -1); void MenuButtonOnClick(Widgets::BacklogEntry* target); @@ -23,7 +23,7 @@ class BacklogMenu : public Menu { float PageY = 0.0f; - private: + protected: int CurrentId = 0; float ItemsHeight = 0.0f; glm::vec2 CurrentEntryPos;