Skip to content

Commit

Permalink
Merge pull request #66 from CommitteeOfZero/cclcc/fix-titlemenu
Browse files Browse the repository at this point in the history
Title menu animations and accurate behavior
  • Loading branch information
KKhanhH authored Sep 27, 2024
2 parents 1d36869 + ef1b298 commit 8f64e29
Show file tree
Hide file tree
Showing 28 changed files with 564 additions and 225 deletions.
6 changes: 0 additions & 6 deletions profiles/cclcc/hud/savemenu.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
root.SaveMenu = {
Type = SaveMenuType.CCLCC,
DrawType = DrawComponentType.SystemMenu,
SaveMenuBackgroundSprite = "SaveMenuBackground",
EmptyThumbnailSprite = "EmptyThumbnail",
EntryStartXL = 143,
EntryStartYL = 152,
Expand All @@ -14,11 +13,6 @@ root.SaveMenu = {

};

root.Sprites["SaveMenuBackground"] = {
Sheet = "MenuBG",
Bounds = { X = 0, Y = 0, Width = 1920, Height = 1080 },
};

root.Sprites["EmptyThumbnail"] = {
Sheet = "SaveMenu",
Bounds = { X = 0, Y = 0, Width = 0, Height = 0 }
Expand Down
14 changes: 5 additions & 9 deletions profiles/cclcc/hud/tipsmenu.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
root.TipsMenu = {
Type = TipsMenuType.CCLCC,
DrawType = DrawComponentType.SystemMenu,
BackgroundSprite = "TipsMenuBackground",
FadeInDuration = 0.2,
FadeOutDuration = 0.2,
TipsBookLayerSprite = "TipsBookLayer",
FadeInDuration = 0.4,
FadeOutDuration = 0.4,
TransitionInDuration = 0.4,
TransitionOutDuration = 0.4,
BackgroundSprite = "TipsBookLayer",
TipsGuideSprite = "TipsGuide",
TipsGuideX = 0,
TipsGuideY = 990,
Expand Down Expand Up @@ -47,11 +48,6 @@ root.TipsMenu = {
TipsMask = "TipsMask",
};

root.Sprites["TipsMenuBackground"] = {
Sheet = "Title",
Bounds = { X = 0, Y = 1080, Width = 1920, Height = 1080 }
};

root.Sprites["TipsBookLayer"] = {
Sheet = "Tips",
Bounds = { X = 0, Y = 0, Width = 1920, Height = 1080 }
Expand Down
20 changes: 11 additions & 9 deletions profiles/cclcc/hud/titlemenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ root.TitleMenu = {
PressToStartY = 749,
PressToStartAnimDurationIn = 0.6,
PressToStartAnimDurationOut = 0.6,
ItemFadeInDuration = 0.3,
ItemFadeOutDuration = 0.6,
SecondaryItemFadeInDuration = 0.2,
SecondaryItemFadeOutDuration = 0.2,
PrimaryFadeInDuration = 0.3,
PrimaryFadeOutDuration = 0.3,
SecondaryFadeInDuration = 0.512,
SecondaryFadeOutDuration = 0.512,
PrimaryFadeInDuration = 0.7,
PrimaryFadeOutDuration = 0.7,
SecondaryFadeInDuration = 0.4,
SecondaryFadeOutDuration = 0.4,
SlideItemsAnimationDurationIn = 0.5,
SlideItemsAnimationDurationOut = 0.5,
PressToStartSprite = "TitleMenuPressToStart",
BackgroundSprite = "TitleMenuBackground",
MainBackgroundSprite = "MainMenuBackground",
Expand Down Expand Up @@ -62,7 +60,11 @@ root.TitleMenu = {
TitleAnimationFileId = 32,
MenuEntriesSprites = {},
MenuEntriesHighlightedSprites = {},
MenuEntriesNum = 5
MenuEntriesNum = 5,
ChoiceBlinkAnimationDurationIn = 1,
HighlightAnimationDurationIn = 0.2,
HighlightAnimationDurationOut = 0.2,
ExtraDisabledTint = 0x703030,
};

for i = 0, 4 do
Expand Down
1 change: 0 additions & 1 deletion profiles/chlcc/hud/savemenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ root.SaveMenu = {
{X = 91, Y = 381}, {X = 91, Y = 508},
{X = 661, Y = 127}, {X = 661, Y = 508}
},
SaveMenuBackgroundSprite = "SaveMenuBackground",
EmptyThumbnailSprite = "EmptyThumbnail",
EntryStartX = 153,
EntryXPadding = 512,
Expand Down
4 changes: 2 additions & 2 deletions src/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ enum AnimationLoopMode { ALM_Stop, ALM_ReverseDirection, ALM_Loop };

class Animation {
public:
float DurationIn;
float DurationOut;
float DurationIn = 0;
float DurationOut = 0;
// 1 = in, -1 = out
float Direction = 1;
// 0 = fully out, 1 = fully in
Expand Down
1 change: 0 additions & 1 deletion src/games/cclcc/savemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ void SaveMenu::Update(float dt) {
void SaveMenu::Render() {
if (State != Hidden) {
glm::vec4 col(1.0f, 1.0f, 1.0f, FadeAnimation.Progress);
Renderer->DrawSprite(SaveMenuBackgroundSprite, glm::vec2(0.0f), col);
Renderer->DrawSprite(MenuTextSprite[ScrWork[SW_SAVEMENUMODE]], {11, 10},
col);
Renderer->DrawSprite(EntrySlotsSprite[ScrWork[SW_SAVEMENUMODE]], {135, 0},
Expand Down
143 changes: 108 additions & 35 deletions src/games/cclcc/tipsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,23 @@ TipsMenu::TipsMenu() : TipViewItems(this) {
FadeAnimation.LoopMode = ALM_Stop;
FadeAnimation.DurationIn = FadeInDuration;
FadeAnimation.DurationOut = FadeOutDuration;
TransitionAnimation.DurationIn = TransitionInDuration;
TransitionAnimation.DurationOut = TransitionOutDuration;

Name = new Label();
Pronounciation = new Label();
Category = new Label();
Number = new Label();

Name->Bounds.X = NamePos.x;
Name->Bounds.Y = NamePos.y;

Pronounciation = new Label();
Pronounciation->Bounds.X = PronounciationPos.x;
Pronounciation->Bounds.Y = PronounciationPos.y;

Category = new Label();
Category->Bounds.X = CategoryPos.x;
Category->Bounds.Y = CategoryPos.y;

Number = new Label();
Number->Bounds.X = NumberPos.x;
Number->Bounds.Y = NumberPos.y;

Expand All @@ -130,13 +133,13 @@ TipsMenu::TipsMenu() : TipViewItems(this) {

void TipsMenu::Show() {
if (State != Shown) {
LastYPos = 0;
State = Showing;
FadeAnimation.StartIn();

if (UI::FocusedMenu != 0) {
LastFocusedMenu = UI::FocusedMenu;
LastFocusedMenu->IsFocused = false;
}
IsFocused = true;
UI::FocusedMenu = this;

for (int i = 0; i < TabCount; i++) {
Expand All @@ -145,26 +148,47 @@ void TipsMenu::Show() {
CurrentTabType = static_cast<TipsTabType>(i);
}
}

Name->Bounds.X = NamePos.x;
Name->Bounds.Y = NamePos.y;

Pronounciation->Bounds.X = PronounciationPos.x;
Pronounciation->Bounds.Y = PronounciationPos.y;

Category->Bounds.X = CategoryPos.x;
Category->Bounds.Y = CategoryPos.y;

Number->Bounds.X = NumberPos.x;
Number->Bounds.Y = NumberPos.y;

TipsTabs[CurrentTabType]->Show();
TipViewItems.Show();
if (ScrWork[SW_SYSSUBMENUCT] != 32) {
TipsTabs[CurrentTabType]->Move({0, Profile::DesignHeight / 2});
TipViewItems.Move({0, Profile::DesignHeight / 2});
TextPage.Move({0, Profile::DesignHeight / 2});
TransitionAnimation.StartIn();
} else {
TransitionAnimation.Progress = 1.0f;
LastYPos = Profile::DesignHeight / 2;
}
FadeAnimation.StartIn();
}
}
void TipsMenu::Hide() {
if (State != Hidden) {
State = Hiding;
FadeAnimation.StartOut();
if (ScrWork[SW_SYSSUBMENUCT] != 0) {
TransitionAnimation.StartOut();
} else {
TransitionAnimation.Progress = 0.0f;
}
if (LastFocusedMenu != 0) {
UI::FocusedMenu = LastFocusedMenu;
LastFocusedMenu->IsFocused = true;
} else {
UI::FocusedMenu = 0;
}
IsFocused = false;
CurrentlyDisplayedTipId = -1;
TipsTabs[CurrentTabType]->Hide();
TipViewItems.Hide();
delete TipsScrollbar;
TipsScrollbar = nullptr;
}
}

Expand Down Expand Up @@ -230,13 +254,21 @@ void TipsMenu::UpdateInput() {

void TipsMenu::Update(float dt) {
if (!HasInitialized) return;
if (ScrWork[SW_SYSSUBMENUCT] < 32 && State == Shown &&
(ScrWork[SW_SYSSUBMENUNO] == 2)) {
if (ScrWork[SW_SYSSUBMENUCT] < 32 && State == Shown) {
Hide();
} else if (ScrWork[SW_SYSSUBMENUCT] >= 32 && State == Hidden &&
} else if (ScrWork[SW_SYSSUBMENUCT] > 0 && State == Hidden &&
(ScrWork[SW_SYSSUBMENUNO] == 2)) {
Show();
}

if (State != Hidden) {
FadeAnimation.Update(dt);
TransitionAnimation.Update(dt);
for (int i = 0; i < TabCount; i++) {
TipsTabs[i]->Update(dt);
}
}

if (State == Shown && ScrWork[SW_SYSSUBMENUNO] == 2) {
float oldPageY = TipPageY;
UpdateInput();
Expand All @@ -247,45 +279,86 @@ void TipsMenu::Update(float dt) {
TextPage.Move({0, oldPageY - TipPageY});
}
}
for (int i = 0; i < TabCount; i++) {
TipsTabs[i]->Update(dt);
}
}
FadeAnimation.Update(dt);
if (State == Showing && FadeAnimation.Progress == 1.0f) {

if (State == Showing && FadeAnimation.Progress == 1.0f &&
TransitionAnimation.Progress == 1.0f && ScrWork[SW_SYSSUBMENUCT] == 32) {
State = Shown;
} else if (State == Hiding && FadeAnimation.Progress == 0.0f) {
IsFocused = true;
} else if (State == Hiding && FadeAnimation.Progress == 0.0f &&
TransitionAnimation.Progress == 0.0f &&
ScrWork[SW_SYSSUBMENUCT] == 0) {
State = Hidden;
IsFocused = false;
if (UI::FocusedMenu) UI::FocusedMenu->IsFocused = true;
CurrentlyDisplayedTipId = -1;
TipsTabs[CurrentTabType]->Hide();
TipViewItems.Hide();
delete TipsScrollbar;
TipsScrollbar = nullptr;
}

auto Move = [this](glm::vec2 offset) {
LastYPos += offset.y;
TipViewItems.Move(-offset);
TipsTabs[CurrentTabType]->Move(-offset);
TextPage.Move(-offset);
if (TipsScrollbar) {
TipsScrollbar->Move(-offset);
}
};

if (TransitionAnimation.State == AS_Playing) {
float move = glm::mix(0.0f, Profile::DesignHeight / 2,
TransitionAnimation.Progress) -
LastYPos;
Move({0, move});

} else if (TransitionAnimation.IsIn() && LastYPos != 0) {
float move = Profile::DesignHeight / 2 - LastYPos;
Move({0, move});
} else if (TransitionAnimation.IsOut() &&
LastYPos != Profile::DesignHeight / 2 && LastYPos != 0) {
float move = -LastYPos;
Move({0, move});
}
}

void TipsMenu::Render() {
if (!HasInitialized) return;
if (State != Hidden && ScrWork[SW_SYSMENUCT] == 32 &&
ScrWork[SW_SYSSUBMENUNO] == 2) {
glm::vec4 transition(1.0f, 1.0f, 1.0f, FadeAnimation.Progress);
glm::vec4 maskTint = glm::vec4(1.0f);
maskTint.a = 0.85f * FadeAnimation.Progress;

Renderer->DrawSprite(BackgroundSprite, glm::vec2(0.0f));
Renderer->DrawSprite(TipsBookLayerSprite, glm::vec2(0.0f), transition);
if (State != Hidden) {
glm::vec4 fade(1.0f, 1.0f, 1.0f,
glm::smoothstep(0.0f, 1.0f, FadeAnimation.Progress));
glm::vec4 maskTint = fade;
maskTint.a *= 0.85f;

Renderer->DrawSprite(BackgroundSprite,
glm::vec2(0.0f, Profile::DesignHeight / 2 - LastYPos),
fade);
TipsTabs[CurrentTabType]->Tint.a = fade.a;
TipsTabs[CurrentTabType]->Render();

Renderer->DrawSprite(TipsGuideSprite, glm::vec2(TipsGuideX, TipsGuideY),
transition);
Renderer->DrawSprite(
TipsGuideSprite,
glm::vec2(TipsGuideX,
TipsGuideY + Profile::DesignHeight / 2 - LastYPos),
fade);
if (CurrentlyDisplayedTipId != -1) {
TipViewItems.Tint.a = fade.a;
TipViewItems.Render();

Renderer->DrawProcessedText(
TextPage.Glyphs, Profile::Dialogue::DialogueFont,
FadeAnimation.Progress, FadeAnimation.Progress,
RendererOutlineMode::RO_None, true, &TipsMaskSheet);

TipsScrollbar->Render();
}

Renderer->DrawSprite(
TipsMaskSprite,
RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight),
maskTint);
Renderer->DrawSprite(TipsMaskSprite,
RectF(0.0f, Profile::DesignHeight / 2 - LastYPos,
Profile::DesignWidth, Profile::DesignHeight),
maskTint);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/games/cclcc/tipsmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class TipsMenu : public UI::TipsMenu {
float ScrollPercentage = 0.0f;
bool HasInitialized = false;
void SetActiveTab(TipsTabType type);

float LastYPos = 0.0f;

Animation TransitionAnimation;
};

} // namespace CCLCC
Expand Down
Loading

0 comments on commit 8f64e29

Please sign in to comment.