DailySignView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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_t0.Play(() =>
  72. {
  73. if (m_holderSign != null)
  74. {
  75. m_holderSign.visible = true;
  76. }
  77. });
  78. _month = TimeUtil.GetCurMonth();
  79. _day = TimeUtil.GetCurDay();
  80. _ui.m_txtMonth.text = NumberUtil.GetOldChiniseNumberText(_month);
  81. UpdateSignView();
  82. }
  83. protected override void OnHide()
  84. {
  85. base.OnHide();
  86. _ui.m_t0.Stop();
  87. }
  88. protected override void RemoveEventListener()
  89. {
  90. base.RemoveEventListener();
  91. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSignView);
  92. }
  93. private void UpdateSignView()
  94. {
  95. _signCount = MathHelper.CountOnes(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignDay));
  96. _ui.m_proSign.m_txtSignCount.text = _signCount.ToString();
  97. List<DailySignBonusCfg> signBonusCfgs = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month);
  98. _ui.m_proSign.target.max = signBonusCfgs.Count;
  99. _ui.m_proSign.target.value = _signCount;
  100. _ui.m_proSign.m_holder.x = _signCount / signBonusCfgs.Count * _ui.m_proSign.target.width - 68;
  101. List<DailySignCfg> signCfgs = DailySignCfgArray.Instance.GetCfgsBymonth(_month);
  102. _ui.m_proSign.m_holderReward.visible = false;
  103. for (int i = 0; i < signCfgs.Count; i++)
  104. {
  105. GComponent comProBonus = _ui.m_proSign.target.GetChild("comProBonus" + i).asCom;
  106. comProBonus.x = ((float)signCfgs[i].day / (float)signBonusCfgs.Count) * _ui.m_proSign.target.width;
  107. UI_ComProBonus item = UI_ComProBonus.Proxy(comProBonus);
  108. item.m_loaIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(signCfgs[i].bonusArr[0][0]));
  109. item.m_txtCount.text = signCfgs[i].bonusArr[0][1].ToString();
  110. item.m_txtDay.text = signCfgs[i].day.ToString();
  111. if (item.target.data == null)
  112. {
  113. item.target.onClick.Add(OnBtnGetProBonus);
  114. }
  115. item.target.data = signCfgs[i];
  116. bool isGot = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward), signCfgs[i].day);
  117. item.m_imgGot.visible = isGot;
  118. bool canGet = _signCount >= signCfgs[i].day && !isGot;
  119. if (canGet)
  120. {
  121. if (_gameObject5 == null)
  122. {
  123. string resPath5 = ResPathUtil.GetViewEffectPath("ui_Activity", "Everyday_enable");
  124. SceneController.AddObjectToView(null, null, _ui.m_proSign.m_holderReward, resPath5, out _gameObject5, out _wrapper5);
  125. }
  126. _ui.m_proSign.m_holderReward.visible = canGet;
  127. _ui.m_proSign.m_holderReward.position = new Vector2(item.target.x, 35);
  128. }
  129. RedDotController.Instance.SetComRedDot(item.target, canGet);
  130. UI_ComProBonus.ProxyEnd();
  131. }
  132. _ui.m_list.numItems = signBonusCfgs.Count > 29 ? signBonusCfgs.Count + 1 : signBonusCfgs.Count;
  133. }
  134. private async void OnBtnGetProBonus(EventContext context)
  135. {
  136. GObject obj = context.sender as GObject;
  137. DailySignCfg signCfg = obj.data as DailySignCfg;
  138. if (_signCount < signCfg.day || MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward), signCfg.day))
  139. {
  140. GoodsItemTipsController.ShowItemTips(signCfg.bonusArr[0][0]);
  141. }
  142. else
  143. {
  144. bool result = await DailyWelfareSProxy.ReqGetSignReward(signCfg.day);
  145. if (result)
  146. {
  147. UpdateSignView();
  148. }
  149. }
  150. }
  151. private void ListItemRender(int index, GObject obj)
  152. {
  153. UI_ListSignItem item = UI_ListSignItem.Proxy(obj);
  154. if (index == 29)
  155. {
  156. item.target.touchable = false;
  157. item.target.visible = false;
  158. return;
  159. }
  160. int _index = index >= 29 ? index - 1 : index;
  161. DailySignBonusCfg bonusCfg = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month)[_index];
  162. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(bonusCfg.bonusArr[0][0]);
  163. bool isGot = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignDay), bonusCfg.day);
  164. if (bonusCfg.day == _day && !isGot && _gameObject3 == null)
  165. {
  166. string resPath3 = ResPathUtil.GetViewEffectPath("ui_Activity", "everyday_kuang");
  167. SceneController.AddObjectToView(null, null, item.m_holderSign, resPath3, out _gameObject3, out _wrapper3);
  168. m_holderSign = item.m_holderSign;
  169. }
  170. item.m_holderSign.visible = false;
  171. item.m_c1.selectedIndex = itemCfg.itemType == ConstItemType.DRESS_UP ? 0 : bonusCfg.type;
  172. item.m_txtDay.text = NumberUtil.GetChiniseNumberText(bonusCfg.day);// bonusCfg.day.ToString();
  173. if (item.m_comItem.data == null)
  174. {
  175. item.m_comItem.data = new ItemView(item.m_comItem);
  176. }
  177. ItemData itemData = ItemUtil.createItemData(bonusCfg.bonusArr[0]);
  178. (item.m_comItem.data as ItemView).SetData(itemData);
  179. (item.m_comItem.data as ItemView).ShowTips = false;
  180. (item.m_comItem.data as ItemView).ChangeTxtCountStyle();
  181. item.m_imgMask.visible = isGot || bonusCfg.day < _day && !isGot;
  182. item.m_imgGot.visible = isGot;
  183. item.m_imgNotGet.visible = bonusCfg.day < _day && !isGot;
  184. RedDotController.Instance.SetComRedDot(item.target, bonusCfg.day == _day && !isGot);
  185. if (item.target.data == null)
  186. {
  187. item.target.onClick.Add(OnGetSignBonus);
  188. }
  189. item.target.data = bonusCfg.day;
  190. UI_ListSignItem.ProxyEnd();
  191. }
  192. private async void OnGetSignBonus(EventContext context)
  193. {
  194. GObject obj = context.sender as GObject;
  195. int day = (int)obj.data;
  196. bool result = false;
  197. if (day > _day) return;
  198. bool isGot = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignDay), day);
  199. if (isGot)
  200. {
  201. PromptController.Instance.ShowFloatTextPrompt("已领取");
  202. return;
  203. }
  204. if (day < _day)
  205. {
  206. int[] cost = GlobalCfgArray.globalCfg.dailySignConsumeArr[0];
  207. AlertUI.Show(string.Format("是否确定花费{0}{1}补签?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  208. SetLeftButton(true, "否").
  209. SetRightButton(true, "是", async (object param) =>
  210. {
  211. if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
  212. {
  213. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  214. return;
  215. }
  216. result = await DailyWelfareSProxy.ReqReSign(day);
  217. });
  218. }
  219. else
  220. {
  221. result = await DailyWelfareSProxy.ReqSign(day);
  222. }
  223. if (result)
  224. {
  225. _ui.m_list.numItems = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month).Count;
  226. }
  227. }
  228. }
  229. }