LevelChoosePanel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Excel2Json;
  2. using Fort23.Core;
  3. using Fort23.UTool;
  4. using UnityEngine;
  5. namespace Fort23.Mono
  6. {
  7. [UIBinding(prefab = "LevelChoosePanel")]
  8. public partial class LevelChoosePanel : UIPanel
  9. {
  10. private BigMapItem _bigMapItem;
  11. private PlacesItem placesItem;
  12. private void Init()
  13. {
  14. isAddStack = true;
  15. IsShowAppBar = false;
  16. }
  17. protected override void AddEvent()
  18. {
  19. }
  20. protected override void DelEvent()
  21. {
  22. }
  23. public override void AddButtonEvent()
  24. {
  25. Btn_RenJie.onClick.AddListener(async () => { ChangeMap(1); });
  26. Btn_Close.onClick.AddListener(() =>
  27. {
  28. if (placesItem != null)
  29. {
  30. placesItem?.Dispose();
  31. placesItem = null;
  32. Sv2.gameObject.SetActive(false);
  33. return;
  34. }
  35. else
  36. {
  37. UIManager.Instance.HideUIUIPanel(this);
  38. }
  39. });
  40. }
  41. public async CTask ChangeMap(int bigMapId)
  42. {
  43. Sv2.gameObject.SetActive(false);
  44. _bigMapItem?.Dispose();
  45. _bigMapItem = null;
  46. WorldMapConfig worldMapConfig = ConfigComponent.Instance.Get<WorldMapConfig>(bigMapId);
  47. _bigMapItem = new BigMapItem();
  48. GameObjectPool gameObjectPool2 = await GObjectPool.Instance.FetchAsync<GameObjectPool>(worldMapConfig.bigMapPrefabName + ".prefab");
  49. gameObjectPool2.own.transform.parent = MapRoot;
  50. gameObjectPool2.own.transform.localScale = Vector3.one;
  51. gameObjectPool2.own.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  52. _bigMapItem.CustomInit(worldMapConfig.ID, gameObjectPool2, BigMapOnClick);
  53. }
  54. private async void BigMapOnClick(ItemWidgetBasic obj)
  55. {
  56. BigMapWidget bigMapWidget = obj as BigMapWidget;
  57. ChangePlaces(bigMapWidget.bigMap.ID);
  58. }
  59. private async void PlacesOnClick(ItemWidgetBasic obj)
  60. {
  61. PlacesWidget placesWidget = obj as PlacesWidget;
  62. //加载地图
  63. AccountFileInfo.PlacesData lastPlacesData = PlayerManager.Instance.GetPlacesData(placesWidget.placesConfig.ID - 1);
  64. if (placesWidget.placesConfig.ID > 1 && (lastPlacesData == null || lastPlacesData.progress < 100))
  65. {
  66. TipMessagePanel.OpenTipMessagePanel("上一个关卡没有解锁");
  67. return;
  68. }
  69. AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(placesWidget.placesConfig.ID);
  70. if (currentPlacesData == null)
  71. {
  72. currentPlacesData = new AccountFileInfo.PlacesData();
  73. currentPlacesData.id = placesWidget.placesConfig.ID;
  74. AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  75. }
  76. PlayerManager.Instance.CurrentPlaces = currentPlacesData;
  77. UIManager.Instance.HideUIUIPanel(this);
  78. EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  79. }
  80. public async void ChangePlaces(int bigMapId)
  81. {
  82. Sv2.gameObject.SetActive(true);
  83. placesItem?.Dispose();
  84. placesItem = null;
  85. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(bigMapId);
  86. GameObjectPool gameObjectPool2 = await GObjectPool.Instance.FetchAsync<GameObjectPool>(bigMapConfig.mapPrefabName + ".prefab");
  87. gameObjectPool2.own.transform.parent = PlacesRoot ;
  88. gameObjectPool2.own.transform.localScale = Vector3.one;
  89. gameObjectPool2.own.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  90. placesItem = new PlacesItem();
  91. placesItem.CustomInit(bigMapConfig.ID, gameObjectPool2, PlacesOnClick);
  92. }
  93. public async void CustomInit()
  94. {
  95. int PlacesId = PlayerManager.Instance.GetMaxPlacesId();
  96. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(PlacesId);
  97. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  98. await ChangeMap(bigMapConfig.ID);
  99. ChangePlaces(bigMapConfig.ID);
  100. }
  101. public async static CTask OpenPanel()
  102. {
  103. LevelChoosePanel levelChoosePanel = await UIManager.Instance.LoadAndOpenPanel<LevelChoosePanel>(null);
  104. levelChoosePanel.CustomInit();
  105. }
  106. public override void Close()
  107. {
  108. placesItem?.Dispose();
  109. placesItem = null;
  110. _bigMapItem?.Dispose();
  111. _bigMapItem = null;
  112. base.Close();
  113. }
  114. }
  115. }