2025-11-27 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Editor Appearance Plugin
|
|
|
|
|
|
* 编辑器外观插件
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import type { ServiceContainer } from '@esengine/ecs-framework';
|
2025-10-17 23:47:04 +08:00
|
|
|
|
import { createLogger } from '@esengine/ecs-framework';
|
2025-12-03 22:15:22 +08:00
|
|
|
|
import type { IPlugin, IEditorModuleLoader, ModuleManifest } from '@esengine/editor-core';
|
2025-11-27 20:42:46 +08:00
|
|
|
|
import { SettingsRegistry } from '@esengine/editor-core';
|
|
|
|
|
|
import { SettingsService } from '../../services/SettingsService';
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
|
|
|
|
|
const logger = createLogger('EditorAppearancePlugin');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-27 20:42:46 +08:00
|
|
|
|
* Editor Appearance 编辑器模块
|
2025-10-17 23:47:04 +08:00
|
|
|
|
*/
|
2025-11-27 20:42:46 +08:00
|
|
|
|
class EditorAppearanceEditorModule implements IEditorModuleLoader {
|
|
|
|
|
|
async install(services: ServiceContainer): Promise<void> {
|
2025-11-02 23:50:41 +08:00
|
|
|
|
const settingsRegistry = services.resolve(SettingsRegistry);
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
settingsRegistry.registerCategory({
|
|
|
|
|
|
id: 'appearance',
|
|
|
|
|
|
title: '外观',
|
|
|
|
|
|
description: '配置编辑器的外观设置',
|
|
|
|
|
|
sections: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'font',
|
|
|
|
|
|
title: '字体设置',
|
|
|
|
|
|
description: '配置编辑器字体样式',
|
|
|
|
|
|
settings: [
|
|
|
|
|
|
{
|
|
|
|
|
|
key: 'editor.fontSize',
|
|
|
|
|
|
label: '字体大小 (px)',
|
|
|
|
|
|
type: 'range',
|
|
|
|
|
|
defaultValue: 13,
|
|
|
|
|
|
description: '编辑器界面的字体大小',
|
|
|
|
|
|
min: 11,
|
|
|
|
|
|
max: 18,
|
|
|
|
|
|
step: 1
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2025-11-18 14:46:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'inspector',
|
|
|
|
|
|
title: '检视器设置',
|
|
|
|
|
|
description: '配置属性检视器显示',
|
|
|
|
|
|
settings: [
|
|
|
|
|
|
{
|
|
|
|
|
|
key: 'inspector.decimalPlaces',
|
|
|
|
|
|
label: '数字小数位数',
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
defaultValue: 4,
|
|
|
|
|
|
description: '数字类型属性显示的小数位数,设置为 -1 表示不限制',
|
|
|
|
|
|
min: -1,
|
|
|
|
|
|
max: 10,
|
|
|
|
|
|
step: 1
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2025-12-04 14:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'scriptEditor',
|
|
|
|
|
|
title: '脚本编辑器',
|
|
|
|
|
|
description: '配置用于打开脚本文件的外部编辑器',
|
|
|
|
|
|
settings: [
|
|
|
|
|
|
{
|
|
|
|
|
|
key: 'editor.scriptEditor',
|
|
|
|
|
|
label: '脚本编辑器',
|
|
|
|
|
|
type: 'select',
|
|
|
|
|
|
defaultValue: 'system',
|
|
|
|
|
|
description: '双击脚本文件时使用的编辑器',
|
|
|
|
|
|
options: SettingsService.SCRIPT_EDITORS.map(editor => ({
|
|
|
|
|
|
value: editor.id,
|
|
|
|
|
|
label: editor.name
|
|
|
|
|
|
}))
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
key: 'editor.customScriptEditorCommand',
|
|
|
|
|
|
label: '自定义编辑器命令',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
defaultValue: '',
|
|
|
|
|
|
description: '当选择"自定义"时,填写编辑器的命令行命令(如 notepad++)',
|
|
|
|
|
|
placeholder: '例如:notepad++'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2025-11-02 23:50:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
});
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
this.applyFontSettings();
|
|
|
|
|
|
this.setupSettingsListener();
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
logger.info('Installed');
|
|
|
|
|
|
}
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
async uninstall(): Promise<void> {
|
|
|
|
|
|
logger.info('Uninstalled');
|
|
|
|
|
|
}
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
async onEditorReady(): Promise<void> {
|
|
|
|
|
|
logger.info('Editor is ready');
|
|
|
|
|
|
}
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
private applyFontSettings(): void {
|
|
|
|
|
|
const settings = SettingsService.getInstance();
|
|
|
|
|
|
const baseFontSize = settings.get<number>('editor.fontSize', 13);
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
logger.info(`Applying font size: ${baseFontSize}px`);
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
|
root.style.setProperty('--font-size-xs', `${baseFontSize - 2}px`);
|
|
|
|
|
|
root.style.setProperty('--font-size-sm', `${baseFontSize - 1}px`);
|
|
|
|
|
|
root.style.setProperty('--font-size-base', `${baseFontSize}px`);
|
|
|
|
|
|
root.style.setProperty('--font-size-md', `${baseFontSize + 1}px`);
|
|
|
|
|
|
root.style.setProperty('--font-size-lg', `${baseFontSize + 3}px`);
|
|
|
|
|
|
root.style.setProperty('--font-size-xl', `${baseFontSize + 5}px`);
|
|
|
|
|
|
}
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
private setupSettingsListener(): void {
|
|
|
|
|
|
window.addEventListener('settings:changed', ((event: CustomEvent) => {
|
|
|
|
|
|
const changedSettings = event.detail;
|
|
|
|
|
|
logger.info('Settings changed event received', changedSettings);
|
2025-10-17 23:47:04 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
if ('editor.fontSize' in changedSettings) {
|
|
|
|
|
|
logger.info('Font size changed, applying...');
|
|
|
|
|
|
this.applyFontSettings();
|
|
|
|
|
|
}
|
|
|
|
|
|
}) as EventListener);
|
|
|
|
|
|
}
|
2025-10-17 23:47:04 +08:00
|
|
|
|
}
|
2025-11-27 20:42:46 +08:00
|
|
|
|
|
2025-12-03 22:15:22 +08:00
|
|
|
|
const manifest: ModuleManifest = {
|
2025-11-27 20:42:46 +08:00
|
|
|
|
id: '@esengine/editor-appearance',
|
2025-12-03 22:15:22 +08:00
|
|
|
|
name: '@esengine/editor-appearance',
|
|
|
|
|
|
displayName: 'Editor Appearance',
|
2025-11-27 20:42:46 +08:00
|
|
|
|
version: '1.0.0',
|
|
|
|
|
|
description: 'Configure editor appearance settings',
|
2025-12-03 22:15:22 +08:00
|
|
|
|
category: 'Other',
|
2025-11-27 20:42:46 +08:00
|
|
|
|
icon: 'Palette',
|
|
|
|
|
|
isCore: true,
|
2025-12-03 22:15:22 +08:00
|
|
|
|
defaultEnabled: true,
|
|
|
|
|
|
isEngineModule: true,
|
|
|
|
|
|
canContainContent: false,
|
|
|
|
|
|
dependencies: [],
|
|
|
|
|
|
exports: {}
|
2025-11-27 20:42:46 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-01 22:28:51 +08:00
|
|
|
|
export const EditorAppearancePlugin: IPlugin = {
|
2025-12-03 22:15:22 +08:00
|
|
|
|
manifest,
|
2025-11-27 20:42:46 +08:00
|
|
|
|
editorModule: new EditorAppearanceEditorModule()
|
|
|
|
|
|
};
|