GameStartView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.MiniGame;
  6. using UnityEngine;
  7. using System.Text.RegularExpressions;
  8. namespace GFGGame
  9. {
  10. public class GameStartView : BaseWindow
  11. {
  12. private UI_GameStartUI _ui;
  13. //后续这里改成读表内容,1:CardGame,2:Merge2048Game,3:HuarongRoadGame
  14. private List<string> viewJumpName = new List<string>() {"","FlipGameView", "TZFEGameCheckView" ,"ActivityHuaRongDaoView"};
  15. private List<ActivityOpenCfg> activityGameDate;
  16. private List<int> GameType = new List<int>();
  17. private List<int> ChallengeList = new List<int>();
  18. //由于每个游戏都有一个表
  19. private List<CardGame> CardGameDate;
  20. private List<Merge2048Game> Merge2048GameDate;
  21. private int NumTicketOne = 3;
  22. private int NumTicketTwo = 3;
  23. private EffectUI _effectUI1;
  24. private EffectUI _effectUI2;
  25. private EffectUI _effectUI3;
  26. private EffectUI _effectUI4;
  27. public override void Dispose()
  28. {
  29. EffectUIPool.Recycle(_effectUI1);
  30. _effectUI1 = null;
  31. EffectUIPool.Recycle(_effectUI2);
  32. _effectUI2 = null;
  33. EffectUIPool.Recycle(_effectUI3);
  34. _effectUI3 = null;
  35. EffectUIPool.Recycle(_effectUI4);
  36. _effectUI4 = null;
  37. if (_ui != null)
  38. {
  39. _ui.Dispose();
  40. _ui = null;
  41. }
  42. base.Dispose();
  43. }
  44. protected override void OnInit()
  45. {
  46. base.OnInit();
  47. packageName = UI_GameStartUI.PACKAGE_NAME;
  48. _ui = UI_GameStartUI.Create();
  49. this.viewCom = _ui.target;
  50. isfullScreen = true;
  51. isReturnView = true;
  52. _ui.m_game1.onClick.Add(OnClickBtnGameOne);
  53. _ui.m_game2.onClick.Add(OnClickBtnGameTwo);
  54. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  55. _ui.m_shopBtn.onClick.Add(OnClickBtnShop);
  56. _ui.m_addIcon.onClick.Add(OnClickBtnAdd);
  57. _ui.m_rewardBtn.target.onClick.Add(OnClickBtnReward);
  58. _ui.m_tipsOne.onClick.Add(RuleController.ShowRuleView);
  59. _ui.m_tipsTwo.onClick.Add(RuleController.ShowRuleView);
  60. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effectIcon1, "ui_Activity", "YXJY_Icon");
  61. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_effectText1, "ui_Activity", "YXJY_Game_Text");
  62. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_effectIcon2, "ui_Activity", "SGLL_Icon");
  63. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_effectText2, "ui_Activity", "SGLL_Game_Text");
  64. }
  65. protected override void OnShown()
  66. {
  67. base.OnShown();
  68. activityGameDate = ActivityOpenCfgArray.Instance.GetCfgsBytype(ConstLimitTimeActivityType.ActLimitStlyc);
  69. GetGameIdByActivityDate();
  70. UpdateChallengeBtn();
  71. ReqChallageReward();
  72. UpdateView();
  73. }
  74. protected override void AddEventListener()
  75. {
  76. base.AddEventListener();
  77. EventAgent.AddEventListener(ConstMessage.MINI_GAME_UPDATE, UpdateRed);
  78. }
  79. protected override void RemoveEventListener()
  80. {
  81. base.RemoveEventListener();
  82. EventAgent.RemoveEventListener(ConstMessage.MINI_GAME_UPDATE, UpdateRed);
  83. }
  84. protected override void OnHide()
  85. {
  86. GameType.Clear();
  87. ChallengeList.Clear();
  88. base.OnHide();
  89. }
  90. private void UpdateRed()
  91. {
  92. RedDotController.Instance.SetComRedDot(_ui.m_rewardBtn.target, MiniGameDateManager.Instance.GetRewardRot());
  93. }
  94. private void UpdateView()
  95. {
  96. if(ChallengeList.Count == 0)
  97. {
  98. _ui.m_rewardBtn.target.visible = false;
  99. }
  100. else
  101. {
  102. _ui.m_rewardBtn.target.visible = true;
  103. }
  104. CardGame cardGameDate = CardGameArray.Instance.GetCfgsBytypeAndsubType(GameType[0],GameType[1])[0];
  105. int consumeID;
  106. if (cardGameDate.comsumePassArr.Length > 0)
  107. {
  108. NumTicketOne = cardGameDate.comsumePassArr[0][1];
  109. consumeID = cardGameDate.comsumePassArr[0][0];
  110. }
  111. else
  112. {
  113. NumTicketOne = 3;
  114. consumeID = 3000017;
  115. }
  116. _ui.m_ticket.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(consumeID).res,"png");
  117. _ui.m_needNum1.text = NumTicketOne.ToString();
  118. _ui.m_needIcon1.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(consumeID).res,"png");
  119. _ui.m_needIcon2.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(consumeID).res, "png");
  120. _ui.m_needNum2.text = NumTicketTwo.ToString();
  121. _ui.m_needNum2.visible = false;
  122. _ui.m_needIcon2.visible = false;
  123. _ui.m_game1.url = "";
  124. _ui.m_game2.url = "";
  125. _ui.m_tipsOne.data = 300026;
  126. _ui.m_tipsTwo.data = 300027;
  127. ItemData item;
  128. if (BagDataManager.Instance.GetBagData().TryGetValue(consumeID, out item))
  129. {
  130. _ui.m_ticketNum.text = item.num.ToString();
  131. }
  132. else
  133. {
  134. _ui.m_ticketNum.text = "0";
  135. }
  136. }
  137. private void OnClickBtnBack()
  138. {
  139. this.Hide();
  140. }
  141. private void OnClickBtnShop()
  142. {
  143. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_ACTIVITY_EXCHANGE });
  144. }
  145. private void OnClickBtnReward()
  146. {
  147. ViewManager.Show<ChallengeRewardView>(new object[] { ChallengeList });
  148. }
  149. private async void ReqChallageReward()
  150. {
  151. var result = await MiniGameProxy.ReqGetChallengeReward(activityGameDate[0].id);
  152. if (!result) return;
  153. RedDotController.Instance.SetComRedDot(_ui.m_rewardBtn.target, MiniGameDateManager.Instance.GetRewardRot());
  154. }
  155. private void OnClickBtnAdd()
  156. {
  157. object[] sourceDatas = new object[] { 3000017, null };
  158. GoodsItemTipsController.ShowItemTips(3000017, sourceDatas);
  159. }
  160. private async void OnClickBtnGameOne()
  161. {
  162. var result = await MiniGameProxy.ReqMiniGameStart(CardGameArray.Instance.GetCfgsBytypeAndsubType(GameType[0], GameType[1])[0].id, GameType[0], activityGameDate[0].id);
  163. if (!result) return;
  164. ViewManager.Show($"GFGGame.{viewJumpName[GameType[0]]}", new object[] { CardGameArray.Instance.GetCfgsBytypeAndsubType(GameType[0], GameType[1])[0].id });
  165. }
  166. private void OnClickBtnGameTwo()
  167. {
  168. ViewManager.Show($"GFGGame.{viewJumpName[GameType[2]]}",new object[] { GameType[2],GameType[3]});
  169. }
  170. private void GetGameIdByActivityDate()
  171. {
  172. string pattern = @"\d+";
  173. for(int i = 0; i < activityGameDate[0].params5Arr.Length; i++)
  174. {
  175. MatchCollection matches = Regex.Matches(activityGameDate[0].params5Arr[i], pattern);
  176. foreach (Match match in matches)
  177. {
  178. GameType.Add(int.Parse(match.Value));
  179. }
  180. }
  181. }
  182. private void OnNumericChange()
  183. {
  184. ItemData item;
  185. if (BagDataManager.Instance.GetBagData().TryGetValue(3000017, out item))
  186. {
  187. _ui.m_ticketNum.text = item.num.ToString();
  188. }
  189. else
  190. {
  191. _ui.m_ticketNum.text = "0";
  192. }
  193. }
  194. private void UpdateChallengeBtn()
  195. {
  196. int index = 0;
  197. //当两个游戏都只有一关时,奖励按钮隐藏
  198. for(int i = 0;i<GameType.Count;i+=2)
  199. {
  200. switch (GameType[i])
  201. {
  202. case 1:
  203. List<CardGame> CardGameDate = CardGameArray.Instance.GetCfgsBytypeAndsubType(GameType[i], GameType[i +1]);
  204. if( CardGameDate.Count <= 1)
  205. {
  206. ChallengeList.Add(GameType[i]);
  207. ChallengeList.Add(GameType[i+1]);
  208. }
  209. if(i < 1)
  210. {
  211. //NumTicketOne = CardGameDate[0].comsumeStartArr[0][1];
  212. }
  213. else
  214. {
  215. //NumTicketTwo = CardGameDate[0].comsumeStartArr[0][1];
  216. }
  217. break;
  218. case 2:
  219. List<Merge2048Game> Merge2048GameDate = Merge2048GameArray.Instance.GetCfgsBytypeAndsubType(GameType[i], GameType[i + 1]);
  220. if (Merge2048GameDate.Count <= 1 || Merge2048GameDate[0].bonusWinFirstArr.Length > 0)
  221. {
  222. ChallengeList.Add(GameType[i]);
  223. ChallengeList.Add(GameType[i + 1]);
  224. }
  225. if (i < 1)
  226. {
  227. //NumTicketOne = CardGameDate[0].comsumeStartArr[0][1];
  228. }
  229. else
  230. {
  231. //NumTicketTwo = CardGameDate[0].comsumeStartArr[0][1];
  232. }
  233. break;
  234. case 3:
  235. List <HuarongRoadGame> HuarongRoadGameDate = HuarongRoadGameArray.Instance.GetCfgsBytypeAndsubType(GameType[i], GameType[i + 1]);
  236. if (HuarongRoadGameDate.Count <= 1)
  237. {
  238. ChallengeList.Add(GameType[i]);
  239. ChallengeList.Add(GameType[i + 1]);
  240. }
  241. if (i < 1)
  242. {
  243. //NumTicketOne = CardGameDate[0].comsumeStartArr[0][1];
  244. }
  245. else
  246. {
  247. //NumTicketTwo = CardGameDate[0].comsumeStartArr[0][1];
  248. }
  249. break;
  250. }
  251. }
  252. }
  253. }
  254. }