PlacesInfoPanel.cs 5.1 KB

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