DailySignView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using cfg.GfgCfg;
  5. using ET;
  6. using FairyGUI;
  7. using Hutool;
  8. using UI.DailyWelfare;
  9. using UnityEngine;
  10. namespace GFGGame
  11. {
  12. public class DailySignView : BaseWindow
  13. {
  14. private UI_DailySignUI _ui;
  15. private EffectUI _effectUI0;
  16. private EffectUI _effectUI1;
  17. private EffectUI _effectUI2;
  18. private EffectUI _effectUI3;
  19. private EffectUI _effectUI4;
  20. private EffectUI _effectUI5;
  21. private GGraph m_holderSign;
  22. private float _signCount;
  23. private int _year;
  24. private int _month;
  25. private int _day;
  26. private bool isOpenPanel = true;
  27. DateTime dateTime;
  28. public override void Dispose()
  29. {
  30. EffectUIPool.Recycle(_effectUI0);
  31. _effectUI0 = null;
  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. EffectUIPool.Recycle(_effectUI5);
  41. _effectUI5 = null;
  42. if (_ui != null)
  43. {
  44. _ui.Dispose();
  45. _ui = null;
  46. }
  47. base.Dispose();
  48. }
  49. protected override void OnInit()
  50. {
  51. base.OnInit();
  52. packageName = UI_DailySignUI.PACKAGE_NAME;
  53. _ui = UI_DailySignUI.Create();
  54. this.viewCom = _ui.target;
  55. this.viewCom.Center();
  56. this.modal = true;
  57. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  58. _ui.m_btnClose.onClick.Add(Hide);
  59. _ui.m_list.itemRenderer = ListItemRender;
  60. EffectUIPool.CreateEffectUI(_ui.m_holderFlower, "ui_league", "Answer_bgtx",
  61. onComplete: (effect) =>
  62. {
  63. if (effect != null)
  64. {
  65. _effectUI0 = effect;
  66. }
  67. });
  68. EffectUIPool.CreateEffectUI(_ui.m_holderLizi, "ui_Activity", "Everyday_2lizi",
  69. onComplete: (effect) =>
  70. {
  71. if (effect != null)
  72. {
  73. _effectUI1 = effect;
  74. }
  75. });
  76. EffectUIPool.CreateEffectUI(_ui.m_holderRole, "ui_Activity", "Everydayy_people",
  77. onComplete: (effect) =>
  78. {
  79. if (effect != null)
  80. {
  81. _effectUI2 = effect;
  82. }
  83. });
  84. EffectUIPool.CreateEffectUI(_ui.m_proSign.m_holder, "ui_fight_new", "Progress_head",
  85. onComplete: (effect) =>
  86. {
  87. if (effect != null)
  88. {
  89. _effectUI4 = effect;
  90. }
  91. });
  92. }
  93. protected override void AddEventListener()
  94. {
  95. base.AddEventListener();
  96. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSignView);
  97. }
  98. protected override void OnShown()
  99. {
  100. base.OnShown();
  101. _ui.m_proSign.m_holder.visible = false;
  102. GRoot.inst.touchable = false;
  103. _ui.m_t0.SetHook("touch", () => { GRoot.inst.touchable = true; });
  104. _ui.m_t0.Play(() =>
  105. {
  106. //不知道sethook会不会出问题,在这里也加一个
  107. GRoot.inst.touchable = true;
  108. if (m_holderSign != null)
  109. {
  110. m_holderSign.visible = true;
  111. }
  112. });
  113. _year = TimeUtil.GetCurYear();
  114. _month = TimeUtil.GetCurMonth();
  115. _day = TimeUtil.GetCurDay();
  116. _ui.m_txtMonth.text = NumberUtil.GetOldChiniseNumberText(_month);
  117. //这个是0时区的0时间戳,所以转换为中国时间(东八区)需要加八个小时的毫秒
  118. DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0);
  119. double chinaTime = GameGlobal.OpenServerTime + 28800000;
  120. dateTime = unixStartTime.AddMilliseconds(chinaTime);
  121. UpdateSignView();
  122. //从主界面自动打开这个界面的话,就显示 1
  123. if (this.viewData != null)
  124. {
  125. Timers.inst.Add(0.8f, 1, (obj) =>
  126. {
  127. //防止手速超快关了又开
  128. if (ViewManager.isViewOpen(nameof(DailySignView)))
  129. {
  130. int sourceType = (int)(this.viewData as object[])[0];
  131. if (sourceType == 1)
  132. {
  133. SignBonus(_day);
  134. }
  135. }
  136. }
  137. );
  138. }
  139. GameGlobal.AutoDailySignView = false;
  140. }
  141. protected override void OnHide()
  142. {
  143. base.OnHide();
  144. _ui.m_t0.Stop();
  145. m_holderSign = null;
  146. }
  147. protected override void RemoveEventListener()
  148. {
  149. base.RemoveEventListener();
  150. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSignView);
  151. }
  152. private void UpdateSignView()
  153. {
  154. _signCount = MathUtil.CountOnes2(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay));
  155. _ui.m_proSign.m_txtSignCount.text = _signCount.ToString();
  156. List<DailySignBonusCfg> signBonusCfgs = CommonDataManager.Tables.TblDailySignBonusCfg.DataList
  157. .Where(a => a.Month == _month).ToList();
  158. List<DailySignCfg> signCfgs = CommonDataManager.Tables.TblDailySignCfg.DataList
  159. .Where(a => a.Month == _month).ToList();
  160. _ui.m_proSign.target.max = signCfgs[signCfgs.Count - 1].Day;
  161. _ui.m_proSign.target.value = _signCount;
  162. if (_signCount >= signCfgs[signCfgs.Count - 1].Day)
  163. {
  164. _ui.m_proSign.m_holder.visible = false;
  165. }
  166. else
  167. {
  168. _ui.m_proSign.m_holder.visible = true;
  169. }
  170. _ui.m_proSign.m_holder.x = _signCount / signCfgs[signCfgs.Count - 1].Day * _ui.m_proSign.target.width - 88;
  171. _ui.m_proSign.m_holderReward.visible = false;
  172. for (int i = 0; i < signCfgs.Count; i++)
  173. {
  174. GComponent comProBonus = _ui.m_proSign.target.GetChild("comProBonus" + i).asCom;
  175. if (i == signCfgs.Count - 1)
  176. {
  177. comProBonus.x = ((float)signCfgs[i].Day / (float)signCfgs[signCfgs.Count - 1].Day) *
  178. _ui.m_proSign.target.width - 48;
  179. }
  180. else
  181. {
  182. comProBonus.x = ((float)signCfgs[i].Day / (float)signCfgs[signCfgs.Count - 1].Day) *
  183. _ui.m_proSign.target.width - 20;
  184. }
  185. UI_ComProBonus item = UI_ComProBonus.Proxy(comProBonus);
  186. item.target.visible = true;
  187. item.m_loaIcon.url =
  188. ResPathUtil.GetIconPath(
  189. CommonDataManager.Tables.TblItemCfg.GetOrDefault(signCfgs[i].Bonus[0].ItemId));
  190. item.m_txtCount.text = signCfgs[i].Bonus[0].Count.ToString();
  191. item.m_txtDay.text = signCfgs[i].Day.ToString();
  192. if (item.target.data == null)
  193. {
  194. item.target.onClick.Add(OnBtnGetProBonus);
  195. }
  196. item.target.data = signCfgs[i];
  197. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward),
  198. signCfgs[i].Day);
  199. item.m_imgGot.visible = isGot;
  200. bool canGet = _signCount >= signCfgs[i].Day && !isGot;
  201. if (canGet)
  202. {
  203. if (_effectUI5 == null)
  204. {
  205. EffectUIPool.CreateEffectUI(_ui.m_proSign.m_holderReward, "ui_Activity",
  206. "Everyday_enable",
  207. onComplete: (effect) =>
  208. {
  209. if (effect != null)
  210. {
  211. _effectUI5 = effect;
  212. }
  213. });
  214. }
  215. _ui.m_proSign.m_holderReward.visible = canGet;
  216. _ui.m_proSign.m_holderReward.position = new Vector2(item.target.x, 35);
  217. }
  218. RedDotController.Instance.SetComRedDot(item.target, canGet);
  219. UI_ComProBonus.ProxyEnd();
  220. }
  221. if ((_month > dateTime.Month && _year == dateTime.Year) || _year > dateTime.Year)
  222. {
  223. _ui.m_list.numItems = signBonusCfgs.Count > 29 ? signBonusCfgs.Count + 1 : signBonusCfgs.Count;
  224. }
  225. else if (_month == dateTime.Month)
  226. {
  227. _ui.m_list.numItems = signBonusCfgs.Count > 29
  228. ? signBonusCfgs.Count + 1 - dateTime.Day
  229. : signBonusCfgs.Count - dateTime.Day + 1;
  230. }
  231. }
  232. private async void OnBtnGetProBonus(EventContext context)
  233. {
  234. GObject obj = context.sender as GObject;
  235. DailySignCfg signCfg = obj.data as DailySignCfg;
  236. if (_signCount < signCfg.Day ||
  237. MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.SignReward), signCfg.Day))
  238. {
  239. GoodsItemTipsController.ShowItemTips(signCfg.Bonus[0].ItemId);
  240. }
  241. else
  242. {
  243. bool result = await DailyWelfareSProxy.ReqGetSignReward(signCfg.Day);
  244. if (result)
  245. {
  246. UpdateSignView();
  247. }
  248. }
  249. }
  250. private void ListItemRender(int index, GObject obj)
  251. {
  252. UI_ListSignItem item = UI_ListSignItem.Proxy(obj);
  253. if (_month == dateTime.Month)
  254. {
  255. index += dateTime.Day - 1;
  256. }
  257. if (index == 29 && _ui.m_list.numItems > 29)
  258. {
  259. item.target.touchable = false;
  260. item.target.visible = false;
  261. return;
  262. }
  263. int _index = index >= 29 && _ui.m_list.numItems > 29 ? index - 1 : index;
  264. DailySignBonusCfg bonusCfg = CommonDataManager.Tables.TblDailySignBonusCfg.DataList
  265. .Where(a => a.Month == _month).ToList()[_index];
  266. int itemType = ItemDataManager.GetItemType(bonusCfg.Bonus[0].ItemId);
  267. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay), bonusCfg.Day);
  268. if (bonusCfg.Day == _day && !isGot && _effectUI3 == null)
  269. {
  270. EffectUIPool.CreateEffectUI(item.m_holderSign, "ui_Activity", "everyday_kuang",
  271. onComplete: (effect) =>
  272. {
  273. if (effect != null)
  274. {
  275. _effectUI3 = effect;
  276. }
  277. });
  278. m_holderSign = item.m_holderSign;
  279. }
  280. item.m_holderSign.visible = false;
  281. item.m_c1.selectedIndex = itemType == ConstItemType.DRESS_UP ? 0 : bonusCfg.Type;
  282. item.m_txtDay.text = NumberUtil.GetChiniseNumberText(bonusCfg.Day); // bonusCfg.day.ToString();
  283. if (item.m_comItem.data == null)
  284. {
  285. item.m_comItem.data = new ItemView(item.m_comItem);
  286. }
  287. ItemData itemData = ItemUtil.createItemData(bonusCfg.Bonus[0].ToGfgGameItemParam());
  288. (item.m_comItem.data as ItemView).SetData(itemData);
  289. (item.m_comItem.data as ItemView).ShowTips = false;
  290. (item.m_comItem.data as ItemView).ChangeTxtCountStyle();
  291. item.m_imgMask.visible = isGot || bonusCfg.Day < _day && !isGot;
  292. item.m_imgGot.visible = isGot;
  293. item.m_imgNotGet.visible = bonusCfg.Day < _day && !isGot;
  294. RedDotController.Instance.SetComRedDot(item.target, bonusCfg.Day == _day && !isGot);
  295. if (item.target.data == null)
  296. {
  297. item.target.onClick.Add(OnGetSignBonus);
  298. }
  299. item.target.data = bonusCfg.Day;
  300. UI_ListSignItem.ProxyEnd();
  301. }
  302. private async void OnGetSignBonus(EventContext context)
  303. {
  304. GObject obj = context.sender as GObject;
  305. int day = (int)obj.data;
  306. if (day > _day) return;
  307. SignBonus(day);
  308. }
  309. private async void SignBonus(int day)
  310. {
  311. bool isGot = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsLong(NumericType.SignDay), day);
  312. bool result = false;
  313. if (isGot)
  314. {
  315. PromptController.Instance.ShowFloatTextPrompt("已领取");
  316. return;
  317. }
  318. if (day < _day)
  319. {
  320. ViewManager.Show<ReDailySignTipsView>(day);
  321. }
  322. else
  323. {
  324. result = await DailyWelfareSProxy.ReqSign(day);
  325. }
  326. // if (result)
  327. // {
  328. // _ui.m_list.numItems = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month).Count;
  329. // }
  330. }
  331. }
  332. }