Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
feat: hide controller when inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiya10 committed Apr 29, 2024
1 parent be5612e commit de4056d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
37 changes: 35 additions & 2 deletions src/components/replay/ReplayController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const router = useRouter();
const sliderProgress = ref(0);
const syncProgress = ref(true);
const isControllerHidden = ref(false);
let idleTimer: number | null = null;
watch(
() => props.frame,
Expand All @@ -50,10 +52,32 @@ const slideend = () => {
const endReplay = () => {
router.back();
};
const mouseenter = () => {
isControllerHidden.value = false;
if (idleTimer != null) {
window.clearTimeout(idleTimer);
idleTimer = null;
}
};
const mouseleave = () => {
if (idleTimer == null) {
idleTimer = window.setTimeout(() => {
isControllerHidden.value = true;
idleTimer = null;
}, 5000);
}
};
</script>

<template>
<div class="replay-controller">
<div
class="replay-controller"
:class="{ hide: isControllerHidden }"
@mouseenter="mouseenter"
@mouseleave="mouseleave"
>
<div class="replay-progress">
<ProgressBar
class="progress-bar"
Expand All @@ -65,7 +89,7 @@ const endReplay = () => {
v-if="!loading"
v-model="sliderProgress"
class="progress-slider"
:class="{ loaded: !loading }"
:class="{ loaded: !loading, hide: isControllerHidden }"
:min="0"
:max="frames"
@change="slidestart"
Expand Down Expand Up @@ -127,6 +151,11 @@ const endReplay = () => {
background-color: color-mix(in srgb, transparent, var(--p-surface-700) 85%);
z-index: 900;
pointer-events: all;
transition: bottom 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}
.replay-controller.hide {
bottom: -48px;
}
.replay-progress {
Expand All @@ -152,6 +181,10 @@ const endReplay = () => {
background-color: transparent;
}
.progress-slider.hide:deep(> .p-slider-handle) {
opacity: 0;
}
.progress-bar.loaded {
background-color: color-mix(
in srgb,
Expand Down
27 changes: 14 additions & 13 deletions src/view/ReplayView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const currentFrame = ref(0);
const progress = ref(0);
const events = ref<Events[]>([]);
const replayData = ref<Frame[]>([]);
let player: number | null = null;
let playerTimer: number | null = null;
let idleTimer: number | null = null;
const currentRtsFrame = computed((): RtsFrame | undefined => {
if (!replayData.value.length) return;
Expand Down Expand Up @@ -96,24 +97,24 @@ const scheduleNextFrame = () => {
const next = replayData.value[currentFrame.value + 1];
if (next) {
if (player == null) {
player = window.setTimeout(() => {
if (playerTimer == null) {
playerTimer = window.setTimeout(() => {
if (isPlaying.value) {
currentFrame.value++;
progress.value = (currentFrame.value / replayData.value.length) * 100;
player = null;
playerTimer = null;
scheduleNextFrame();
} else {
if (player != null) {
window.clearTimeout(player);
player = null;
if (playerTimer != null) {
window.clearTimeout(playerTimer);
playerTimer = null;
}
}
}, next.time - current.time);
} else {
if (player != null) {
window.clearTimeout(player);
player = null;
if (playerTimer != null) {
window.clearTimeout(playerTimer);
playerTimer = null;
}
}
}
Expand All @@ -126,9 +127,9 @@ const resume = () => {
const pause = () => {
isPlaying.value = false;
if (player != null) {
window.clearTimeout(player);
player = null;
if (playerTimer != null) {
window.clearTimeout(playerTimer);
playerTimer = null;
}
};
Expand Down

0 comments on commit de4056d

Please sign in to comment.