MainPanel.cs 15 KB

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