-
Notifications
You must be signed in to change notification settings - Fork 1
/
hud-widget-feedback.vue
298 lines (289 loc) · 12.5 KB
/
hud-widget-feedback.vue
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!--
/*
** HUDS ~~ Head-Up-Display Server (HUDS)
** Copyright (c) 2020-2024 Dr. Ralf S. Engelschall <[email protected]>
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-->
<template>
<div v-bind:style="style" class="feedback">
<div v-show="shown" class="feedback-container">
<div
v-for="item of items"
v-bind:key="item.type"
v-bind:ref="(el) => itemEls.push(el)"
v-bind:data-type="item.type"
v-bind:class="[ 'item', 'item-' + item.type ]">
<div class="icon-bg">
<i class="fas fa-circle"></i>
</div>
<div class="icon">
<i v-bind:class="[ 'fas', 'fa-' + item.icon ]"></i>
</div>
<div v-show="item.count > 1" class="badge">
{{ item.count }}
</div>
</div>
</div>
</div>
</template>
<style lang="less" scoped>
.feedback {
opacity: var(--opacity);
position: relative;
.feedback-container {
width: 400px;
height: 990px;
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: flex-end;
.item {
width: 100px;
height: 100px;
position: relative;
.icon-bg {
opacity: 0.8;
position: absolute;
left: 0px;
bottom: 0px;
font-size: 100px;
}
.icon {
position: absolute;
left: 0px;
bottom: 0px;
font-size: 100px;
}
.badge {
position: absolute;
right: 0px;
top: -4px;
width: 30px;
height: 30px;
text-align: center;
border-radius: 15px;
padding-top: 0px;
padding-left: 0px;
font-family: "TypoPRO Fira Sans";
font-weight: normal;
font-size: 16pt;
}
&.item-surprise {
.icon-bg { color: var(--surprisecolor1); }
.icon { color: var(--surprisecolor2); }
.badge { background-color: var(--surprisecolor3);
color: var(--surprisecolor4); }
}
&.item-smile {
.icon-bg { color: var(--smilecolor1); }
.icon { color: var(--smilecolor2); }
.badge { background-color: var(--smilecolor3);
color: var(--smilecolor4); }
}
&.item-frown {
.icon-bg { color: var(--frowncolor1); }
.icon { color: var(--frowncolor2); }
.badge { background-color: var(--frowncolor3);
color: var(--frowncolor4); }
}
&.item-sadness {
.icon-bg { color: var(--sadnesscolor1); }
.icon { color: var(--sadnesscolor2); }
.badge { background-color: var(--sadnesscolor3);
color: var(--sadnesscolor4); }
}
&.item-thumbsup {
.icon-bg { color: var(--thumbsupcolor1); }
.icon { color: var(--thumbsupcolor2); font-size: 60px; left: 22px; top: 3px; }
.badge { background-color: var(--thumbsupcolor3);
color: var(--thumbsupcolor4); }
}
&.item-thumbsdn {
.icon-bg { color: var(--thumbsdncolor1); }
.icon { color: var(--thumbsdncolor2); font-size: 60px; left: 20px; top: 10px; }
.badge { background-color: var(--thumbsdncolor3);
color: var(--thumbsdncolor4); }
}
}
}
}
</style>
<script>
export default {
name: "feedback",
props: {
opacity: { type: Number, default: 1.0 },
surprisecolor1: { type: String, default: "" },
surprisecolor2: { type: String, default: "" },
surprisecolor3: { type: String, default: "" },
surprisecolor4: { type: String, default: "" },
smilecolor1: { type: String, default: "" },
smilecolor2: { type: String, default: "" },
smilecolor3: { type: String, default: "" },
smilecolor4: { type: String, default: "" },
frowncolor1: { type: String, default: "" },
frowncolor2: { type: String, default: "" },
frowncolor3: { type: String, default: "" },
frowncolor4: { type: String, default: "" },
sadnesscolor1: { type: String, default: "" },
sadnesscolor2: { type: String, default: "" },
sadnesscolor3: { type: String, default: "" },
sadnesscolor4: { type: String, default: "" },
thumbsupcolor1: { type: String, default: "" },
thumbsupcolor2: { type: String, default: "" },
thumbsupcolor3: { type: String, default: "" },
thumbsupcolor4: { type: String, default: "" },
thumbsdncolor1: { type: String, default: "" },
thumbsdncolor2: { type: String, default: "" },
thumbsdncolor3: { type: String, default: "" },
thumbsdncolor4: { type: String, default: "" }
},
data: () => ({
feedbacks: {},
shown: false,
items: []
}),
computed: {
style: HUDS.vueprop2cssvar()
},
setup () {
const itemEls = Vue.ref([])
Vue.onBeforeUpdate(() => { itemEls.value = [] })
return { itemEls }
},
methods: {
/* receive the feedback events */
event (data) {
this.feedbacks[data.client] = {
seen: (new Date()).getTime(),
type: data.type
}
}
},
created () {
/* expire feedbacks */
this.timer = setInterval(() => {
/* expire or take over feedbacks */
const items = {}
const now = (new Date()).getTime()
for (const client of Object.keys(this.feedbacks)) {
const seen = this.feedbacks[client].seen
if (seen + ((30 + 2) * 1000) < now)
delete this.feedbacks[client]
else {
const type = this.feedbacks[client].type
if (items[type] === undefined)
items[type] = 0
items[type]++
}
}
/* merge items into data model and determine what is coming and going */
const coming = []
const going = []
for (const type of Object.keys(items)) {
let item = this.items.find((item) => item.type === type)
if (item)
item.count = items[type]
else {
let icon
if (type === "surprise") icon = "surprise"
else if (type === "smile") icon = "grin-wink"
else if (type === "frown") icon = "angry"
else if (type === "sadness") icon = "sad-tear"
else if (type === "thumbsup") icon = "thumbs-up"
else if (type === "thumbsdn") icon = "thumbs-down"
else icon = "smile"
item = { type, count: items[type], icon, coming: true }
this.items.push(item)
coming.push(item)
}
}
for (const item of this.items) {
if (!item.coming && !item.going && items[item.type] === undefined) {
item.going = true
item.count = 0
going.push(item)
}
}
/* determine whether widget should be shown at all */
this.shown = (this.items.length > 0)
/* animate items (once Vue has updated the DOM) */
this.$nextTick(() => {
const findElement = (type) => {
const els = this.itemEls
for (let i = 0; i < els.length; i++)
if (els[i].getAttribute("data-type") === type)
return els[i]
return null
}
/* animate coming items */
for (const item of coming) {
const el = findElement(item.type)
if (el !== null) {
soundfx.play("beep6")
const tl = anime.timeline({
targets: el,
direction: "normal",
loop: false,
autoplay: true
})
tl.add({ duration: 5300, easing: "easeInOutSine", rotate: [ 0, 360 ] }, 0)
tl.add({ duration: 1000, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: [ -200, 700 ] }, 0)
tl.add({ duration: 1000, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 1000)
tl.add({ duration: 750, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 500 }, 2000)
tl.add({ duration: 750, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 2750)
tl.add({ duration: 500, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 300 }, 3500)
tl.add({ duration: 500, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 4000)
tl.add({ duration: 250, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 100 }, 4500)
tl.add({ duration: 250, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 4750)
tl.add({ duration: 150, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 25 }, 5000)
tl.add({ duration: 150, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 5150)
tl.finished.then(() => {
item.coming = false
})
}
}
/* animate going items */
for (const item of going) {
const el = findElement(item.type)
if (el !== null) {
const tl = anime.timeline({
targets: el,
direction: "normal",
loop: false,
autoplay: true
})
tl.add({ duration: 1500, easing: "easeInOutSine", rotate: [ 0, 360 ] }, 0)
tl.add({ duration: 500, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 300 }, 0)
tl.add({ duration: 500, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: 0 }, 500)
tl.add({ duration: 250, easing: "cubicBezier(0.0,0.5,0.3,1.0)", bottom: 100 }, 1000)
tl.add({ duration: 250, easing: "cubicBezier(0.5,0.0,1.0,0.3)", bottom: -200 }, 1250)
tl.finished.then(() => {
this.items = this.items.filter((x) => x !== item)
})
}
}
})
}, 1 * 1000)
}
}
</script>