Skip to content

Commit 448370c

Browse files
committed
feat(editor2): set default title with selecting level
1 parent 1be3634 commit 448370c

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/components/editor2/InfoEditor.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { memo } from 'react'
1414
import { Paths } from 'type-fest'
1515

1616
import { i18n, useTranslation } from '../../i18n/i18n'
17+
import { isCustomLevel } from '../../models/level'
1718
import { DifficultyPicker } from './DifficultyPicker'
1819
import { LevelSelect } from './LevelSelect'
1920
import { editorAtoms, useEdit } from './editor-state'
@@ -100,10 +101,19 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
100101
<LevelSelect
101102
difficulty={info.difficulty}
102103
value={info.stageName}
103-
onChange={(value) => {
104+
onChange={(stageId, level) => {
104105
edit(() => {
105106
setInfo((prev) => {
106-
prev.stageName = value
107+
prev.stageName = stageId
108+
109+
if (level && !prev.doc.title) {
110+
// 如果没有标题,则使用关卡名作为标题
111+
prev.doc.title = isCustomLevel(level)
112+
? level.name
113+
: [level.catTwo, level.catThree, level.name]
114+
.filter(Boolean)
115+
.join(' - ')
116+
}
107117
})
108118
return {
109119
action: 'update-level',

src/components/editor2/LevelSelect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface LevelSelectProps {
2727
inputRef?: Ref<HTMLInputElement>
2828
disabled?: boolean
2929
value?: string
30-
onChange: (level: string) => void
30+
onChange: (stageId: string, level?: Level) => void
3131
}
3232

3333
export const LevelSelect: FC<LevelSelectProps> = ({
@@ -203,7 +203,7 @@ export const LevelSelect: FC<LevelSelectProps> = ({
203203
// 重置 query 以显示同类关卡
204204
updateQuery('', true)
205205
}
206-
onChange(level.stageId)
206+
onChange(level.stageId, level)
207207
}}
208208
createNewItemFromQuery={(query) => createCustomLevel(query)}
209209
createNewItemRenderer={(query, active, handleClick) => (

src/i18n/translations.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3402,12 +3402,18 @@
34023402
"en": "Failed to parse operation"
34033403
}
34043404
},
3405+
"level": {
3406+
"custom_level": {
3407+
"cn": "自定义关卡",
3408+
"en": "Custom Stage"
3409+
}
3410+
},
34053411
"operator": {
34063412
"operator": {
34073413
"cn": "干员",
34083414
"en": "Operator"
34093415
},
3410-
"operator_group":{
3416+
"operator_group": {
34113417
"cn": "干员组",
34123418
"en": "Operator Group"
34133419
},

src/models/level.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* Only the first two kinds are supported in MAA Copilot.
1010
*/
11+
import { i18n } from '../i18n/i18n'
1112
import { Level, OpDifficulty } from './operation'
1213

1314
const HARD_MODE_SUFFIX = '#f#'
@@ -22,7 +23,7 @@ export function createCustomLevel(name: string): Level {
2223
name,
2324
stageId: name,
2425
levelId: '',
25-
catOne: '自定义关卡',
26+
catOne: i18n.models.level.custom_level,
2627
catTwo: '',
2728
catThree: name,
2829
width: 0,

0 commit comments

Comments
 (0)