DailySignView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using Hutool;
  6. using UI.DailyWelfare;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class DailySignView : BaseWindow
  11. {
  12. private UI_DailySignUI _ui;
  13. private GameObject _gameObject0;
  14. private GameObject _gameObject1;
  15. private GameObject _gameObject2;
  16. private GameObject _gameObject3;
  17. private GameObject _gameObject4;
  18. private GameObject _gameObject5;
  19. private GoWrapper _wrapper0;
  20. private GoWrapper _wrapper1;
  21. private GoWrapper _wrapper2;
  22. private GoWrapper _wrapper3;
  23. private GoWrapper _wrapper4;
  24. private GoWrapper _wrapper5;
  25. private GGraph m_holderSign;
  26. private float _signCount;
  27. private int _month;
  28. private int _day;
  29. public override void Dispose()
  30. {
  31. base.Dispose();
  32. SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);
  33. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  34. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  35. SceneController.DestroyObjectFromView(_gameObject3, _wrapper3);
  36. SceneController.DestroyObjectFromView(_gameObject4, _wrapper4);
  37. SceneController.DestroyObjectFromView(_gameObject5, _wrapper5);
  38. if (_ui != null)
  39. {
  40. _ui.Dispose();
  41. _ui = null;
  42. }
  43. }
  44. protected override void OnInit()
  45. {
  46. base.OnInit();
  47. packageName = UI_DailySignUI.PACKAGE_NAME;
  48. _ui = UI_DailySignUI.Create();
  49. this.viewCom = _ui.target;
  50. this.viewCom.Center();
  51. this.modal = true;
  52. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  53. _ui.m_btnClose.onClick.Add(Hide);
  54. _ui.m_list.itemRenderer = ListItemRender;
  55. string resPath = ResPathUtil.GetViewEffectPath("ui_league", "Answer_bgtx");
  56. SceneController.AddObjectToView(null, null, _ui.m_holderFlower, resPath, out _gameObject0, out _wrapper0);
  57. string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Everyday_2lizi");
  58. SceneController.AddObjectToView(null, null, _ui.m_holderLizi, resPath1, out _gameObject1, out _wrapper1);
  59. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Everydayy_people");
  60. SceneController.AddObjectToView(null, null, _ui.m_holderRole, resPath2, out _gameObject2, out _wrapper2);
  61. string resPath4 = ResPathUtil.GetViewEffectPath("ui_fight_new", "Progress_head");
  62. SceneController.AddObjectToView(null, null, _ui.m_proSign.m_holder, resPath4, out _gameObject4, out _wrapper4, 90);
  63. }
  64. protected override void AddEventListener()
  65. {
  66. base.AddEventListener();
  67. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSignView);
  68. }
  69. protected override void OnShown()
  70. {
  71. base.OnShown();
  72. _ui.m_proSign.m_holder.visible = false;
  73. _ui.m_t0.Play(() =>
  74. {
  75. _ui.m_proSign.m_holder.visible = true;
  76. if (m_holderSign != null)
  77. {
  78. m_holderSign.visible = true;
  79. }
  80. });
  81. _month = TimeUtil.GetCurMonth();
  82. _day = TimeUtil.GetCurDay();
  83. _ui.m_txtMonth.text = NumberUtil.GetOldChiniseNumberText(_month);
  84. UpdateSignView();
  85. }
  86. protected override void OnHide()
  87. {
  88. base.OnHide();
  89. _ui.m_t0.Stop();
  90. m_holderSign = null;
  91. }
  92. protected override void RemoveEventListener()
  93. {
  94. base.RemoveEventListener();
  95. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSignView);
  96. }
  97. private void UpdateSignView()
  98. {
  99. _signCount = MathUtil.CountOnes2(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay));
  100. _ui.m_proSign.m_txtSignCount.text = _signCount.ToString();
  101. List<DailySignBonusCfg> signBonusCfgs = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month);
  102. _ui.m_proSign.target.max = signBonusCfgs.Count;
  103. _ui.m_proSign.target.value = _signCount;
  104. _ui.m_proSign.m_holder.x = _signCount / signBonusCfgs.Count * _ui.m_proSign.target.width - 68;
  105. List<DailySignCfg> signCfgs = DailySignCfgArray.Instance.GetCfgsBymonth(_month);
  106. _ui.m_proSign.m_holderReward.visible = false;
  107. for (int i = 0; i < signCfgs.Count; i++)
  108. {
  109. GComponent comProBonus = _ui.m_proSign.target.GetChild("comProBonus" + i).asCom;
  110. comProBonus.x = ((float)signCfgs[i].day / (float)signBonusCfgs.Count) * _ui.m_proSign.target.width;
  111. UI_ComProBonus item = UI_ComProBonus.Proxy(comProBonus);
  112. item.m_loaIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(signCfgs[i].bonusArr[0][0]));
  113. item.m_txtCount.text = signCfgs[i].bonusArr[0][1].ToString();
  114. item.m_txtDay.text = signCfgs[i].day.ToString();
  115. if (item.target.data == null)
  116. {
  117. item.target.onClick.Add(OnBtnGetProBonus);
  118. }
  119. item.target.data = signCfgs[i];
  120. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward), signCfgs[i].day);
  121. item.m_imgGot.visible = isGot;
  122. bool canGet = _signCount >= signCfgs[i].day && !isGot;
  123. if (canGet)
  124. {
  125. if (_gameObject5 == null)
  126. {
  127. string resPath5 = ResPathUtil.GetViewEffectPath("ui_Activity", "Everyday_enable");
  128. SceneController.AddObjectToView(null, null, _ui.m_proSign.m_holderReward, resPath5, out _gameObject5, out _wrapper5);
  129. }
  130. _ui.m_proSign.m_holderReward.visible = canGet;
  131. _ui.m_proSign.m_holderReward.position = new Vector2(item.target.x, 35);
  132. }
  133. RedDotController.Instance.SetComRedDot(item.target, canGet);
  134. UI_ComProBonus.ProxyEnd();
  135. }
  136. _ui.m_list.numItems = signBonusCfgs.Count > 29 ? signBonusCfgs.Count + 1 : signBonusCfgs.Count;
  137. }
  138. private async void OnBtnGetProBonus(EventContext context)
  139. {
  140. GObject obj = context.sender as GObject;
  141. DailySignCfg signCfg = obj.data as DailySignCfg;
  142. if (_signCount < signCfg.day || MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward), signCfg.day))
  143. {
  144. GoodsItemTipsController.ShowItemTips(signCfg.bonusArr[0][0]);
  145. }
  146. else
  147. {
  148. bool result = await DailyWelfareSProxy.ReqGetSignReward(signCfg.day);
  149. if (result)
  150. {
  151. UpdateSignView();
  152. }
  153. }
  154. }
  155. private void ListItemRender(int index, GObject obj)
  156. {
  157. UI_ListSignItem item = UI_ListSignItem.Proxy(obj);
  158. if (index == 29)
  159. {
  160. item.target.touchable = false;
  161. item.target.visible = false;
  162. return;
  163. }
  164. int _index = index >= 29 ? index - 1 : index;
  165. DailySignBonusCfg bonusCfg = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month)[_index];
  166. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(bonusCfg.bonusArr[0][0]);
  167. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay), bonusCfg.day);
  168. if (bonusCfg.day == _day && !isGot && _gameObject3 == null)
  169. {
  170. string resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "everyday_kuang");
  171. SceneController.AddObjectToView(null, null, item.m_holderSign, resPath3, out _gameObject3, out _wrapper3);
  172. m_holderSign = item.m_holderSign;
  173. }
  174. item.m_holderSign.visible = false;
  175. item.m_c1.selectedIndex = itemCfg.itemType == ConstItemType.DRESS_UP ? 0 : bonusCfg.type;
  176. item.m_txtDay.text = NumberUtil.GetChiniseNumberText(bonusCfg.day);// bonusCfg.day.ToString();
  177. if (item.m_comItem.data == null)
  178. {
  179. item.m_comItem.data = new ItemView(item.m_comItem);
  180. }
  181. ItemData itemData = ItemUtil.createItemData(bonusCfg.bonusArr[0]);
  182. (item.m_comItem.data as ItemView).SetData(itemData);
  183. (item.m_comItem.data as ItemView).ShowTips = false;
  184. (item.m_comItem.data as ItemView).ChangeTxtCountStyle();
  185. item.m_imgMask.visible = isGot || bonusCfg.day < _day && !isGot;
  186. item.m_imgGot.visible = isGot;
  187. item.m_imgNotGet.visible = bonusCfg.day < _day && !isGot;
  188. RedDotController.Instance.SetComRedDot(item.target, bonusCfg.day == _day && !isGot);
  189. if (item.target.data == null)
  190. {
  191. item.target.onClick.Add(OnGetSignBonus);
  192. }
  193. item.target.data = bonusCfg.day;
  194. UI_ListSignItem.ProxyEnd();
  195. }
  196. private async void OnGetSignBonus(EventContext context)
  197. {
  198. GObject obj = context.sender as GObject;
  199. int day = (int)obj.data;
  200. bool result = false;
  201. if (day > _day) return;
  202. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay), day);
  203. if (isGot)
  204. {
  205. PromptController.Instance.ShowFloatTextPrompt("已领取");
  206. return;
  207. }
  208. if (day < _day)
  209. {
  210. int[] cost = GlobalCfgArray.globalCfg.dailySignConsumeArr[0];
  211. AlertUI.Show(string.Format("是否确定花费{0}{1}补签?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  212. SetLeftButton(true, "否").
  213. SetRightButton(true, "是", async (object param) =>
  214. {
  215. if (!ItemUtil.CheckItemEnough(cost[0], cost[1]))
  216. {
  217. long has = ItemDataManager.GetItemNum(cost[0]);
  218. ItemUtil.BuyCurrency(cost[0], cost[1] - has);
  219. return;
  220. }
  221. result = await DailyWelfareSProxy.ReqReSign(day);
  222. });
  223. }
  224. else
  225. {
  226. result = await DailyWelfareSProxy.ReqSign(day);
  227. }
  228. // if (result)
  229. // {
  230. // _ui.m_list.numItems = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month).Count;
  231. // }
  232. }
  233. }
  234. }