mvc
This commit is contained in:
2452
source/lib/fairygui.d.ts
vendored
Normal file
2452
source/lib/fairygui.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
source/src/MVC/BaseFuiView.ts
Normal file
10
source/src/MVC/BaseFuiView.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/** 用于承载fui界面 */
|
||||
class BaseFuiView extends BaseView {
|
||||
/** 界面名称 */
|
||||
protected _name: string;
|
||||
|
||||
constructor(name: string){
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
25
source/src/MVC/BaseSingle.ts
Normal file
25
source/src/MVC/BaseSingle.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/** 用于表示单例类 */
|
||||
class BaseSingle {
|
||||
private static _instance: any;
|
||||
|
||||
public static getInstance<T>(): T {
|
||||
if (this._instance == null) {
|
||||
this._instance = new this();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
/**清除fgui元素 */
|
||||
protected clearFuiObj(obj: fairygui.GObject): boolean {
|
||||
if (obj) {
|
||||
egret.Tween.removeTweens(obj.displayObject);
|
||||
if (obj.displayObject && obj.displayObject.parent) {
|
||||
obj.displayObject.parent.removeChild(obj.displayObject);
|
||||
}
|
||||
obj.dispose();
|
||||
obj = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
41
source/src/MVC/BaseView.ts
Normal file
41
source/src/MVC/BaseView.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/** 所有视图的基类 */
|
||||
class BaseView extends egret.DisplayObjectContainer {
|
||||
/** 界面数据 */
|
||||
protected _data: any;
|
||||
/** 在打开界面前触发 */
|
||||
protected init(){
|
||||
|
||||
}
|
||||
|
||||
/** 窗口打开时触发 */
|
||||
public show(data?: any) {
|
||||
|
||||
}
|
||||
|
||||
/** 刷新界面数据 由mvc控制 */
|
||||
public refreshData(data?: any){
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
/** 刷新界面逻辑 */
|
||||
public refreshView(){
|
||||
|
||||
}
|
||||
|
||||
/** 关闭窗口 */
|
||||
public close() {
|
||||
|
||||
}
|
||||
|
||||
/** 销毁窗口 */
|
||||
public destroy(){
|
||||
if (this.parent){
|
||||
this.parent.removeChild(this);
|
||||
}
|
||||
|
||||
/** 循环删除此界面下所有节点 */
|
||||
while (this.numChildren > 0) {
|
||||
this.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
source/src/MVC/ViewManager.ts
Normal file
64
source/src/MVC/ViewManager.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
class ViewManager extends BaseSingle {
|
||||
private _openDic: BaseFuiView[] = [];
|
||||
|
||||
/**
|
||||
* 刷新界面
|
||||
* @param viewClass 界面类型
|
||||
* @param data 界面数据
|
||||
*/
|
||||
public refreshView(viewClass: any, data?: any){
|
||||
let view = this.getView<BaseFuiView>(viewClass);
|
||||
|
||||
if (view){
|
||||
/** 压入数据 */
|
||||
view.refreshData(data);
|
||||
/** 执行刷新逻辑 */
|
||||
view.refreshView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开界面
|
||||
* @param viewClass 界面类型
|
||||
* @param data 界面数据
|
||||
* @param complete 界面加载完成回调
|
||||
*/
|
||||
public openView(viewClass: any, data?: any, complete?: Function){
|
||||
let newView = this.getView<BaseFuiView>(viewClass);
|
||||
if (!newView){
|
||||
newView = new viewClass();
|
||||
}
|
||||
|
||||
/** 如果界面已打开 则执行刷新界面 */
|
||||
if (this.existView(viewClass)){
|
||||
newView.refreshData(data);
|
||||
newView.refreshView();
|
||||
return;
|
||||
}
|
||||
|
||||
this._openDic.push(newView);
|
||||
// TODO: 加载资源
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取界面 可能为null
|
||||
* @param viewClass 界面类型
|
||||
*/
|
||||
public getView<T>(viewClass: any): T {
|
||||
let result: any = this._openDic.firstOrDefault(a => {
|
||||
return a instanceof viewClass;
|
||||
});
|
||||
|
||||
return result as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 界面是否存在
|
||||
* @param viewClass 界面类型
|
||||
*/
|
||||
public existView(viewClass: any): boolean {
|
||||
return this._openDic.findIndex(a => {
|
||||
return a instanceof viewClass;
|
||||
}) != -1;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
declare class fui {}
|
||||
|
||||
class ContentManager {
|
||||
protected loadedAssets: Map<string, any> = new Map<string, any>();
|
||||
|
||||
/** 异步加载资源 */
|
||||
public load(name: string, local: boolean = true): Promise<any> {
|
||||
public loadRes(name: string, local: boolean = true): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let res = this.loadedAssets.get(name);
|
||||
if (res) {
|
||||
@@ -30,7 +32,7 @@ class ContentManager {
|
||||
})
|
||||
}
|
||||
|
||||
public dispose(){
|
||||
public dispose() {
|
||||
this.loadedAssets.forEach(value => {
|
||||
let assetsToRemove = value;
|
||||
assetsToRemove.dispose();
|
||||
|
||||
Reference in New Issue
Block a user