PageRenderTime 31ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/com/lele/Manager/ApplicationManager.as

https://gitlab.com/Treeky-NULL/LezaiNiubi
ActionScript | 357 lines | 339 code | 11 blank | 7 comment | 14 complexity | 0cd8475280bbbaa37c7e16f2b2073ed9 MD5 | raw file
  1. package com.lele.Manager
  2. {
  3. import com.lele.Data.GloableData;
  4. import com.lele.Manager.Interface.IApplicationManager;
  5. import com.lele.Manager.Interface.IApplyAppContainer;
  6. import com.lele.Manager.Interface.IDialog;
  7. import com.lele.Link.AppDataLink;
  8. import com.lele.Data.IAppData;
  9. import com.lele.Manager.Events.App_Game_ManagerEvent;
  10. import com.lele.Manager.Events.AppData_App_ManagerEvent;
  11. import com.lele.Manager.Interface.IReport;
  12. import com.lele.Manager.Interface.IResourceLoader;
  13. import flash.display.Sprite;
  14. import flash.events.Event;
  15. /**
  16. * ...
  17. * @author Lele
  18. */
  19. public class ApplicationManager implements IReport,IDialog,IApplicationManager
  20. {
  21. private static var _instance:IDialog;
  22. private var _applyContainer:IApplyAppContainer;
  23. private var _report:IReport;
  24. private var _resourceLoader:IResourceLoader;
  25. private var _AppData:Object;//AppUnit对象集合 //均通过对象URL查询
  26. private var _AppUrlList:Array;//表集合,一个表示当前加载的应用的集合
  27. private var _AppParams:Object;//一个参数集合
  28. private var _AppContainer:Object;//AppUnit对象存储容器的临时存储容器
  29. public function ApplicationManager(resourceloader:IResourceLoader,repoter:IReport,applyContainer:IApplyAppContainer)
  30. {
  31. _AppParams = new Object();
  32. _AppUrlList = new Array();
  33. _AppContainer = new Object();
  34. _AppData = new Object();
  35. _report = repoter;
  36. _resourceLoader = resourceloader;
  37. _instance = this;
  38. _applyContainer = applyContainer;
  39. }
  40. public function StartAppMultiply(app:String,...arg)
  41. {
  42. GetAppUnitByUrl(AppDataLink.GetUrlByName(app)).StartAppMultiply(arg);
  43. }
  44. public static function GetIDialog():IDialog
  45. {
  46. return _instance;
  47. }
  48. public function StartApp(app:String, ...arg)
  49. {
  50. GetAppUnitByUrl(AppDataLink.GetUrlByName(app)).StartApp(arg);
  51. }
  52. public function ShowDialog(...arg)
  53. {
  54. try
  55. {
  56. GetAppUnitByUrl(AppDataLink.GetUrlByName("Dialog"))._AppContainer = _applyContainer.GetAppContainer();
  57. if(arg.length==1&&arg[0] is Array)
  58. GetAppUnitByUrl(AppDataLink.GetUrlByName("Dialog")).StartAppMultiply(arg[0]);
  59. else
  60. GetAppUnitByUrl(AppDataLink.GetUrlByName("Dialog")).StartAppMultiply(arg);
  61. }
  62. catch (er:Error) { trace(er.message);//资源未加载完
  63. }
  64. }
  65. public function AddNote(...arg)//[0]:标志位 0为YesNote 1为YNNote [1]为函数位 [2][3][4][5][6] title content mo day time
  66. {
  67. GetAppUnitByUrl(AppDataLink.GetUrlByName("LittleNote")).StartApp(arg);
  68. }
  69. public function LoadApp(url:String,container:Sprite,useUI:Boolean=false,UIType:String="NULL")
  70. {
  71. if (InTheList(url)) { return; }//如果存在就不加载
  72. _AppContainer[url] = container;
  73. AddToList(url);//添加到表单
  74. _resourceLoader.LoadResource("AppManager", url, OnLoadAppComplete, useUI, UIType);
  75. }
  76. private function OnLoadAppComplete(evt:Event)
  77. {
  78. var tempAppUnit:AppUnit = new AppUnit(evt.target.content, _AppContainer[(evt.target.content as IAppData).FileUrl]);
  79. tempAppUnit.Report = this;//一定要记着给Report;
  80. _AppData[tempAppUnit.URL] = tempAppUnit;
  81. }
  82. public function LoadStartApp(url:String, container:Sprite, useUI:Boolean = false, UIType:String = "NULL",params:Array=null)
  83. {
  84. if (InTheList(url)) { trace("App in the list,the loadStart request is refused"); return; }//如果存在就不加载
  85. _AppContainer[url] = container;
  86. AddToList(url);//添加到表单
  87. _AppParams[url] = params;//添加参数
  88. _resourceLoader.LoadResource("AppManager", url, OnLoadStartAppComplete, useUI, UIType);
  89. }
  90. private function OnLoadStartAppComplete(evt:Event)
  91. {
  92. var tempAppUnit:AppUnit = new AppUnit(evt.target.content, _AppContainer[(evt.target.content as IAppData).FileUrl]);
  93. tempAppUnit.Report = this;//一定要记着给Report;
  94. _AppData[tempAppUnit.URL] = tempAppUnit;
  95. tempAppUnit.StartApp(_AppParams[tempAppUnit.URL]);
  96. _AppParams[tempAppUnit.URL] = null;//再清除引用
  97. }
  98. private function GetAppUnitByUrl(url:String):AppUnit
  99. {
  100. return _AppData[url];
  101. }
  102. ///对List的一些操作
  103. private function AddToList(url:String)
  104. {
  105. if (InTheList(url)) { return; }
  106. _AppUrlList.push(url);
  107. }
  108. private function RemoveFromList(url:String)
  109. {
  110. if (!InTheList(url)) { return; }
  111. for (var a:int = 0; a < _AppUrlList.length; a++ )
  112. {
  113. if (_AppUrlList[a] == url) { _AppUrlList.splice(a, 1); return; }
  114. }
  115. }
  116. private function InTheList(url:String):Boolean
  117. {
  118. for (var a:int = 0; a < _AppUrlList.length; a++ )
  119. {
  120. if (_AppUrlList[a] == url) { return true; }
  121. }
  122. return false;
  123. }
  124. private function CloseApp(appUrl:String)
  125. {
  126. var url:String = appUrl;
  127. var unit:AppUnit = GetAppUnitByUrl(url);
  128. _AppData[url] = null;
  129. unit.StopApp();
  130. unit.Delete();
  131. RemoveFromList(url);
  132. _resourceLoader.UnLoadResource("AppManager", url);
  133. }
  134. public function OnReceive(evbbbbt:Event)
  135. {
  136. var event:App_Game_ManagerEvent;
  137. if (evbbbbt is App_Game_ManagerEvent)
  138. {
  139. event = evbbbbt as App_Game_ManagerEvent;
  140. switch(event.EvtType)
  141. {
  142. case App_Game_ManagerEvent.CLOSEAPP_GAME:
  143. {
  144. CloseApp(AppDataLink.GetUrlByName(event.CLOSEAPP_GAME_name));
  145. return;
  146. }
  147. case App_Game_ManagerEvent.ARGTOAPP_GAME:
  148. {
  149. GetAppUnitByUrl(AppDataLink.GetUrlByName(event.ARGTOAPP_GAME_name)).AppDocStart(event.ARGTOAPP_GAME_args);
  150. return;
  151. }
  152. case App_Game_ManagerEvent.CREATACCOUNTRESULT_GAME:
  153. {
  154. var tempArray:Array = new Array();
  155. tempArray.push(event.CREATACCOUNTRESULT_GAME_result);
  156. tempArray.push(event.CREATACCOUNTRESULT_GAME_id);
  157. GetAppUnitByUrl(AppDataLink.GetUrlByName("ApplyPanelApp")).AppDocStart(tempArray);
  158. return;
  159. }
  160. case App_Game_ManagerEvent.NCHATLISTDATAS_GAME:
  161. {
  162. StartApp("FriendsApp", 6, event.NCHATLISTDATAS_GAME_data);
  163. return;
  164. }
  165. }
  166. }
  167. }
  168. public function OnReport(evt:Event):void
  169. {
  170. if (evt is AppData_App_ManagerEvent)
  171. {
  172. var event:AppData_App_ManagerEvent = evt as AppData_App_ManagerEvent;
  173. switch(event.EvtType)
  174. {
  175. case AppData_App_ManagerEvent.CLOSE:
  176. {
  177. CloseApp(event.CLOSE_url);
  178. return;
  179. }
  180. case AppData_App_ManagerEvent.CALLDOACTION:
  181. {
  182. var appGame:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.CALLDOACTION);
  183. appGame.CALLDOACTION_actionName = event.CALLDOACTION_actionName;
  184. _report.OnReport(appGame);
  185. return;
  186. }
  187. case AppData_App_ManagerEvent.SUBMITARTICLE:
  188. {
  189. var subArt:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.SUBMITARTICLE);
  190. subArt.SUBMITARTICLE_head = event.SUBMITARTICLE_head;
  191. subArt.SUBMITARTICLE_body = event.SUBMITARTICLE_body;
  192. _report.OnReport(subArt);
  193. return;
  194. }
  195. case AppData_App_ManagerEvent.SHOWSIMPLEDIALOG:
  196. {
  197. //"emoy", "sad", "与服务器的连接断开了,重新登陆吧!", null
  198. GetIDialog().ShowDialog("emoy", event.SHOWSIMPLEDIALOG_emo, event.SHOWSIMPLEDIALOG_info, event.SHOWSIMPLEDIALOG_callback);
  199. return;
  200. }
  201. case AppData_App_ManagerEvent.GOTOLOGIN:
  202. {
  203. var ett:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.GOTOLOGIN);
  204. _report.OnReport(ett);
  205. return;
  206. }
  207. case AppData_App_ManagerEvent.GOTOREGIST:
  208. {
  209. var ett:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.GOTOREGIST);
  210. _report.OnReport(ett);
  211. return;
  212. }
  213. case AppData_App_ManagerEvent.LOGIN:
  214. {
  215. var ettt:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.LOGIN);
  216. ettt.LOGIN_id = event.LOGIN_id;
  217. ettt.LOGIN_pwd = event.LOGIN_pwd;
  218. _report.OnReport(ettt);
  219. return;
  220. }
  221. case AppData_App_ManagerEvent.CREATACCOUNT:
  222. {
  223. var ett:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.CREATACCOUNT);
  224. ett.CREATACCOUNT_pwd = event.CREATACCOUNT_pwd;
  225. _report.OnReport(ett);
  226. return;
  227. }
  228. case AppData_App_ManagerEvent.OPENAPP:
  229. {
  230. var appName:String = event.OPENAPP_name;
  231. LoadStartApp(AppDataLink.GetUrlByName(appName), _applyContainer.GetAppContainer());
  232. return;
  233. }
  234. case AppData_App_ManagerEvent.CREATEMOLE:
  235. {
  236. var cm:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.CREATEMOLE);
  237. cm.CREATEMOLE_color = event.CREATEMOLE_color;
  238. cm.CREATEMOLE_name = event.CREATEMOLE_name;
  239. _report.OnReport(cm);
  240. return;
  241. }
  242. case AppData_App_ManagerEvent.ONTHROWITEM:
  243. {
  244. var ot:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.ONTHROWITEM);
  245. ot.ONTHROWITEM_actionDir = event.ONTHROWITEM_actionDir;
  246. ot.ONTHROWITEM_actionName = event.ONTHROWITEM_actionName;
  247. ot.ONTHROWITEM_aimStyle = event.ONTHROWITEM_aimStyle;
  248. ot.ONTHROWITEM_blood = GloableData.ThrowItemHurt;
  249. ot.ONTHROWITEM_itemStyle = event.ONTHROWITEM_itemStyle;
  250. _report.OnReport(ot);
  251. return;
  252. }
  253. case AppData_App_ManagerEvent.FRIENDCHATSEND:
  254. {
  255. //直达通路,简化数据传输过程。降低中心管理器负载
  256. GameManager.NetManagerFuncer.OnReceive(evt);
  257. return;
  258. }
  259. case AppData_App_ManagerEvent.RCHATLISTDATAS:
  260. {
  261. GameManager.NetManagerFuncer.OnReceive(evt);
  262. return;
  263. }
  264. case AppData_App_ManagerEvent.NCHATLISTDATAS:
  265. {
  266. var nc:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.NCHATLISTDATAS);
  267. _report.OnReport(nc);
  268. return;
  269. }
  270. case AppData_App_ManagerEvent.MAKEFRIEND:
  271. {
  272. GameManager.NetManagerFuncer.OnReceive(evt);
  273. return;
  274. }
  275. case AppData_App_ManagerEvent.ONDRESSCHANGE:
  276. {
  277. var dressChange:App_Game_ManagerEvent = new App_Game_ManagerEvent(App_Game_ManagerEvent.ONDRESSCHANGE);
  278. _report.OnReport(dressChange);
  279. return;
  280. }
  281. }
  282. }
  283. }//end function
  284. }
  285. }
  286. import com.lele.Data.IAppData;
  287. import com.lele.Manager.Interface.IReport;
  288. import flash.display.Sprite;
  289. class AppUnit //应用单元
  290. {
  291. private var _AppDoc:IAppData;
  292. public var _currentApp:Sprite;
  293. public var _multiplyApp:Array;
  294. public var _AppContainer:Sprite;
  295. public function AppUnit(appDoc:IAppData,appContainer:Sprite)
  296. {
  297. _multiplyApp = new Array();
  298. _AppDoc = appDoc;
  299. _AppContainer = appContainer;
  300. }
  301. public function StartApp(arg:Array=null)
  302. {
  303. _AppDoc.Start(arg);
  304. _currentApp = _AppDoc.App;
  305. _AppContainer.addChild(_currentApp);
  306. }
  307. public function StartAppMultiply(arg:Array=null)
  308. {
  309. _AppDoc.Start(arg);
  310. _multiplyApp.push(_AppDoc.App);
  311. _AppContainer.addChild(_multiplyApp[_multiplyApp.length - 1] as Sprite);
  312. }
  313. public function StopApp()
  314. {
  315. _AppDoc.Stop();
  316. _AppContainer.removeChild(_currentApp);
  317. }
  318. public function StopAppMultiply()
  319. {
  320. _AppDoc.Stop();
  321. for (var a:int = 0; a < _multiplyApp.length; a++ )
  322. {
  323. _AppContainer.removeChild(_multiplyApp[a] as Sprite);
  324. }
  325. }
  326. public function AppDocStart(arg:Array=null)
  327. {
  328. _AppDoc.Start(arg);
  329. }
  330. public function Delete()
  331. {
  332. _AppDoc.CleanResource();
  333. _AppDoc = null;
  334. _AppContainer = null;
  335. _currentApp = null;
  336. _multiplyApp = null;
  337. }
  338. public function get URL():String
  339. {
  340. return _AppDoc.FileUrl;
  341. }
  342. public function set Report(report:IReport)
  343. {
  344. _AppDoc.Repoter = report;
  345. }
  346. }