PartnerSbBagNestedCtrl.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame.Database;
  10. using XGame.Framework.Persistence;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PartnerSbBagNestedCtrl : UIController<PartnerSbBagNestedVM>
  19. {
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. InitView();
  24. VM.OpenSelect.selectedIndex = 1;
  25. ShowUI();
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.OnStrongBtn.onClick.Add(OnClickOnStrongBtn);
  35. VM.SortBtn.onClick.Add(OnClickSortBtn);
  36. VM.ShangZhenBtn.onClick.Add(OnClickSortTypeBtn);
  37. VM.PinZhiBtn.onClick.Add(OnClickSortTypeBtn);
  38. VM.DengJiBtn.onClick.Add(OnClickSortTypeBtn);
  39. VM.IDBtn.onClick.Add(OnClickSortTypeBtn);
  40. VM.PanelEvent.Add(OnClickPanel);
  41. Context.AddListener(EventDefine.PartnerDown, OnUpdateList);
  42. Context.AddListener(EventDefine.PartnerUp, OnUpdateList);
  43. Context.AddListener(EventDefine.PartnerUpLevel, OnUpdateList);
  44. Context.AddListener(EventDefine.PartnerStrongAll, OnUpdateList);
  45. Context.AddListener(EventDefine.PartnerUpStar, OnUpdateList);
  46. Context.AddListener(EventDefine.PartnerBinding, OnUpdateList);
  47. }
  48. private void RemoveUIListenres()
  49. {
  50. VM.OnStrongBtn.onClick.Remove(OnClickOnStrongBtn);
  51. VM.SortBtn.onClick.Remove(OnClickSortBtn);
  52. VM.ShangZhenBtn.onClick.Remove(OnClickSortTypeBtn);
  53. VM.PinZhiBtn.onClick.Remove(OnClickSortTypeBtn);
  54. VM.DengJiBtn.onClick.Remove(OnClickSortTypeBtn);
  55. VM.IDBtn.onClick.Remove(OnClickSortTypeBtn);
  56. VM.PanelEvent.Remove(OnClickPanel);
  57. Context.RemoveListener(EventDefine.PartnerDown, OnUpdateList);
  58. Context.RemoveListener(EventDefine.PartnerUp, OnUpdateList);
  59. Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateList);
  60. Context.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateList);
  61. Context.RemoveListener(EventDefine.PartnerUpStar, OnUpdateList);
  62. Context.RemoveListener(EventDefine.PartnerBinding, OnUpdateList);
  63. }
  64. private void OnClickPanel()
  65. {
  66. if (VM.OpenSelect.selectedIndex == 1)
  67. return;
  68. VM.OpenSelect.selectedIndex = 1;
  69. }
  70. private void OnClickSortTypeBtn(EventContext context)
  71. {
  72. context.StopPropagation();
  73. if (_curSortType == VM.CurSelect.selectedIndex)
  74. return;
  75. _curSortType = VM.CurSelect.selectedIndex;
  76. Persistence.Write(
  77. PlayerData.Instance.UID + PersistenceKeys.partner_sort_type,
  78. _curSortType
  79. );
  80. ShowUI();
  81. }
  82. private void OnClickOnStrongBtn(EventContext context)
  83. {
  84. var list = PartnersData.Instance.PartnerList;
  85. var canUp = false;
  86. foreach (var item in list)
  87. {
  88. var table = partnerStarUpTableRepo.GetPartnerStarTable(
  89. item.TableId,
  90. item.RisingStarLv
  91. );
  92. var nextTable = partnerStarUpTableRepo.GetPartnerStarTable(
  93. item.TableId,
  94. item.RisingStarLv + 1
  95. );
  96. XGame.Framework.Assert.IsNotNull(
  97. table,
  98. $"圣兵表升星不存在,id{item.TableId},starlv:{item.RisingStarLv}"
  99. );
  100. if (
  101. nextTable != null
  102. && ItemService.Instance.IsEnough(table.PetId, table.StarUpCost, false)
  103. )
  104. {
  105. canUp = true;
  106. break;
  107. }
  108. }
  109. if (canUp)
  110. PartnersService.Instance.RequestPartnerOneKeyStarUp();
  111. else
  112. {
  113. Context.ShowTips(EStringDefine.PartnerCantStarUpAll);
  114. }
  115. }
  116. private void OnClickSortBtn(EventContext context)
  117. {
  118. context.StopPropagation();
  119. VM.OpenSelect.selectedIndex = VM.OpenSelect.selectedIndex > 0 ? 0 : 1;
  120. }
  121. private void OnUpdateList(int eventId, object args)
  122. {
  123. ShowUI();
  124. }
  125. #endregion
  126. private List<PartnerSbBagListParam> _dataList = new List<PartnerSbBagListParam>();
  127. private bool _init = false;
  128. private int _curSortType = 0;
  129. private void InitView()
  130. {
  131. if (_init)
  132. return;
  133. _init = true;
  134. VM.CurSelect.selectedIndex = Persistence.Read(
  135. PlayerData.Instance.UID + PersistenceKeys.partner_sort_type,
  136. 0
  137. );
  138. VM.List.ListType = EGListType.Virtual;
  139. }
  140. private void ShowUI()
  141. {
  142. var allSbList = PartnerTableRepo.GetAll();
  143. var haveList = new List<int>();
  144. var noHaveList = new List<int>();
  145. foreach (var sb in allSbList)
  146. {
  147. var attr = PartnersData.Instance.GetPartnerAttrByTableId(sb.Id);
  148. if (attr != null)
  149. {
  150. haveList.Add(sb.Id);
  151. }
  152. else
  153. {
  154. noHaveList.Add(sb.Id);
  155. }
  156. }
  157. haveList.Sort(
  158. (a, b) =>
  159. {
  160. PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr);
  161. PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr);
  162. switch (VM.CurSelect.selectedIndex)
  163. {
  164. case 0:
  165. if (aAttr.Status != bAttr.Status)
  166. {
  167. return bAttr.Status - aAttr.Status;
  168. }
  169. break;
  170. case 1:
  171. var aTable = PartnerTableRepo.Get(a);
  172. var bTable = PartnerTableRepo.Get(b);
  173. if (aTable.Quality != bTable.Quality)
  174. {
  175. return bTable.Quality - aTable.Quality;
  176. }
  177. break;
  178. case 2:
  179. if (bAttr.Level != aAttr.Level)
  180. {
  181. return bAttr.Level - aAttr.Level;
  182. }
  183. break;
  184. }
  185. return a - b;
  186. }
  187. );
  188. noHaveList.Sort(
  189. (a, b) =>
  190. {
  191. switch (VM.CurSelect.selectedIndex)
  192. {
  193. case 1:
  194. var aTable = PartnerTableRepo.Get(a);
  195. var bTable = PartnerTableRepo.Get(b);
  196. if (aTable.Quality != bTable.Quality)
  197. {
  198. return bTable.Quality - aTable.Quality;
  199. }
  200. break;
  201. }
  202. return a - b;
  203. }
  204. );
  205. _dataList.Clear();
  206. var list = new List<int>();
  207. if (haveList.Count > 0)
  208. {
  209. _dataList.Add(new PartnerSbBagListParam() { Type = 0, Title = EStringDefine.Have.ToI18n() });
  210. foreach (var have in haveList)
  211. {
  212. list.Add(have);
  213. if (list.Count >= 5)
  214. {
  215. _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
  216. list = new List<int>();
  217. }
  218. }
  219. if (list.Count > 0)
  220. {
  221. _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
  222. list = new List<int>();
  223. }
  224. }
  225. if (noHaveList.Count > 0)
  226. {
  227. _dataList.Add(
  228. new PartnerSbBagListParam() { Type = 0, Title = EStringDefine.NoHave.ToI18n() }
  229. );
  230. foreach (var noHave in noHaveList)
  231. {
  232. list.Add(noHave);
  233. if (list.Count >= 5)
  234. {
  235. _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
  236. list = new List<int>();
  237. }
  238. }
  239. if (list.Count > 0)
  240. {
  241. _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
  242. list = new List<int>();
  243. }
  244. }
  245. //var dataList = new List<int>();
  246. //foreach (var item in allSbList)
  247. //{
  248. // dataList.Add(item.Id);
  249. //}
  250. //dataList.Sort((a, b) =>
  251. //{
  252. // PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr);
  253. // PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr);
  254. // if (aAttr != null && bAttr != null)
  255. // {
  256. // if (aAttr.Status != bAttr.Status)
  257. // {
  258. // return bAttr.Status - aAttr.Status;
  259. // }
  260. // else if (bAttr.Level != aAttr.Level)
  261. // {
  262. // return bAttr.Level - aAttr.Level;
  263. // }
  264. // }
  265. // else if (aAttr == null && bAttr != null)
  266. // {
  267. // return 1;
  268. // }
  269. // else if (aAttr != null && bAttr == null)
  270. // {
  271. // return -1;
  272. // }
  273. // return b - a;
  274. //});
  275. VM.List.BindDatas(_dataList);
  276. }
  277. }
  278. }