MainHomePanelCtrl.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System;
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame;
  10. using XGame.Database;
  11. using XGame.Framework.Time;
  12. using XGame.Framework.UI;
  13. namespace FL.FGUI
  14. {
  15. /// <summary>
  16. /// UI逻辑处理类
  17. /// </summary>
  18. /// <typeparam name=""></typeparam>
  19. public partial class MainHomePanelCtrl : UIController<MainHomePanelVM>
  20. {
  21. private ITimer _mapRewardTimer;
  22. protected override void OnEnable(object intent)
  23. {
  24. AddUIListenres();
  25. Context.AddListener(EventDefine.PveFightEnd, RefreshMapReward);
  26. Context.AddListener(EventDefine.PveReceivedRewards, RefreshMapReward);
  27. InitView();
  28. RefreshPlayerInfo();
  29. RefreshMapReward();
  30. RefreshHdList();
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. Context.RemoveListener(EventDefine.PveFightEnd, RefreshMapReward);
  36. Context.RemoveListener(EventDefine.PveReceivedRewards, RefreshMapReward);
  37. _mapRewardTimer?.Cancel();
  38. _mapRewardTimer = null;
  39. }
  40. #region UI事件
  41. private void AddUIListenres()
  42. {
  43. VM.SysMenuBtn.onClick.Add(OnClickSysMenuBtn);
  44. VM.FriendBtn.onClick.Add(OnClickFriendBtn);
  45. VM.MailBtn.onClick.Add(OnClickMailBtn);
  46. VM.NoticeBtn.onClick.Add(OnClickNoticeBtn);
  47. VM.SettingBtn.onClick.Add(OnClickSettingBtn);
  48. VM.ExchangeBtn.onClick.Add(OnClickExchangeBtn);
  49. VM.BagBtn.onClick.Add(OnClickBagBtn);
  50. VM.MapRewardBtn.onClick.Add(OnClickMapRewardBtn);
  51. VM.GoldNested.VM.PanelEvent.Add(OnClickGoldNested);
  52. VM.DiamondNested.VM.PanelEvent.Add(OnClickDiamondNested);
  53. }
  54. private void RemoveUIListenres()
  55. {
  56. VM.SysMenuBtn.onClick.Remove(OnClickSysMenuBtn);
  57. VM.FriendBtn.onClick.Remove(OnClickFriendBtn);
  58. VM.MailBtn.onClick.Remove(OnClickMailBtn);
  59. VM.NoticeBtn.onClick.Remove(OnClickNoticeBtn);
  60. VM.SettingBtn.onClick.Remove(OnClickSettingBtn);
  61. VM.ExchangeBtn.onClick.Remove(OnClickExchangeBtn);
  62. VM.BagBtn.onClick.Remove(OnClickBagBtn);
  63. VM.MapRewardBtn.onClick.Remove(OnClickMapRewardBtn);
  64. VM.GoldNested.VM.PanelEvent.Remove(OnClickGoldNested);
  65. VM.DiamondNested.VM.PanelEvent.Remove(OnClickDiamondNested);
  66. }
  67. private void OnClickSysMenuBtn(EventContext context)
  68. {
  69. VM.SysMenuActive = !VM.SysMenuActive;
  70. }
  71. private void OnClickFriendBtn(EventContext context)
  72. {
  73. Context.ShowTips("OnClickFriendBtn");
  74. VM.SysMenuActive = false;
  75. }
  76. private void OnClickMailBtn(EventContext context)
  77. {
  78. //Context.ShowTips("OnClickMailBtn");
  79. VM.SysMenuActive = false;
  80. MailService.Instance.RequestMailInto();
  81. }
  82. private void OnClickNoticeBtn(EventContext context)
  83. {
  84. Context.ShowTips("OnClickNoticeBtn");
  85. VM.SysMenuActive = false;
  86. // 临时测试GM消息按钮
  87. Context.UI.OpenAsync(UIKeys.GmToolSendMsgPanel);
  88. }
  89. private void OnClickSettingBtn(EventContext context)
  90. {
  91. Context.ShowTips("OnClickSettingBtn");
  92. VM.SysMenuActive = false;
  93. }
  94. private void OnClickExchangeBtn(EventContext context)
  95. {
  96. Context.ShowTips("OnClickExchangeBtn");
  97. VM.SysMenuActive = false;
  98. // 临时测试GM消息入口按钮
  99. Context.UI.OpenAsync(UIKeys.GmToolSendMsgPanel);
  100. }
  101. private void OnClickBagBtn(EventContext context)
  102. {
  103. Context.UI.OpenAsync(UIKeys.BagBackpackPanel);
  104. VM.SysMenuActive = false;
  105. }
  106. private void OnClickMapRewardBtn(EventContext context)
  107. {
  108. //Context.ShowTips("OnClickMapRewardBtn");
  109. if (FunctionService.Instance.IsUnlock((int)EFunctionUnlockType.AutoRwd))
  110. {
  111. Context.UI.OpenAsync(UIKeys.BattleRewardPreviewPanel);
  112. }
  113. else
  114. {
  115. Context.ShowTips(EStringDefine.FunctionIsLock);
  116. }
  117. }
  118. private void OnClickGoldNested(EventContext context)
  119. { // 金币商店
  120. ShopService.Instance.RequestShopInto();
  121. }
  122. private void OnClickDiamondNested(EventContext context)
  123. { // 钻石商店
  124. ShopService.Instance.RequestShopInto();
  125. }
  126. #endregion
  127. private void RefreshMapReward(int eventId, object args)
  128. {
  129. RefreshMapReward();
  130. }
  131. private bool _init = false;
  132. private void InitView()
  133. {
  134. if (_init)
  135. return;
  136. _init = true;
  137. VM.RightHdList.ListType = EGListType.Virtual;
  138. VM.LeftMenuBtnsList.ListType = EGListType.Virtual;
  139. }
  140. void RefreshPlayerInfo()
  141. {
  142. //TODO
  143. var player = PlayerData.Instance;
  144. VM.PlayerHead.icon = "itemicon_99"; // player.HeadIcon;
  145. VM.PlayerNameTxt.text = player.Name;
  146. VM.PlayerLvTxt.text = player.Level.ToString();
  147. VM.PlayerPowerIcon.icon = AddressableDefine.itemicon_power;
  148. VM.PlayerPowerTxt.text = player.Power.ToNumberString();
  149. VM.GoldNested.Ctrl.ShowUI(ItemData.GoldId, ItemData.Instance.Gold);
  150. VM.DiamondNested.Ctrl.ShowUI(ItemData.DiamondId, ItemData.Instance.Diamond);
  151. }
  152. void RefreshMapReward()
  153. {
  154. _mapRewardTimer?.Cancel();
  155. if (!FunctionService.Instance.IsUnlock((int)EFunctionUnlockType.AutoRwd))
  156. {
  157. VM.SetMapRewardState(3);
  158. VM.SetMapRewardUnlockTxt(FunctionService.Instance.GetUnlockText((int)EFunctionUnlockType.AutoRwd, 1));
  159. //VM.SetMapRewardUnlockTxt()
  160. return;
  161. }
  162. var pveData = PveData.Instance;
  163. long remainTime = KeyValue.PlaceRewardsLimit * 1000;
  164. var lastTime = Context.Time.GetNowTime();
  165. var state = 0;
  166. if (pveData.lastTime == 0)
  167. { // 没有结算过奖励
  168. }
  169. else
  170. {
  171. remainTime -= (lastTime - pveData.lastTime + pveData.overTime);
  172. if (remainTime <= 0)
  173. {
  174. state = 2;
  175. remainTime = KeyValue.PlaceRewardsLimit * 1000;
  176. }
  177. else
  178. {
  179. state = 1;
  180. }
  181. }
  182. VM.MapRewardBtn.title = remainTime.ToTimeString(@"hh\:mm\:ss");
  183. if (state < 2)
  184. {
  185. _mapRewardTimer = Context.Time.AddLooperTimer(
  186. 500,
  187. _ =>
  188. {
  189. var nowTime = Context.Time.GetNowTime();
  190. remainTime -= (nowTime - lastTime);
  191. if (remainTime <= 0)
  192. {
  193. remainTime = 0;
  194. _mapRewardTimer.Cancel();
  195. _mapRewardTimer = null;
  196. VM.SetMapRewardState(2);
  197. return;
  198. }
  199. VM.MapRewardBtn.title = remainTime.ToTimeString(@"hh\:mm\:ss");
  200. lastTime = nowTime;
  201. }
  202. );
  203. }
  204. VM.SetMapRewardState(state);
  205. }
  206. private void RefreshHdList()
  207. {
  208. ShowLeftMenusBtns();
  209. var list = hdActivityTableRepo.GetListByPos(1);
  210. var count = list.Count;
  211. if (count > 7)
  212. {
  213. count = 7;
  214. }
  215. VM.RightHdList.height =
  216. count * VM.RightHdList.defaultItemSize.y
  217. + (count - 1 * VM.RightHdList.lineGap)
  218. + VM.RightHdList.margin.top;
  219. VM.RightHdList.BindDatas(list);
  220. }
  221. private void ShowLeftMenusBtns()
  222. {
  223. var list = hdActivityTableRepo.GetListByPos(0);
  224. var count = list.Count;
  225. if (count == 0)
  226. {
  227. VM.LeftMenuBtns.visible = false;
  228. return;
  229. }
  230. else if (count > 7)
  231. {
  232. count = 7;
  233. }
  234. VM.LeftMenuBtns.visible = true;
  235. VM.LeftMenuBtnsList.height =
  236. count * VM.LeftMenuBtnsList.defaultItemSize.y
  237. + (count - 1 * VM.LeftMenuBtnsList.lineGap)
  238. + VM.LeftMenuBtnsList.margin.top;
  239. VM.LeftMenuBtnsList.BindDatas(list);
  240. }
  241. }
  242. }