MainPanel.cs 22 KB

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