MainPanel.cs 18 KB

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