TravelDressupView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System.Collections.Generic;
  2. using cfg.GfgCfg;
  3. using ET;
  4. using FairyGUI;
  5. using UI.Travel;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class TravelDressupView : BaseWindow
  10. {
  11. private UI_TravelDressupUI _ui;
  12. private List<int> _selectTravelSuitIds = new List<int>();
  13. private List<int> _travelSuitIds = new List<int>();
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_TravelDressupUI.PACKAGE_NAME;
  27. _ui = UI_TravelDressupUI.Create();
  28. this.viewCom = _ui.target;
  29. this.viewCom.Center();
  30. this.modal = true;
  31. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  32. _ui.m_list.itemRenderer = RenderListItem;
  33. _ui.m_list.onClickItem.Add(OnListItemClick);
  34. _ui.m_btnCancle.onClick.Add(Hide);
  35. _ui.m_btnGo.onClick.Add(OnBtnGoClick);
  36. _ui.m_comDress0.target.onClick.Add(OnComDressClick0);
  37. _ui.m_comDress1.target.onClick.Add(OnComDressClick);
  38. _ui.m_comDress2.target.onClick.Add(OnComDressClick);
  39. _ui.m_comDress0.m_c1.selectedIndex = 2;
  40. }
  41. protected override void AddEventListener()
  42. {
  43. base.AddEventListener();
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. UpdateView();
  49. }
  50. protected override void OnHide()
  51. {
  52. base.OnHide();
  53. _selectTravelSuitIds.Clear();
  54. _travelSuitIds.Clear();
  55. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  56. _ui.m_comDress1.target.data = null;
  57. _ui.m_comDress2.target.data = null;
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. }
  63. private void UpdateView()
  64. {
  65. _travelSuitIds = new List<int>(DressUpMenuSuitDataManager.TravelSuitIDList.ToArray());
  66. for (int i = 0; i < _selectTravelSuitIds.Count; i++)
  67. {
  68. if (_travelSuitIds.IndexOf(_selectTravelSuitIds[i]) >= 0)
  69. {
  70. _travelSuitIds.Remove(_selectTravelSuitIds[i]);
  71. }
  72. }
  73. _ui.m_list.numItems = _travelSuitIds.Count;
  74. _ui.m_comDress1.m_c1.selectedIndex = _ui.m_comDress1.target.data == null ? 0 : 1;
  75. if (_ui.m_comDress1.target.data != null)
  76. {
  77. UpdateComDress(_ui.m_comDress1.target, (int)_ui.m_comDress1.target.data);
  78. }
  79. _ui.m_comDress2.m_c1.selectedIndex = _ui.m_comDress2.target.data == null ? 0 : 1;
  80. if (_ui.m_comDress2.target.data != null)
  81. {
  82. UpdateComDress(_ui.m_comDress2.target, (int)_ui.m_comDress2.target.data);
  83. }
  84. }
  85. private void RenderListItem(int index, GObject obj)
  86. {
  87. UI_ComDress item = UI_ComDress.Proxy(obj);
  88. item.m_c1.selectedIndex = 1;
  89. UI_ComDress.ProxyEnd();
  90. UpdateComDress(obj, _travelSuitIds[index]);
  91. }
  92. private void UpdateComDress(GObject obj, int travelSuitId)
  93. {
  94. TravelSuitCfg travelSuitCfg = CommonDataManager.Tables.TblTravelSuitCfg.GetOrDefault(travelSuitId);
  95. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(travelSuitCfg.SuitId);
  96. UI_ComDress item = UI_ComDress.Proxy(obj);
  97. item.m_txtName.text = suitCfg.Name;
  98. item.m_loaDress.url = ResPathUtil.GetIconPath(suitCfg.Res, "png");
  99. RarityIconController.UpdateRarityIcon(item.m_loaRarity, suitCfg.Id, false, true);
  100. item.target.data = travelSuitCfg.Id;
  101. UI_ComDress.ProxyEnd();
  102. }
  103. private void OnListItemClick(EventContext context)
  104. {
  105. if (_selectTravelSuitIds.Count >= 2)
  106. {
  107. PromptController.Instance.ShowFloatTextPrompt("行囊已满");
  108. return;
  109. }
  110. GObject obj = context.data as GObject;
  111. int travelSuitId = (int)obj.data;
  112. _selectTravelSuitIds.Add(travelSuitId);
  113. if (_ui.m_comDress1.target.data == null)
  114. {
  115. _ui.m_comDress1.target.data = travelSuitId;
  116. }
  117. else
  118. {
  119. _ui.m_comDress2.target.data = travelSuitId;
  120. }
  121. UpdateView();
  122. }
  123. private void OnComDressClick0()
  124. {
  125. PromptController.Instance.ShowFloatTextPrompt("必带服装不能取消");
  126. }
  127. private void OnComDressClick(EventContext context)
  128. {
  129. GObject obj = context.sender as GObject;
  130. if (obj.data == null)
  131. {
  132. PromptController.Instance.ShowFloatTextPrompt("请选择游历要带的服装");
  133. return;
  134. }
  135. int travelSuitId = (int)obj.data;
  136. _selectTravelSuitIds.Remove(travelSuitId);
  137. obj.data = null;
  138. UpdateView();
  139. }
  140. private async void OnBtnGoClick()
  141. {
  142. if (_selectTravelSuitIds.Count < 2)
  143. {
  144. PromptController.Instance.ShowFloatTextPrompt("需带齐3套服装才能出发");
  145. return;
  146. }
  147. bool result = await TravelSProxy.ReqGoTravel(_selectTravelSuitIds);
  148. if (result)
  149. {
  150. this.Hide();
  151. }
  152. }
  153. }
  154. }