Skip to content

Commit 597c2ee

Browse files
committed
feat(editor2): i18n operator names
1 parent 9910bcd commit 597c2ee

File tree

7 files changed

+139
-104
lines changed

7 files changed

+139
-104
lines changed

src/components/editor2/action/ActionItem.tsx

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,18 @@ import { Tooltip2 } from '@blueprintjs/popover2'
1212

1313
import clsx from 'clsx'
1414
import { Draft } from 'immer'
15-
import { PrimitiveAtom, atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
15+
import { PrimitiveAtom, useAtom, useAtomValue, useSetAtom } from 'jotai'
1616
import { useImmerAtom } from 'jotai-immer'
1717
import { selectAtom } from 'jotai/utils'
18-
import {
19-
FC,
20-
ReactNode,
21-
memo,
22-
useEffect,
23-
useMemo,
24-
useRef,
25-
useState,
26-
} from 'react'
18+
import { FC, ReactNode, memo, useEffect, useRef, useState } from 'react'
2719

2820
import { i18n, languageAtom, useTranslation } from '../../../i18n/i18n'
2921
import { CopilotDocV1 } from '../../../models/copilot.schema'
3022
import {
3123
actionDocColors,
3224
alternativeOperatorSkillUsages,
3325
findOperatorByName,
26+
getLocalizedOperatorName,
3427
getSkillUsageAltTitle,
3528
} from '../../../models/operator'
3629
import { findActionType } from '../../../models/types'
@@ -664,45 +657,43 @@ const ActionTarget: FC<{
664657
>
665658
>
666659
}> = ({ actionAtom }) => {
660+
const language = useAtomValue(languageAtom)
667661
const t = useTranslation()
668662
const edit = useEdit()
669-
const [action, setAction] = useAtom(actionAtom)
663+
const [{ name }, setAction] = useAtom(actionAtom)
670664
const groupNames = useAtomValue(groupNamesAtom)
671-
const operator = useAtomValue(
672-
useMemo(
673-
() =>
674-
atom((get) =>
675-
get(editorAtoms.operators).find((op) => op.name === action.name),
676-
),
677-
[action.name],
678-
),
679-
)
665+
680666
const isGroup = (name?: string) =>
681667
name !== undefined && groupNames.includes(name)
682668

683-
const operatorInfo = operator && findOperatorByName(operator.name)
684-
const displayName =
685-
operatorInfo?.name ||
686-
action.name ||
687-
(isGroup(action.name)
688-
? t.components.editor2.ActionItem.unnamed_group
689-
: t.components.editor2.ActionItem.select_target)
690-
const subtitle = isGroup(action.name)
691-
? t.components.editor2.ActionItem.group
692-
: operatorInfo
693-
? operatorInfo?.prof === 'TOKEN'
694-
? t.components.editor2.ActionItem.token
695-
: t.components.editor2.ActionItem.operator
696-
: // 自定义干员、关卡里的道具之类
697-
t.components.editor2.ActionItem.unknown_target
669+
let displayName: string | undefined
670+
let subtitle = '<<<'
671+
672+
if (name !== undefined) {
673+
if (isGroup(name)) {
674+
displayName = name || t.components.editor2.ActionItem.unnamed_group
675+
subtitle = t.components.editor2.label.operation.groups._item
676+
} else {
677+
displayName = getLocalizedOperatorName(name, language)
678+
679+
const operatorInfo = findOperatorByName(name)
680+
subtitle = operatorInfo
681+
? operatorInfo.prof === 'TOKEN'
682+
? t.components.editor2.ActionItem.token
683+
: t.components.editor2.label.opers._item
684+
: // 自定义干员、关卡里的道具之类
685+
t.components.editor2.ActionItem.unknown_target
686+
}
687+
}
688+
698689
return (
699690
<OperatorSelect
700691
liftPicked
701692
className="shrink-0"
702-
value={action.name}
693+
value={name}
703694
onSelect={(name) => {
704695
edit(() => {
705-
setAction({ ...action, name })
696+
setAction((prev) => ({ ...prev, name }))
706697
return {
707698
action: 'set-action-name',
708699
desc: i18n.actions.editor2.set_action_target,
@@ -714,21 +705,24 @@ const ActionTarget: FC<{
714705
<div className="flex items-center">
715706
<OperatorAvatar
716707
className="w-16 h-16"
717-
name={isGroup(action.name) ? undefined : action.name}
718-
fallback={
719-
isGroup(action.name) ? (
720-
<Icon icon="people" size={32} />
721-
) : (
722-
action.name
723-
)
724-
}
708+
name={isGroup(name) ? undefined : name}
709+
fallback={isGroup(name) ? <Icon icon="people" size={32} /> : name}
725710
/>
726711
<div className="ml-1 w-[6.5em]">
727712
<div
728-
className={clsx('truncate', displayName.length > 6 && 'text-xs')}
729-
title={displayName.length > 6 ? displayName : undefined}
713+
className={clsx(
714+
'leading-4 tracking-tighter',
715+
displayName && displayName?.length > 6 && 'text-xs',
716+
)}
717+
title={displayName}
730718
>
731-
{displayName}
719+
{displayName === undefined ? (
720+
<span className="text-gray-500">
721+
{t.components.editor2.ActionItem.select_target}
722+
</span>
723+
) : (
724+
displayName
725+
)}
732726
</div>
733727
<Divider className="m-0 mr-1" />
734728
<div className="text-gray-500 text-xs font-normal truncate">

src/components/editor2/operator/OperatorEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
1818
import { selectAtom, useAtomCallback } from 'jotai/utils'
1919
import { FC, memo, useCallback, useMemo } from 'react'
2020

21-
import { i18n, useTranslation } from '../../../i18n/i18n'
21+
import { i18n, languageAtom, useTranslation } from '../../../i18n/i18n'
22+
import { getLocalizedOperatorName } from '../../../models/operator'
2223
import { Droppable, Sortable } from '../../dnd'
2324
import { AtomRenderer } from '../AtomRenderer'
2425
import {
@@ -322,6 +323,7 @@ const operatorErrorsAtom = atom((get) => {
322323

323324
const OperatorError = () => {
324325
const errors = useAtomValue(operatorErrorsAtom)
326+
const language = useAtomValue(languageAtom)
325327
const t = useTranslation()
326328
if (!errors) return null
327329

@@ -332,12 +334,12 @@ const OperatorError = () => {
332334
<p key={operator.id + path.join()} className="error-message">
333335
{fieldLabel
334336
? t.components.editor2.OperatorEditor.operator_field_error({
335-
name: operator.name,
337+
name: getLocalizedOperatorName(operator.name, language),
336338
field: fieldLabel,
337339
error: message,
338340
})
339341
: t.components.editor2.OperatorEditor.operator_error({
340-
name: operator.name,
342+
name: getLocalizedOperatorName(operator.name, language),
341343
error: message,
342344
})}
343345
</p>

src/components/editor2/operator/OperatorItem.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
getEliteIconUrl,
2626
getSkillCount,
2727
getSkillUsageAltTitle,
28+
useLocalizedOperatorName,
2829
withDefaultRequirements,
2930
} from '../../../models/operator'
3031
import { MasteryIcon } from '../../MasteryIcon'
@@ -64,6 +65,7 @@ export const OperatorItem: FC<OperatorItemProps> = memo(
6465
}) => {
6566
const t = useTranslation()
6667
const edit = useEdit()
68+
const displayName = useLocalizedOperatorName(operator.name)
6769
const [skillLevels, setSkillLevels] = useAtom(
6870
editorAtoms.skillLevelOverrides(operator.id),
6971
)
@@ -117,15 +119,15 @@ export const OperatorItem: FC<OperatorItemProps> = memo(
117119
id={info?.id}
118120
rarity={info?.rarity}
119121
className="w-24 h-24 rounded-b-none"
120-
fallback={operator.name}
122+
fallback={displayName}
121123
/>
122124
<h4
123125
className={clsx(
124-
'm-1 leading-5 font-bold pointer-events-none',
125-
operator.name && operator.name.length >= 7 && 'text-xs',
126+
'm-1 leading-4 font-semibold tracking-tighter pointer-events-none',
127+
displayName.length >= 12 && 'text-xs',
126128
)}
127129
>
128-
{operator.name}
130+
{displayName}
129131
</h4>
130132
{info && info.prof !== 'TOKEN' && (
131133
<img

0 commit comments

Comments
 (0)