MainPanel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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.curPhase == 3)
  142. {
  143. return;
  144. }
  145. if (PlayerGuideManager.Instance.GuideIsCanDo(1, 3))
  146. {
  147. PlayerGuideManager.Instance.NextGuide();
  148. }
  149. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  150. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  151. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  152. if (eventConfig.EventTriggerType == 4)
  153. {
  154. if (eventList.isCompleted1)
  155. {
  156. EventSystemManager.Instance.CompleteEvent(eventList);
  157. return;
  158. }
  159. }
  160. if (eventList != null)
  161. {
  162. EventSystemManager.Instance.CancelEvent();
  163. if (EventSystemManager.Instance.isTriggerEvent)
  164. return;
  165. if (eventList.isCompleted)
  166. return;
  167. EventSystemManager.Instance.TriggerEvent(eventList);
  168. }
  169. });
  170. Btn_Daoyou.onClick.AddListener(() => { DaoYouGuaJiPanel.OpenPanel(); });
  171. Btn_Box.onClick.AddListener(() => { BoxPanel.OpenBoxPanel(); });
  172. Btn_PlayerName.onClick.AddListener(async () => { AlterNamePanel.OpenPanel(); });
  173. }
  174. public override CTask<bool> AsyncInit(object[] uiData)
  175. {
  176. return base.AsyncInit(uiData);
  177. }
  178. public async override CTask Show()
  179. {
  180. await base.Show();
  181. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  182. SmallPlacesConfig smallPlacesConfig =
  183. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  184. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  185. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  186. ChagneShenshiBtnActive();
  187. CreatShengShiEvent();
  188. ChangeMap(null);
  189. UpdateDaoYouCoun();
  190. bool isHIde = false;
  191. foreach (var skillInfo in PlayerManager.Instance.GongFaControl.allUseSkill)
  192. {
  193. if (skillInfo != null)
  194. {
  195. isHIde = true;
  196. break;
  197. }
  198. }
  199. if (!isHIde && !isShowSkillPanel)
  200. {
  201. isShowSkillPanel = true;
  202. SkillSelectPanel.OpenSkillSelectPanel();
  203. }
  204. CameraSelect.value = 0.2f;
  205. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  206. HeroPowerUpConfig[] heroPowerUpConfigs = ConfigComponent.Instance.GetAll<HeroPowerUpConfig>().ToList()
  207. .Where(hpc =>
  208. hpc.jingjie1 == PlayerManager.Instance.myHero.powerUpConfig.jingjie1 &&
  209. hpc.jingjie2 == PlayerManager.Instance.myHero.powerUpConfig.jingjie2).ToArray();
  210. int allexp = 0;
  211. foreach (var heroPowerUpConfig in heroPowerUpConfigs)
  212. {
  213. allexp += heroPowerUpConfig.levelUpExp;
  214. }
  215. int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  216. float heroAllexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  217. heroAllexp = PlayerManager.Instance.myHero.heroData.exp + heroAllexp;
  218. int bl = (int)((heroAllexp / allexp) * 100);
  219. Text_jingjie.text =
  220. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[0]) +
  221. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[1]) + " " +
  222. bl + "%";
  223. foreach (var energyWidget in widgets)
  224. {
  225. UIManager.Instance.DormancyGComponent(energyWidget);
  226. }
  227. widgets.Clear();
  228. foreach (var item in moRen)
  229. {
  230. EnergyWidget energyWidget =
  231. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  232. energyWidget.CustomInit(item);
  233. widgets.Add(energyWidget);
  234. }
  235. // UpdateTaskInfo();
  236. }
  237. private void AlterName(IEventData e)
  238. {
  239. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  240. }
  241. public void ChangeMap(IEventData e)
  242. {
  243. SmallPlacesConfig smallPlacesConfig =
  244. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  245. PlacesConfig placesConfig =
  246. ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  247. Text_bigMapName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  248. Text_ExplorationProgress.text = LanguageManager.Instance.Text(10302,
  249. LanguageManager.Instance.Text(placesConfig.placeName),
  250. LanguageManager.Instance.Text(smallPlacesConfig.placeName));
  251. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  252. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  253. }
  254. private void CameraSelect_onValueChanged(float value)
  255. {
  256. if (CombatController.currActiveCombat == null ||
  257. CombatController.currActiveCombat.CombatCameraControllder == null)
  258. {
  259. return;
  260. }
  261. CombatController.currActiveCombat.CombatCameraControllder.CameraSelect_onValueChanged(value);
  262. }
  263. private void ShengShiOnClick(IEventData e)
  264. {
  265. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  266. ChagneShenshiBtnActive();
  267. CreatShengShiEvent();
  268. }
  269. public async void CreatShengShiEvent()
  270. {
  271. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  272. {
  273. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  274. }
  275. _shengShiConditionWidgets.Clear();
  276. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  277. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  278. if (eventList != null)
  279. {
  280. var randomEventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  281. Text_EventName.text = LanguageManager.Instance.Text(randomEventConfig.EventName);
  282. Text_EventTag.text = EventHelper.GetEventType(randomEventConfig.EventTag);
  283. AccountFileInfo.EventLinkData eventLinkData =
  284. eventList.eventLinks.FirstOrDefault(el => el.eventLinkId == eventList.curStep);
  285. EventLinkConfig evenkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(eventLinkData.eventLinkId);
  286. if (eventLinkData != null && eventLinkData.eventConditions != null &&
  287. eventLinkData.eventConditions.Count > 0)
  288. {
  289. foreach (var eventConditionData in eventLinkData.eventConditions)
  290. {
  291. ShengShiConditionWidget shengShiConditionWidget =
  292. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null,
  293. EventConditionRoot);
  294. shengShiConditionWidget.CustomInit(eventConditionData);
  295. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  296. }
  297. }
  298. else if (evenkConfig.EventConditionMessage != 0)
  299. {
  300. ShengShiConditionWidget shengShiConditionWidget =
  301. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null, EventConditionRoot);
  302. shengShiConditionWidget.CustomInit(
  303. LanguageManager.Instance.Text(evenkConfig.EventConditionMessage));
  304. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  305. }
  306. }
  307. else
  308. {
  309. Text_EventName.text = "";
  310. Text_EventTag.text = "";
  311. }
  312. }
  313. // [CustomMethod(CustomMethodType.Update)]
  314. // public void Update()
  315. // {
  316. // if (Input.GetKeyDown(KeyCode.Y))
  317. // {
  318. // EventSystemManager.Instance.DetectRandomEvents();
  319. // }
  320. //
  321. //
  322. // int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  323. //
  324. // float allexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  325. //
  326. // Slider_Exp.value = PlayerManager.Instance.myHero.heroData.exp + allexp;
  327. // }
  328. public async static CTask<MainPanel> OpenPanel()
  329. {
  330. MainPanel mainPanel = await UIManager.Instance.LoadAndOpenPanel<MainPanel>(null);
  331. return mainPanel;
  332. }
  333. public async override CTask Close()
  334. {
  335. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  336. {
  337. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  338. }
  339. _shengShiConditionWidgets.Clear();
  340. foreach (var energyWidget in widgets)
  341. {
  342. UIManager.Instance.DormancyGComponent(energyWidget);
  343. }
  344. widgets.Clear();
  345. await base.Close();
  346. }
  347. }
  348. }