Skip to content

Commit 9e9eb1c

Browse files
committed
拖拽替换 PV
1 parent 5a8e93f commit 9e9eb1c

File tree

6 files changed

+109
-17
lines changed

6 files changed

+109
-17
lines changed

AquaMai

MaiChartManager/Front/src/components/DragDropDispatcher/index.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { useDropZone } from '@vueuse/core';
22
import { defineComponent, PropType, ref, computed, watch, shallowRef } from 'vue';
33
import { startProcess as startProcessMusicImport } from '@/components/ImportCreateChartButton/ImportChartButton';
4+
import { uploadFlow as uploadFlowMovie } from '@/components/MusicEdit/SetMovieButton';
5+
import { selectedADir, selectedMusic } from '@/store/refs';
46

57
export const mainDivRef = shallowRef<HTMLDivElement>();
68

9+
enum DropType {
10+
None,
11+
Charts,
12+
Video,
13+
}
14+
715
export default defineComponent({
816
// props: {
917
// },
@@ -13,12 +21,24 @@ export default defineComponent({
1321
console.log(files);
1422
const items = e.dataTransfer?.items;
1523
if (!items?.length) return;
24+
const firstType = items[0].type;
25+
console.log(firstType);
1626
const handles = await Promise.all(Array.from(items).map(item => item.getAsFileSystemHandle()));
1727
console.log(handles);
1828
if (handles.every(handle => handle instanceof FileSystemDirectoryHandle)) {
1929
startProcessMusicImport(handles.length === 1 ? handles[0] : handles);
2030
}
31+
else if (handles.length === 1 && handles[0] instanceof FileSystemFileHandle) {
32+
if (selectedADir.value === 'A000') return;
33+
if (!selectedMusic.value) return;
34+
const file = handles[0] as FileSystemFileHandle;
35+
if (file.kind === 'file' && (firstType.startsWith('video/') || ['dat', 'usm'].includes(file.name.toLowerCase().split('.').pop()!))) {
36+
uploadFlowMovie(file);
37+
}
38+
}
2139
}
40+
const dropType = ref<DropType>(DropType.None);
41+
2242

2343
const { isOverDropZone } = useDropZone(mainDivRef, {
2444
onDrop,
@@ -29,13 +49,41 @@ export default defineComponent({
2949
// whether to prevent default behavior for unhandled events
3050
preventDefaultForUnhandled: true,
3151
onOver(f, e) {
52+
dropType.value = DropType.None;
3253
e.stopPropagation();
33-
if (e.dataTransfer)
54+
if (e.dataTransfer) {
55+
// 由于没法判断是不是文件夹也不知道扩展名,所以没法给出推理
56+
// const items = e.dataTransfer.items;
57+
// console.log(items[0].type);
58+
// if (items?.length) {
59+
// const allDirectories = Array.from(items).every(item => item.kind === 'file' && item.type === '');
60+
// if (allDirectories) {
61+
// dropType.value = DropType.Charts;
62+
// }
63+
// }
64+
// if (items.length === 1) {
65+
// const item = items[0];
66+
// if (item.type.startsWith('video/') && selectedMusic.value){
67+
// dropType.value = DropType.Video;
68+
// }
69+
// }
70+
71+
// if (dropType.value === DropType.None) {
72+
// e.dataTransfer.dropEffect = 'none';
73+
// }
74+
// else {
3475
e.dataTransfer.dropEffect = 'copy';
76+
// }
77+
}
3578
},
3679
});
3780

3881
return () => <>
82+
{isOverDropZone.value && dropType.value !== DropType.None && <div class="absolute-full z-100 bg-white/50 backdrop-blur-sm flex justify-center items-center" >
83+
{/* {dropType.value === DropType.Charts && selectedADir.value !== 'A000' && <div class="text-2xl">
84+
松开鼠标导入谱面
85+
</div>} */}
86+
</div>}
3987
</>;
4088
},
4189
});

MaiChartManager/Front/src/components/MusicEdit/SetMovieButton.tsx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ enum STEP {
1616
Progress,
1717
}
1818

19+
export let uploadFlow = async (fileHandle?: FileSystemFileHandle) => {
20+
}
21+
1922
export default defineComponent({
2023
props: {
2124
disabled: Boolean,
@@ -84,28 +87,48 @@ export default defineComponent({
8487
});
8588
})
8689

87-
const uploadFlow = async () => {
90+
uploadFlow = async (fileHandle?: FileSystemFileHandle) => {
8891
step.value = STEP.Select
8992
try {
90-
const [fileHandle] = await window.showOpenFilePicker({
91-
id: 'movie',
92-
startIn: 'downloads',
93-
types: [
94-
{
95-
description: t('music.edit.supportedFileTypes'),
96-
accept: {
97-
"video/*": [".dat"],
98-
"image/*": [],
93+
if (!fileHandle) {
94+
[fileHandle] = await window.showOpenFilePicker({
95+
id: 'movie',
96+
startIn: 'downloads',
97+
types: [
98+
{
99+
description: t('music.edit.supportedFileTypes'),
100+
accept: {
101+
"video/*": [".dat"],
102+
"image/*": [],
103+
},
99104
},
100-
},
101-
],
102-
});
105+
],
106+
});
107+
}
103108
step.value = STEP.None
104109
if (!fileHandle) return;
105110
const file = await fileHandle.getFile() as File;
106111

107112
if (file.name.endsWith('.dat')) {
108113
load.value = true;
114+
await new Promise<void>((resolve, reject) => {
115+
dialog.info({
116+
showIcon: false,
117+
title: t('common.confirm'),
118+
content: t('music.edit.confirmSetMovie', { filename: file.name }),
119+
positiveText: t('common.confirm'),
120+
negativeText: t('common.cancel'),
121+
positiveButtonProps: {
122+
type: 'primary',
123+
},
124+
onPositiveClick: () => {
125+
resolve();
126+
},
127+
onNegativeClick: () => {
128+
reject(new DOMException('', 'AbortError'));
129+
},
130+
})
131+
})
109132
await api.SetMovie(props.song.id!, selectedADir.value, { file, padding: 0 });
110133
} else if (version.value?.license !== LicenseStatus.Active) {
111134
showNeedPurchaseDialog.value = true;
@@ -134,7 +157,7 @@ export default defineComponent({
134157
}
135158
}
136159

137-
return () => <NButton secondary onClick={uploadFlow} loading={load.value} disabled={props.disabled}>
160+
return () => <NButton secondary onClick={() => uploadFlow()} loading={load.value} disabled={props.disabled}>
138161
{t('music.edit.setPv')}
139162

140163
<NDrawer show={step.value === STEP.Select} height={250} placement="bottom">
@@ -151,7 +174,7 @@ export default defineComponent({
151174
</NDrawer>
152175
<NModal
153176
preset="card"
154-
class="w-[min(30vw,25em)]"
177+
class="w-[min(30vw,30em)]"
155178
title={t('music.edit.setOffsetSeconds')}
156179
show={step.value === STEP.Offset}
157180
onUpdateShow={() => step.value = STEP.None}

MaiChartManager/Front/src/locales/en.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ mod:
342342
button2P: 2P Button {index}
343343
select1P: 1P Select
344344
select2P: 2P Select
345+
soundChannel:
346+
P1SpeakerLeft: 1P Speaker Left
347+
P1SpeakerRight: 1P Speaker Right
348+
P1HeadphoneLeft: 1P Headphone Left
349+
P1HeadphoneRight: 1P Headphone Right
350+
P2SpeakerLeft: 2P Speaker Left
351+
P2SpeakerRight: 2P Speaker Right
352+
P2HeadphoneLeft: 2P Headphone Left
353+
P2HeadphoneRight: 2P Headphone Right
354+
None: Disabled
345355
judgeAccuracyInfo:
346356
author: 'Author: '
347357
viewDoc: View Documentation

MaiChartManager/Front/src/locales/zh-TW.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ mod:
311311
button2P: 2P 按鍵 {index}
312312
select1P: 1P 選擇鍵
313313
select2P: 2P 選擇鍵
314+
soundChannel:
315+
P1SpeakerLeft: 1P 外放左
316+
P1SpeakerRight: 1P 外放右
317+
P1HeadphoneLeft: 1P 耳機左
318+
P1HeadphoneRight: 1P 耳機右
319+
P2SpeakerLeft: 2P 外放左
320+
P2SpeakerRight: 2P 外放右
321+
P2HeadphoneLeft: 2P 耳機左
322+
P2HeadphoneRight: 2P 耳機右
323+
None: 停用
314324
judgeAccuracyInfo:
315325
author: 作者:
316326
viewDoc: 檢視說明檔案

MaiChartManager/Front/src/locales/zh.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ music:
121121
如果游戏版本是 1.{gameVersion} 的话,这里的数字大于等于 {b15ver} 就会让歌出现在 B15 里面,否则就会出现在 B35
122122
里面。这个值还会控制按上线时间排序时的顺序
123123
idConflictWarning: 以下目录中存在冲突的 ID
124+
confirmSetMovie: 确认要使用 {filename} 替换当前的 PV 吗
124125
batch:
125126
title: 批量操作
126127
batchAndSearch: 批量操作与搜索

0 commit comments

Comments
 (0)