TravelShowView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UI.FieldGuide;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. using System;
  6. namespace GFGGame
  7. {
  8. public class TravelShowView : BaseWindow
  9. {
  10. private UI_TravelShowUI _ui;
  11. private TravelGuideCfg _cfg;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. _ui = UI_TravelShowUI.Create();
  25. this.viewCom = _ui.target;
  26. isfullScreen = true;
  27. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  28. _ui.m_btnReward.target.onClick.Add(OnBtnRewardClick);
  29. _ui.m_list.itemRenderer = RenderListItem;
  30. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xqfs_bj");
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. _cfg = this.viewData as TravelGuideCfg;
  36. UpdateView();
  37. }
  38. protected override void AddEventListener()
  39. {
  40. base.AddEventListener();
  41. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRewardState);
  42. }
  43. protected override void OnHide()
  44. {
  45. base.OnHide();
  46. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  47. }
  48. protected override void RemoveEventListener()
  49. {
  50. base.RemoveEventListener();
  51. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRewardState);
  52. }
  53. private void OnClickBtnBack()
  54. {
  55. ViewManager.GoBackFrom(typeof(TravelShowView).FullName);
  56. }
  57. private void UpdateView()
  58. {
  59. _ui.m_list.numItems = _cfg.locationsArr.Length;
  60. UpdateRewardState();
  61. }
  62. private void UpdateRewardState()
  63. {
  64. // int state = TravelDataManager.Instance.ListTravelAreaRewardState[_index];
  65. _ui.m_btnReward.m_c1.selectedIndex = TravelDataManager.Instance.GetGuideRewardStateByAreaId(_cfg.id) == ConstBonusStatus.GOT ? 0 : 1;
  66. RedDotController.Instance.SetComRedDot(_ui.m_btnReward.target, RedDotDataManager.Instance.GetTravelGuideAreaRed(_cfg.id));
  67. }
  68. private void RenderListItem(int index, GObject obj)
  69. {
  70. TravelLoactionCfg locationCfg = TravelLoactionCfgArray.Instance.GetCfgBylocation(_cfg.locationsArr[index]);
  71. UI_ListTravelLocationItem item = UI_ListTravelLocationItem.Proxy(obj);
  72. item.m_txtName.text = locationCfg.name;
  73. item.m_comLocation.m_loaLocation.url = ResPathUtil.GetTravelBgPath(locationCfg.res);
  74. int count = TravelDataManager.Instance.GetTravelCountByLocationId(locationCfg.id);
  75. item.m_txtCount.text = string.Format("已到达:{0}次", count);
  76. item.m_c1.selectedIndex = count > 0 ? 1 : 0;
  77. UI_ListTravelLocationItem.ProxyEnd();
  78. }
  79. private void OnBtnRewardClick()
  80. {
  81. int state = TravelDataManager.Instance.GetGuideRewardStateByAreaId(_cfg.id);
  82. if (state == ConstBonusStatus.CAN_NOT_GET)
  83. {
  84. List<ItemData> rewards = ItemUtil.CreateItemDataList(_cfg.rewardsArr);
  85. ViewManager.Show<RewardPreView>(new object[] { rewards, "活跃度奖励", "到达该区域所有地点时可领取" });
  86. }
  87. else if (state == ConstBonusStatus.CAN_GET)
  88. {
  89. TravelSProxy.ReqGetTravelGuideReward(_cfg.id).Coroutine();
  90. }
  91. }
  92. }
  93. }