MainPanel.cs 14 KB

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