mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-27 12:24:30 +08:00
refactor: 迁移旧ui至新ui系统
This commit is contained in:
1 parent
9a97a470f1
commit
8fcc570e5d
29 files changed
+219
-320
No files matched your search
@@ -302,9 +302,10 @@ hotkey
|
||||
const [x, y] = flags.mouseLoc ?? [];
|
||||
const [mx, my] = getLocFromMouseLoc(x, y);
|
||||
if (core.getBlockCls(mx, my)?.startsWith('enemy')) {
|
||||
core.plugin.fixedDetailPanel = 'special';
|
||||
mota.plugin.fixed.showFixed.value = false;
|
||||
mota.plugin.ui.fixedDetailOpened.value = true;
|
||||
mota.ui.main.open('fixedDetail', void 0, {
|
||||
panel: 'special'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -314,9 +315,10 @@ hotkey
|
||||
const [x, y] = flags.mouseLoc ?? [];
|
||||
const [mx, my] = getLocFromMouseLoc(x, y);
|
||||
if (core.getBlockCls(mx, my)?.startsWith('enemy')) {
|
||||
core.plugin.fixedDetailPanel = 'critical';
|
||||
mota.plugin.fixed.showFixed.value = false;
|
||||
mota.plugin.ui.fixedDetailOpened.value = true;
|
||||
mota.ui.main.open('fixedDetail', void 0, {
|
||||
panel: 'critical'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -124,6 +124,12 @@ interface ShowableGameUi {
|
||||
type UiVOn = Record<string, (param?: any) => void>;
|
||||
type UiVBind = Record<string, any>;
|
||||
|
||||
interface MountedVBind {
|
||||
num: number;
|
||||
ui: GameUi;
|
||||
[x: string]: any;
|
||||
}
|
||||
|
||||
export class GameUi extends EventEmitter<GameUiEvent> {
|
||||
static uiList: GameUi[] = [];
|
||||
|
||||
@@ -151,6 +157,11 @@ export class GameUi extends EventEmitter<GameUiEvent> {
|
||||
|
||||
interface IndexedGameUi extends ShowableGameUi {
|
||||
num: number;
|
||||
vBind?: MountedVBind;
|
||||
}
|
||||
|
||||
interface HoldOnController {
|
||||
end(): void;
|
||||
}
|
||||
|
||||
export class UiController extends Focus<IndexedGameUi> {
|
||||
@@ -166,11 +177,13 @@ export class UiController extends Focus<IndexedGameUi> {
|
||||
this.on('splice', spliced => {
|
||||
spliced.forEach(v => {
|
||||
v.ui.emit('close');
|
||||
if (this.stack.length === 0) {
|
||||
if (!this.hold) this.emit('end');
|
||||
this.hold = false;
|
||||
}
|
||||
});
|
||||
if (this.stack.length === 0) {
|
||||
console.log(this.hold);
|
||||
|
||||
if (!this.hold) this.emit('end');
|
||||
this.hold = false;
|
||||
}
|
||||
});
|
||||
this.on('add', item => {
|
||||
if (this.stack.length === 1) {
|
||||
@@ -201,11 +214,17 @@ export class UiController extends Focus<IndexedGameUi> {
|
||||
* 暂时保持下一次删除ui不会导致ui整体被关闭,引起ui背景闪烁。
|
||||
* 例如可以用于道具栏,打开道具时就应当 holdOn,然后通过道具使用钩子来判断接下来是否要隐藏 app:
|
||||
* ```txt
|
||||
* hold on -> close -> use item -> hook -> stack.length === 0 ? hide app : no action
|
||||
* hold on -> close -> use item -> hook -> stack.length === 0 ? end() : no action
|
||||
* ```
|
||||
*/
|
||||
holdOn() {
|
||||
holdOn(): HoldOnController {
|
||||
this.hold = true;
|
||||
|
||||
return {
|
||||
end: () => {
|
||||
this.emit('end');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +241,6 @@ export class UiController extends Focus<IndexedGameUi> {
|
||||
* @param id 要关闭的ui的id
|
||||
*/
|
||||
closeByName(id: string) {
|
||||
console.log(id);
|
||||
if (!this.equal) {
|
||||
const ui = this.stack.findIndex(v => v.ui.id === id);
|
||||
this.spliceIndex(ui);
|
||||
@@ -245,7 +263,15 @@ export class UiController extends Focus<IndexedGameUi> {
|
||||
const ui = this.get(id);
|
||||
if (!ui) return -1;
|
||||
const num = this.num++;
|
||||
this.add({ num, ...ui.with(vOn, vBind) });
|
||||
const sui = ui.with(vOn, {
|
||||
num,
|
||||
ui,
|
||||
...(vBind ?? {})
|
||||
});
|
||||
this.add({
|
||||
num,
|
||||
...sui
|
||||
} as IndexedGameUi);
|
||||
return num;
|
||||
}
|
||||
|
||||
@@ -292,4 +318,12 @@ export class UiController extends Focus<IndexedGameUi> {
|
||||
getByNum(num: number) {
|
||||
return this.stack.find(v => v.num === num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ui的唯一标识符来判断当前是否存在某个ui
|
||||
* @param id ui的唯一标识符
|
||||
*/
|
||||
hasName(id: string) {
|
||||
return this.stack.some(v => v.ui.id === id);
|
||||
}
|
||||
}
|
||||
+24
-36
@@ -1,21 +1,4 @@
|
||||
import Book from '@ui/book.vue';
|
||||
import Toolbox from '@ui/toolbox.vue';
|
||||
import Equipbox from '@ui/equipbox.vue';
|
||||
import Settings from '@ui/settings.vue';
|
||||
import Desc from '@ui/desc.vue';
|
||||
import Skill from '@ui/skill.vue';
|
||||
import SkillTree from '@ui/skillTree.vue';
|
||||
import Fly from '@ui/fly.vue';
|
||||
import FixedDetail from '@ui/fixedDetail.vue';
|
||||
import Shop from '@ui/shop.vue';
|
||||
import Achievement from '@ui/achievement.vue';
|
||||
import Bgm from '@ui/bgmList.vue';
|
||||
import StatusBar from '@ui/statusBar.vue';
|
||||
import Mark from '@ui/markedEnemy.vue';
|
||||
import Fixed from '@ui/fixed.vue';
|
||||
import Chapter from '@ui/chapter.vue';
|
||||
import CompleteAchi from '@ui/completeAchievement.vue';
|
||||
import Start from '@ui/start.vue';
|
||||
import * as UI from '@ui/.';
|
||||
import { GameUi, UiController } from '../custom/ui';
|
||||
import { Hotkey } from '../custom/hotkey';
|
||||
import { KeyCode } from '@/plugin/keyCodes';
|
||||
@@ -38,29 +21,29 @@ exitKey
|
||||
|
||||
export const mainUi = new UiController();
|
||||
mainUi.register(
|
||||
new GameUi('book', Book, exitKey),
|
||||
new GameUi('toolbox', Toolbox, exitKey),
|
||||
new GameUi('equipbox', Equipbox, exitKey),
|
||||
new GameUi('settings', Settings, exitKey),
|
||||
new GameUi('desc', Desc, exitKey),
|
||||
new GameUi('skill', Skill, exitKey),
|
||||
new GameUi('skillTree', SkillTree, exitKey),
|
||||
new GameUi('fly', Fly, exitKey),
|
||||
new GameUi('fixedDetail', FixedDetail, exitKey),
|
||||
new GameUi('shop', Shop, exitKey),
|
||||
new GameUi('achievement', Achievement, exitKey),
|
||||
new GameUi('bgm', Bgm, exitKey)
|
||||
new GameUi('book', UI.Book, exitKey),
|
||||
new GameUi('toolbox', UI.Toolbox, exitKey),
|
||||
new GameUi('equipbox', UI.Equipbox, exitKey),
|
||||
new GameUi('settings', UI.Settings, exitKey),
|
||||
new GameUi('desc', UI.Desc, exitKey),
|
||||
new GameUi('skill', UI.Skill, exitKey),
|
||||
new GameUi('skillTree', UI.SkillTree, exitKey),
|
||||
new GameUi('fly', UI.Fly, exitKey),
|
||||
new GameUi('fixedDetail', UI.FixedDetail, exitKey),
|
||||
new GameUi('shop', UI.Shop, exitKey),
|
||||
new GameUi('achievement', UI.Achievement, exitKey),
|
||||
new GameUi('bgm', UI.BgmList, exitKey)
|
||||
// todo: 把游戏主 div 加入到 mainUi 里面
|
||||
);
|
||||
|
||||
export const fixedUi = new UiController(true);
|
||||
fixedUi.register(
|
||||
new GameUi('statusBar', StatusBar),
|
||||
new GameUi('markedEnemy', Mark),
|
||||
new GameUi('fixed', Fixed),
|
||||
new GameUi('chapter', Chapter),
|
||||
new GameUi('completeAchi', CompleteAchi),
|
||||
new GameUi('start', Start)
|
||||
new GameUi('statusBar', UI.StatusBar),
|
||||
new GameUi('markedEnemy', UI.Marked),
|
||||
new GameUi('fixed', UI.Fixed),
|
||||
new GameUi('chapter', UI.Chapter),
|
||||
new GameUi('completeAchi', UI.CompleteAchi),
|
||||
new GameUi('start', UI.Start)
|
||||
);
|
||||
|
||||
hook.once('mounted', () => {
|
||||
@@ -69,9 +52,11 @@ hook.once('mounted', () => {
|
||||
|
||||
mainUi.on('start', () => {
|
||||
ui.style.display = 'flex';
|
||||
core.lockControl();
|
||||
});
|
||||
mainUi.on('end', () => {
|
||||
ui.style.display = 'none';
|
||||
core.closePanel();
|
||||
});
|
||||
fixedUi.on('start', () => {
|
||||
fixed.style.display = 'block';
|
||||
@@ -79,4 +64,7 @@ hook.once('mounted', () => {
|
||||
fixedUi.on('end', () => {
|
||||
fixed.style.display = 'none';
|
||||
});
|
||||
|
||||
// todo: 暂时先这么搞,之后重写加载界面,需要改成先显示加载界面,加载完毕后再打开这个界面
|
||||
fixedUi.open('start');
|
||||
});
|
||||
Reference in new issue
Block a user