mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-29 05:24:30 +08:00
feat: 自定义状态栏编辑工具框架
This commit is contained in:
1 parent
49d8050e03
commit
60d708e5e3
8 files changed
+164
-14
No files matched your search
@@ -1,7 +1,13 @@
|
||||
import { EmitableEvent, EventEmitter } from '@/core/common/eventEmitter';
|
||||
import { KeyCode } from '@/plugin/keyCodes';
|
||||
import { flipBinary, has } from '@/plugin/utils';
|
||||
import { FunctionalComponent, nextTick, reactive } from 'vue';
|
||||
import {
|
||||
FunctionalComponent,
|
||||
markRaw,
|
||||
nextTick,
|
||||
reactive,
|
||||
shallowReactive
|
||||
} from 'vue';
|
||||
import { createToolbarComponents } from '../init/toolbar';
|
||||
import { gameKey } from '../init/hotkey';
|
||||
import { unwarpBinary } from './hotkey';
|
||||
@@ -12,7 +18,7 @@ interface CustomToolbarEvent extends EmitableEvent {
|
||||
add: (item: ValueOf<ToolbarItemMap>) => void;
|
||||
delete: (item: ValueOf<ToolbarItemMap>) => void;
|
||||
set: (id: string, data: Partial<SettableItemData>) => void;
|
||||
emit: (id: string) => void;
|
||||
emit: (id: string, item: ValueOf<ToolbarItemMap>) => void;
|
||||
}
|
||||
|
||||
interface ToolbarItemBase<T extends ToolbarItemType> {
|
||||
@@ -70,7 +76,7 @@ const comMap: {
|
||||
|
||||
export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
|
||||
static num: number = 0;
|
||||
static list: CustomToolbar[] = [];
|
||||
static list: CustomToolbar[] = shallowReactive([]);
|
||||
|
||||
items: ValueOf<ToolbarItemMap>[] = reactive([]);
|
||||
num: number = CustomToolbar.num++;
|
||||
@@ -97,7 +103,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
|
||||
add<K extends ToolbarItemType>(item: Omit<ToolbarItemMap[K], 'com'>) {
|
||||
// @ts-ignore
|
||||
const data: ToolbarItemMap[K] = {
|
||||
com: comMap[item.type],
|
||||
com: markRaw(comMap[item.type]),
|
||||
...item
|
||||
} as ToolbarItemMap[K];
|
||||
this.items.push(data);
|
||||
@@ -141,7 +147,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
|
||||
emitTool(id: string) {
|
||||
const item = this.items.find(v => v.id === id);
|
||||
if (!item) return this;
|
||||
this.emit(id);
|
||||
this.emit('emit', id, item);
|
||||
if (item.type === 'hotkey') {
|
||||
// 按键
|
||||
const assist = item.assist | this.assistKey;
|
||||
|
||||
@@ -8,7 +8,7 @@ interface Components {
|
||||
BooleanSetting: SettingComponent;
|
||||
NumberSetting: SettingComponent;
|
||||
HotkeySetting: SettingComponent;
|
||||
ToolbarSetting: SettingComponent;
|
||||
ToolbarEditor: SettingComponent;
|
||||
}
|
||||
|
||||
export function createSettingComponents() {
|
||||
@@ -17,7 +17,7 @@ export function createSettingComponents() {
|
||||
BooleanSetting,
|
||||
NumberSetting,
|
||||
HotkeySetting,
|
||||
ToolbarSetting
|
||||
ToolbarEditor
|
||||
};
|
||||
return com;
|
||||
}
|
||||
@@ -104,15 +104,14 @@ function HotkeySetting(props: SettingComponentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function ToolbarSetting(props: SettingComponentProps) {
|
||||
// todo: toolSetting.vue
|
||||
function ToolbarEditor(props: SettingComponentProps) {
|
||||
return (
|
||||
<div style="display: flex; justify-content: center">
|
||||
<Button
|
||||
style="font-size: 75%"
|
||||
type="primary"
|
||||
size="large"
|
||||
onClick={() => showSpecialSetting('toolSetting')}
|
||||
onClick={() => showSpecialSetting('toolEditor')}
|
||||
>
|
||||
自定义工具栏
|
||||
</Button>
|
||||
|
||||
@@ -16,7 +16,8 @@ mainUi.register(
|
||||
new GameUi('shop', UI.Shop),
|
||||
new GameUi('achievement', UI.Achievement),
|
||||
new GameUi('bgm', UI.BgmList),
|
||||
new GameUi('hotkey', UI.Hotkey)
|
||||
new GameUi('hotkey', UI.Hotkey),
|
||||
new GameUi('toolEditor', UI.ToolEditor)
|
||||
// todo: 把游戏主 div 加入到 mainUi 里面
|
||||
);
|
||||
mainUi.showAll();
|
||||
|
||||
@@ -391,7 +391,7 @@ mainSetting
|
||||
.register('fixed', '定点查看', true, COM.BooleanSetting)
|
||||
.register('hotkey', '快捷键', false, COM.HotkeySetting)
|
||||
.setDisplayFunc('hotkey', () => '')
|
||||
.register('toolbar', '自定义工具栏', false, COM.BooleanSetting)
|
||||
.register('toolbar', '自定义工具栏', false, COM.ToolbarEditor)
|
||||
.setDisplayFunc('toolbar', () => '')
|
||||
)
|
||||
.register(
|
||||
|
||||
Reference in new issue
Block a user