MainPanel.cs 19 KB

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