LevelChoosePanel.cs 6.7 KB

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