PlacesInfoPanel.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "PlacesInfoPanel")]
  9. public partial class PlacesInfoPanel : UIPanel
  10. {
  11. private int PlacesId;
  12. private SmallPlacesConfig smallPlacesConfig;
  13. private PlacesConfig placesConfig;
  14. List<ShopBtnWidget> _shopBtnWidgets = new List<ShopBtnWidget>();
  15. private void Init()
  16. {
  17. isPopUi = true;
  18. isAddStack = false;
  19. }
  20. protected override void AddEvent()
  21. {
  22. }
  23. protected override void DelEvent()
  24. {
  25. }
  26. public override void AddButtonEvent()
  27. {
  28. Btn_Go.onClick.AddListener(Click_Go);
  29. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  30. }
  31. public async override CTask<bool> AsyncInit(object[] uiData)
  32. {
  33. PlacesId = (int)(uiData[0]);
  34. // smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlacesId);
  35. placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(PlacesId);
  36. foreach (var placesConfigSmallPlacersId in placesConfig.SmallPlacersIds)
  37. {
  38. ShopBtnWidget shopBtnWidget = await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, Content);
  39. shopBtnWidget.CustomInit(placesConfigSmallPlacersId);
  40. shopBtnWidget.OnClick = OnClick;
  41. _shopBtnWidgets.Add(shopBtnWidget);
  42. }
  43. toggleList.GetChildObj();
  44. _shopBtnWidgets[0].OnPointerClick();
  45. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  46. Text_BigMapName.text = LanguageManager.Instance.Text(bigMapConfig.mapName);
  47. Text_PlacesName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  48. Text_PlacesComplteProgress.text = $"完成度:{PlayerManager.Instance.GetMapBl(placesConfig.ID)}%";
  49. return await base.AsyncInit(uiData);
  50. }
  51. private void OnClick(ItemWidgetBasic obj)
  52. {
  53. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  54. toggleList.ClickWidget(shopBtnWidget.uiToggle);
  55. smallPlacesConfig = shopBtnWidget.SmallPlacesConfig;
  56. }
  57. private async void Click_Go()
  58. {
  59. if (smallPlacesConfig.ID == 0)
  60. return;
  61. AccountFileInfo.SmallPlacesData lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  62. SmallPlacesConfig lastSmallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  63. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null || lastSmallPlacesData.completionEventCount < lastSmallPlacesConfig.CompletionEventCount))
  64. {
  65. TipMessagePanel.OpenTipMessagePanel("上一个关卡事件完成度不足");
  66. return;
  67. }
  68. AccountFileInfo.SmallPlacesData smallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.PlacesId);
  69. if (smallPlacesData == null)
  70. {
  71. smallPlacesData = new AccountFileInfo.SmallPlacesData();
  72. smallPlacesData.id = smallPlacesConfig.ID;
  73. AccountFileInfo.Instance.playerData.smallPlacesDatas.Add(smallPlacesData);
  74. }
  75. AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.ID);
  76. if (currentPlacesData == null)
  77. {
  78. currentPlacesData = new AccountFileInfo.PlacesData();
  79. currentPlacesData.id = placesConfig.ID;
  80. AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  81. }
  82. PlayerManager.Instance.CurrentsmallPlaces = smallPlacesData;
  83. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  84. UIManager.Instance.HideUIUIPanel(this);
  85. EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  86. }
  87. public static async CTask OpenPanel(int placesId)
  88. {
  89. await UIManager.Instance.LoadAndOpenPanel<PlacesInfoPanel>(null, UILayer.Top, uiData: new object[] { placesId }, isShowBG: true);
  90. }
  91. public override void Close()
  92. {
  93. foreach (var shopBtnWidget in _shopBtnWidgets)
  94. {
  95. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  96. }
  97. _shopBtnWidgets.Clear();
  98. smallPlacesConfig = default;
  99. base.Close();
  100. }
  101. }
  102. }