PlacesInfoPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(placesConfig.ID);
  67. int jindu =placesData == null ? 0 : placesData.progress;
  68. Text_PlacesComplteProgress.text = $"章节事件:{jindu}/{placesConfig.TotalScore}";
  69. return await base.AsyncInit(uiData);
  70. }
  71. private void OnClick(ItemWidgetBasic obj)
  72. {
  73. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  74. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  75. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID - 1);
  76. SmallPlacesConfig lastSmallPlacesConfig =
  77. ConfigComponent.Instance.Get<SmallPlacesConfig>(shopBtnWidget.SmallPlacesConfig.ID - 1);
  78. if (shopBtnWidget.SmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  79. lastSmallPlacesData.completionEventCount <
  80. lastSmallPlacesConfig.CompletionEventCount))
  81. {
  82. TipMessagePanel.OpenTipMessagePanel(
  83. $"[{LanguageManager.Instance.Text(shopBtnWidget.SmallPlacesConfig.placeName)}]未解锁, 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁. ");
  84. return;
  85. }
  86. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  87. {
  88. AccountFileInfo.EventList eventList =
  89. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  90. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  91. if (eventList == null || !eventList.isCompleted)
  92. {
  93. EventConfig eventConfig =
  94. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  95. TipMessagePanel.OpenTipMessagePanel(
  96. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 主线任务{eventConfig.EventName}后, 可解锁. ");
  97. return;
  98. }
  99. }
  100. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  101. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID);
  102. if (currentSmallPlacesData == null)
  103. {
  104. TipMessagePanel.OpenTipMessagePanel("通过上一个地点解锁");
  105. return;
  106. }
  107. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  108. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID + 1);
  109. //解锁下一个地图
  110. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(shopBtnWidget.SmallPlacesConfig.ID + 1))
  111. {
  112. Text_Go.text = "解锁下一地点";
  113. }
  114. else
  115. {
  116. Text_Go.text = "前往";
  117. }
  118. // toggleList.ClickWidget(shopBtnWidget.uiToggle);
  119. smallPlacesConfig = shopBtnWidget.SmallPlacesConfig;
  120. AccountFileInfo.SmallPlacesData smallPlacesData =
  121. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  122. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  123. float tansuodu = smallPlacesData == null ? 0 : smallPlacesData.completionEventCount;
  124. Slider_SmallJD.value = tansuodu;
  125. Text_TanSuDu.text =
  126. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]探索度 {(tansuodu / smallPlacesConfig.CompletionEventCount) * 100}%";
  127. }
  128. private bool IsSmallPlacesDataUlock(int id)
  129. {
  130. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  131. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  132. SmallPlacesConfig lastSmallPlacesConfig =
  133. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  134. if (id > 1 && (lastSmallPlacesData == null ||
  135. lastSmallPlacesData.completionEventCount <
  136. lastSmallPlacesConfig.CompletionEventCount))
  137. {
  138. return false;
  139. }
  140. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  141. {
  142. AccountFileInfo.EventList eventList =
  143. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  144. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  145. if (eventList == null || !eventList.isCompleted)
  146. {
  147. return false;
  148. }
  149. }
  150. return true;
  151. }
  152. private async void Click_Go()
  153. {
  154. if (smallPlacesConfig.ID == 0)
  155. return;
  156. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  157. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID + 1);
  158. //解锁下一个地图
  159. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID + 1))
  160. {
  161. isChange = true;
  162. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  163. UIManager.Instance.HideUIUIPanel(this);
  164. //切换下一个地图
  165. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID + 1);
  166. // CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  167. // CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  168. // UIManager.Instance.SetEventSystemEnable(false);
  169. // await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  170. // CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  171. // UIManager.Instance.SetEventSystemEnable(true);
  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. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  211. UIManager.Instance.HideUIUIPanel(this);
  212. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  213. callBack?.Invoke(true);
  214. callBack = null;
  215. }
  216. }
  217. public static async CTask OpenPanel(int placesId, Action<bool> callBack)
  218. {
  219. await UIManager.Instance.LoadAndOpenPanel<PlacesInfoPanel>(null, UILayer.Top,
  220. uiData: new object[] { placesId, callBack }, isShowBG: true);
  221. }
  222. public async override CTask Close()
  223. {
  224. foreach (var shopBtnWidget in _shopBtnWidgets)
  225. {
  226. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  227. }
  228. _shopBtnWidgets.Clear();
  229. // smallPlacesConfig = default;
  230. if (!isChange)
  231. {
  232. callBack?.Invoke(false);
  233. callBack = null;
  234. }
  235. await base.Close();
  236. }
  237. }
  238. }