TravelDressupView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Travel;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class TravelDressupView : BaseWindow
  9. {
  10. private UI_TravelDressupUI _ui;
  11. private List<int> _selectTravelSuitIds = new List<int>();
  12. private List<int> _travelSuitIds = new List<int>();
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_TravelDressupUI.PACKAGE_NAME;
  26. _ui = UI_TravelDressupUI.Create();
  27. this.viewCom = _ui.target;
  28. isfullScreen = true;
  29. _ui.m_btnCancle.onClick.Add(Hide);
  30. _ui.m_btnGo.onClick.Add(OnBtnGoClick);
  31. _ui.m_comDress0.target.onClick.Add(OnComDressClick0);
  32. _ui.m_comDress1.target.onClick.Add(OnComDressClick);
  33. _ui.m_comDress2.target.onClick.Add(OnComDressClick);
  34. }
  35. protected override void AddEventListener()
  36. {
  37. base.AddEventListener();
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. UpdateView();
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. _selectTravelSuitIds.Clear();
  48. _travelSuitIds.Clear();
  49. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  50. }
  51. protected override void RemoveEventListener()
  52. {
  53. base.RemoveEventListener();
  54. }
  55. private void UpdateView()
  56. {
  57. _travelSuitIds = new List<int>(DressUpMenuSuitDataManager.TravelSuitIDList.ToArray());
  58. for (int i = 0; i < _selectTravelSuitIds.Count; i++)
  59. {
  60. if (_travelSuitIds.IndexOf(_selectTravelSuitIds[i]) >= 0)
  61. {
  62. _travelSuitIds.Remove(_selectTravelSuitIds[i]);
  63. }
  64. }
  65. _ui.m_list.numItems = _travelSuitIds.Count;
  66. }
  67. private void OnListItemClick(EventContext context)
  68. {
  69. if (_selectTravelSuitIds.Count >= 2)
  70. {
  71. PromptController.Instance.ShowFloatTextPrompt("行囊已满");
  72. return;
  73. }
  74. GObject obj = context.sender as GObject;
  75. if (obj.data == null)
  76. {
  77. PromptController.Instance.ShowFloatTextPrompt("请选择游历要带的服装");
  78. return;
  79. }
  80. int travelSuitId = (int)obj.data;
  81. _selectTravelSuitIds.Add(travelSuitId);
  82. UpdateView();
  83. }
  84. private void OnComDressClick0()
  85. {
  86. PromptController.Instance.ShowFloatTextPrompt("必带服装不能取消");
  87. }
  88. private void OnComDressClick(EventContext context)
  89. {
  90. GObject obj = context.sender as GObject;
  91. int travelSuitId = (int)obj.data;
  92. _selectTravelSuitIds.Remove(travelSuitId);
  93. obj.data = null;
  94. UpdateView();
  95. }
  96. private async void OnBtnGoClick()
  97. {
  98. if (_selectTravelSuitIds.Count < 2)
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("需带齐服装才能出发");
  101. return;
  102. }
  103. bool result = await TravelSProxy.ReqGoTravel(_selectTravelSuitIds);
  104. if (result)
  105. {
  106. this.Hide();
  107. }
  108. }
  109. }
  110. }