feat(achievements): black fade in and out from home and settings screen

This commit is contained in:
2026-01-26 17:54:13 +01:00
parent 944f84944c
commit 28212bdbf3
14 changed files with 161 additions and 72 deletions

View File

@@ -29,21 +29,14 @@ onClick((x, y) => {
}); });
onRender((ctx) => { onRender((ctx) => {
assets.images.home.bottomScreen.background.draw(ctx, 0, 0);
ctx.globalAlpha = store.isIntro
? store.intro.stage1Opacity
: store.isOutro
? store.outro.stage1Opacity
: 1;
ctx.fillStyle = "#000000"; ctx.fillStyle = "#000000";
ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT); ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT);
// achievement list (reversed iteration because they appear in cascade) // achievement list (reversed iteration because they appear in cascade)
ctx.globalAlpha = store.isIntro ctx.globalAlpha = store.isIntro
? store.intro.stage2Opacity ? store.intro.stage1Opacity
: store.isOutro : store.isOutro
? store.outro.stage2Opacity ? store.outro.stage1Opacity
: 1; : 1;
ctx.font = "7px NDS7"; ctx.font = "7px NDS7";
ctx.textBaseline = "top"; ctx.textBaseline = "top";
@@ -78,9 +71,9 @@ onRender((ctx) => {
} }
ctx.globalAlpha = store.isIntro ctx.globalAlpha = store.isIntro
? store.intro.stage2Opacity ? store.intro.stage1Opacity
: store.isOutro : store.isOutro
? store.outro.stage3Opacity ? store.outro.stage2Opacity
: 1; : 1;
assets.images.achievements.quit.draw(ctx, QUIT_X, QUIT_Y); assets.images.achievements.quit.draw(ctx, QUIT_X, QUIT_Y);
}); });

View File

@@ -0,0 +1,17 @@
<script setup lang="ts">
const { onRender } = useScreen();
const store = useAchievementsScreen();
onRender((ctx) => {
if (!store.fadeToBlack.active) return;
if (store.fadeToBlack.isOutro && store.fadeToBlack.opacity === 0) return;
ctx.globalAlpha = store.fadeToBlack.opacity;
ctx.fillStyle = "#000000";
ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT);
}, 9999);
defineOptions({
render: () => null,
});
</script>

View File

