@@ -12,25 +12,18 @@ import { Tooltip2 } from '@blueprintjs/popover2'
12
12
13
13
import clsx from 'clsx'
14
14
import { Draft } from 'immer'
15
- import { PrimitiveAtom , atom , useAtom , useAtomValue , useSetAtom } from 'jotai'
15
+ import { PrimitiveAtom , useAtom , useAtomValue , useSetAtom } from 'jotai'
16
16
import { useImmerAtom } from 'jotai-immer'
17
17
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'
27
19
28
20
import { i18n , languageAtom , useTranslation } from '../../../i18n/i18n'
29
21
import { CopilotDocV1 } from '../../../models/copilot.schema'
30
22
import {
31
23
actionDocColors ,
32
24
alternativeOperatorSkillUsages ,
33
25
findOperatorByName ,
26
+ getLocalizedOperatorName ,
34
27
getSkillUsageAltTitle ,
35
28
} from '../../../models/operator'
36
29
import { findActionType } from '../../../models/types'
@@ -664,45 +657,43 @@ const ActionTarget: FC<{
664
657
>
665
658
>
666
659
} > = ( { actionAtom } ) => {
660
+ const language = useAtomValue ( languageAtom )
667
661
const t = useTranslation ( )
668
662
const edit = useEdit ( )
669
- const [ action , setAction ] = useAtom ( actionAtom )
663
+ const [ { name } , setAction ] = useAtom ( actionAtom )
670
664
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
+
680
666
const isGroup = ( name ?: string ) =>
681
667
name !== undefined && groupNames . includes ( name )
682
668
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
+
698
689
return (
699
690
< OperatorSelect
700
691
liftPicked
701
692
className = "shrink-0"
702
- value = { action . name }
693
+ value = { name }
703
694
onSelect = { ( name ) => {
704
695
edit ( ( ) => {
705
- setAction ( { ...action , name } )
696
+ setAction ( ( prev ) => ( { ...prev , name } ) )
706
697
return {
707
698
action : 'set-action-name' ,
708
699
desc : i18n . actions . editor2 . set_action_target ,
@@ -714,21 +705,24 @@ const ActionTarget: FC<{
714
705
< div className = "flex items-center" >
715
706
< OperatorAvatar
716
707
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 }
725
710
/>
726
711
< div className = "ml-1 w-[6.5em]" >
727
712
< 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 }
730
718
>
731
- { displayName }
719
+ { displayName === undefined ? (
720
+ < span className = "text-gray-500" >
721
+ { t . components . editor2 . ActionItem . select_target }
722
+ </ span >
723
+ ) : (
724
+ displayName
725
+ ) }
732
726
</ div >
733
727
< Divider className = "m-0 mr-1" />
734
728
< div className = "text-gray-500 text-xs font-normal truncate" >
0 commit comments