feat(settings): animate buttons
This commit is contained in:
@@ -14,6 +14,10 @@ export const useConfirmationModal = defineStore("confirmationModal", {
|
||||
onConfirm: null as (() => void) | null,
|
||||
onCancel: null as (() => void) | null,
|
||||
onClosed: null as ((choice: "confirm" | "cancel") => void) | null,
|
||||
keepButtonsDown: null as
|
||||
| boolean
|
||||
| ((choice: "confirm" | "cancel") => boolean)
|
||||
| null,
|
||||
offsetY: MODAL_MAX_Y_OFFSET,
|
||||
buttonsYOffset: 0,
|
||||
modalButtonsYOffset: BUTTONS_MAX_Y_OFFSET,
|
||||
@@ -29,6 +33,7 @@ export const useConfirmationModal = defineStore("confirmationModal", {
|
||||
onCancel?: () => void;
|
||||
onConfirm?: () => void;
|
||||
onClosed?: (choice: "confirm" | "cancel") => void;
|
||||
keepButtonsDown?: boolean | ((choice: "confirm" | "cancel") => boolean);
|
||||
timeout?: number;
|
||||
}) {
|
||||
gsap.killTweensOf(this);
|
||||
@@ -38,6 +43,7 @@ export const useConfirmationModal = defineStore("confirmationModal", {
|
||||
this.onConfirm = options.onConfirm ?? null;
|
||||
this.onCancel = options.onCancel ?? null;
|
||||
this.onClosed = options.onClosed ?? null;
|
||||
this.keepButtonsDown = options.keepButtonsDown ?? null;
|
||||
this.isVisible = true;
|
||||
this.isClosing = false;
|
||||
this.isOpen = true;
|
||||
@@ -80,7 +86,12 @@ export const useConfirmationModal = defineStore("confirmationModal", {
|
||||
|
||||
this.isClosing = true;
|
||||
|
||||
gsap
|
||||
const keepButtonsDown =
|
||||
typeof this.keepButtonsDown === "function"
|
||||
? this.keepButtonsDown(choice)
|
||||
: !!this.keepButtonsDown;
|
||||
|
||||
const tl = gsap
|
||||
.timeline()
|
||||
// modal buttons down
|
||||
.to(this, {
|
||||
@@ -93,18 +104,25 @@ export const useConfirmationModal = defineStore("confirmationModal", {
|
||||
offsetY: MODAL_MAX_Y_OFFSET,
|
||||
duration: MODAL_TIME,
|
||||
ease: "none",
|
||||
})
|
||||
});
|
||||
|
||||
if (!keepButtonsDown) {
|
||||
// standard buttons up
|
||||
.to(this, {
|
||||
tl.to(this, {
|
||||
buttonsYOffset: 0,
|
||||
duration: BUTTONS_TIME,
|
||||
ease: "none",
|
||||
})
|
||||
.call(() => {
|
||||
const closedCallback = this.onClosed;
|
||||
this.$reset();
|
||||
closedCallback?.(choice);
|
||||
});
|
||||
}
|
||||
|
||||
tl.call(() => {
|
||||
const closedCallback = this.onClosed;
|
||||
this.$reset();
|
||||
if (keepButtonsDown) {
|
||||
this.buttonsYOffset = BUTTONS_MAX_Y_OFFSET;
|
||||
}
|
||||
closedCallback?.(choice);
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -49,6 +49,8 @@ export const useSettingsStore = defineStore("settings", {
|
||||
opacity: 0,
|
||||
},
|
||||
|
||||
submenuButtonsOffsetY: 0,
|
||||
|
||||
animatingNotification: false,
|
||||
|
||||
isIntro: true,
|
||||
@@ -77,10 +79,25 @@ export const useSettingsStore = defineStore("settings", {
|
||||
{ offsetY: 16, opacity: 0 },
|
||||
{ offsetY: 0, opacity: 1, duration: 0.25, ease: "none" },
|
||||
"+=0.05",
|
||||
)
|
||||
.to(this, {
|
||||
submenuButtonsOffsetY: 24,
|
||||
duration: 0.167,
|
||||
ease: "none",
|
||||
})
|
||||
.call(() => {
|
||||
this.currentSubMenu = submenu;
|
||||
})
|
||||
.to(
|
||||
this,
|
||||
{
|
||||
submenuButtonsOffsetY: 0,
|
||||
duration: 0.167,
|
||||
ease: "none",
|
||||
},
|
||||
"+=0.05",
|
||||
);
|
||||
|
||||
this.currentSubMenu = submenu;
|
||||
|
||||
const achievements = useAchievementsStore();
|
||||
if (!achievements.advancement.visitedSettings.includes(submenu)) {
|
||||
achievements.advancement.visitedSettings.push(submenu);
|
||||
@@ -94,14 +111,33 @@ export const useSettingsStore = defineStore("settings", {
|
||||
},
|
||||
|
||||
async closeSubMenu() {
|
||||
this.currentSubMenu = null;
|
||||
const confirmationModal = useConfirmationModal();
|
||||
confirmationModal.buttonsYOffset = 0;
|
||||
|
||||
await gsap
|
||||
.timeline()
|
||||
.to(this, {
|
||||
submenuButtonsOffsetY: 24,
|
||||
duration: 0.167,
|
||||
ease: "none",
|
||||
})
|
||||
.call(() => {
|
||||
this.currentSubMenu = null;
|
||||
})
|
||||
.fromTo(
|
||||
this.submenuBackground,
|
||||
{ offsetY: 0, opacity: 1 },
|
||||
{ offsetY: 16, opacity: 0, duration: 0.25, ease: "none" },
|
||||
0.167,
|
||||
)
|
||||
.to(
|
||||
this,
|
||||
{
|
||||
submenuButtonsOffsetY: 0,
|
||||
duration: 0.167,
|
||||
ease: "none",
|
||||
},
|
||||
0.217,
|
||||
)
|
||||
.fromTo(
|
||||
this.submenuTransition,
|
||||
|
||||
Reference in New Issue
Block a user