Repository navigation
Expand file tree
/
Copy pathHUD.vue
More file actions
111 lines (99 loc) · 2.22 KB
/
Copy pathHUD.vue
File metadata and controls
111 lines (99 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<div class="hud">
<div class="hud-bubble">
<div class="gold-display">
<div class="gold-icon"></div>
<span class="gold-amount">{{ gold }}</span>
</div>
<div v-if="goldChange" class="gold-change" :class="{ 'positive': goldChange > 0, 'negative': goldChange < 0 }">
{{ goldChange > 0 ? '+' : '' }}{{ goldChange }}
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useGameStore } from '../stores/game'
import { computed, ref, watch } from 'vue'
const gameStore = useGameStore()
const persona = gameStore.usePersona()
const previousGold = ref(0)
const goldChange = ref(0)
const gold = computed(() => {
return persona.value.gold || '0'
})
// Watch for gold changes and animate the difference
watch(gold, (newValue, oldValue) => {
const newGold = parseInt(newValue || '0')
const oldGold = parseInt(oldValue || '0')
if (!isNaN(newGold) && !isNaN(oldGold)) {
goldChange.value = newGold - oldGold
// Clear the change after animation
setTimeout(() => {
goldChange.value = 0
}, 2000)
}
previousGold.value = newGold
}, { immediate: true })
</script>
<style scoped>
.hud {
position: absolute;
top: 20px;
right: 20px;
z-index: 1000;
}
.hud-bubble {
background-color: rgba(40, 40, 40, 0.8);
border-radius: 12px;
padding: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.gold-display {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 12px;
color: white;
font-weight: bold;
}
.gold-amount {
font-size: 1.1em;
}
.gold-change {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-size: 0.9em;
font-weight: bold;
padding: 2px 8px;
border-radius: 8px;
animation: fadeUp 2s ease-out forwards;
white-space: nowrap;
}
.gold-change.positive {
color: #4caf50;
background-color: rgba(76, 175, 80, 0.2);
}
.gold-change.negative {
color: #f44336;
background-color: rgba(244, 67, 54, 0.2);
}
@keyframes fadeUp {
0% {
opacity: 0;
transform: translate(-50%, 0);
}
20% {
opacity: 1;
transform: translate(-50%, -10px);
}
80% {
opacity: 1;
transform: translate(-50%, -10px);
}
100% {
opacity: 0;
transform: translate(-50%, -20px);
}
}
</style>