GameStartView.cs 12 KB

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