DailySignView.cs 11 KB

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