LevelChoosePanel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System.Linq;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "LevelChoosePanel")]
  11. public partial class LevelChoosePanel : UIPanel
  12. {
  13. private BigMapItem _bigMapItem;
  14. private PlacesItem placesItem;
  15. private void Init()
  16. {
  17. isAddStack = true;
  18. IsShowAppBar = false;
  19. }
  20. protected override void AddEvent()
  21. {
  22. }
  23. protected override void DelEvent()
  24. {
  25. }
  26. public override void AddButtonEvent()
  27. {
  28. // Btn_RenJie.onClick.AddListener(async () => { ChangeMap(1); });
  29. Btn_Close.onClick.AddListener(() =>
  30. {
  31. // if (placesItem != null)
  32. // {
  33. // placesItem?.Dispose();
  34. // placesItem = null;
  35. // Sv2.gameObject.SetActive(false);
  36. // return;
  37. // }
  38. // else
  39. {
  40. UIManager.Instance.HideUIUIPanel(this);
  41. }
  42. });
  43. }
  44. // public async CTask ChangeMap(int bigMapId)
  45. // {
  46. // Sv2.gameObject.SetActive(false);
  47. //
  48. // _bigMapItem?.Dispose();
  49. // _bigMapItem = null;
  50. // WorldMapConfig worldMapConfig = ConfigComponent.Instance.Get<WorldMapConfig>(bigMapId);
  51. // _bigMapItem = new BigMapItem();
  52. // GameObjectPool gameObjectPool2 = await GObjectPool.Instance.FetchAsync<GameObjectPool>(worldMapConfig.bigMapPrefabName + ".prefab");
  53. // gameObjectPool2.own.transform.parent = MapRoot;
  54. // gameObjectPool2.own.transform.localScale = Vector3.one;
  55. // gameObjectPool2.own.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  56. // _bigMapItem.CustomInit(worldMapConfig.ID, gameObjectPool2, BigMapOnClick);
  57. // }
  58. // private async void BigMapOnClick(ItemWidgetBasic obj)
  59. // {
  60. // BigMapWidget bigMapWidget = obj as BigMapWidget;
  61. // ChangePlaces(bigMapWidget.bigMap.ID);
  62. // }
  63. private async void PlacesOnClick(ItemWidgetBasic obj)
  64. {
  65. PlacesWidget placesWidget = obj as PlacesWidget;
  66. //加载地图
  67. PlacesInfoPanel.OpenPanel(placesWidget.placesConfig.ID);
  68. //
  69. // if (placesWidget.placesConfig.ID > 1 && PlayerManager.Instance.GetMapBl(placesWidget.placesConfig.ID - 1) < 100)
  70. // {
  71. // TipMessagePanel.OpenTipMessagePanel("上一个关卡没有解锁");
  72. // return;
  73. // }
  74. //
  75. // AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(placesWidget.placesConfig.ID);
  76. // if (currentPlacesData == null)
  77. // {
  78. // currentPlacesData = new AccountFileInfo.PlacesData();
  79. // currentPlacesData.id = placesWidget.placesConfig.ID;
  80. // AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  81. // }
  82. //
  83. // PlayerManager.Instance.CurrentPlaces = currentPlacesData;
  84. //
  85. // UIManager.Instance.HideUIUIPanel(this);
  86. // EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  87. }
  88. public async CTask ChangePlaces(int bigMapId)
  89. {
  90. Sv2.gameObject.SetActive(true);
  91. placesItem?.Dispose();
  92. placesItem = null;
  93. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(bigMapId);
  94. WorldMapConfig[] worldMapConfigs = ConfigComponent.Instance.GetAll<WorldMapConfig>();
  95. foreach (var worldMapConfig in worldMapConfigs)
  96. {
  97. if (worldMapConfig.bigMapId.Contains(bigMapConfig.ID))
  98. {
  99. Text_WorldMapName.text = LanguageManager.Instance.Text(worldMapConfig.worldName);
  100. break;
  101. }
  102. }
  103. PlacesConfig placesConfig =
  104. ConfigComponent.Instance.Get<PlacesConfig>(PlayerManager.Instance.CurrentPlaces.id);
  105. Text_PlacesComplteProgress.text =
  106. $"{LanguageManager.Instance.Text(placesConfig.placeName)}完成度:{PlayerManager.Instance.PlacesBl}%";
  107. GameObjectPool gameObjectPool2 = await GObjectPool.Instance.FetchAsync<GameObjectPool>(bigMapConfig.mapPrefabName + ".prefab");
  108. gameObjectPool2.own.transform.parent = PlacesRoot;
  109. gameObjectPool2.own.transform.localScale = Vector3.one;
  110. gameObjectPool2.own.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  111. placesItem = new PlacesItem();
  112. await placesItem.CustomInit(bigMapConfig.ID, gameObjectPool2, PlacesOnClick);
  113. }
  114. public async void CustomInit()
  115. {
  116. int PlacesId = PlayerManager.Instance.GetMaxPlacesId();
  117. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(PlacesId);
  118. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  119. await ChangePlaces(bigMapConfig.ID);
  120. // await ChangeMap(bigMapConfig.ID);
  121. Sv2.gameObject.SetActive(true);
  122. LayoutRebuilder.ForceRebuildLayoutImmediate(PlacesRoot);
  123. foreach (var placesItemPlacesWidget in placesItem.PlacesWidgets)
  124. {
  125. if (placesItemPlacesWidget.placesConfig.ID == PlayerManager.Instance.CurrentPlaces.id)
  126. {
  127. // Rect_BiaoJi.anchoredPosition = transform.worldToLocalMatrix * placesItemPlacesWidget.Pos.position;
  128. Rect_BiaoJi.position = placesItemPlacesWidget.Pos.position;
  129. }
  130. }
  131. }
  132. public async static CTask OpenPanel()
  133. {
  134. LevelChoosePanel levelChoosePanel = await UIManager.Instance.LoadAndOpenPanel<LevelChoosePanel>(null);
  135. levelChoosePanel.CustomInit();
  136. }
  137. public override void Close()
  138. {
  139. placesItem?.Dispose();
  140. placesItem = null;
  141. _bigMapItem?.Dispose();
  142. _bigMapItem = null;
  143. base.Close();
  144. }
  145. }
  146. }