({ onClose, settingsRegistry, initialCategoryId }: SettingsWindowProps)
| 33 | } |
| 34 | |
| 35 | export function SettingsWindow({ onClose, settingsRegistry, initialCategoryId }: SettingsWindowProps) { |
| 36 | const { t } = useLocale(); |
| 37 | |
| 38 | /** |
| 39 | * Resolve localizable text - if it starts with '$', treat as translation key |
| 40 | * 解析可本地化文本 - 如果以 '$' 开头,作为翻译键处理 |
| 41 | */ |
| 42 | const resolveText = (text: string | undefined): string => { |
| 43 | if (!text) return ''; |
| 44 | if (isTranslationKey(text)) { |
| 45 | return t(getTranslationKey(text)); |
| 46 | } |
| 47 | return text; |
| 48 | }; |
| 49 | |
| 50 | const [categories, setCategories] = useState<SettingCategory[]>([]); |
| 51 | const [selectedCategoryId, setSelectedCategoryId] = useState<string | null>(initialCategoryId || null); |
| 52 | const [values, setValues] = useState<Map<string, any>>(new Map()); |
| 53 | const [errors, setErrors] = useState<Map<string, string>>(new Map()); |
| 54 | const [searchTerm, setSearchTerm] = useState(''); |
| 55 | const [expandedSections, setExpandedSections] = useState<Set<string>>(new Set()); |
| 56 | const [expandedMainCategories, setExpandedMainCategories] = useState<Set<string>>(new Set(['general'])); |
| 57 | |
| 58 | // 将分类组织成主分类和子分类 |
| 59 | // Organize categories into main categories and sub-categories |
| 60 | const mainCategories = useMemo((): MainCategory[] => { |
| 61 | const categoryMap = new Map<string, SettingCategory[]>(); |
| 62 | |
| 63 | // 定义主分类映射(使用配置 ID 作为键) |
| 64 | // Main category mapping (using config IDs as keys) |
| 65 | const mainCategoryMapping: Record<string, string> = { |
| 66 | 'appearance': 'general', |
| 67 | 'general': 'general', |
| 68 | 'project': 'general', |
| 69 | 'plugins': 'general', |
| 70 | 'editor': 'general', |
| 71 | 'physics': 'global', |
| 72 | 'rendering': 'global', |
| 73 | 'audio': 'global', |
| 74 | 'world': 'worldPartition', |
| 75 | 'local': 'worldPartitionLocal', |
| 76 | 'performance': 'performance' |
| 77 | }; |
| 78 | |
| 79 | categories.forEach((cat) => { |
| 80 | const mainCatId = mainCategoryMapping[cat.id] || 'other'; |
| 81 | if (!categoryMap.has(mainCatId)) { |
| 82 | categoryMap.set(mainCatId, []); |
| 83 | } |
| 84 | categoryMap.get(mainCatId)!.push(cat); |
| 85 | }); |
| 86 | |
| 87 | // 定义固定的主分类顺序(使用配置 ID) |
| 88 | // Define fixed main category order (using config IDs) |
| 89 | const orderedMainCategories = [ |
| 90 | 'general', |
| 91 | 'global', |
| 92 | 'worldPartition', |
nothing calls this directly
no test coverage detected