import { KeyCode, KeyCodeUtils } from '@/plugin/keyCodes'; import type { CustomToolbarComponent, CustomToolbarProps } from '../custom/toolbar'; import BoxAnimate from '@/components/boxAnimate.vue'; import { checkAssist } from '../custom/hotkey'; import { getVitualKeyOnce } from '@/plugin/utils'; import { cloneDeep } from 'lodash-es'; import { Button, InputNumber, Select, SelectOption, Switch } from 'ant-design-vue'; import { mainSetting } from '../setting'; import Minimap from '@/components/minimap.vue'; // todo: 新增更改设置的ToolItem interface Components { DefaultTool: CustomToolbarComponent; KeyTool: CustomToolbarComponent<'hotkey'>; ItemTool: CustomToolbarComponent<'item'>; AssistKeyTool: CustomToolbarComponent<'assistKey'>; MinimapTool: CustomToolbarComponent<'minimap'>; } export function createToolbarComponents() { const com: Components = { DefaultTool, KeyTool, ItemTool, AssistKeyTool, MinimapTool }; return com; } export function createToolbarEditorComponents() { const com: Components = { DefaultTool: DefaultToolEditor, KeyTool: KeyToolEdtior, ItemTool: ItemToolEditor, AssistKeyTool: AssistKeyToolEditor, MinimapTool: MinimapToolEditor }; return com; } function DefaultTool(props: CustomToolbarProps) { return 未知工具; } function KeyTool(props: CustomToolbarProps<'hotkey'>) { const { item, toolbar } = props; return ( toolbar.emitTool(item.id)}> {KeyCodeUtils.toString(item.key)} ); } function ItemTool(props: CustomToolbarProps<'item'>) { const { item, toolbar } = props; const scale = mainSetting.getValue('ui.toolbarScale', 100) / 100; return (
toolbar.emitTool(item.id)} >
); } function AssistKeyTool(props: CustomToolbarProps<'assistKey'>) { const { item, toolbar } = props; const pressed = checkAssist(toolbar.assistKey, item.assist); return ( toolbar.emitTool(item.id).refresh()} > {KeyCodeUtils.toString(item.assist)} ); } function MinimapTool(props: CustomToolbarProps<'minimap'>) { const { item, toolbar } = props; return (
); } function DefaultToolEditor(props: CustomToolbarProps) { return ; } function KeyToolEdtior(props: CustomToolbarProps<'hotkey'>) { const { item, toolbar } = props; const getKey = async () => { const { key, assist } = await getVitualKeyOnce(false, item.assist); toolbar.set<'hotkey'>(item.id, { key, assist }); }; const unwarpAssist = (assist: number) => { let res = ''; if (assist & (1 << 0)) { res += 'Ctrl + '; } if (assist & (1 << 1)) { res += 'Shift + '; } if (assist & (1 << 2)) { res += 'Alt + '; } return res; }; const getKeyShow = (key: KeyCode, assist: number) => { return unwarpAssist(assist) + KeyCodeUtils.toString(key); }; return (
触发按键 {getKeyShow(item.key, item.assist)}
); } function ItemToolEditor(props: CustomToolbarProps<'item'>) { const { item, toolbar } = props; const items = cloneDeep(core.status.hero.items.constants); Object.assign(items, core.status.hero.items.tools); return (
使用道具
); } function AssistKeyToolEditor(props: CustomToolbarProps<'assistKey'>) { const { item, toolbar } = props; return (
辅助按键
); } function MinimapToolEditor(props: CustomToolbarProps<'minimap'>) { const { item, toolbar } = props; type K = keyof typeof item; const setConfig: (key: T, value: (typeof item)[T]) => void = ( key, value ) => { let v = value; if (key === 'height' || key === 'height') { if ((v as number) > 1000) (v as number) = 1000; if ((v as number) < 50) (v as number) = 50; } else if (key === 'scale') { if ((v as number) > 20) (v as number) = 20; if ((v as number) < 1) (v as number) = 1; } toolbar.set(item.id, { [key]: v }); toolbar.refresh(); }; return (
宽度
setConfig('width', value as number)} >
高度
setConfig('height', value as number)} >
放缩比例
setConfig('scale', value as number)} >
无边框模式 setConfig('noBorder', !item.noBorder)} >
显示漏怪 setConfig('showInfo', !item.showInfo)} >
自动居中 setConfig('autoLocate', !item.autoLocate)} >
允许交互 setConfig('action', !item.action)} >
); }