MainPanel.cs 16 KB

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