MainPanel.cs 19 KB

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