forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharacterOrderDialog.vue
371 lines (324 loc) · 9.66 KB
/
CharacterOrderDialog.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<template>
<QDialog
v-model="modelValueComputed"
maximized
transitionShow="jump-up"
transitionHide="jump-down"
class="transparent-backdrop"
>
<QLayout container view="hHh Lpr lff" class="bg-background">
<QHeader class="q-py-sm">
<QToolbar>
<div class="column">
<QToolbarTitle class="text-display">{{
hasNewCharacter
? "追加キャラクターの紹介"
: "設定 / キャラクター並び替え・試聴"
}}</QToolbarTitle>
</div>
<QSpace />
<div class="row items-center no-wrap">
<QBtn
unelevated
label="完了"
color="toolbar-button"
textColor="toolbar-button-display"
class="text-no-wrap"
@click="closeDialog"
/>
</div>
</QToolbar>
</QHeader>
<QDrawer
bordered
showIfAbove
:modelValue="true"
:width="$q.screen.width / 3 > 300 ? 300 : $q.screen.width / 3"
:breakpoint="0"
>
<div class="character-portrait-wrapper">
<img :src="portrait" class="character-portrait" />
</div>
</QDrawer>
<QPageContainer>
<QPage class="main">
<div class="character-items-container">
<span class="text-h6 q-py-md">サンプルボイス一覧</span>
<div>
<CharacterTryListenCard
v-for="characterInfo of characterInfos"
:key="characterInfo.metas.speakerUuid"
:characterInfo
:isSelected="
selectedCharacter === characterInfo.metas.speakerUuid
"
:isNewCharacter="
newCharacters.includes(characterInfo.metas.speakerUuid)
"
:playing
:togglePlayOrStop
@update:portrait="updatePortrait"
@update:selectCharacter="selectCharacter"
/>
</div>
</div>
<div class="character-order-container">
<div class="text-subtitle1 text-weight-bold text-center q-py-md">
キャラクター並び替え
</div>
<Draggable
v-model="characterOrder"
class="character-order q-px-sm"
:itemKey="keyOfCharacterOrderItem"
@start="characterOrderDragging = true"
@end="characterOrderDragging = false"
>
<template #item="{ element }">
<div
class="character-order-item q-py-sm"
:class="[
selectedCharacter === element.metas.speakerUuid &&
'selected-character-order-item',
]"
@mouseenter="
// ドラッグ中はバグるので無視
characterOrderDragging ||
selectCharacterWithChangePortrait(
element.metas.speakerUuid,
)
"
>
{{ element.metas.speakerName }}
</div>
</template>
</Draggable>
</div>
</QPage>
</QPageContainer>
</QLayout>
</QDialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import Draggable from "vuedraggable";
import { useQuasar } from "quasar";
import CharacterTryListenCard from "./CharacterTryListenCard.vue";
import { useStore } from "@/store";
import { CharacterInfo, SpeakerId, StyleId, StyleInfo } from "@/type/preload";
const props = defineProps<{
modelValue: boolean;
characterInfos: CharacterInfo[];
}>();
const emit = defineEmits<{
(event: "update:modelValue", value: boolean): void;
}>();
const $q = useQuasar();
const store = useStore();
const modelValueComputed = computed({
get: () => props.modelValue,
set: (val) => emit("update:modelValue", val),
});
const characterInfosMap = computed(() => {
const map: { [key: SpeakerId]: CharacterInfo } = {};
props.characterInfos.forEach((characterInfo) => {
map[characterInfo.metas.speakerUuid] = characterInfo;
});
return map;
});
// 新しいキャラクター
const newCharacters = ref<SpeakerId[]>([]);
const hasNewCharacter = computed(() => newCharacters.value.length > 0);
// サンプルボイス一覧のキャラクター順番
const sampleCharacterOrder = ref<SpeakerId[]>([]);
// 選択中のキャラクター
const selectedCharacter = ref(props.characterInfos[0].metas.speakerUuid);
const selectCharacter = (speakerUuid: SpeakerId) => {
selectedCharacter.value = speakerUuid;
};
const selectCharacterWithChangePortrait = (speakerUuid: SpeakerId) => {
selectCharacter(speakerUuid);
portrait.value = characterInfosMap.value[speakerUuid].portraitPath;
};
// キャラクター表示順序
const characterOrder = ref<CharacterInfo[]>([]);
// ダイアログが開かれたときに初期値を求める
watch(
() => props.modelValue,
async (newValue, oldValue) => {
if (!oldValue && newValue) {
// 新しいキャラクター
newCharacters.value = await store.actions.GET_NEW_CHARACTERS();
// サンプルの順番、新しいキャラクターは上に
sampleCharacterOrder.value = [
...newCharacters.value,
...props.characterInfos
.filter(
(info) => !newCharacters.value.includes(info.metas.speakerUuid),
)
.map((info) => info.metas.speakerUuid),
];
selectedCharacter.value = sampleCharacterOrder.value[0];
// 保存済みのキャラクターリストを取得
// FIXME: 不明なキャラを無視しているので、不明キャラの順番が保存時にリセットされてしまう
characterOrder.value = store.state.userCharacterOrder
.map((speakerUuid) => characterInfosMap.value[speakerUuid])
.filter((info) => info != undefined);
// 含まれていないキャラクターを足す
const notIncludesCharacterInfos = props.characterInfos.filter(
(characterInfo) =>
!characterOrder.value.find(
(characterInfoInList) =>
characterInfoInList.metas.speakerUuid ===
characterInfo.metas.speakerUuid,
),
);
characterOrder.value = [
...characterOrder.value,
...notIncludesCharacterInfos,
];
}
},
);
// draggable用
const keyOfCharacterOrderItem = (item: CharacterInfo) => item.metas.speakerUuid;
// 音声再生
const playing = ref<{
speakerUuid: SpeakerId;
styleId: StyleId;
index: number;
}>();
const audio = new Audio();
audio.volume = 0.5;
audio.onended = () => stop();
const play = (
speakerUuid: SpeakerId,
{ styleId, voiceSamplePaths }: StyleInfo,
index: number,
) => {
if (audio.src !== "") stop();
audio.src = voiceSamplePaths[index];
void audio.play();
playing.value = { speakerUuid, styleId, index };
};
const stop = () => {
if (audio.src === "") return;
audio.pause();
audio.removeAttribute("src");
playing.value = undefined;
};
// 再生していたら停止、再生していなかったら再生
const togglePlayOrStop = (
speakerUuid: SpeakerId,
styleInfo: StyleInfo,
index: number,
) => {
if (
playing.value == undefined ||
speakerUuid !== playing.value.speakerUuid ||
styleInfo.styleId !== playing.value.styleId ||
index !== playing.value.index
) {
play(speakerUuid, styleInfo, index);
} else {
stop();
}
};
// ドラッグ中かどうか
const characterOrderDragging = ref(false);
const closeDialog = () => {
void store.actions.SET_USER_CHARACTER_ORDER(
characterOrder.value.map((info) => info.metas.speakerUuid),
);
stop();
modelValueComputed.value = false;
};
const portrait = ref<string | undefined>(
characterInfosMap.value[selectedCharacter.value].portraitPath,
);
const updatePortrait = (portraitPath: string) => {
portrait.value = portraitPath;
};
</script>
<style scoped lang="scss">
@use "@/styles/variables" as vars;
@use "@/styles/colors" as colors;
.q-toolbar div:first-child {
min-width: 0;
}
.character-portrait-wrapper {
display: grid;
justify-content: center;
width: 100%;
height: 100%;
overflow: hidden;
.character-portrait {
margin: auto;
}
}
.main {
height: calc(
100vh - #{vars.$menubar-height + vars.$toolbar-height +
vars.$window-border-width}
);
display: flex;
flex-direction: row;
}
.character-items-container {
height: 100%;
padding: 5px 16px;
flex-grow: 1;
display: flex;
flex-direction: column;
overflow-y: scroll;
> div {
display: grid;
grid-template-columns: repeat(auto-fit, vars.$character-item-size);
grid-auto-rows: vars.$character-item-size;
column-gap: 10px;
row-gap: 10px;
align-content: center;
justify-content: center;
}
}
.character-order-container {
width: 180px;
height: 100%;
display: flex;
flex-direction: column;
.character-order {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.5rem;
height: 100%;
overflow-y: auto;
.character-order-item {
border-radius: 10px;
border: 2px solid rgba(colors.$display-rgb, 0.15);
text-align: center;
cursor: grab;
&.selected-character-order-item {
border: 2px solid colors.$primary;
}
}
}
}
.q-layout-container > :deep(.absolute-full) {
right: 0 !important;
> .scroll {
width: unset !important;
overflow: hidden;
}
}
@media screen and (max-width: 880px) {
.q-drawer-container {
display: none;
}
.q-page-container {
padding-left: unset !important;
.q-page-sticky {
left: 0 !important;
}
}
}
</style>