PlacesInfoPanel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. bool isSelect = false;
  54. for (var i = 0; i < _shopBtnWidgets.Count; i++)
  55. {
  56. if (PlayerManager.Instance.CurrentsmallPlaces.id == _shopBtnWidgets[i].SmallPlacesConfig.ID)
  57. {
  58. isSelect = true;
  59. _shopBtnWidgets[i].OnPointerClick();
  60. break;
  61. }
  62. }
  63. if (!isSelect)
  64. {
  65. for (var i = _shopBtnWidgets.Count - 1; i >= _shopBtnWidgets.Count; i--)
  66. {
  67. if (_shopBtnWidgets[i].iaUlock)
  68. {
  69. _shopBtnWidgets[i].OnPointerClick();
  70. break;
  71. }
  72. }
  73. }
  74. // toggleList.GetChildObj();
  75. BigMapConfig bigMapConfig = ConfigComponent.Instance.Get<BigMapConfig>(placesConfig.bigMapID);
  76. Text_BigMapName.text = LanguageManager.Instance.Text(bigMapConfig.mapName);
  77. Text_PlacesName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  78. // int triggerCount = 0;
  79. // foreach (var i in placesConfig.MainTaskID)
  80. // {
  81. // if (EventSystemManager.Instance.IsEventTrigger(i))
  82. // {
  83. // triggerCount++;
  84. // }
  85. // }
  86. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(placesConfig.ID);
  87. int jindu = placesData == null ? 0 : placesData.progress;
  88. Text_PlacesComplteProgress.text = $"章节事件:{jindu}/{placesConfig.TotalScore}";
  89. return await base.AsyncInit(uiData);
  90. }
  91. private void OnClick(ItemWidgetBasic obj)
  92. {
  93. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  94. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  95. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID - 1);
  96. SmallPlacesConfig lastSmallPlacesConfig =
  97. ConfigComponent.Instance.Get<SmallPlacesConfig>(shopBtnWidget.SmallPlacesConfig.ID - 1);
  98. if (shopBtnWidget.SmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  99. lastSmallPlacesData.completionEventCount <
  100. lastSmallPlacesConfig.CompletionEventCount))
  101. {
  102. TipMessagePanel.OpenTipMessagePanel(
  103. $"[{LanguageManager.Instance.Text(shopBtnWidget.SmallPlacesConfig.placeName)}]未解锁, 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁. ");
  104. return;
  105. }
  106. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  107. {
  108. AccountFileInfo.EventList eventList =
  109. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  110. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  111. if (eventList == null || !eventList.isCompleted)
  112. {
  113. EventConfig eventConfig =
  114. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  115. TipMessagePanel.OpenTipMessagePanel(
  116. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 主线任务{eventConfig.EventName}后, 可解锁. ");
  117. return;
  118. }
  119. }
  120. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  121. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID);
  122. if (currentSmallPlacesData == null)
  123. {
  124. TipMessagePanel.OpenTipMessagePanel("通过上一个地点解锁");
  125. return;
  126. }
  127. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  128. PlayerManager.Instance.GetSmallPlacesData(shopBtnWidget.SmallPlacesConfig.ID + 1);
  129. //解锁下一个地图
  130. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(shopBtnWidget.SmallPlacesConfig.ID + 1))
  131. {
  132. Text_Go.text = "解锁下一地点";
  133. }
  134. else
  135. {
  136. Text_Go.text = "前往";
  137. }
  138. // toggleList.ClickWidget(shopBtnWidget.uiToggle);
  139. smallPlacesConfig = shopBtnWidget.SmallPlacesConfig;
  140. AccountFileInfo.SmallPlacesData smallPlacesData =
  141. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  142. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  143. float tansuodu = smallPlacesData == null ? 0 : smallPlacesData.completionEventCount;
  144. Slider_SmallJD.value = tansuodu;
  145. Text_TanSuDu.text =
  146. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]探索度 {(tansuodu / smallPlacesConfig.CompletionEventCount) * 100}%";
  147. }
  148. private bool IsSmallPlacesDataUlock(int id)
  149. {
  150. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  151. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  152. SmallPlacesConfig lastSmallPlacesConfig =
  153. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  154. if (id > 1 && (lastSmallPlacesData == null ||
  155. lastSmallPlacesData.completionEventCount <
  156. lastSmallPlacesConfig.CompletionEventCount))
  157. {
  158. return false;
  159. }
  160. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  161. {
  162. AccountFileInfo.EventList eventList =
  163. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  164. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  165. if (eventList == null || !eventList.isCompleted)
  166. {
  167. return false;
  168. }
  169. }
  170. return true;
  171. }
  172. private async void Click_Go()
  173. {
  174. if (smallPlacesConfig.ID == 0)
  175. return;
  176. AccountFileInfo.SmallPlacesData nextSmallPlacesData =
  177. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID + 1);
  178. //解锁下一个地图
  179. if (nextSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID + 1))
  180. {
  181. isChange = true;
  182. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  183. UIManager.Instance.HideUIUIPanel(this);
  184. //切换下一个地图
  185. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID + 1);
  186. // CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  187. // CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  188. // UIManager.Instance.SetEventSystemEnable(false);
  189. // await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  190. // CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  191. // UIManager.Instance.SetEventSystemEnable(true);
  192. callBack?.Invoke(true);
  193. callBack = null;
  194. }
  195. else
  196. {
  197. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  198. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  199. SmallPlacesConfig lastSmallPlacesConfig =
  200. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  201. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  202. lastSmallPlacesData.completionEventCount <
  203. lastSmallPlacesConfig.CompletionEventCount))
  204. {
  205. TipMessagePanel.OpenTipMessagePanel(
  206. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁. ");
  207. return;
  208. }
  209. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  210. {
  211. AccountFileInfo.EventList eventList =
  212. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  213. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  214. EventConfig eventConfig =
  215. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  216. if (eventList == null || !eventList.isCompleted)
  217. {
  218. TipMessagePanel.OpenTipMessagePanel(
  219. $"[{LanguageManager.Instance.Text(smallPlacesConfig.placeName)}]未解锁, 主线任务{eventConfig.EventName}后, 可解锁. ");
  220. return;
  221. }
  222. }
  223. if (smallPlacesConfig.ID == PlayerManager.Instance.CurrentsmallPlaces.id)
  224. {
  225. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  226. UIManager.Instance.HideUIUIPanel(this);
  227. return;
  228. }
  229. isChange = true;
  230. UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  231. UIManager.Instance.HideUIUIPanel(this);
  232. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  233. callBack?.Invoke(true);
  234. callBack = null;
  235. }
  236. }
  237. public static async CTask OpenPanel(int placesId, Action<bool> callBack)
  238. {
  239. await UIManager.Instance.LoadAndOpenPanel<PlacesInfoPanel>(null, UILayer.Top,
  240. uiData: new object[] { placesId, callBack }, isShowBG: true);
  241. }
  242. public async override CTask Close()
  243. {
  244. foreach (var shopBtnWidget in _shopBtnWidgets)
  245. {
  246. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  247. }
  248. _shopBtnWidgets.Clear();
  249. // smallPlacesConfig = default;
  250. if (!isChange)
  251. {
  252. callBack?.Invoke(false);
  253. callBack = null;
  254. }
  255. await base.Close();
  256. }
  257. }
  258. }