forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultStyleListDialog.vue
302 lines (279 loc) · 8.94 KB
/
DefaultStyleListDialog.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
<template>
<DefaultStyleSelectDialog
v-if="
selectedCharacterInfo &&
selectedStyleIndexes[selectedCharacterInfo.metas.speakerUuid] !==
undefined
"
v-model:isOpen="showStyleSelectDialog"
v-model:selectedStyleIndex="
selectedStyleIndexes[selectedCharacterInfo.metas.speakerUuid]
"
:characterInfo="selectedCharacterInfo"
/>
<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"
>設定 / デフォルトスタイル・試聴</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>
<QPageContainer>
<QPage class="main">
<div class="character-items-container">
<div>
<QItem
v-for="speaker of speakerWithMultipleStyles"
:key="speaker.metas.speakerUuid"
v-ripple="isHoverableItem"
clickable
class="q-pa-none character-item"
:class="[isHoverableItem && 'hoverable-character-item']"
@click="openStyleSelectDialog(speaker)"
>
<div class="character-item-inner">
<img
:src="
speaker.metas.styles[
selectedStyleIndexes[speaker.metas.speakerUuid]
].iconPath
"
class="style-icon"
/>
<span
class="text-subtitle1 q-mt-sm q-mb-xs text-weight-bold"
>{{
characterInfosMap[speaker.metas.speakerUuid].metas
.speakerName
}}</span
>
<div
v-if="
characterInfosMap[speaker.metas.speakerUuid].metas.styles
.length > 1
"
class="style-select-container"
>
<span>{{
selectedStyles[speaker.metas.speakerUuid]
? selectedStyles[speaker.metas.speakerUuid].styleName
: DEFAULT_STYLE_NAME
}}</span
><span class="text-caption"
>全{{
characterInfosMap[speaker.metas.speakerUuid].metas
.styles.length
}}スタイル</span
>
</div>
</div>
</QItem>
</div>
</div>
</QPage>
</QPageContainer>
</QLayout>
</QDialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import DefaultStyleSelectDialog from "./DefaultStyleSelectDialog.vue";
import { useStore } from "@/store";
import { DEFAULT_STYLE_NAME } from "@/store/utility";
import { CharacterInfo, SpeakerId, StyleInfo } from "@/type/preload";
const props = defineProps<{
modelValue: boolean;
characterInfos: CharacterInfo[];
}>();
const emit = defineEmits<{
(e: "update:modelValue", val: boolean): void;
}>();
const store = useStore();
const modelValueComputed = computed({
get: () => props.modelValue,
set: (val) => emit("update:modelValue", val),
});
// 選択中のキャラクター
const selectedCharacter = ref(props.characterInfos[0].metas.speakerUuid);
const showStyleSelectDialog = ref<boolean>(false);
const selectedCharacterInfo = computed(() => {
return props.characterInfos.find(
(characterInfo) =>
characterInfo.metas.speakerUuid === selectedCharacter.value,
);
});
const characterInfosMap = computed(() => {
const map: { [key: SpeakerId]: CharacterInfo } = {};
props.characterInfos.forEach((characterInfo) => {
map[characterInfo.metas.speakerUuid] = characterInfo;
});
return map;
});
// サンプルボイス一覧のキャラクター順番
const speakerWithMultipleStyles = ref<CharacterInfo[]>([]);
// 選択中のスタイル
const selectedStyleIndexes = ref<Record<SpeakerId, number>>({});
const selectedStyles = computed(() => {
const map: { [key: string]: StyleInfo } = {};
props.characterInfos.forEach((characterInfo) => {
const selectedStyleIndex: number | undefined =
selectedStyleIndexes.value[characterInfo.metas.speakerUuid];
map[characterInfo.metas.speakerUuid] =
characterInfo.metas.styles[selectedStyleIndex ?? 0];
});
return map;
});
// ダイアログが開かれたときに初期値を求める
watch([() => props.modelValue], async ([newValue]) => {
if (newValue) {
speakerWithMultipleStyles.value = store.state.userCharacterOrder
.map((speakerUuid) => characterInfosMap.value[speakerUuid])
.filter((characterInfo) => characterInfo != undefined)
.filter((characterInfo) => characterInfo.metas.styles.length > 1);
// FIXME: エンジン未起動状態でデフォルトスタイル選択ダイアログを開くと
// 未起動エンジンのキャラのデフォルトスタイルが消えてしまう
selectedStyleIndexes.value = Object.fromEntries(
[
...store.state.userCharacterOrder.map(
(speakerUuid) => [speakerUuid, 0] as const,
),
...store.state.defaultStyleIds.map(
(defaultStyle) =>
[
defaultStyle.speakerUuid,
characterInfosMap.value[
defaultStyle.speakerUuid
]?.metas.styles.findIndex(
(style) => style.styleId === defaultStyle.defaultStyleId,
),
] as const,
),
].filter(([speakerUuid]) => speakerUuid in characterInfosMap.value),
);
}
});
// キャラクター枠のホバー状態を表示するかどうか
// 再生ボタンなどにカーソルがある場合はキャラクター枠のホバーUIを表示しないようにするため
const isHoverableItem = ref(true);
const closeDialog = () => {
void store.dispatch(
"SET_DEFAULT_STYLE_IDS",
Object.entries(selectedStyleIndexes.value).map(
([speakerUuidStr, styleIndex]) => {
const speakerUuid = SpeakerId(speakerUuidStr);
return {
speakerUuid,
defaultStyleId:
characterInfosMap.value[speakerUuid].metas.styles[styleIndex]
.styleId,
engineId:
characterInfosMap.value[speakerUuid].metas.styles[styleIndex]
.engineId,
};
},
),
);
stop();
modelValueComputed.value = false;
};
const openStyleSelectDialog = (characterInfo: CharacterInfo) => {
stop();
selectedCharacter.value = characterInfo.metas.speakerUuid;
showStyleSelectDialog.value = true;
};
</script>
<style scoped lang="scss">
@use "@/styles/variables" as vars;
@use "@/styles/colors" as colors;
.q-toolbar div:first-child {
min-width: 0;
}
.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 {
$character-item-size: 200px;
display: grid;
grid-template-columns: repeat(auto-fit, $character-item-size);
grid-auto-rows: 200px;
column-gap: 10px;
row-gap: 10px;
align-content: center;
justify-content: center;
.character-item {
box-shadow: 0 0 0 1px rgba(colors.$primary-rgb, 0.5);
border-radius: 10px;
overflow: hidden;
&.selected-character-item {
box-shadow: 0 0 0 2px colors.$primary;
}
&:hover :deep(.q-focus-helper) {
opacity: 0 !important;
}
&.hoverable-character-item:hover :deep(.q-focus-helper) {
opacity: 0.15 !important;
}
.character-item-inner {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
.style-icon {
$icon-size: $character-item-size / 2;
width: $icon-size;
height: $icon-size;
border-radius: 5px;
}
.style-select-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
}
}
}
}
.q-layout-container > :deep(.absolute-full) {
right: 0 !important;
> .scroll {
width: unset !important;
overflow: hidden;
}
}
</style>