ui控制器添加根据num聚焦的方法

This commit is contained in:
unanmed 2023-09-05 19:26:19 +08:00
parent df98da5d67
commit e6d96f6e2a
4 changed files with 45 additions and 12 deletions

View File

@ -78,7 +78,7 @@ dam4.png ---- 存档 59
[] 优化开头动画 [] 优化开头动画
[x] 玩家可以设置字体大小 [x] 玩家可以设置字体大小
[] 完全删除 functions.js [] 完全删除 functions.js
[x] 优化插件加载系统 [] 优化插件加载系统
[] 优化 Scroll 组件 [] 优化 Scroll 组件
[] 重写技能控制系统 [] 重写技能控制系统
[] 自定义快捷键 [] 自定义快捷键
@ -102,3 +102,4 @@ dam4.png ---- 存档 59
[x] 着色器特效 [x] 着色器特效
[] 完全删除 core.plugin?(待定) [] 完全删除 core.plugin?(待定)
[] 通用 Addon 接口 [] 通用 Addon 接口
[] 完善加载系统

View File

@ -423,6 +423,13 @@ export class ShaderEffect extends EventEmitter<ShaderEvent> {
`; `;
} }
interface GameCanvasReplacer {
recover(): void;
append(): void;
remove(): void;
update(compile?: boolean): void;
}
function floorPower2(value: number) { function floorPower2(value: number) {
return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2)); return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
} }
@ -484,7 +491,16 @@ export function setTickerFor(effect: ShaderEffect) {
return ticker; return ticker;
} }
export function replaceGameCanvas(effect: ShaderEffect, canvas: string[]) { /**
*
* @param effect
* @param canvas
* @returns
*/
export function replaceGameCanvas(
effect: ShaderEffect,
canvas: string[]
): GameCanvasReplacer {
let zIndex = 0; let zIndex = 0;
canvas.forEach(v => { canvas.forEach(v => {
const canvas = core.canvas[v].canvas; const canvas = core.canvas[v].canvas;

View File

@ -1,4 +1,4 @@
import { Component, h, shallowReactive } from 'vue'; import { Component, shallowReactive } from 'vue';
import { EmitableEvent, EventEmitter } from '../../common/eventEmitter'; import { EmitableEvent, EventEmitter } from '../../common/eventEmitter';
import { KeyCode } from '../../../plugin/keyCodes'; import { KeyCode } from '../../../plugin/keyCodes';
import { Hotkey } from './hotkey'; import { Hotkey } from './hotkey';
@ -212,7 +212,7 @@ export class UiController extends Focus<IndexedGameUi> {
*/ */
open(id: string, vOn?: UiVOn, vBind?: UiVBind) { open(id: string, vOn?: UiVOn, vBind?: UiVBind) {
const ui = this.get(id); const ui = this.get(id);
if (!ui) return; if (!ui) return -1;
const num = this.num++; const num = this.num++;
this.add({ num, ...ui.with(vOn, vBind) }); this.add({ num, ...ui.with(vOn, vBind) });
return num; return num;
@ -223,18 +223,34 @@ export class UiController extends Focus<IndexedGameUi> {
* @param id ui的id * @param id ui的id
* @param ui GameUi实例 * @param ui GameUi实例
*/ */
resgister(id: string, ui: GameUi) { register(...ui: GameUi[]) {
if (id in this.list) { ui.forEach(v => {
console.warn(`已存在id为'${id}'的ui已将其覆盖`); const id = v.id;
} if (id in this.list) {
this.list[id] = ui; console.warn(`已存在id为'${id}'的ui已将其覆盖`);
}
this.list[id] = v;
});
} }
/** /**
* ui * ui
* @param id ui的id * @param id ui的id
*/ */
unregister(id: string) { unregister(...id: string[]) {
delete this.list[id]; id.forEach(v => {
delete this.list[v];
});
return this;
}
/**
* ui的唯一标识符进行聚焦
* @param num ui的唯一标识符
*/
focusByNum(num: number, add?: boolean) {
const ui = this.stack.find(v => v.num === num);
if (!ui) return;
this.focus(ui);
} }
} }

View File

@ -62,4 +62,4 @@ fixedUi.register(
new GameUi('completeAchi', CompleteAchi) new GameUi('completeAchi', CompleteAchi)
); );
mainUi.focus(mainUi.get('start'), true); mainUi.focusByNum(mainUi.open('start'));