DailySignView.cs 11 KB

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