@@ -2,7 +2,6 @@
const { onRender } = useScreen(); const { onRender } = useScreen();
const store = useAchievementsScreen(); const store = useAchievementsScreen();
const achievementsStore = useAchievementsStore(); const achievementsStore = useAchievementsStore();
const { assets } = useAssets();
const PROGRESS_BAR_WIDTH = 140; const PROGRESS_BAR_WIDTH = 140;
const PROGRESS_BAR_HEIGHT = 10; const PROGRESS_BAR_HEIGHT = 10;
@@ -15,21 +14,14 @@ onMounted(() => {
}); });
onRender((ctx) => { onRender((ctx) => {
assets.images.home.topScreen.background.draw(ctx, 0, 0);
ctx.globalAlpha = store.isIntro
? store.intro.stage1Opacity
: store.isOutro
? store.outro.stage1Opacity
: 1;
ctx.fillStyle = "#000000"; ctx.fillStyle = "#000000";
ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT); ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT);
// header // header
ctx.globalAlpha = store.isIntro ctx.globalAlpha = store.isIntro
? store.intro.stage2Opacity ? store.intro.stage1Opacity
: store.isOutro : store.isOutro
? store.outro.stage3Opacity ? store.outro.stage2Opacity
: 1; : 1;
ctx.fillStyle = "#ffffff"; ctx.fillStyle = "#ffffff";
ctx.textBaseline = "top"; ctx.textBaseline = "top";
@@ -87,9 +79,9 @@ onRender((ctx) => {
// achievement list (reversed iteration because they appear in cascade) // achievement list (reversed iteration because they appear in cascade)
ctx.globalAlpha = store.isIntro ctx.globalAlpha = store.isIntro
? store.intro.stage2Opacity ? store.intro.stage1Opacity
: store.isOutro : store.isOutro
? store.outro.stage2Opacity ? store.outro.stage1Opacity
: 1; : 1;
ctx.font = "7px NDS7"; ctx.font = "7px NDS7";
for (let i = ACHIEVEMENTS_TOP_SCREEN_COUNT - 1; i >= 0; i--) { for (let i = ACHIEVEMENTS_TOP_SCREEN_COUNT - 1; i >= 0; i--) {

View File

@@ -5,6 +5,6 @@ import Buttons from "./Buttons.vue";
<template> <template>
<Background /> <Background />
<Buttons /> <Buttons />
<AchievementsFadeToBlack />
</template> </template>

View File

@@ -17,7 +17,7 @@ const { selected, selectorPosition } = useButtonNavigation({
settings: [112, 167, 31, 26], settings: [112, 167, 31, 26],
achievements: [225, 167, 31, 26], achievements: [225, 167, 31, 26],
}, },
initialButton: "projects", initialButton: store.selectedButton,
onButtonClick: (button) => { onButtonClick: (button) => {
if (button === "theme") throw new Error(`Not implemented: ${button}`); if (button === "theme") throw new Error(`Not implemented: ${button}`);
@@ -64,6 +64,10 @@ const { selected, selectorPosition } = useButtonNavigation({
}, },
}); });
watch(selected, (newSelected) => {
store.selectedButton = newSelected;
});
const getButtonOffset = (button: (typeof selected)["value"]) => { const getButtonOffset = (button: (typeof selected)["value"]) => {
if (selected.value === button) return store.outro.buttonOffsetY; if (selected.value === button) return store.outro.buttonOffsetY;
return 0; return 0;

View File

@@ -7,8 +7,7 @@ import StatusBar from "./StatusBar.vue";
const store = useHomeStore(); const store = useHomeStore();
onMounted(() => { onMounted(() => {
store.$reset(); store.reset();
store.animateIntro();
}); });
</script> </script>
@@ -17,4 +16,5 @@ onMounted(() => {
<Calendar /> <Calendar />
<Clock /> <Clock />
<StatusBar /> <StatusBar />
<AchievementsFadeToBlack />
</template> </template>

View File

@@ -8,4 +8,5 @@ import Menus from "./Menus/Menus.vue";
<CommonBars /> <CommonBars />
<Menus /> <Menus />
<CommonConfirmationModal /> <CommonConfirmationModal />
<AchievementsFadeToBlack />
</template> </template>

View File

@@ -28,6 +28,7 @@ const { onRender, onClick } = useScreen();
const app = useAppStore(); const app = useAppStore();
const store = useSettingsStore(); const store = useSettingsStore();
const achievements = useAchievementsStore(); const achievements = useAchievementsStore();
const achievementsScreen = useAchievementsScreen();
const confirmationModal = useConfirmationModal(); const confirmationModal = useConfirmationModal();
const handleCancel = () => { const handleCancel = () => {
@@ -44,7 +45,7 @@ const handleReset = () => {
}; };
const handleVisitAll = () => { const handleVisitAll = () => {
throw new Error("Not implemented"); achievementsScreen.animateFadeToBlackIntro();
}; };
onClick((x, y) => { onClick((x, y) => {

View File

@@ -52,7 +52,7 @@ const { select, selected, selectorPosition } = useButtonNavigation({
touchScreen: [175, 119, 49, 49], touchScreen: [175, 119, 49, 49],
}, },
initialButton: "options", initialButton: settingsStore.selectedButton,
onButtonClick: (buttonName) => { onButtonClick: (buttonName) => {
if (isSubMenu(buttonName)) { if (isSubMenu(buttonName)) {
settingsStore.openSubMenu(buttonName); settingsStore.openSubMenu(buttonName);
@@ -154,6 +154,8 @@ provide("menusContext", {
watch( watch(
selected, selected,
(newSelected) => { (newSelected) => {
settingsStore.selectedButton = newSelected;
if (settingsStore.currentSubMenu === null) { if (settingsStore.currentSubMenu === null) {
if (isMainMenu(newSelected)) { if (isMainMenu(newSelected)) {
settingsStore.openMenu(newSelected, false); settingsStore.openMenu(newSelected, false);

View File

@@ -12,4 +12,5 @@ import Notifications from "./Notifications.vue";
<Clock /> <Clock />
<StatusBar /> <StatusBar />
<Notifications /> <Notifications />
<AchievementsFadeToBlack />
</template> </template>

View File

@@ -2,9 +2,14 @@ import gsap from "gsap";
export const useAchievementsScreen = defineStore("achievementsScreen", { export const useAchievementsScreen = defineStore("achievementsScreen", {
state: () => ({ state: () => ({
fadeToBlack: {
opacity: 0,
active: false,
isOutro: false,
},
intro: { intro: {
stage1Opacity: 0, stage1Opacity: 0,
stage2Opacity: 0,
itemOffsets: {} as Record<number, number>, itemOffsets: {} as Record<number, number>,
progressBar: 0, progressBar: 0,
}, },
@@ -12,7 +17,6 @@ export const useAchievementsScreen = defineStore("achievementsScreen", {
outro: { outro: {
stage1Opacity: 1, stage1Opacity: 1,
stage2Opacity: 1, stage2Opacity: 1,
stage3Opacity: 1,
}, },
isIntro: true, isIntro: true,
@@ -20,6 +24,51 @@ export const useAchievementsScreen = defineStore("achievementsScreen", {
}), }),
actions: { actions: {
animateFadeToBlackIntro() {
this.fadeToBlack.active = true;
this.fadeToBlack.isOutro = false;
gsap
.timeline({
onComplete: () => {
const app = useAppStore();
app.navigateTo("achievements");
},
})
.fromTo(
this.fadeToBlack,
{ opacity: 0 },
{
opacity: 1,
duration: 0.4,
ease: "none",
},
);
},
animateFadeToBlackOutro() {
this.fadeToBlack.active = true;
this.fadeToBlack.isOutro = true;
this.fadeToBlack.opacity = 1;
gsap
.timeline({
onComplete: () => {
this.fadeToBlack.active = false;
this.isOutro = false;
},
})
.fromTo(
this.fadeToBlack,
{ opacity: 1 },
{
opacity: 0,
duration: 0.4,
ease: "none",
},
);
},
animateIntro() { animateIntro() {
this.isIntro = true; this.isIntro = true;
this.isOutro = false; this.isOutro = false;
@@ -41,30 +90,20 @@ export const useAchievementsScreen = defineStore("achievementsScreen", {
{ stage1Opacity: 0 }, { stage1Opacity: 0 },
{ {
stage1Opacity: 1, stage1Opacity: 1,
duration: 0.3, duration: 0.5,
ease: "none", ease: "none",
}, },
) 0.5,
.fromTo( ).fromTo(
this.intro, this.intro,
{ stage2Opacity: 0 }, { progressBar: 0 },
{ {
stage2Opacity: 1, progressBar: 1,
duration: 0.5, duration: 1.5,
ease: "none", ease: "power2.out",
}, },
0.5, 0.25,
) );
.fromTo(
this.intro,
{ progressBar: 0 },
{
progressBar: 1,
duration: 1.5,
ease: "power2.out",
},
0.25,
);
for (let i = 0; i < itemCount; i++) { for (let i = 0; i < itemCount; i++) {
tl.to( tl.to(
@@ -85,6 +124,14 @@ export const useAchievementsScreen = defineStore("achievementsScreen", {
gsap gsap
.timeline() .timeline()
.fromTo(
this.outro,
{ stage1Opacity: 1 },
{
stage1Opacity: 0,
duration: 0.3,
},
)
.fromTo( .fromTo(
this.outro, this.outro,
{ stage2Opacity: 1 }, { stage2Opacity: 1 },
@@ -92,28 +139,12 @@ export const useAchievementsScreen = defineStore("achievementsScreen", {
stage2Opacity: 0, stage2Opacity: 0,
duration: 0.3, duration: 0.3,
}, },
)
.fromTo(
this.outro,
{ stage3Opacity: 1 },
{
stage3Opacity: 0,
duration: 0.3,
},
"-=0.15", "-=0.15",
) )
.fromTo(
this.outro,
{ stage1Opacity: 1 },
{
stage1Opacity: 0,
duration: 0.3,
ease: "none",
},
)
.call(() => { .call(() => {
const app = useAppStore(); const app = useAppStore();
app.navigateTo("home"); app.navigateTo(app.previousScreen);
this.animateFadeToBlackOutro();
}); });
}, },

View File

@@ -29,6 +29,7 @@ export const useAppStore = defineStore("app", {
return { return {
booted: false, booted: false,
settings, settings,
previousScreen: "home" as AppScreen,
screen: "home" as AppScreen, screen: "home" as AppScreen,
camera: null as THREE.Camera | null, camera: null as THREE.Camera | null,
}; };
@@ -40,6 +41,7 @@ export const useAppStore = defineStore("app", {
}, },
navigateTo(screen: AppScreen) { navigateTo(screen: AppScreen) {
this.previousScreen = this.screen;
this.screen = screen; this.screen = screen;
const achievements = useAchievementsStore(); const achievements = useAchievementsStore();

View File

@@ -1,5 +1,13 @@
import gsap from "gsap"; import gsap from "gsap";
export type HomeButton =
| "projects"
| "contact"
| "gallery"
| "theme"
| "settings"
| "achievements";
export const useHomeStore = defineStore("home", { export const useHomeStore = defineStore("home", {
state: () => ({ state: () => ({
intro: { intro: {
@@ -14,11 +22,25 @@ export const useHomeStore = defineStore("home", {
animateTop: false, animateTop: false,
}, },
selectedButton: "projects" as HomeButton,
isIntro: true, isIntro: true,
isOutro: false, isOutro: false,
}), }),
actions: { actions: {
reset() {
const app = useAppStore();
if (app.previousScreen === "achievements") {
return;
}
const selectedButton = this.selectedButton;
this.$reset();
this.selectedButton = selectedButton;
this.animateIntro();
},
animateIntro() { animateIntro() {
this.isIntro = true; this.isIntro = true;
@@ -52,12 +74,18 @@ export const useHomeStore = defineStore("home", {
}, },
animateOutro(to: AppScreen) { animateOutro(to: AppScreen) {
if (to === "achievements") {
const achievementsScreen = useAchievementsScreen();
achievementsScreen.animateFadeToBlackIntro();
return;
}
this.isOutro = true; this.isOutro = true;
this.outro.animateTop = to !== "settings"; this.outro.animateTop = to !== "settings";
const timeline = gsap.timeline({ const timeline = gsap.timeline({
onComplete: () => { onComplete: () => {
this.isOutro = true; this.isOutro = false;
const app = useAppStore(); const app = useAppStore();
if (to === "gallery") { if (to === "gallery") {

View File

@@ -1,8 +1,25 @@
export type SettingsButton =
| "options"
| "optionsLanguage"
| "optionsGbaMode"
| "optionsStartUp"
| "clock"
| "clockAlarm"
| "clockTime"
| "clockDate"
| "user"
| "userBirthday"
| "userUserName"
| "userMessage"
| "userColor"
| "touchScreen";
export const useSettingsStore = defineStore("settings", { export const useSettingsStore = defineStore("settings", {
state: () => ({ state: () => ({
currentMenu: null as SettingsMenu | null, currentMenu: null as SettingsMenu | null,
currentSubMenu: null as SettingsSubMenu | null, currentSubMenu: null as SettingsSubMenu | null,
menuExpanded: false, menuExpanded: false,
selectedButton: "options" as SettingsButton,
}), }),
actions: { actions: {