MainPanel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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.jingjie1 == PlayerManager.Instance.myHero.powerUpConfig.jingjie2).ToArray();
  206. int allexp = 0;
  207. foreach (var heroPowerUpConfig in heroPowerUpConfigs)
  208. {
  209. allexp += heroPowerUpConfig.levelUpExp;
  210. }
  211. int bl = (PlayerManager.Instance.myHero.exp.Value / allexp) * 100;
  212. Text_jingjie.text =
  213. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[0]) +
  214. LanguageManager.Instance.Text(PlayerManager.Instance.myHero.powerUpConfig.jingjieLanIDs[1]) + " " +
  215. bl + "%";
  216. foreach (var energyWidget in widgets)
  217. {
  218. UIManager.Instance.DormancyGComponent(energyWidget);
  219. }
  220. widgets.Clear();
  221. foreach (var item in moRen)
  222. {
  223. EnergyWidget energyWidget =
  224. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  225. energyWidget.CustomInit(item);
  226. widgets.Add(energyWidget);
  227. }
  228. // UpdateTaskInfo();
  229. }
  230. private void AlterName(IEventData e)
  231. {
  232. Text_PlayerName.text = PlayerManager.Instance.PlayerName;
  233. }
  234. public void ChangeMap(IEventData e)
  235. {
  236. SmallPlacesConfig smallPlacesConfig =
  237. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  238. PlacesConfig placesConfig =
  239. ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  240. Text_bigMapName.text = LanguageManager.Instance.Text(placesConfig.placeName);
  241. Text_ExplorationProgress.text = LanguageManager.Instance.Text(10302,
  242. LanguageManager.Instance.Text(placesConfig.placeName),
  243. LanguageManager.Instance.Text(smallPlacesConfig.placeName));
  244. Slider_SmallJD.maxValue = smallPlacesConfig.CompletionEventCount;
  245. Slider_SmallJD.value = PlayerManager.Instance.CurrentsmallPlaces.completionEventCount;
  246. }
  247. private void CameraSelect_onValueChanged(float value)
  248. {
  249. if (CombatController.currActiveCombat == null ||
  250. CombatController.currActiveCombat.CombatCameraControllder == null)
  251. {
  252. return;
  253. }
  254. CombatController.currActiveCombat.CombatCameraControllder.CameraSelect_onValueChanged(value);
  255. }
  256. private void ShengShiOnClick(IEventData e)
  257. {
  258. Text_EventNum.text = EventSystemManager.Instance.GetShenShiCount().ToString();
  259. ChagneShenshiBtnActive();
  260. CreatShengShiEvent();
  261. }
  262. public async void CreatShengShiEvent()
  263. {
  264. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  265. {
  266. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  267. }
  268. _shengShiConditionWidgets.Clear();
  269. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  270. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  271. if (eventList != null)
  272. {
  273. var randomEventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  274. Text_EventName.text = LanguageManager.Instance.Text(randomEventConfig.EventName);
  275. Text_EventTag.text = EventHelper.GetEventType(randomEventConfig.EventTag);
  276. AccountFileInfo.EventLinkData eventLinkData =
  277. eventList.eventLinks.FirstOrDefault(el => el.eventLinkId == eventList.curStep);
  278. EventLinkConfig evenkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(eventLinkData.eventLinkId);
  279. if (eventLinkData != null && eventLinkData.eventConditions != null &&
  280. eventLinkData.eventConditions.Count > 0)
  281. {
  282. foreach (var eventConditionData in eventLinkData.eventConditions)
  283. {
  284. ShengShiConditionWidget shengShiConditionWidget =
  285. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null,
  286. EventConditionRoot);
  287. shengShiConditionWidget.CustomInit(eventConditionData);
  288. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  289. }
  290. }
  291. else if (evenkConfig.EventConditionMessage != 0)
  292. {
  293. ShengShiConditionWidget shengShiConditionWidget =
  294. await UIManager.Instance.CreateGComponent<ShengShiConditionWidget>(null, EventConditionRoot);
  295. shengShiConditionWidget.CustomInit(
  296. LanguageManager.Instance.Text(evenkConfig.EventConditionMessage));
  297. _shengShiConditionWidgets.Add(shengShiConditionWidget);
  298. }
  299. }
  300. else
  301. {
  302. Text_EventName.text = "";
  303. Text_EventTag.text = "";
  304. }
  305. }
  306. // [CustomMethod(CustomMethodType.Update)]
  307. // public void Update()
  308. // {
  309. // if (Input.GetKeyDown(KeyCode.Y))
  310. // {
  311. // EventSystemManager.Instance.DetectRandomEvents();
  312. // }
  313. //
  314. //
  315. // int currentMiao = (int)((TimeHelper.ClientNow() - PlayerManager.Instance.myHero.heroData.upTime) / 1000);
  316. //
  317. // float allexp = currentMiao * PlayerManager.Instance.myHero.powerUpConfig.AutoXiuwei;
  318. //
  319. // Slider_Exp.value = PlayerManager.Instance.myHero.heroData.exp + allexp;
  320. // }
  321. public async static CTask<MainPanel> OpenPanel()
  322. {
  323. MainPanel mainPanel = await UIManager.Instance.LoadAndOpenPanel<MainPanel>(null);
  324. return mainPanel;
  325. }
  326. public async override CTask Close()
  327. {
  328. foreach (var shengShiConditionWidget in _shengShiConditionWidgets)
  329. {
  330. UIManager.Instance.DormancyGComponent(shengShiConditionWidget);
  331. }
  332. _shengShiConditionWidgets.Clear();
  333. foreach (var energyWidget in widgets)
  334. {
  335. UIManager.Instance.DormancyGComponent(energyWidget);
  336. }
  337. widgets.Clear();
  338. await base.Close();
  339. }
  340. }
  341. }