refactor: 设置的修改部分

This commit is contained in:
unanmed 2023-11-16 22:50:13 +08:00
parent 9271e25dd9
commit d8c98ad7d5
7 changed files with 186 additions and 1555 deletions

View File

@ -2,8 +2,9 @@
<div id="ui-new"> <div id="ui-new">
<div id="ui-main"> <div id="ui-main">
<div id="ui-list"> <div id="ui-list">
<div class="ui-one" v-for="ui of mainUi.stack"> <div class="ui-one" v-for="(ui, index) of mainUi.stack">
<component <component
v-if="show(index)"
:is="ui.ui.component" :is="ui.ui.component"
v-on="ui.vOn ?? {}" v-on="ui.vOn ?? {}"
v-bind="ui.vBind ?? {}" v-bind="ui.vBind ?? {}"
@ -31,6 +32,11 @@ import { hook } from '@/core/main/game';
onMounted(() => { onMounted(() => {
hook.emit('mounted'); hook.emit('mounted');
}); });
function show(index: number) {
if (mainUi.show === 'all') return true;
if (mainUi.show === 'end') return index === mainUi.stack.length - 1;
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -168,6 +168,7 @@ export class UiController extends Focus<IndexedGameUi> {
static list: UiController[] = []; static list: UiController[] = [];
list: Record<string, GameUi> = {}; list: Record<string, GameUi> = {};
num: number = 0; num: number = 0;
show: 'end' | 'all' = 'all';
private hold: boolean = false; private hold: boolean = false;
@ -191,6 +192,20 @@ export class UiController extends Focus<IndexedGameUi> {
}); });
} }
/**
* ui
*/
showEnd() {
this.show = 'end';
}
/**
* ui
*/
showAll() {
this.show = 'all';
}
/** /**
* *
* @param key KeyCode * @param key KeyCode

View File

@ -0,0 +1,110 @@
import type { SettingComponent, SettingComponentProps } from '../setting';
import { Button, InputNumber } from 'ant-design-vue';
import { mainUi } from './ui';
interface Components {
DefaultSetting: SettingComponent;
BooleanSetting: SettingComponent;
NumberSetting: SettingComponent;
HotkeySetting: SettingComponent;
ToolbarSetting: SettingComponent;
}
export function createSettingComponents() {
const com: Components = {
DefaultSetting,
BooleanSetting,
NumberSetting,
HotkeySetting,
ToolbarSetting
};
return com;
}
function DefaultSetting(props: SettingComponentProps) {
return (
<div>
<span> </span>
</div>
);
}
function BooleanSetting(props: SettingComponentProps) {
const { setting, displayer, item } = props;
const changeValue = () => {
setting.setValue(displayer.selectStack.join('.'), !item.value);
displayer.update();
};
return (
<div>
<span> {item.value ? '开启' : '关闭'}</span>
<Button type="primary" size="large" onClick={changeValue}>
{item.value ? '开启' : '关闭'}
</Button>
</div>
);
}
function NumberSetting(props: SettingComponentProps) {
const { setting, displayer, item } = props;
const changeValue = () => {
setting.setValue(displayer.selectStack.join('.'), !item.value);
displayer.update();
};
return (
<div>
<span> </span>
<InputNumber
class="number-input"
size="large"
keyboard={true}
min={item.step?.[0] ?? 0}
max={item.step?.[1] ?? 100}
step={item.step?.[2] ?? 1}
value={item.value as number}
onChange={changeValue}
></InputNumber>
</div>
);
}
function showSpecialSetting(id: string) {
const ui = mainUi.get(id);
mainUi.showEnd();
ui.once('close', () => {
mainUi.showAll();
});
mainUi.open(id);
}
function HotkeySetting(props: SettingComponentProps) {
// todo: hotkey.vue
return (
<div>
<Button
type="primary"
size="large"
onClick={() => showSpecialSetting('hotkey')}
>
</Button>
</div>
);
}
function ToolbarSetting(props: SettingComponentProps) {
// todo: toolSetting.vue
return (
<div>
<Button
type="primary"
size="large"
onClick={() => showSpecialSetting('toolSetting')}
>
</Button>
</div>
);
}

View File

@ -35,6 +35,7 @@ mainUi.register(
new GameUi('bgm', UI.BgmList, exitKey) new GameUi('bgm', UI.BgmList, exitKey)
// todo: 把游戏主 div 加入到 mainUi 里面 // todo: 把游戏主 div 加入到 mainUi 里面
); );
mainUi.showAll();
export const fixedUi = new UiController(true); export const fixedUi = new UiController(true);
fixedUi.register( fixedUi.register(
@ -45,6 +46,7 @@ fixedUi.register(
new GameUi('completeAchi', UI.CompleteAchi), new GameUi('completeAchi', UI.CompleteAchi),
new GameUi('start', UI.Start) new GameUi('start', UI.Start)
); );
fixedUi.showAll();
hook.once('mounted', () => { hook.once('mounted', () => {
const ui = document.getElementById('ui-main')!; const ui = document.getElementById('ui-main')!;

View File

@ -1,21 +1,28 @@
import { Component, reactive } from 'vue'; import { FunctionalComponent, reactive } from 'vue';
import { EmitableEvent, EventEmitter } from '../common/eventEmitter'; import { EmitableEvent, EventEmitter } from '../common/eventEmitter';
import { loading } from '../loader/load'; import { loading } from '../loader/load';
import { hook } from './game'; import { hook } from './game';
import { GameStorage } from './storage'; import { GameStorage } from './storage';
import { triggerFullscreen } from '@/plugin/utils'; import { triggerFullscreen } from '@/plugin/utils';
import { createSettingComponents } from './init/settings';
export interface SettingComponentProps {
item: MotaSettingItem;
setting: MotaSetting;
displayer: SettingDisplayer;
}
export type SettingComponent = FunctionalComponent<SettingComponentProps>;
type MotaSettingType = boolean | number | MotaSetting; type MotaSettingType = boolean | number | MotaSetting;
export interface MotaSettingItem<T extends MotaSettingType = MotaSettingType> { export interface MotaSettingItem<T extends MotaSettingType = MotaSettingType> {
name: string; name: string;
key: string; key: string;
value: T; value: T;
controller: SettingComponent;
defaults?: boolean | number; defaults?: boolean | number;
step?: [number, number, number]; step?: [number, number, number];
display?: (value: T) => string; display?: (value: T) => string;
controller?: Component;
special?: string;
} }
interface SettingEvent extends EmitableEvent { interface SettingEvent extends EmitableEvent {
@ -36,6 +43,8 @@ export interface SettingDisplayInfo {
text: string[]; text: string[];
} }
const COM = createSettingComponents();
export class MotaSetting extends EventEmitter<SettingEvent> { export class MotaSetting extends EventEmitter<SettingEvent> {
readonly list: Record<string, MotaSettingItem> = {}; readonly list: Record<string, MotaSettingItem> = {};
@ -49,15 +58,6 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
} }
} }
/**
*
*/
markSpecial(key: string, sp: string) {
const setting = this.getSettingBy(key.split('.'));
setting.special = sp;
return this;
}
/** /**
* *
* @param key * @param key
@ -67,6 +67,7 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
key: string, key: string,
name: string, name: string,
value: number, value: number,
com?: SettingComponent,
step?: [number, number, number] step?: [number, number, number]
): this; ): this;
/** /**
@ -74,17 +75,24 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
* @param key * @param key
* @param value * @param value
*/ */
register(key: string, name: string, value: boolean | MotaSetting): this; register(
key: string,
name: string,
value: boolean | MotaSetting,
com?: SettingComponent
): this;
register( register(
key: string, key: string,
name: string, name: string,
value: MotaSettingType, value: MotaSettingType,
com: SettingComponent = COM.DefaultSetting,
step: [number, number, number] = [0, 100, 1] step: [number, number, number] = [0, 100, 1]
) { ) {
const setting: MotaSettingItem = { const setting: MotaSettingItem = {
name, name,
value, value,
key key,
controller: com
}; };
if (!(value instanceof MotaSetting)) setting.defaults = value; if (!(value instanceof MotaSetting)) setting.defaults = value;
if (typeof value === 'number') setting.step = step; if (typeof value === 'number') setting.step = step;
@ -148,7 +156,12 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
return this; return this;
} }
setValueController(key: string, com: Component) { /**
*
* @param key
* @param com
*/
setValueController(key: string, com: SettingComponent) {
const setting = this.getSettingBy(key.split('.')); const setting = this.getSettingBy(key.split('.'));
setting.controller = com; setting.controller = com;
return this; return this;
@ -359,43 +372,41 @@ mainSetting
'screen', 'screen',
'显示设置', '显示设置',
new MotaSetting() new MotaSetting()
.register('fullscreen', '全屏游戏', false) .register('fullscreen', '全屏游戏', false, COM.BooleanSetting)
.register('halo', '光环显示', true) .register('halo', '光环显示', true, COM.BooleanSetting)
.register('itemDetail', '宝石血瓶显伤', true) .register('itemDetail', '宝石血瓶显伤', true, COM.BooleanSetting)
.register('heroDetail', '勇士显伤', false) .register('heroDetail', '勇士显伤', false, COM.BooleanSetting)
.register('transition', '界面动画', false) .register('transition', '界面动画', false, COM.BooleanSetting)
.register('antiAlias', '抗锯齿', false) .register('antiAlias', '抗锯齿', false, COM.BooleanSetting)
.register('fontSize', '字体大小', 16, [8, 28, 1]) .register('fontSize', '字体大小', 16, COM.NumberSetting, [8, 28, 1])
.register('smoothView', '平滑镜头', true) .register('smoothView', '平滑镜头', true, COM.BooleanSetting)
.register('criticalGem', '临界显示方式', false) .register('criticalGem', '临界显示方式', false, COM.BooleanSetting)
.setDisplayFunc('criticalGem', value => (value ? '宝石数' : '攻击')) .setDisplayFunc('criticalGem', value => (value ? '宝石数' : '攻击'))
) )
.register( .register(
'action', 'action',
'操作设置', '操作设置',
new MotaSetting() new MotaSetting()
.register('autoSkill', '自动切换技能', true) .register('autoSkill', '自动切换技能', true, COM.BooleanSetting)
.register('fixed', '定点查看', true) .register('fixed', '定点查看', true, COM.BooleanSetting)
.register('hotkey', '快捷键', false) .register('hotkey', '快捷键', false, COM.BooleanSetting)
.markSpecial('hotkey', 'hotkey')
.setDisplayFunc('hotkey', () => '') .setDisplayFunc('hotkey', () => '')
.register('toolbar', '自定义工具栏', false) .register('toolbar', '自定义工具栏', false, COM.BooleanSetting)
.markSpecial('toolbar', 'toolbar')
.setDisplayFunc('toolbar', () => '') .setDisplayFunc('toolbar', () => '')
) )
.register( .register(
'utils', 'utils',
'系统设置', '系统设置',
new MotaSetting() new MotaSetting()
.register('betterLoad', '优化加载', true) .register('betterLoad', '优化加载', true, COM.BooleanSetting)
.register('autoScale', '自动放缩', true) .register('autoScale', '自动放缩', true, COM.BooleanSetting)
) )
.register( .register(
'fx', 'fx',
'特效设置', '特效设置',
new MotaSetting() new MotaSetting()
.register('paraLight', '野外阴影', true) .register('paraLight', '野外阴影', true, COM.BooleanSetting)
.register('frag', '打怪特效', true) .register('frag', '打怪特效', true, COM.BooleanSetting)
); );
interface SettingStorage { interface SettingStorage {

View File

@ -52,43 +52,13 @@
></div> ></div>
<a-divider class="info-divider" dashed></a-divider> <a-divider class="info-divider" dashed></a-divider>
<div class="info-editor" v-if="!!selectedItem"> <div class="info-editor" v-if="!!selectedItem">
<div class="editor-custom" v-if="!!selectedItem.controller"> <div class="editor-custom">
<component :is="selectedItem.controller"></component> <component
</div> :is="selectedItem.controller"
<div v-else-if="!!selectedItem.special"></div> :item="selectedItem"
<div :displayer="displayer"
class="editor-number" :setting="setting"
v-else-if="typeof selectedItem.value === 'number'" ></component>
>
<span>修改设置</span>
<a-input-number
class="number-input"
size="large"
:min="selectedItem.step?.[0] ?? 0"
:max="selectedItem.step?.[1] ?? 100"
:step="selectedItem.step?.[2] ?? 1"
:keyboard="true"
:value="selectedItem.value"
@change="changeValue"
></a-input-number>
</div>
<div
class="editor-boolean"
v-else-if="typeof selectedItem.value === 'boolean'"
>
<span
>当前{{
selectedItem.value ? '开启' : '关闭'
}}</span
>
<a-button
class="boolean-button"
type="primary"
size="large"
@click="changeValue(!selectedItem.value)"
>
{{ selectedItem.value ? '关闭' : '开启' }}设置
</a-button>
</div> </div>
</div> </div>
</div> </div>

File diff suppressed because it is too large Load Diff