Skip to content

Commit

Permalink
Merge pull request #74 from CommitteeOfZero/cclcc/sysmenu
Browse files Browse the repository at this point in the history
Cclcc/sysmenu
  • Loading branch information
KKhanhH authored Oct 16, 2024
2 parents cbd784c + 1524fba commit e0bb8b7
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 221 deletions.
41 changes: 29 additions & 12 deletions profiles/cclcc/hud/systemmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ root.SystemMenu = {
Type = SystemMenuType.CCLCC,
DrawType = DrawComponentType.SystemMenu,

FadeInDuration = 64 / 60,
FadeOutDuration = 64 / 60,
TitleFadeInDuration = 40 / 60,
TitleFadeOutDuration = 28 / 60,
FadeInDuration = 40 / 60,
FadeOutDuration = 40 / 60,
MoveInDuration = 40 / 60,
MoveOutDuration = 28 / 60,

MenuEntriesNum =9,
ItemsFadeInDuration = 20/60,
ItemsFadeOutDuration = 20/60,

Seed = 0,

MenuEntriesNum = 9,
MenuEntriesHNum = 9,
------
--Not used since it isn't laid out in a way that would make it easier to use this
MenuEntriesX = 173,
MenuEntriesXOffset = 0,
MenuEntriesFirstY = 445,
MenuEntriesYPadding = 0,
------

FocusTint = 0xff9cb6,
MenuEntriesPositions = {
{X=41, Y=-4},
Expand All @@ -28,10 +27,28 @@ root.SystemMenu = {
{X=41, Y=649},
{X=41, Y=725},
},

MenuEntriesButtonBounds = {
{X=120, Y= 74, Width=228, Height=60},
{X=120, Y=172, Width=260, Height=60},
{X=120, Y=268, Width=260, Height=60},
{X=120, Y=362, Width=128, Height=60},
{X=120, Y=454, Width=128, Height=60},
{X=120, Y=552, Width=228, Height=60},
{X=120, Y=650, Width=186, Height=60},
{X=120, Y=742, Width=128, Height=60},
{X=120, Y=838, Width=316, Height=60},
},
MenuEntriesSprites = {},
MenuEntriesHighlightedSprites = {},

MenuButtonGuide = "SystemMenuButtonGuide",
SystemMenuBG = "SystemMenuBG"
};

root.Sprites["SystemMenuBG"] = {
Sheet = "MenuBG",
Bounds = {X = 0, Y = 0, Width = 3000, Height = 1500}
};

root.Sprites["SystemMenuBacklog"] = {
Expand Down
9 changes: 1 addition & 8 deletions src/games/cclcc/mapsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <array>
#include <algorithm>
#include <cstdint>
#include <random>

#include "../../util.h"
#include "../../mem.h"
#include "../../vm/interface/input.h"
#include "../../profile/scriptvars.h"
Expand Down Expand Up @@ -149,13 +149,6 @@ constexpr uint32_t LineColors2[] = {
0xDC0FA, 0xDC0FA, 0xDC0FA,
};

inline int CALCrnd(int max) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(0, 0x7FFF);
return distr(gen) * max >> 0xf;
}

void MapSystemCCLCC::MapInit() {
// Silence unused var warning, this table is probably going to be useful later
(void)MapArticleOffsets;
Expand Down
91 changes: 66 additions & 25 deletions src/games/cclcc/systemmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "systemmenu.h"
#include <glm/common.hpp>
#include "../../profile/games/cclcc/systemmenu.h"
#include "../../renderer/renderer.h"
#include "../../ui/ui.h"
#include "../../vm/interface/input.h"
#include "../../profile/ui/systemmenu.h"
#include "../../profile/game.h"
#include "../../ui/widgets/cclcc/sysmenubutton.h"

namespace Impacto {
Expand All @@ -27,23 +29,28 @@ void SystemMenu::MenuButtonOnClick(Widgets::Button* target) {
SystemMenu::SystemMenu() {
MenuTransition.Direction = 1;
MenuTransition.LoopMode = ALM_Stop;
MenuTransition.DurationIn = FadeInDuration;
MenuTransition.DurationOut = FadeOutDuration;
MenuTransition.DurationIn = MoveInDuration;
MenuTransition.DurationOut = MoveOutDuration;

MenuFade.Direction = 1.0f;
MenuFade.LoopMode = ALM_Stop;
MenuFade.DurationIn = TitleFadeInDuration;
MenuFade.DurationOut = TitleFadeOutDuration;
MenuFade.DurationIn = FadeInDuration;
MenuFade.DurationOut = FadeOutDuration;

ItemsFade.Direction = 1.0f;
ItemsFade.LoopMode = ALM_Stop;
ItemsFade.DurationIn = ItemsFadeInDuration;
ItemsFade.DurationOut = ItemsFadeOutDuration;

auto onClick =
std::bind(&SystemMenu::MenuButtonOnClick, this, std::placeholders::_1);

MainItems = new Widgets::Group(this);

for (int i = 0; i < MenuEntriesNum; i++) {
SysMenuButton* menuButton =
new SysMenuButton(i, MenuEntriesSprites[i], Sprite(),
MenuEntriesHSprites[i], MenuEntriesPositions[i]);
SysMenuButton* menuButton = new SysMenuButton(
i, MenuEntriesSprites[i], Sprite(), MenuEntriesHSprites[i],
MenuEntriesPositions[i], MenuEntriesButtonBounds[i]);

menuButton->OnClickHandler = onClick;
MainItems->Add(menuButton, FDIR_DOWN);
Expand All @@ -57,8 +64,7 @@ void SystemMenu::Show() {
if (State != Shown) {
State = Showing;
MenuTransition.StartIn();
MainItems->Show();

MenuFade.StartIn();
// If the function was called due to a submenu opening directly,
// then don't take over focus
if (!(ScrWork[SW_SYSMENUCT] == 32 && ScrWork[SW_SYSSUBMENUCT] ||
Expand All @@ -69,15 +75,18 @@ void SystemMenu::Show() {
}
IsFocused = true;
UI::FocusedMenu = this;
ItemsFade.StartIn();
MainItems->Show();
}
}
}

void SystemMenu::Hide() {
if (State != Hidden) {
State = Hiding;
MenuFade.StartOut();
MenuTransition.StartOut();
MainItems->Hide();
ItemsFade.StartOut();
if (LastFocusedMenu != 0) {
UI::FocusedMenu = LastFocusedMenu;
LastFocusedMenu->IsFocused = true;
Expand All @@ -91,28 +100,47 @@ void SystemMenu::Hide() {
void SystemMenu::Update(float dt) {
UpdateInput();

if (State == Shown && (GetFlag(SF_TITLEMODE) || ScrWork[SW_SYSMENUCT] == 0) ||
ScrWork[SW_SYSMENUALPHA] == 0) {
if (State == Shown &&
((GetFlag(SF_TITLEMODE) || ScrWork[SW_SYSMENUCT] < 32) ||
ScrWork[SW_SYSMENUALPHA] == 0)) {
Hide();
return;
}
if (MenuTransition.IsIn() && State == Showing) {
if (State == Hidden &&
((ScrWork[SW_SYSMENUCT] > 0) || ScrWork[SW_SYSMENUALPHA] > 0)) {
Show();
return;
}
if (State == Showing && ScrWork[SW_SYSMENUCT] == 32) {
State = Shown;
return;
} else if (MenuTransition.IsOut() && State == Hiding) {
} else if (State == Hiding && MenuFade.IsOut() && MenuTransition.IsOut() &&
ItemsFade.IsOut() && ScrWork[SW_SYSMENUCT] == 0) {
State = Hidden;
MainItems->Hide();
return;
}

if (State != Hidden) {
MenuTransition.Update(dt);
if (MenuTransition.Direction == -1.0f && MenuTransition.Progress <= 0.72f) {
MenuFade.StartOut();
} else if (MenuTransition.IsIn() &&
(MenuFade.Direction == 1.0f || MenuFade.IsOut())) {
MenuFade.StartIn();
}
MenuFade.Update(dt);
if (ItemsFade.IsIn() && ScrWork[SW_SYSSUBMENUCT] > 0 && State == Shown &&
ItemsFadeComplete) {
ItemsFade.StartOut();
ItemsFadeComplete = false;
} else if (ItemsFade.IsOut() && ScrWork[SW_SYSSUBMENUCT] < 32 &&
State == Shown && ItemsFadeComplete) {
ItemsFade.StartIn();
ItemsFadeComplete = false;
}
ItemsFade.Update(dt);
if (!ItemsFadeComplete) {
if (ItemsFade.IsIn() && ScrWork[SW_SYSSUBMENUCT] == 0) {
ItemsFadeComplete = true;
} else if (ItemsFade.IsOut() && ScrWork[SW_SYSSUBMENUCT] == 32) {
ItemsFadeComplete = true;
}
}
}

if (State == Shown && IsFocused) {
Expand All @@ -125,18 +153,31 @@ void SystemMenu::Render() {
}
glm::vec3 tint = {1.0f, 1.0f, 1.0f};
// Alpha goes from 0 to 1 in half the time
float alpha =
MenuTransition.Progress < 0.5f ? MenuTransition.Progress * 2.0f : 1.0f;
float alpha = MenuFade.Progress;
// Renderer->DrawSprite(BackgroundFilter, RectF(0.0f, 0.0f, 1280.0f,
// 720.0f),
// glm::vec4(tint, alpha));
float yOffset = 0;

MainItems->Tint = glm::vec4(tint, 1.0f);
Sprite repositionedBG = SystemMenuBG;
glm::vec2 bgOffset;
bgOffset.x = (ScrWork[SW_SYSSUBMENUCT] * 3000.0 * 0.03125 * 0.5);
repositionedBG.Bounds.X = (BGPosition.x - 0.5 * bgOffset.x) - 600;
repositionedBG.Bounds.Width = 1860;
repositionedBG.Bounds.Y = BGPosition.y - 165;
repositionedBG.Bounds.Height = 1205;
Renderer->DrawSprite(repositionedBG,
{0, 0, Profile::DesignWidth, Profile::DesignHeight},
glm::vec4{tint, alpha});

MainItems->Tint =
glm::vec4(tint, glm::smoothstep(0.0f, 1.0f, ItemsFade.Progress));
MainItems->Render();
}
}

void SystemMenu::InitPosition() {
BGPosition = {CALCrnd(390) + 1350, CALCrnd(295) + 165};
}

} // namespace CCLCC
} // namespace UI
} // namespace Impacto
8 changes: 6 additions & 2 deletions src/games/cclcc/systemmenu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <glm/fwd.hpp>
#include "../../ui/menu.h"
#include "../../ui/widgets/group.h"
#include "../../ui/widgets/button.h"
Expand All @@ -12,6 +13,7 @@ class SystemMenu : public Menu {
public:
SystemMenu();

void InitPosition();
void Show();
void Hide();
void Update(float dt);
Expand All @@ -20,11 +22,13 @@ class SystemMenu : public Menu {
void MenuButtonOnClick(Widgets::Button* target);

private:
void DrawCircles();
void DrawErin();
Widgets::Group* MainItems;
Animation MenuTransition;
Animation MenuFade;
Animation ItemsFade;
bool ItemsFadeComplete = false;

glm::vec2 BGPosition{};
};

} // namespace CCLCC
Expand Down
9 changes: 5 additions & 4 deletions src/games/mo6tw/systemmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ SystemMenu::SystemMenu() {
std::bind(&SystemMenu::MenuButtonOnClick, this, std::placeholders::_1);

for (int i = 0; i < MenuEntriesNum; i++) {
Button* menuButton = new Button(
i, MenuEntriesSprites[i], MenuEntriesSprites[i],
MenuEntriesHighlightedSprite,
glm::vec2(MenuEntriesX, MenuEntriesFirstY + (i * MenuEntriesYPadding)));
Button* menuButton =
new Button(i, MenuEntriesSprites[i], MenuEntriesSprites[i],
MenuEntriesHighlightedSprite,
glm::vec2(*MenuEntriesX,
*MenuEntriesFirstY + (*MenuEntriesYPadding * i)));

menuButton->OnClickHandler = onClick;
MainItems->Add(menuButton, FDIR_DOWN);
Expand Down
7 changes: 4 additions & 3 deletions src/games/mo8/systemmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ SystemMenu::SystemMenu() {
nullSprite.Bounds = RectF(0.0f, 0.0f, 0.0f, 0.0f);

for (int i = 0; i < MenuEntriesNum; i++) {
Button* menuButton = new Button(
i, MenuEntriesSprites[i], MenuEntriesHSprites[i], nullSprite,
glm::vec2(MenuEntriesX, MenuEntriesFirstY + (i * MenuEntriesYPadding)));
Button* menuButton =
new Button(i, MenuEntriesSprites[i], MenuEntriesHSprites[i], nullSprite,
glm::vec2(*MenuEntriesX,
*MenuEntriesFirstY + (*MenuEntriesYPadding * i)));
menuButton->LockedSprite = MenuEntriesLSprites[i];

menuButton->OnClickHandler = onClick;
Expand Down
7 changes: 4 additions & 3 deletions src/games/rne/systemmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ SystemMenu::SystemMenu() {
for (int i = 0; i < MenuEntriesNum; i++) {
SysMenuButton* menuButton = new SysMenuButton(
i, MenuEntriesSprites[i], nullSprite, MenuEntriesHSprites[i],
glm::vec2(MenuEntriesX, MenuEntriesFirstY + (i * MenuEntriesYPadding)));
glm::vec2(*MenuEntriesX,
*MenuEntriesFirstY + (*MenuEntriesYPadding * i)));

menuButton->OnClickHandler = onClick;
MainItems->Add(menuButton, FDIR_DOWN);
Expand Down Expand Up @@ -120,9 +121,9 @@ void SystemMenu::Update(float dt) {

int idx = 0;
for (auto& item : MainItems->Children) {
item->MoveTo(glm::vec2(((idx * MenuEntriesXSkew) + MenuEntriesXOffset) *
item->MoveTo(glm::vec2(((idx * MenuEntriesXSkew) + *MenuEntriesXOffset) *
(1.0f - EntriesMoveAnimation.Progress),
MenuEntriesFirstY + (idx * MenuEntriesYPadding)));
*MenuEntriesFirstY + (*MenuEntriesYPadding * idx)));
item->Tint.a = glm::smoothstep(
0.0f, 1.0f, 1.0f - (idx + 1) * (1.0f - EntriesMoveAnimation.Progress));
Button* button = (Button*)item;
Expand Down
11 changes: 9 additions & 2 deletions src/profile/games/cclcc/systemmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ namespace CCLCC {
namespace SystemMenu {

void Configure() {
TitleFadeInDuration = EnsureGetMemberFloat("TitleFadeInDuration");
TitleFadeOutDuration = EnsureGetMemberFloat("TitleFadeOutDuration");
MoveInDuration = EnsureGetMemberFloat("MoveInDuration");
MoveOutDuration = EnsureGetMemberFloat("MoveOutDuration");
ItemsFadeInDuration = EnsureGetMemberFloat("ItemsFadeInDuration");
ItemsFadeOutDuration = EnsureGetMemberFloat("ItemsFadeOutDuration");

GetMemberVec2Array(MenuEntriesPositions, Profile::SystemMenu::MenuEntriesNum,
"MenuEntriesPositions");

GetMemberRectFArray(MenuEntriesButtonBounds,
Profile::SystemMenu::MenuEntriesNum,
"MenuEntriesButtonBounds");

SystemMenuBG = EnsureGetMemberSprite("SystemMenuBG");
MenuButtonGuide = EnsureGetMemberSprite("MenuButtonGuide");

auto drawType = Game::DrawComponentType::_from_integral_unchecked(
Expand Down
8 changes: 6 additions & 2 deletions src/profile/games/cclcc/systemmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace CCLCC {
namespace SystemMenu {
constexpr int MenuEntriesNumMax = 16;

inline Sprite SystemMenuBG;
inline Sprite MenuButtonGuide;
inline float TitleFadeInDuration;
inline float TitleFadeOutDuration;
inline float MoveInDuration;
inline float MoveOutDuration;
inline float ItemsFadeInDuration;
inline float ItemsFadeOutDuration;
inline glm::vec2 MenuEntriesPositions[MenuEntriesNumMax];
inline RectF MenuEntriesButtonBounds[MenuEntriesNumMax];

void Configure();

Expand Down
Loading

0 comments on commit e0bb8b7

Please sign in to comment.