PartnerEpiMainPanelCtrl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PartnerEpiMainPanelCtrl : UIController<PartnerEpiMainPanelVM>
  19. {
  20. private bool _initialized = false;
  21. private bool _showPlanSwitch = false;
  22. //private Controller _switchBtnCtrl;
  23. protected override void OnEnable(object intent)
  24. {
  25. AddUIListenres();
  26. AddEventListenres();
  27. InitList();
  28. UpView();
  29. }
  30. protected override void OnDisable()
  31. {
  32. RemoveUIListenres();
  33. RemoveEventListenres();
  34. ClearView();
  35. }
  36. #region UI事件
  37. private void AddUIListenres()
  38. {
  39. VM.OneUpBtn.onClick.Add(OnClickOneUpBtn);
  40. VM.OneStrongBtn.onClick.Add(OnClickOneStrongBtn);
  41. //VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  42. VM.MaskBtn.onClick.Add(OnClickMaskBtn);
  43. }
  44. private void RemoveUIListenres()
  45. {
  46. VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn);
  47. VM.OneStrongBtn.onClick.Remove(OnClickOneStrongBtn);
  48. //VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  49. VM.MaskBtn.onClick.Remove(OnClickMaskBtn);
  50. }
  51. //private void OnClickChangeBtn(EventContext context)
  52. //{
  53. // _showPlanSwitch = !_showPlanSwitch;
  54. // if (EpigraphData.Instance.UpModeSelect > 0)
  55. // {
  56. // EpigraphService.Instance.FinishUpMode();
  57. // }
  58. // ShowPlanNested();
  59. // RefreshBagEpigraph();
  60. //}
  61. private void OnClickMaskBtn(EventContext context)
  62. {
  63. EpigraphService.Instance.FinishUpMode();
  64. }
  65. #region 事件监听
  66. private void AddEventListenres()
  67. {
  68. Context.AddListener(EventDefine.PartnerUp, OnUpdateAll);
  69. Context.AddListener(EventDefine.PartnerDown, OnUpdateAll);
  70. Context.AddListener(EventDefine.PartnerBinding, OnUpdateAll);
  71. Context.AddListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  72. Context.AddListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  73. Context.AddListener(EventDefine.PartnerUpStar, OnUpdateAll);
  74. Context.AddListener(EventDefine.PartnerWearAll, OnUpdateAll);
  75. Context.AddListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  76. Context.AddListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
  77. Context.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  78. Context.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  79. Context.AddListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  80. }
  81. private void RemoveEventListenres()
  82. {
  83. Context.RemoveListener(EventDefine.PartnerUp, OnUpdateAll);
  84. Context.RemoveListener(EventDefine.PartnerDown, OnUpdateAll);
  85. Context.RemoveListener(EventDefine.PartnerBinding, OnUpdateAll);
  86. Context.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  87. Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  88. Context.RemoveListener(EventDefine.PartnerUpStar, OnUpdateAll);
  89. Context.RemoveListener(EventDefine.PartnerWearAll, OnUpdateAll);
  90. Context.RemoveListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  91. Context.RemoveListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
  92. Context.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  93. Context.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  94. Context.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  95. }
  96. #endregion
  97. private void OnClickOneUpBtn(EventContext context)
  98. {
  99. EpigraphService.Instance.RequestEpiWearAll();
  100. }
  101. private void OnClickOneStrongBtn(EventContext context)
  102. {
  103. var list = EpigraphData.Instance.EpiList;
  104. var canUp = false;
  105. foreach (var epigraph in list)
  106. {
  107. var lvTable = epigraphUpTableRepo.GetEpiragphUp(epigraph.TableId, epigraph.StarLv);
  108. if (lvTable == null)
  109. {
  110. Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
  111. }
  112. if (ItemService.Instance.IsEnough(epigraph.TableId, lvTable.LevelUpCost, false))
  113. {
  114. canUp = true;
  115. break;
  116. }
  117. }
  118. if (canUp)
  119. {
  120. EpigraphService.Instance.RequestEpiStrongAll();
  121. }
  122. else
  123. {
  124. Context.ShowTips(StringDefine.EpigraphCantStarUpAll);
  125. }
  126. }
  127. #endregion
  128. #region 事件
  129. private void OnEpiUpSelect(int eventId, object args)
  130. {
  131. var sbId = (int)args;
  132. if (sbId == 0)
  133. {
  134. Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
  135. EpigraphService.Instance.FinishUpMode();
  136. return;
  137. }
  138. if (EpigraphData.Instance.UpModeSelect > 0)
  139. {
  140. EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
  141. }
  142. }
  143. private void OnReName(int eventId, object args)
  144. {
  145. //UpdatePlanName();
  146. }
  147. private void OnUpdateAll(int eventId, object args)
  148. {
  149. RefreshBagEpigraph();
  150. RefreshGoneUpPartners();
  151. }
  152. private void OnPlanChange(int eventId, object args)
  153. {
  154. //UpdatePlanName();
  155. RefreshBagEpigraph();
  156. RefreshGoneUpPartners();
  157. }
  158. private void OnEpiUpdate(int eventId, object args)
  159. {
  160. RefreshBagEpigraph();
  161. RefreshGoneUpPartners();
  162. }
  163. /// <summary>
  164. /// 铭文上阵打开事件
  165. /// </summary>
  166. /// <param name="eventId"></param>
  167. /// <param name="args"></param>
  168. private void OnOpenUpMode(int eventId, object args)
  169. {
  170. if (_showPlanSwitch)
  171. {
  172. //ShowPlanNested();
  173. RefreshBagEpigraph();
  174. }
  175. ShowUpMode();
  176. }
  177. private void OnFinishUpMode(int eventId, object args)
  178. {
  179. ShowUpMode();
  180. }
  181. #endregion
  182. private void InitList()
  183. {
  184. if (_initialized)
  185. return;
  186. VM.UpList.ListType = EGListType.None;
  187. VM.BagList.ListType = EGListType.Virtual;
  188. //_switchBtnCtrl = VM.ChangeBtn.GetController("arr");
  189. _initialized = true;
  190. }
  191. private void UpView()
  192. {
  193. RefreshBagEpigraph();
  194. RefreshGoneUpPartners();
  195. //UpdatePlanName();
  196. //ShowPlanNested();
  197. ShowUpMode();
  198. }
  199. private void RefreshGoneUpPartners()
  200. {
  201. var list = new List<int>();
  202. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  203. {
  204. list.Add(i);
  205. }
  206. VM.UpList.BindDatas(list);
  207. }
  208. //private void UpdatePlanName()
  209. //{
  210. // //VM.PlanLabel.text = plan.Name;
  211. //}
  212. private void RefreshBagEpigraph()
  213. {
  214. if (VM.State.selectedIndex == 1)
  215. return;
  216. var list = EpigraphTableRepo.GetAll();
  217. VM.BagList.BindDatas(list);
  218. ShowOwnerAttr();
  219. }
  220. //private void ShowPlanNested()
  221. //{
  222. // VM.State.selectedIndex = _showPlanSwitch ? 1 : 0;
  223. // //_switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0;
  224. // if (_showPlanSwitch)
  225. // {
  226. // VM.PlanNested.Enable(null);
  227. // VM.PlanNested.Ctrl.ShowUI();
  228. // }
  229. // else
  230. // {
  231. // VM.PlanNested.Disable();
  232. // }
  233. //}
  234. private void ShowUpMode()
  235. {
  236. if (PartnersData.Instance.UpModeSelect > 0)
  237. {
  238. VM.SelectMode.selectedIndex = 1;
  239. }
  240. else if (EpigraphData.Instance.UpModeSelect > 0)
  241. {
  242. VM.SelectMode.selectedIndex = 1;
  243. }
  244. else
  245. {
  246. VM.SelectMode.selectedIndex = 0;
  247. }
  248. }
  249. private void ClearView()
  250. {
  251. EpigraphService.Instance.FinishUpMode();
  252. PartnersService.Instance.FinishUpPartnerMode();
  253. _showPlanSwitch = false;
  254. }
  255. public void ShowOwnerAttr()
  256. {
  257. var list = EpigraphData.Instance.EpiList;
  258. //var map = new Dictionary<int, int>();
  259. var val = 0;
  260. foreach (var epigraph in list)
  261. {
  262. var starTable = epigraphUpTableRepo.GetEpiragphUp(
  263. epigraph.TableId,
  264. epigraph.StarLv
  265. );
  266. if (starTable == null)
  267. {
  268. Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
  269. continue;
  270. }
  271. var attrsArray = starTable.LvOwnAttr;
  272. if (attrsArray?.Length > 0)
  273. {
  274. //for (int i = 0; i < attrsArray.Length; i += 2)
  275. //{
  276. // if (map.TryGetValue(attrsArray[i], out var attr))
  277. // {
  278. // map.Remove(attrsArray[i]);
  279. // map.Add(attrsArray[i], attr + attrsArray[i + 1]);
  280. // }
  281. // else
  282. // {
  283. // map.Add(attrsArray[i], attrsArray[i + 1]);
  284. // }
  285. //}
  286. val += attrsArray[1];
  287. }
  288. }
  289. VM.AttrLabel.SetVar("val", (val / 100).ToString()).FlushVars();
  290. //if (map.Count > 0)
  291. //{
  292. // var desc = StringBuilderUtils.Acquire();
  293. // int index = 0;
  294. // foreach (var pair in map)
  295. // {
  296. // if (index > 0)
  297. // {
  298. // desc.Append(",");
  299. // index++;
  300. // }
  301. // GetAttributeDesc(pair.Key, pair.Value, ref desc);
  302. // }
  303. // VM.AttrLabel.text = desc.ToString();
  304. // VM.HaveLabel.visible = true;
  305. // VM.AttrLabel.visible = true;
  306. //}
  307. //else
  308. //{
  309. // VM.HaveLabel.visible = false;
  310. // VM.AttrLabel.visible = false;
  311. //}
  312. }
  313. //private void GetAttributeDesc(int attrType, int attrValue, ref StringBuilder desc)
  314. //{
  315. // var attributeInfo = AttrDescTableRepo.Get(attrType);
  316. // string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  317. // desc.Append(attributeInfo?.ShowName);
  318. // desc.Append(valStr);
  319. // desc.Append("%");
  320. //}
  321. }
  322. }