PlacesInfoPanel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Language;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Combat;
  9. using GameLogic.Combat.CombatTool;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. namespace Fort23.Mono
  13. {
  14. [UIBinding(prefab = "PlacesInfoPanel")]
  15. public partial class PlacesInfoPanel : UIPanel
  16. {
  17. private int PlacesId;
  18. private int needSmallPlacesId;
  19. private SmallPlacesConfig smallPlacesConfig;
  20. private PlacesConfig placesConfig;
  21. List<PlacesInfoWidget> placesInfoWidgets = new List<PlacesInfoWidget>();
  22. private Action<bool> callBack;
  23. public bool isChange;
  24. private PlacesInfoWidget currentNeedPlacesInfoWidget;
  25. private void Init()
  26. {
  27. isPopUi = true;
  28. isAddStack = false;
  29. }
  30. protected override void AddEvent()
  31. {
  32. }
  33. protected override void DelEvent()
  34. {
  35. }
  36. public override void AddButtonEvent()
  37. {
  38. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  39. }
  40. public async override CTask<bool> AsyncInit(object[] uiData)
  41. {
  42. PlacesId = (int)(uiData[0]);
  43. callBack = uiData[1] as Action<bool>;
  44. needSmallPlacesId = (int)(uiData[2]);
  45. isChange = false;
  46. placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(PlacesId);
  47. sv.vertical = true;
  48. int maxY = 131 * placesConfig.SmallPlacersIds.Length + (placesConfig.SmallPlacersIds.Length) * 33;
  49. Content.sizeDelta = new Vector2(551, maxY);
  50. for (var i = 0; i < placesConfig.SmallPlacersIds.Length; i++)
  51. {
  52. PlacesInfoWidget shopBtnWidget =
  53. await UIManager.Instance.CreateGComponent<PlacesInfoWidget>(null, Content);
  54. shopBtnWidget.CustomInit(placesConfig.SmallPlacersIds[i], callBack);
  55. shopBtnWidget.transform.anchoredPosition = new Vector2(0, -131 * i - 33 * i);
  56. if (needSmallPlacesId == shopBtnWidget.smallPlacesConfig.ID && shopBtnWidget.isUlock)
  57. {
  58. currentNeedPlacesInfoWidget = shopBtnWidget;
  59. int y = 131 * (i - 1) + 33 * (i - 1);
  60. if (y < 0)
  61. {
  62. y = 0;
  63. }
  64. else if (y >= maxY)
  65. {
  66. y = maxY;
  67. }
  68. Content.anchoredPosition = new Vector2(0, y);
  69. sv.vertical = false;
  70. }
  71. placesInfoWidgets.Add(shopBtnWidget);
  72. }
  73. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  74. Text_BigMapName.text = LanguageManager.Instance.Text(bigMapConfig.mapName);
  75. Text_PlacesName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  76. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(placesConfig.ID);
  77. int jindu = placesData == null ? 0 : placesData.progress;
  78. Text_PlacesComplteProgress.text =
  79. LanguageManager.Instance.Text(10378, (jindu / placesConfig.TotalScore * 100f).ToString("0"));
  80. return await base.AsyncInit(uiData);
  81. }
  82. public async override CTask Show()
  83. {
  84. base.Show();
  85. // LayoutRebuilder.ForceRebuildLayoutImmediate(Content);
  86. GuideHand.gameObject.SetActive(currentNeedPlacesInfoWidget != null);
  87. }
  88. [CustomMethod(CustomMethodType.Update)]
  89. public void Update()
  90. {
  91. if (currentNeedPlacesInfoWidget != null)
  92. {
  93. if (currentNeedPlacesInfoWidget.currentSmallPlacesData == null &&
  94. currentNeedPlacesInfoWidget.IsSmallPlacesDataUlock(currentNeedPlacesInfoWidget.smallPlacesConfig
  95. .ID))
  96. {
  97. Vector3 localPos =
  98. transform.InverseTransformPoint(currentNeedPlacesInfoWidget.Btn_Jiesuo.transform.position);
  99. GuideHand.transform.localPosition = localPos;
  100. }
  101. else
  102. {
  103. Vector3 localPos =
  104. transform.InverseTransformPoint(
  105. currentNeedPlacesInfoWidget.Btn_Qianwang.transform.position);
  106. GuideHand.transform.localPosition = localPos;
  107. }
  108. }
  109. }
  110. public static async CTask OpenPanel(int placesId, Action<bool> callBack, int needSmallPlacesId = 0)
  111. {
  112. await UIManager.Instance.LoadAndOpenPanel<PlacesInfoPanel>(null, UILayer.Top,
  113. uiData: new object[] { placesId, callBack, needSmallPlacesId }, isShowBG: true);
  114. }
  115. public async override CTask Close()
  116. {
  117. foreach (var shopBtnWidget in placesInfoWidgets)
  118. {
  119. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  120. }
  121. placesInfoWidgets.Clear();
  122. if (!isChange)
  123. {
  124. callBack?.Invoke(false);
  125. callBack = null;
  126. }
  127. currentNeedPlacesInfoWidget = null;
  128. await base.Close();
  129. }
  130. }
  131. }