MainPanel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. Debug.Log("zhuce click Btn_QianKunDai");
  163. Btn_QianKunDai.onClick.AddListener(() =>
  164. {
  165. Debug.Log("click Btn_QianKunDai");
  166. QiankundaiPanel.OpenPanel();
  167. });
  168. Btn_StartEvent.onClick.AddListener(async () =>
  169. {
  170. if (PlayerGuideManager.Instance.curPhase == 3)
  171. {
  172. return;
  173. }
  174. if (PlayerGuideManager.Instance.GuideIsCanDo(1, 3))
  175. {
  176. PlayerGuideManager.Instance.NextGuide();
  177. }
  178. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  179. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  180. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  181. if (eventConfig.EventTriggerType == 4)
  182. {
  183. if (eventList.isCompleted1)
  184. {
  185. EventSystemManager.Instance.CompleteEvent(eventList);
  186. return;
  187. }
  188. }
  189. if (eventList != null)
  190. {
  191. EventSystemManager.Instance.CancelEvent();
  192. if (EventSystemManager.Instance.isTriggerEvent)
  193. return;
  194. if (eventList.isCompleted)
  195. return;
  196. await EventSystemManager.Instance.TriggerEvent(eventList);
  197. }
  198. });
  199. Btn_Daoyou.onClick.AddListener(() => { DaoYouGuaJiPanel.OpenPanel(); });
  200. Btn_Box.onClick.AddListener(() => { BoxPanel.OpenBoxPanel(); });
  201. Btn_PlayerName.onClick.AddListener(async () => { AlterNamePanel.OpenPanel(); });
  202. }
  203. public override CTask<bool> AsyncInit(object[] uiData)
  204. {
  205. return base.AsyncInit(uiData);
  206. }
  207. public async override CTask Show()
  208. {
  209. await base.Show();
  210. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  211. SmallPlacesConfig smallPlacesConfig =
  212. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  213. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  214. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  215. ChagneShenshiBtnActive();
  216. CreatShengShiEvent();
  217. ChangeMap(null);
  218. UpdateDaoYouCoun();
  219. bool isHIde = false;
  220. foreach (var skillInfo in PlayerManager.Instance.GongFaControl.allUseSkill)
  221. {
  222. if (skillInfo != null)
  223. {
  224. isHIde = true;
  225. break;
  226. }
  227. }
  228. if (!isHIde && !isShowSkillPanel)
  229. {
  230. isShowSkillPanel = true;
  231. SkillSelectPanel.OpenSkillSelectPanel();
  232. }
  233. CameraSelect.value = 0.2f;
  234. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  235. HeroPowerUpConfig[] heroPowerUpConfigs = ConfigComponent.Instance.GetAll<HeroPowerUpConfig>().ToList()
  236. .Where(hpc =>
  237. hpc.jingjie1 == PlayerManager.Instance.myHero.powerUpConfig.jingjie1 &&
  238. hpc.jingjie2 == PlayerManager.Instance.myHero.powerUpConfig.jingjie2).ToArray();
  239. int allexp = 0;
  240. foreach (var heroPowerUpConfig in heroPowerUpConfigs)
  241. {
  242. allexp += heroPowerUpConfig.levelUpExp;
  243. }
  244. int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  245. float heroAllexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  246. heroAllexp = PlayerManager.Instance.myHero.heroData.exp + heroAllexp;
  247. int bl = (int)((heroAllexp / allexp) * 100);
  248. Text_jingjie.text =
  249. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[0]) +
  250. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[1]) + " " +
  251. bl + "%";
  252. foreach (var energyWidget in widgets)
  253. {
  254. UIManager.Instance.DormancyGComponent(energyWidget);
  255. }
  256. widgets.Clear();
  257. foreach (var item in moRen)
  258. {
  259. EnergyWidget energyWidget =
  260. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  261. energyWidget.CustomInit(item);
  262. widgets.Add(energyWidget);
  263. }
  264. PlayEventCompletedEfx();
  265. // UpdateTaskInfo();
  266. }
  267. private void PlayEventCompletedEfx()
  268. {
  269. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  270. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  271. if (eventList != null)
  272. {
  273. var eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  274. if (eventConfig.EventTriggerType == 4)
  275. {
  276. if (eventList.isCompleted1)
  277. {
  278. fx_ui_renwu_wancheng_loop.gameObject.SetActive(true);
  279. fx_ui_renwu_wancheng_loop.Play();
  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. else
  292. {
  293. fx_ui_renwu_wancheng_loop.gameObject.SetActive(false);
  294. }
  295. }
  296. private void AlterName(IEventData e)
  297. {
  298. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  299. }
  300. public async void ChangeMapEvent(IEventData e)
  301. {
  302. ChangeMap(e);
  303. // SmallPlacesConfig smallPlacesConfig =
  304. // ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  305. //
  306. // PlacesConfig placesConfig =
  307. // ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  308. // await TimerComponent.Instance.WaitAsync(500);
  309. // PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  310. }
  311. public void ChangeMap(IEventData e)
  312. {
  313. SmallPlacesConfig smallPlacesConfig =
  314. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  315. PlacesConfig placesConfig =
  316. ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  317. Text_bigMapName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  318. Text_ExplorationProgress.text = LanguageManager.Instance.Text(10302,
  319. LanguageManager.Instance.Text(placesConfig.placeName),
  320. LanguageManager.Instance.Text(smallPlacesConfig.placeName));
  321. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  322. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  323. }
  324. private void CameraSelect_onValueChanged(float value)
  325. {
  326. if (CombatController.currActiveCombat == null ||
  327. CombatController.currActiveCombat.CombatCameraControllder == null)
  328. {
  329. return;
  330. }
  331. CombatController.currActiveCombat.CombatCameraControllder.CameraSelect_onValueChanged(value);
  332. }
  333. private void ShengShiOnClick(IEventData e)
  334. {
  335. Debug.Log("click sheng shi");
  336. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  337. ChagneShenshiBtnActive();
  338. CreatShengShiEvent();
  339. }
  340. public async void CreatShengShiEvent()
  341. {
  342. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  343. {
  344. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  345. }
  346. _shengShiConditionWidgets.Clear();
  347. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  348. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  349. if (eventList != null)
  350. {
  351. var randomEventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  352. Text_EventName.text = LanguageManager.Instance.Text(randomEventConfig.EventName);
  353. Text_EventTag.text = EventHelper.GetEventType(randomEventConfig.EventTag);
  354. AccountFileInfo.EventLinkData eventLinkData =
  355. eventList.eventLinks.FirstOrDefault(el => el.eventLinkId == eventList.curStep);
  356. EventLinkConfig evenkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(eventLinkData.eventLinkId);
  357. if (eventLinkData != null && eventLinkData.eventConditions != null &&
  358. eventLinkData.eventConditions.Count > 0)
  359. {
  360. foreach (var eventConditionData in eventLinkData.eventConditions)
  361. {
  362. ShengShiConditionWidget shengShiConditionWidget =
  363. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null,
  364. EventConditionRoot);
  365. shengShiConditionWidget.CustomInit(eventConditionData);
  366. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  367. }
  368. }
  369. else if (evenkConfig.EventConditionMessage != 0)
  370. {
  371. ShengShiConditionWidget shengShiConditionWidget =
  372. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null, EventConditionRoot);
  373. shengShiConditionWidget.CustomInit(
  374. LanguageManager.Instance.Text(evenkConfig.EventConditionMessage));
  375. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  376. }
  377. }
  378. else
  379. {
  380. Text_EventName.text = "";
  381. Text_EventTag.text = "";
  382. }
  383. }
  384. // [CustomMethod(CustomMethodType.Update)]
  385. // public void Update()
  386. // {
  387. // if (Input.GetKeyDown(KeyCode.Y))
  388. // {
  389. // EventSystemManager.Instance.DetectRandomEvents();
  390. // }
  391. //
  392. //
  393. // int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  394. //
  395. // float allexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  396. //
  397. // Slider_Exp.value = PlayerManager.Instance.myHero.heroData.exp + allexp;
  398. // }
  399. public async static CTask<MainPanel> OpenPanel()
  400. {
  401. MainPanel mainPanel = await UIManager.Instance.LoadAndOpenPanel<MainPanel>(null);
  402. return mainPanel;
  403. }
  404. public async override CTask Close()
  405. {
  406. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  407. {
  408. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  409. }
  410. _shengShiConditionWidgets.Clear();
  411. foreach (var energyWidget in widgets)
  412. {
  413. UIManager.Instance.DormancyGComponent(energyWidget);
  414. }
  415. widgets.Clear();
  416. await base.Close();
  417. }
  418. }
  419. }