MainPanel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Audio;
  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. using UnityEngine;
  11. namespace Fort23.Mono
  12. {
  13. [UIBinding(prefab = "MainPanel")]
  14. public partial class MainPanel : UIPanel
  15. {
  16. bool isShowSkillPanel = false;
  17. // private ShengShiEventWidget shengShiEventWidget;
  18. List<int> moRen = new List<int>() { 1001, 1002 };
  19. List<EnergyWidget> widgets = new List<EnergyWidget>();
  20. List<ShengShiConditionWidget> _shengShiConditionWidgets = new List<ShengShiConditionWidget>();
  21. private void Init()
  22. {
  23. isAddStack = true;
  24. IsShowAppBar = true;
  25. }
  26. protected override void AddEvent()
  27. {
  28. EventManager.Instance.AddEventListener(CustomEventType.ShengShiOnClick, ShengShiOnClick);
  29. EventManager.Instance.AddEventListener(CustomEventType.CompleteEvent, CompleteEvent);
  30. EventManager.Instance.AddEventListener(CustomEventType.CompleteUpdate, CompleteUpdate);
  31. EventManager.Instance.AddEventListener(CustomEventType.RemoveEvent, RemoveEvent);
  32. EventManager.Instance.AddEventListener(CustomEventType.ChangeMap, ChangeMapEvent);
  33. EventManager.Instance.AddEventListener(CustomEventType.DaoYouCounUpdate, DaoYouCounUpdate);
  34. EventManager.Instance.AddEventListener(CustomEventType.AlterName, AlterName);
  35. }
  36. private void DaoYouCounUpdate(IEventData e)
  37. {
  38. UpdateDaoYouCoun();
  39. }
  40. public async override CTask GetFocus()
  41. {
  42. await AppBarPanel.OpenPanel(this);
  43. TitlePanel.ClosePanel();
  44. base.GetFocus();
  45. CustomInit();
  46. }
  47. public async void CustomInit()
  48. {
  49. if (AccountFileInfo.Instance.playerData.isTiggerPlot)
  50. {
  51. if (PlayerManager.Instance.PlayerName == "")
  52. {
  53. AlterNamePanel alterNamePanel = await AlterNamePanel.OpenPanel();
  54. await alterNamePanel.UIClosed();
  55. }
  56. if (PlayerGuideManager.Instance.GuideIsCanDo(1))
  57. {
  58. await PlayerGuideManager.Instance.SetGuid(1);
  59. }
  60. if (PlayerGuideManager.Instance.GuideIsCanDo(4))
  61. {
  62. await PlayerGuideManager.Instance.SetGuid(4);
  63. }
  64. }
  65. }
  66. private void RemoveEvent(IEventData e)
  67. {
  68. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  69. CreatShengShiEvent();
  70. ChagneShenshiBtnActive();
  71. }
  72. private void CompleteUpdate(IEventData e)
  73. {
  74. ChangeMap(null);
  75. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  76. // fx_ui_renwu_chuxian.gameObject.SetActive(true);
  77. // fx_ui_renwu_chuxian.Play();
  78. CreatShengShiEvent();
  79. ChagneShenshiBtnActive();
  80. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  81. SmallPlacesConfig smallPlacesConfig =
  82. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  83. if (PlayerManager.Instance.CurrentsmallPlaces.completionEventCount ==
  84. smallPlacesConfig.CompletionEventCount)
  85. {
  86. AudioManager.Instance.PlayAudio("ui_jinduwancheng");
  87. }
  88. PlayEventCompletedEfx();
  89. }
  90. TimerEntity _timerEntity = null;
  91. private void CompleteEvent(IEventData e)
  92. {
  93. _timerEntity?.Dispose();
  94. _timerEntity = null;
  95. PlayEventCompletedEfx();
  96. fx_ui_renwu_chuxian.gameObject.SetActive(true);
  97. fx_ui_renwu_chuxian.Play();
  98. _timerEntity =
  99. TimerComponent.Instance.AddTimer(400, () => { fx_ui_renwu_chuxian.gameObject.SetActive(false); });
  100. }
  101. public void UpdateDaoYouCoun()
  102. {
  103. int count = AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas.Count;
  104. // foreach (var keyValuePair in AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas)
  105. // {
  106. // count += keyValuePair.Value.Count;
  107. // }
  108. if (count > 0)
  109. {
  110. Icon_Daoyou.gameObject.SetActive(true);
  111. Text_DaoyouCount.text = count.ToString();
  112. }
  113. else
  114. {
  115. Icon_Daoyou.gameObject.SetActive(false);
  116. }
  117. }
  118. private void ChagneShenshiBtnActive()
  119. {
  120. // Btn_Event.gameObject.SetActive(event > 0);
  121. }
  122. protected override void DelEvent()
  123. {
  124. EventManager.Instance.RemoveEventListener(CustomEventType.CompleteEvent, CompleteEvent);
  125. EventManager.Instance.RemoveEventListener(CustomEventType.CompleteUpdate, CompleteUpdate);
  126. EventManager.Instance.RemoveEventListener(CustomEventType.RemoveEvent, RemoveEvent);
  127. EventManager.Instance.RemoveEventListener(CustomEventType.ShengShiOnClick, ShengShiOnClick);
  128. EventManager.Instance.RemoveEventListener(CustomEventType.ChangeMap, ChangeMapEvent);
  129. EventManager.Instance.RemoveEventListener(CustomEventType.DaoYouCounUpdate, DaoYouCounUpdate);
  130. }
  131. public override void AddButtonEvent()
  132. {
  133. Btn_Chat.onClick.AddListener(() => { ChatPanel.OpenPanel(); });
  134. CameraSelect.onValueChanged.AddListener(CameraSelect_onValueChanged);
  135. Btn_ChangeMap.onClick.AddListener(() =>
  136. {
  137. SmallPlacesConfig smallPlacesConfig =
  138. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  139. PlacesInfoPanel.OpenPanel(smallPlacesConfig.PlacesId, null);
  140. });
  141. Btn_Event.onClick.AddListener(() =>
  142. {
  143. if (PlayerGuideManager.Instance.curPhase == 1)
  144. {
  145. return;
  146. }
  147. EventSystemManager.Instance.isOpenUi = true;
  148. DivineSenceEventPreviewPanel.OpenPanel();
  149. });
  150. Btn_Map.onClick.AddListener(() => { LevelChoosePanel.OpenPanel(); });
  151. // Btn_DaoYou.onClick.AddListener(() => { DaoYouPanel.OpenPanel(); });
  152. //
  153. // Btn_Tower.onClick.AddListener(() => { TowerPanel.OpenPanel(1); });
  154. Btn_QianKunDai.onClick.AddListener(() => { QiankundaiPanel.OpenPanel(); });
  155. Btn_StartEvent.onClick.AddListener(async () =>
  156. {
  157. if (PlayerGuideManager.Instance.curPhase == 3)
  158. {
  159. return;
  160. }
  161. if (PlayerGuideManager.Instance.GuideIsCanDo(1, 3))
  162. {
  163. PlayerGuideManager.Instance.NextGuide();
  164. }
  165. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  166. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  167. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  168. if (eventConfig.EventTriggerType == 4)
  169. {
  170. if (eventList.isCompleted1)
  171. {
  172. EventSystemManager.Instance.CompleteEvent(eventList);
  173. return;
  174. }
  175. }
  176. if (eventList != null)
  177. {
  178. EventSystemManager.Instance.CancelEvent();
  179. if (EventSystemManager.Instance.isTriggerEvent)
  180. return;
  181. if (eventList.isCompleted)
  182. return;
  183. await EventSystemManager.Instance.TriggerEvent(eventList);
  184. }
  185. });
  186. Btn_Daoyou.onClick.AddListener(() => { DaoYouGuaJiPanel.OpenPanel(); });
  187. Btn_Box.onClick.AddListener(() => { BoxPanel.OpenBoxPanel(); });
  188. Btn_PlayerName.onClick.AddListener(async () => { AlterNamePanel.OpenPanel(); });
  189. }
  190. public override CTask<bool> AsyncInit(object[] uiData)
  191. {
  192. return base.AsyncInit(uiData);
  193. }
  194. public async override CTask Show()
  195. {
  196. await base.Show();
  197. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  198. SmallPlacesConfig smallPlacesConfig =
  199. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  200. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  201. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  202. ChagneShenshiBtnActive();
  203. CreatShengShiEvent();
  204. ChangeMap(null);
  205. UpdateDaoYouCoun();
  206. bool isHIde = false;
  207. foreach (var skillInfo in PlayerManager.Instance.GongFaControl.allUseSkill)
  208. {
  209. if (skillInfo != null)
  210. {
  211. isHIde = true;
  212. break;
  213. }
  214. }
  215. if (!isHIde && !isShowSkillPanel)
  216. {
  217. isShowSkillPanel = true;
  218. SkillSelectPanel.OpenSkillSelectPanel();
  219. }
  220. CameraSelect.value = 0.2f;
  221. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  222. HeroPowerUpConfig[] heroPowerUpConfigs = ConfigComponent.Instance.GetAll<HeroPowerUpConfig>().ToList()
  223. .Where(hpc =>
  224. hpc.jingjie1 == PlayerManager.Instance.myHero.powerUpConfig.jingjie1 &&
  225. hpc.jingjie2 == PlayerManager.Instance.myHero.powerUpConfig.jingjie2).ToArray();
  226. int allexp = 0;
  227. foreach (var heroPowerUpConfig in heroPowerUpConfigs)
  228. {
  229. allexp += heroPowerUpConfig.levelUpExp;
  230. }
  231. int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  232. float heroAllexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  233. heroAllexp = PlayerManager.Instance.myHero.heroData.exp + heroAllexp;
  234. int bl = (int)((heroAllexp / allexp) * 100);
  235. Text_jingjie.text =
  236. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[0]) +
  237. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[1]) + " " +
  238. bl + "%";
  239. foreach (var energyWidget in widgets)
  240. {
  241. UIManager.Instance.DormancyGComponent(energyWidget);
  242. }
  243. widgets.Clear();
  244. foreach (var item in moRen)
  245. {
  246. EnergyWidget energyWidget =
  247. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  248. energyWidget.CustomInit(item);
  249. widgets.Add(energyWidget);
  250. }
  251. PlayEventCompletedEfx();
  252. // UpdateTaskInfo();
  253. }
  254. private void PlayEventCompletedEfx()
  255. {
  256. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  257. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  258. if (eventList != null)
  259. {
  260. var eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  261. if (eventConfig.EventTriggerType == 4)
  262. {
  263. if (eventList.isCompleted1)
  264. {
  265. fx_ui_renwu_wancheng_loop.gameObject.SetActive(true);
  266. fx_ui_renwu_wancheng_loop.Play();
  267. }
  268. else
  269. {
  270. fx_ui_renwu_wancheng_loop.gameObject.SetActive(false);
  271. }
  272. }
  273. else
  274. {
  275. fx_ui_renwu_wancheng_loop.gameObject.SetActive(false);
  276. }
  277. }
  278. else
  279. {
  280. fx_ui_renwu_wancheng_loop.gameObject.SetActive(false);
  281. }
  282. }
  283. private void AlterName(IEventData e)
  284. {
  285. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  286. }
  287. public async void ChangeMapEvent(IEventData e)
  288. {
  289. ChangeMap(e);
  290. // SmallPlacesConfig smallPlacesConfig =
  291. // ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  292. //
  293. // PlacesConfig placesConfig =
  294. // ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  295. // await TimerComponent.Instance.WaitAsync(500);
  296. // PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  297. }
  298. public void ChangeMap(IEventData e)
  299. {
  300. SmallPlacesConfig smallPlacesConfig =
  301. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  302. PlacesConfig placesConfig =
  303. ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  304. Text_bigMapName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  305. Text_ExplorationProgress.text = LanguageManager.Instance.Text(10302,
  306. LanguageManager.Instance.Text(placesConfig.placeName),
  307. LanguageManager.Instance.Text(smallPlacesConfig.placeName));
  308. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  309. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  310. }
  311. private void CameraSelect_onValueChanged(float value)
  312. {
  313. if (CombatController.currActiveCombat == null ||
  314. CombatController.currActiveCombat.CombatCameraControllder == null)
  315. {
  316. return;
  317. }
  318. CombatController.currActiveCombat.CombatCameraControllder.CameraSelect_onValueChanged(value);
  319. }
  320. private void ShengShiOnClick(IEventData e)
  321. {
  322. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  323. ChagneShenshiBtnActive();
  324. CreatShengShiEvent();
  325. }
  326. public async void CreatShengShiEvent()
  327. {
  328. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  329. {
  330. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  331. }
  332. _shengShiConditionWidgets.Clear();
  333. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  334. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  335. if (eventList != null)
  336. {
  337. var randomEventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  338. Text_EventName.text = LanguageManager.Instance.Text(randomEventConfig.EventName);
  339. Text_EventTag.text = EventHelper.GetEventType(randomEventConfig.EventTag);
  340. AccountFileInfo.EventLinkData eventLinkData =
  341. eventList.eventLinks.FirstOrDefault(el => el.eventLinkId == eventList.curStep);
  342. EventLinkConfig evenkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(eventLinkData.eventLinkId);
  343. if (eventLinkData != null && eventLinkData.eventConditions != null &&
  344. eventLinkData.eventConditions.Count > 0)
  345. {
  346. foreach (var eventConditionData in eventLinkData.eventConditions)
  347. {
  348. ShengShiConditionWidget shengShiConditionWidget =
  349. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null,
  350. EventConditionRoot);
  351. shengShiConditionWidget.CustomInit(eventConditionData);
  352. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  353. }
  354. }
  355. else if (evenkConfig.EventConditionMessage != 0)
  356. {
  357. ShengShiConditionWidget shengShiConditionWidget =
  358. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null, EventConditionRoot);
  359. shengShiConditionWidget.CustomInit(
  360. LanguageManager.Instance.Text(evenkConfig.EventConditionMessage));
  361. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  362. }
  363. }
  364. else
  365. {
  366. Text_EventName.text = "";
  367. Text_EventTag.text = "";
  368. }
  369. }
  370. // [CustomMethod(CustomMethodType.Update)]
  371. // public void Update()
  372. // {
  373. // if (Input.GetKeyDown(KeyCode.Y))
  374. // {
  375. // EventSystemManager.Instance.DetectRandomEvents();
  376. // }
  377. //
  378. //
  379. // int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  380. //
  381. // float allexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  382. //
  383. // Slider_Exp.value = PlayerManager.Instance.myHero.heroData.exp + allexp;
  384. // }
  385. public async static CTask<MainPanel> OpenPanel()
  386. {
  387. MainPanel mainPanel = await UIManager.Instance.LoadAndOpenPanel<MainPanel>(null);
  388. return mainPanel;
  389. }
  390. public async override CTask Close()
  391. {
  392. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  393. {
  394. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  395. }
  396. _shengShiConditionWidgets.Clear();
  397. foreach (var energyWidget in widgets)
  398. {
  399. UIManager.Instance.DormancyGComponent(energyWidget);
  400. }
  401. widgets.Clear();
  402. await base.Close();
  403. }
  404. }
  405. }