PlacesInfoPanel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Language;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Combat;
  9. using GameLogic.Combat.CombatTool;
  10. namespace Fort23.Mono
  11. {
  12. [UIBinding(prefab = "PlacesInfoPanel")]
  13. public partial class PlacesInfoPanel : UIPanel
  14. {
  15. private int PlacesId;
  16. private SmallPlacesConfig smallPlacesConfig;
  17. private PlacesConfig placesConfig;
  18. List<ShopBtnWidget> _shopBtnWidgets = new List<ShopBtnWidget>();
  19. private Action<bool> callBack;
  20. private bool isChange;
  21. private void Init()
  22. {
  23. isPopUi = true;
  24. isAddStack = false;
  25. }
  26. protected override void AddEvent()
  27. {
  28. }
  29. protected override void DelEvent()
  30. {
  31. }
  32. public override void AddButtonEvent()
  33. {
  34. Btn_Go.onClick.AddListener(Click_Go);
  35. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  36. }
  37. public async override CTask<bool> AsyncInit(object[] uiData)
  38. {
  39. PlacesId = (int)(uiData[0]);
  40. callBack = uiData[1] as Action<bool>;
  41. isChange = false;
  42. // smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlacesId);
  43. placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(PlacesId);
  44. foreach (var placesConfigSmallPlacersId in placesConfig.SmallPlacersIds)
  45. {
  46. ShopBtnWidget shopBtnWidget =
  47. await UIManager.Instance.CreateGComponentForObject<ShopBtnWidget>(ShopBtnWidgetGame, null, Content,
  48. isInstance: true);
  49. shopBtnWidget.CustomInit(placesConfigSmallPlacersId);
  50. shopBtnWidget.OnClick = OnClick;
  51. _shopBtnWidgets.Add(shopBtnWidget);
  52. }
  53. toggleList.GetChildObj();
  54. _shopBtnWidgets[0].OnPointerClick();
  55. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  56. Text_BigMapName.text = LanguageManager.Instance.Text(bigMapConfig.mapName);
  57. Text_PlacesName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  58. int triggerCount = 0;
  59. foreach (var i in placesConfig.MainTaskID)
  60. {
  61. if (EventSystemManager.Instance.IsEventTrigger(i))
  62. {
  63. triggerCount++;
  64. }
  65. }
  66. Text_PlacesComplteProgress.text = $"章节事件:{triggerCount}/{placesConfig.MainTaskID.Length}";
  67. return await base.AsyncInit(uiData);
  68. }
  69. private void OnClick(ItemWidgetBasic obj)
  70. {
  71. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  72. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  73. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID - 1);
  74. SmallPlacesConfig lastSmallPlacesConfig =
  75. ConfigComponent.Instance.Get<SmallPlacesConfig>(shopBtnWidget.SmallPlacesConfig.ID - 1);
  76. if (shopBtnWidget.SmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  77. lastSmallPlacesData.completionEventCount <
  78. lastSmallPlacesConfig.CompletionEventCount))
  79. {
  80. TipMessagePanel.OpenTipMessagePanel(
  81. $"[{LanguageManager.Instance.Text(shopBtnWidget.SmallPlacesConfig.placeName)}]未解锁, 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁. ");
  82. return;
  83. }
  84. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  85. {
  86. AccountFileInfo.EventList eventList =
  87. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  88. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  89. if (eventList == null || !eventList.isCompleted)
  90. {
  91. EventConfig eventConfig =
  92. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  93. TipMessagePanel.OpenTipMessagePanel(
  94. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 主线任务{eventConfig.EventName}后, 可解锁. ");
  95. return;
  96. }
  97. }
  98. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  99. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID);
  100. if (currentSmallPlacesData == null)
  101. {
  102. TipMessagePanel.OpenTipMessagePanel("通过上一个地点解锁");
  103. return;
  104. }
  105. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  106. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID + 1);
  107. //解锁下一个地图
  108. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(shopBtnWidget.SmallPlacesConfig.ID + 1))
  109. {
  110. Text_Go.text = "解锁下一地点";
  111. }
  112. else
  113. {
  114. Text_Go.text = "前往";
  115. }
  116. toggleList.ClickWidget(shopBtnWidget.uiToggle);
  117. smallPlacesConfig = shopBtnWidget.SmallPlacesConfig;
  118. AccountFileInfo.SmallPlacesData smallPlacesData =
  119. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  120. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  121. float tansuodu = smallPlacesData == null ? 0 : smallPlacesData.completionEventCount;
  122. Slider_SmallJD.value = tansuodu;
  123. Text_TanSuDu.text =
  124. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]探索度 {(tansuodu / smallPlacesConfig.CompletionEventCount) * 100}%";
  125. }
  126. private bool IsSmallPlacesDataUlock(int id)
  127. {
  128. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  129. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  130. SmallPlacesConfig lastSmallPlacesConfig =
  131. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  132. if (id > 1 && (lastSmallPlacesData == null ||
  133. lastSmallPlacesData.completionEventCount <
  134. lastSmallPlacesConfig.CompletionEventCount))
  135. {
  136. return false;
  137. }
  138. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  139. {
  140. AccountFileInfo.EventList eventList =
  141. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  142. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  143. if (eventList == null || !eventList.isCompleted)
  144. {
  145. return false;
  146. }
  147. }
  148. return true;
  149. }
  150. private async void Click_Go()
  151. {
  152. if (smallPlacesConfig.ID == 0)
  153. return;
  154. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  155. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID + 1);
  156. //解锁下一个地图
  157. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID + 1))
  158. {
  159. isChange = true;
  160. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  161. UIManager.Instance.HideUIUIPanel(this);
  162. //切换下一个地图
  163. PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID + 1);
  164. UIManager.Instance.HindCurrAllShowPanel();
  165. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  166. CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  167. UIManager.Instance.SetEventSystemEnable(false);
  168. await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  169. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  170. UIManager.Instance.SetEventSystemEnable(true);
  171. UIManager.Instance.ShowLastHindAllShowPanel();
  172. callBack?.Invoke(true);
  173. callBack = null;
  174. }
  175. else
  176. {
  177. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  178. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  179. SmallPlacesConfig lastSmallPlacesConfig =
  180. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  181. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  182. lastSmallPlacesData.completionEventCount <
  183. lastSmallPlacesConfig.CompletionEventCount))
  184. {
  185. TipMessagePanel.OpenTipMessagePanel(
  186. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁. ");
  187. return;
  188. }
  189. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  190. {
  191. AccountFileInfo.EventList eventList =
  192. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  193. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  194. EventConfig eventConfig =
  195. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  196. if (eventList == null || !eventList.isCompleted)
  197. {
  198. TipMessagePanel.OpenTipMessagePanel(
  199. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 主线任务{eventConfig.EventName}后, 可解锁. ");
  200. return;
  201. }
  202. }
  203. if (smallPlacesConfig.ID == PlayerManager.Instance.CurrentsmallPlaces.id)
  204. {
  205. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  206. UIManager.Instance.HideUIUIPanel(this);
  207. return;
  208. }
  209. isChange = true;
  210. PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  211. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  212. UIManager.Instance.HideUIUIPanel(this);
  213. UIManager.Instance.HindCurrAllShowPanel();
  214. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  215. CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  216. UIManager.Instance.SetEventSystemEnable(false);
  217. await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  218. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  219. UIManager.Instance.SetEventSystemEnable(true);
  220. UIManager.Instance.ShowLastHindAllShowPanel();
  221. callBack?.Invoke(true);
  222. callBack = null;
  223. }
  224. }
  225. public static async CTask OpenPanel(int placesId, Action<bool> callBack)
  226. {
  227. await UIManager.Instance.LoadAndOpenPanel<PlacesInfoPanel>(null, UILayer.Top,
  228. uiData: new object[] { placesId, callBack }, isShowBG: true);
  229. }
  230. public override void Close()
  231. {
  232. foreach (var shopBtnWidget in _shopBtnWidgets)
  233. {
  234. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  235. }
  236. _shopBtnWidgets.Clear();
  237. // smallPlacesConfig = default;
  238. if (!isChange)
  239. {
  240. callBack?.Invoke(false);
  241. callBack = null;
  242. }
  243. base.Close();
  244. }
  245. }
  246. }