PageRenderTime 131ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/com/lele/Manager/UIManager.as

https://gitlab.com/Treeky-NULL/LezaiNiubi
ActionScript | 310 lines | 283 code | 15 blank | 12 comment | 22 complexity | 6858981312ef9eb5e3ee3c5cbbaafe10 MD5 | raw file
  1. package com.lele.Manager
  2. {
  3. import com.lele.Data.GloableData;
  4. import com.lele.Manager.Events.DebugEvent;
  5. import com.lele.Manager.Events.ManagerEventBase;
  6. import com.lele.Manager.Events.UI_Game_ManagerEvent;
  7. import com.lele.Manager.Events.UIData_UI_ManagerEvent;
  8. import com.lele.Manager.Interface.IReport;
  9. import com.lele.Manager.Interface.IResourceLoader;
  10. import com.lele.Data.IUIData;
  11. import flash.display.MovieClip;
  12. import flash.display.Sprite;
  13. import flash.events.Event;
  14. /**
  15. * ...
  16. * @author Lele
  17. */
  18. //这个特别废啊,当初没考虑好,这东西完全可以被AppManager取代
  19. //UIManager存放和管理UI及层次关系,但具体的方法内容,核心由对应的管理器管理
  20. public class UIManager extends Sprite implements IReport//必须继承Sprite不然得自己实现事件系统
  21. {
  22. private static var _resourceCount:int;
  23. private var _resourceLoader:IResourceLoader;
  24. private var _resourceData:Array;//因为UI元素非常多
  25. private var _repoter:IReport;
  26. //UI资源集
  27. private var _container:Object;//定义成OBj通过URL访问,实现跨函数访问,存储容器
  28. private var _loadingItems:int;
  29. //加载条
  30. private var _mapLoadingBarDoc:IUIData;
  31. private var _mapLoadingBar:MovieClip;
  32. private var _itemLoadingBar:MovieClip;
  33. private var _loadingBarContainer:Sprite;
  34. //点击特性
  35. private var _clickStyleContainer:Sprite;
  36. private var _clickStyle:MovieClip;
  37. public function UIManager(resourceLoader:IResourceLoader,repote:IReport)
  38. {
  39. _loadingItems = 0;
  40. _resourceCount = 0;
  41. _container = new Object();
  42. _resourceData = new Array();
  43. _repoter = repote;
  44. _resourceLoader = resourceLoader;
  45. }
  46. public function LoadUI(url:String, container:Sprite,useUI:Boolean=false,UIType:String="NULL")
  47. {
  48. _loadingItems++;
  49. _container[url] = container;//用资源地址做标识存放资源存放容器,
  50. _resourceLoader.LoadResource("UIManager", url, OnLoadUIComplete,useUI,UIType);
  51. }
  52. public function StartUIByUrl(url:String)
  53. {
  54. var tempUnit:UIUnit = GetUIUnitByURL(url);
  55. if (tempUnit != null) { tempUnit.StartUI(); }
  56. }
  57. public function StartLastestUI()
  58. {
  59. (_resourceData[_resourceData.length - 1] as UIUnit).StartUI();
  60. }
  61. public function set highUIContainer(container:Sprite)
  62. {
  63. _loadingBarContainer = container;
  64. }
  65. public function ShowToolBar()
  66. {
  67. GetUIUnitByURL("UI/ToolBar.swf").Show();
  68. }
  69. public function HideToolBar()
  70. {
  71. GetUIUnitByURL("UI/ToolBar.swf").Hide();
  72. }
  73. public function OnPostProgess(evt:UI_Game_ManagerEvent)
  74. {
  75. if (evt._type == "MAP")
  76. {
  77. if (evt._isComplete)
  78. {
  79. _mapLoadingBar.SetText("100%");
  80. _mapLoadingBar.gotoAndPlay(101); //当完成时从101帧播放
  81. _mapLoadingBar.addFrameScript(130, function()
  82. {
  83. _mapLoadingBar.stop();
  84. OnPostProcessOver();
  85. });
  86. return;
  87. }
  88. if (_loadingBarContainer.numChildren == 0) { _loadingBarContainer.addChild(_mapLoadingBar); }//当无内部对象时加载
  89. _mapLoadingBar.gotoAndStop(evt._process);
  90. _mapLoadingBar.SetText(String(int(evt._process)) + "%");
  91. }
  92. }
  93. private function OnPostProcessOver()
  94. {
  95. _loadingBarContainer.removeChildAt(0);
  96. _mapLoadingBar.gotoAndStop(0);
  97. }
  98. private function GetUIUnitByURL(url:String):UIUnit
  99. {
  100. for (var a:int = 0; a < _resourceData.length; a++ )
  101. {
  102. if ((_resourceData[a] as UIUnit).IsEqual(url))
  103. {
  104. return _resourceData[a] as UIUnit;
  105. }
  106. }
  107. return null;
  108. }
  109. private function OnLoadUIComplete(evt:Event)
  110. {
  111. _loadingItems--;
  112. _resourceCount++;
  113. var tempData:IUIData = evt.target.content as IUIData;
  114. var newUIUnit:UIUnit = new UIUnit(tempData, _container[tempData.FileUrl] as Sprite);
  115. tempData.Repoter = this;
  116. _resourceData.push(newUIUnit);
  117. //发送事件
  118. if (_loadingItems > 0) { return; }//说明还在加载
  119. if (tempData.FileUrl == "UI/LoadingBar.swf")
  120. {
  121. _mapLoadingBar = tempData.UI as MovieClip;
  122. _mapLoadingBar.x += 960 / 2;
  123. _mapLoadingBar.y += 540 / 2;
  124. _mapLoadingBarDoc = tempData;
  125. //向上级发送事件
  126. var tempEVT:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.LOADINGBARLOADEDEVENT);
  127. _repoter.OnReport(tempEVT);
  128. }
  129. else
  130. {
  131. var tempEVT:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.UILOADEDEVENT);
  132. _repoter.OnReport(tempEVT);
  133. }
  134. }
  135. public function LoadAndStart( url:String,container:Sprite,useUI:Boolean=false,UIType:String="NULL")
  136. {
  137. _loadingItems++;
  138. _container[url] = container;
  139. _resourceLoader.LoadResource( "UIManager", url, OnLoadStartUIComplete,useUI,UIType);
  140. }
  141. private function OnLoadStartUIComplete(evt:Event)
  142. {
  143. _loadingItems--;
  144. _resourceCount++;
  145. var tempData:IUIData = evt.target.content as IUIData;
  146. var newUIUnit:UIUnit = new UIUnit(tempData, _container[tempData.FileUrl] as Sprite);
  147. tempData.Repoter = this;
  148. _resourceData.push(newUIUnit);
  149. newUIUnit.StartUI();
  150. //发送事件
  151. if (_loadingItems > 0) { return; }
  152. var tempEVT:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.UILOADEDEVENT);
  153. _repoter.OnReport(tempEVT);
  154. }
  155. public function UnLoadUI(url:String)//卸载UI
  156. {
  157. var temp:UIUnit = GetUIUnitByURL(url);
  158. temp.Delete();
  159. _resourceLoader.UnLoadResource("UIManager", url);
  160. for (var a:int = 0; a < _resourceData.length; a++ )
  161. {
  162. if (_resourceData[a] == temp)
  163. {
  164. _resourceData.splice(a, 1);//移除
  165. var tempEvt:DebugEvent = new DebugEvent("UI:" + url + "卸载");
  166. _repoter.OnReport(tempEvt);
  167. return;
  168. }
  169. }
  170. }
  171. public function OnReport(evt:Event):void
  172. {
  173. if (evt is ManagerEventBase)
  174. {
  175. var event:ManagerEventBase = evt as ManagerEventBase;
  176. switch(event.EvtType)
  177. {
  178. case UIData_UI_ManagerEvent.SHOWUIBYURL:
  179. {
  180. var unit:UIUnit = GetUIUnitByURL((evt as UIData_UI_ManagerEvent).SHOWUIBYURL_url);
  181. unit.StartUI();
  182. return;
  183. }
  184. case UIData_UI_ManagerEvent.CHANGEMAP:
  185. {
  186. var uitomap:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.CALLMAPMANAGERCHANGEMAP);
  187. uitomap.CALLMAPMANAGERCHANGEMAP_spawnPoint = (evt as UIData_UI_ManagerEvent).CHANGEMAP_point;
  188. uitomap.CALLMAPMANAGERCHANGEMAP_targetMap = (evt as UIData_UI_ManagerEvent).CHANGEMAP_mapname;
  189. uitomap.CALLMAPMANAGERCHANGEMAP_sourceMap = GloableData.CurrentMap;
  190. if (uitomap.CALLMAPMANAGERCHANGEMAP_targetMap == uitomap.CALLMAPMANAGERCHANGEMAP_sourceMap) { return; }//如果地图相同则直接退出
  191. _repoter.OnReport(uitomap);
  192. return;
  193. }
  194. case UIData_UI_ManagerEvent.STOPUI:
  195. {
  196. var unit:UIUnit = GetUIUnitByURL((evt as UIData_UI_ManagerEvent).STOPUI_url);
  197. unit.StopUI();
  198. return;
  199. }
  200. case UIData_UI_ManagerEvent.CALLLOADAPP:
  201. {
  202. var loadAppEvt:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.CALLLOADAPP);
  203. loadAppEvt.CALLLOADAPP_url = (evt as UIData_UI_ManagerEvent).CALLLOADAPP_url;
  204. loadAppEvt.CALLLOADAPP_params = (evt as UIData_UI_ManagerEvent).CALLLOADAPP_params;
  205. loadAppEvt.CALLLOADAPP_useUI = (evt as UIData_UI_ManagerEvent).CALLLOADAPP_useUI;
  206. loadAppEvt.CALLLOADAPP_uiType = (evt as UIData_UI_ManagerEvent).CALLLOADAPP_uiType;
  207. _repoter.OnReport(loadAppEvt);
  208. return;
  209. }
  210. case UIData_UI_ManagerEvent.CALLUNLOADAPP:
  211. {
  212. var unload:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.CALLUNLOADAPP);
  213. unload.CALLUNLOADAPP_url = (evt as UIData_UI_ManagerEvent).CALLUNLOADAPP_url;
  214. _repoter.OnReport(unload);
  215. return;
  216. }
  217. case UIData_UI_ManagerEvent.PASSDIALOGSTYLE:
  218. {
  219. var evts:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.PASSDIALOGSTYLE);
  220. evts.PASSDIALOGSTYLE_body = (evt as UIData_UI_ManagerEvent).PASSDIALOGSTYLE_body;
  221. _repoter.OnReport(evts);
  222. return;
  223. }
  224. case UIData_UI_ManagerEvent.SHOWMSG:
  225. {
  226. var ev:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.SHOWMSG);
  227. ev.SHOWMSG_msg = (evt as UIData_UI_ManagerEvent).SHOWMSG_msg;
  228. _repoter.OnReport(ev);
  229. return;
  230. }
  231. case UIData_UI_ManagerEvent.SHOWFRIENDLIST:
  232. {
  233. var t:UI_Game_ManagerEvent = new UI_Game_ManagerEvent(UI_Game_ManagerEvent.SHOWFRIENDLIST);
  234. _repoter.OnReport(t);
  235. return;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. }
  242. import com.lele.Data.IUIData;
  243. import flash.display.Sprite;
  244. class UIUnit extends Sprite//UI单元。包含了UI的存在层次和UI数据
  245. {
  246. public var _UIData:IUIData;
  247. public var _UIContainer:Sprite;
  248. private var _isStarted:Boolean;//标识加载完了以后是否显示出来
  249. public function UIUnit(UIData:IUIData,UIContainer:Sprite)
  250. {
  251. _isStarted = false;
  252. _UIContainer = UIContainer;
  253. _UIData = UIData;
  254. }
  255. public function StartUI()
  256. {
  257. if (_isStarted) { return; }//如果开启了就不要重复开启
  258. _isStarted = true;
  259. _UIContainer.addChild(_UIData.UI);
  260. }
  261. public function StopUI()
  262. {
  263. _isStarted = false;
  264. _UIContainer.removeChild(_UIData.UI);
  265. }
  266. public function Delete()
  267. {
  268. _isStarted = false;
  269. _UIContainer.removeChild(_UIData.UI);
  270. _UIData.CleanResource();
  271. _UIData = null;
  272. _UIContainer = null;
  273. }
  274. public function IsEqual(url:String):Boolean
  275. {
  276. if (url == _UIData.FileUrl) { return true; }
  277. return false;
  278. }
  279. public function get IsStarted():Boolean
  280. {
  281. return _isStarted;
  282. }
  283. public function Hide()
  284. {
  285. _UIContainer.alpha = 0;
  286. _UIContainer.mouseEnabled = false;
  287. _UIContainer.mouseChildren = false;
  288. }
  289. public function Show()
  290. {
  291. _UIContainer.alpha = 1;
  292. _UIContainer.mouseEnabled = true;
  293. _UIContainer.mouseChildren = true;
  294. }
  295. }