mirror of
https://github.com/motajs/template.git
synced 2026-12-01 03:04:30 +08:00
feat: 文本框管理器
This commit is contained in:
1 parent
fa759b5d19
commit
6773069c24
3 files changed
+139
-1
No files matched your search
@@ -15,7 +15,7 @@ import {
|
||||
TextContentType,
|
||||
ITextContentTyperHooks
|
||||
} from './textboxTyper';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
import { GameUI, SetupComponentOptions } from '@motajs/system';
|
||||
import { DefaultProps, lwh, useRendererRoot, xywh } from '@motajs/render-vue';
|
||||
import { Icon } from './icon';
|
||||
import { ITextureManager } from '../material';
|
||||
@@ -476,4 +476,6 @@ export const Textbox = defineComponent<
|
||||
);
|
||||
}, textboxOptions);
|
||||
|
||||
export const TextboxUI = new GameUI('textbox', Textbox);
|
||||
|
||||
//#endregion
|
||||
@@ -0,0 +1,71 @@
|
||||
import { IUIController } from '@motajs/system';
|
||||
import { IGameUIPropsBase } from '../types';
|
||||
import { ITextboxInfo, ITextboxManager } from './types';
|
||||
import { TextboxProps, TextboxUI } from './textbox';
|
||||
import { TextContentTyper } from './textboxTyper';
|
||||
import { ITextureManager } from '../material';
|
||||
|
||||
export class TextboxManager implements ITextboxManager {
|
||||
/** 文本框映射 */
|
||||
private readonly textboxMap: Map<number, ITextboxInfo> = new Map();
|
||||
|
||||
constructor(
|
||||
readonly ui: IUIController<IGameUIPropsBase>,
|
||||
readonly materials: ITextureManager
|
||||
) {
|
||||
ui.showAll(false);
|
||||
}
|
||||
|
||||
createTextbox(code: number, props?: TextboxProps): ITextboxInfo {
|
||||
const exist = this.textboxMap.get(code);
|
||||
if (exist) return exist;
|
||||
const typer =
|
||||
props?.typer ?? new TextContentTyper({ materials: this.materials });
|
||||
const instance = this.ui.open(
|
||||
TextboxUI,
|
||||
props ? { ...props, typer, zIndex: code } : { typer, zIndex: code }
|
||||
);
|
||||
const info: ITextboxInfo = {
|
||||
instance,
|
||||
typer
|
||||
};
|
||||
this.textboxMap.set(code, info);
|
||||
return info;
|
||||
}
|
||||
|
||||
deleteTextbox(code: number): void {
|
||||
const info = this.textboxMap.get(code);
|
||||
if (!info) return;
|
||||
this.ui.close(info.instance);
|
||||
this.textboxMap.delete(code);
|
||||
}
|
||||
|
||||
deleteAllTextbox(): void {
|
||||
this.ui.closeAll();
|
||||
this.textboxMap.clear();
|
||||
}
|
||||
|
||||
getTextboxInfo(code: number): ITextboxInfo | null {
|
||||
return this.textboxMap.get(code) ?? null;
|
||||
}
|
||||
|
||||
hideTextbox(code: number): void {
|
||||
const info = this.textboxMap.get(code);
|
||||
if (!info) return;
|
||||
info.instance.hide();
|
||||
}
|
||||
|
||||
showTextbox(code: number): void {
|
||||
const info = this.textboxMap.get(code);
|
||||
if (!info) return;
|
||||
info.instance.show();
|
||||
}
|
||||
|
||||
hideAllTextbox(): void {
|
||||
this.textboxMap.forEach(v => v.instance.hide());
|
||||
}
|
||||
|
||||
showAllTextbox(): void {
|
||||
this.textboxMap.forEach(v => v.instance.show());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { IUIController, IUIInstance } from '@motajs/system';
|
||||
import { IGameUIPropsBase } from '../types';
|
||||
import { TextboxProps } from './textbox';
|
||||
import { TextContentTyper } from './textboxTyper';
|
||||
import { ITextureManager } from '../material';
|
||||
|
||||
export interface ITextboxInfo {
|
||||
/** 文本框对应的 UI 实例 */
|
||||
readonly instance: IUIInstance;
|
||||
/** 打字机对象 */
|
||||
readonly typer: TextContentTyper;
|
||||
}
|
||||
|
||||
export interface ITextboxManager {
|
||||
/** 使用的 UI 控制器 */
|
||||
readonly ui: IUIController<IGameUIPropsBase>;
|
||||
/** 使用的贴图素材管理器 */
|
||||
readonly materials: ITextureManager;
|
||||
|
||||
/**
|
||||
* 创建一个新的文本框,如果代码已存在则会返回已存在的那个。`code` 越大,显示层级越高
|
||||
* @param code 文本框使用的代码,同时负责文本框的标识与 `zIndex` 排序
|
||||
* @param props 传递给 Textbox 的初始参数,填写 `typer` 将会覆盖默认使用的打字机对象,不填也可以通过 `getTextboxInfo` 获取
|
||||
*/
|
||||
createTextbox(code: number, props?: TextboxProps): ITextboxInfo;
|
||||
|
||||
/**
|
||||
* 删除指定代码对应的文本框
|
||||
* @param code 文本框使用的代码
|
||||
*/
|
||||
deleteTextbox(code: number): void;
|
||||
|
||||
/**
|
||||
* 删除所有文本框
|
||||
*/
|
||||
deleteAllTextbox(): void;
|
||||
|
||||
/**
|
||||
* 获取指定代码对应的文本框信息
|
||||
* @param code 文本框使用的代码
|
||||
*/
|
||||
getTextboxInfo(code: number): ITextboxInfo | null;
|
||||
|
||||
/**
|
||||
* 隐藏指定的文本框
|
||||
* @param code 文本框使用的代码
|
||||
*/
|
||||
hideTextbox(code: number): void;
|
||||
|
||||
/**
|
||||
* 显示指定的文本框
|
||||
* @param code 文本框使用的代码
|
||||
*/
|
||||
showTextbox(code: number): void;
|
||||
|
||||
/**
|
||||
* 隐藏所有文本框
|
||||
*/
|
||||
hideAllTextbox(): void;
|
||||
|
||||
/**
|
||||
* 显示所有文本框
|
||||
*/
|
||||
showAllTextbox(): void;
|
||||
}
|
||||
Reference in new issue
Block a user