PartnerSbBagPanelCtrl.cs 10 KB

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