mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 23:29:27 +08:00
丰富ui控制器的api
This commit is contained in:
parent
a12aa293c3
commit
41f0394332
@ -3,7 +3,9 @@ import { SoundController } from './audio/sound';
|
||||
import { EventEmitter } from './common/eventEmitter';
|
||||
import { loading, readyAllResource } from './loader/load';
|
||||
import { ResourceStore, ResourceType } from './loader/resource';
|
||||
import { UiController } from './main/custom/ui';
|
||||
import { GameEvent, hook } from './main/game';
|
||||
import { fixedUi, mainUi } from './main/init/ui';
|
||||
import { GameStorage } from './main/storage';
|
||||
import { resolvePlugin } from './plugin';
|
||||
|
||||
@ -44,6 +46,10 @@ export interface AncTe {
|
||||
hook: EventEmitter<GameEvent>;
|
||||
storage: GameStorage<any>[];
|
||||
};
|
||||
ui: {
|
||||
main: UiController;
|
||||
fixed: UiController;
|
||||
};
|
||||
}
|
||||
|
||||
function ready() {
|
||||
@ -57,6 +63,10 @@ function ready() {
|
||||
game: {
|
||||
hook,
|
||||
storage: GameStorage.list
|
||||
},
|
||||
ui: {
|
||||
main: mainUi,
|
||||
fixed: fixedUi
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -31,12 +31,14 @@ type RegisterData = Omit<HotkeyData, 'id' | 'key' | 'name'>;
|
||||
export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
keyMap: Map<KeyCode, HotkeyData[]> = new Map();
|
||||
list: Record<string, HotkeyData> = {};
|
||||
storage: GameStorage<Record<string, KeyCode>>;
|
||||
storage?: GameStorage<Record<string, KeyCode>>;
|
||||
groups: Record<string, GroupInfo> = {};
|
||||
|
||||
constructor(id: string) {
|
||||
constructor(id: string, storage: boolean = true) {
|
||||
super();
|
||||
this.storage = new GameStorage(GameStorage.fromAncTe(id));
|
||||
if (storage) {
|
||||
this.storage = new GameStorage(GameStorage.fromAuthor('AncTe', id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +49,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
const key = {
|
||||
id,
|
||||
name,
|
||||
key: this.storage.getValue(id, data.defaults),
|
||||
key: this.storage?.getValue(id, data.defaults) ?? data.defaults,
|
||||
...data
|
||||
};
|
||||
this.ensureKey(key.key).push(key);
|
||||
|
@ -185,6 +185,7 @@ export class GameUi extends EventEmitter<GameUiEvent> {
|
||||
|
||||
export class UiController extends Focus<GameUi> {
|
||||
static list: UiController[] = [];
|
||||
list: Record<string, GameUi> = {};
|
||||
|
||||
constructor(equal?: boolean) {
|
||||
super(true, equal);
|
||||
@ -219,7 +220,7 @@ export class UiController extends Focus<GameUi> {
|
||||
* @param id ui的id
|
||||
*/
|
||||
get(id: string) {
|
||||
return [...this.targets.values()].find(v => v.id === id);
|
||||
return this.list[id];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,8 +228,36 @@ export class UiController extends Focus<GameUi> {
|
||||
* @param id 要关闭的ui的id
|
||||
*/
|
||||
close(id: string) {
|
||||
const ui = this.stack.find(v => v.id === id);
|
||||
const ui = this.get(id);
|
||||
if (!ui) return;
|
||||
this.splice(ui);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的ui
|
||||
* @param id 要打开的ui的id
|
||||
*/
|
||||
open(id: string) {
|
||||
const ui = this.get(id);
|
||||
if (!ui) return;
|
||||
this.add(ui);
|
||||
}
|
||||
|
||||
override register(...item: GameUi[]): this {
|
||||
super.register(...item);
|
||||
item.forEach(v => {
|
||||
this.list[v.id] = v;
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
override unregister(...item: GameUi[]): this {
|
||||
super.unregister(...item);
|
||||
item.forEach(v => {
|
||||
delete this.list[v.id];
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -61,3 +61,5 @@ fixedUi.register(
|
||||
new GameUi('chapter', Chapter),
|
||||
new GameUi('completeAchi', CompleteAchi)
|
||||
);
|
||||
|
||||
mainUi.focus(mainUi.get('start'), true);
|
||||
|
@ -403,7 +403,7 @@ interface SettingStorage {
|
||||
}
|
||||
|
||||
const storage = new GameStorage<SettingStorage>(
|
||||
GameStorage.fromAncTe('setting')
|
||||
GameStorage.fromAuthor('AncTe', 'setting')
|
||||
);
|
||||
|
||||
loading.once('coreInit', () => {
|
||||
|
@ -55,8 +55,8 @@ export class GameStorage<T> {
|
||||
return `HumanBreak_${key}`;
|
||||
}
|
||||
|
||||
static fromAncTe(key: string) {
|
||||
return `AncTe@${key}`;
|
||||
static fromAuthor(author: string, key: string) {
|
||||
return `${author}@${key}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user