mvc
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# egret-framework
|
# egret-framework
|
||||||
用于egret的一套框架 包含众多游戏中可能用到的系统
|
这是一套用于egret的游戏框架,里面包含ECS框架用于管理场景实体,MVC框架用于管理ui界面(fairygui),一些常用2D碰撞检测及A*寻路。如果您还需要包含其他的AI系统可以查看作者其他库(行为树、简易FSM、实用AI)。
|
||||||
|
|
||||||
## 当前版本功能
|
## 当前版本功能
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
- [ ] 系统列表
|
- [ ] 系统列表
|
||||||
- [ ] 被动系统
|
- [ ] 被动系统
|
||||||
- [ ] 协调系统
|
- [ ] 协调系统
|
||||||
|
- [ ] 简易MVC框架
|
||||||
- [ ] 数学库
|
- [ ] 数学库
|
||||||
- [ ] 贝塞尔曲线
|
- [ ] 贝塞尔曲线
|
||||||
- [ ] 快速随机数类
|
- [ ] 快速随机数类
|
||||||
|
|||||||
2452
demo/libs/fairygui/fairygui.d.ts
vendored
Normal file
2452
demo/libs/fairygui/fairygui.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
18915
demo/libs/fairygui/fairygui.js
Normal file
18915
demo/libs/fairygui/fairygui.js
Normal file
File diff suppressed because it is too large
Load Diff
1
demo/libs/fairygui/fairygui.min.js
vendored
Normal file
1
demo/libs/fairygui/fairygui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
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 {
|
class ContentManager {
|
||||||
protected loadedAssets: Map<string, any> = new Map<string, any>();
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
let res = this.loadedAssets.get(name);
|
let res = this.loadedAssets.get(name);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
|||||||
Reference in New Issue
Block a user