PlacesInfoWidget.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Linq;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.UTool;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "PlacesInfoWidget")]
  9. public partial class PlacesInfoWidget : UIComponent
  10. {
  11. private AccountFileInfo.SmallPlacesData currentSmallPlacesData;
  12. private AccountFileInfo.SmallPlacesData lastSmallPlacesData;
  13. private SmallPlacesConfig smallPlacesConfig;
  14. private Action<bool> callBack;
  15. private void Init()
  16. {
  17. }
  18. public override void AddEvent()
  19. {
  20. }
  21. public override void DelEvent()
  22. {
  23. }
  24. public override void AddButtonEvent()
  25. {
  26. Btn_Qianwang.onClick.AddListener(async () =>
  27. {
  28. if (smallPlacesConfig.ID == 0)
  29. return;
  30. SmallPlacesConfig lastSmallPlacesConfig =
  31. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  32. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  33. lastSmallPlacesData.completionEventCount <
  34. lastSmallPlacesConfig.CompletionEventCount))
  35. {
  36. TipMessagePanel.OpenTipMessagePanel(
  37. LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount));
  38. return;
  39. }
  40. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  41. {
  42. AccountFileInfo.EventList eventList =
  43. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  44. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  45. EventConfig eventConfig =
  46. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  47. if (eventList == null || !eventList.isCompleted)
  48. {
  49. TipMessagePanel.OpenTipMessagePanel(
  50. LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName)));
  51. return;
  52. }
  53. }
  54. if (smallPlacesConfig.ID == PlayerManager.Instance.CurrentsmallPlaces.id)
  55. {
  56. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  57. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  58. return;
  59. }
  60. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  61. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  62. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  63. PlacesChangeInfoPanel placesChangeInfoPanel =
  64. await PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.ID);
  65. await placesChangeInfoPanel.UIClosed();
  66. callBack?.Invoke(true);
  67. callBack = null;
  68. });
  69. Btn_Jiesuo.onClick.AddListener(async () =>
  70. {
  71. if (smallPlacesConfig.ID == 0)
  72. return;
  73. //解锁下一个地图
  74. if (currentSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID))
  75. {
  76. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  77. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  78. //切换下一个地图
  79. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  80. // PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  81. PlacesChangeInfoPanel placesChangeInfoPanel =
  82. await PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.ID);
  83. await placesChangeInfoPanel.UIClosed();
  84. callBack?.Invoke(true);
  85. callBack = null;
  86. }
  87. });
  88. }
  89. public void CustomInit(int smallPlacesId, Action<bool> callBack)
  90. {
  91. this.callBack = callBack;
  92. smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesId);
  93. Text_Name.text = LanguageManager.Instance.Text(smallPlacesConfig.placeName);
  94. Text_Desc.text = LanguageManager.Instance.Text(smallPlacesConfig.placeDesc);
  95. lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  96. currentSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  97. Btn_Qianwang.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id != smallPlacesConfig.ID);
  98. bool isUlock = IsSmallPlacesDataUlock(smallPlacesConfig.ID);
  99. if (currentSmallPlacesData == null && isUlock)
  100. {
  101. Text_Tips.text = "";
  102. Icon_Marsk.gameObject.SetActive(true);
  103. Btn_Jiesuo.gameObject.SetActive(true);
  104. }
  105. else if (!isUlock)
  106. {
  107. Icon_Marsk.gameObject.SetActive(true);
  108. Text_Tips.text = GetSmallPlacesDataTips(smallPlacesConfig.ID);
  109. Btn_Jiesuo.gameObject.SetActive(false);
  110. }
  111. else
  112. {
  113. Icon_Marsk.gameObject.SetActive(false);
  114. Btn_Jiesuo.gameObject.SetActive(false);
  115. }
  116. }
  117. private string GetSmallPlacesDataTips(int id)
  118. {
  119. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(id);
  120. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  121. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  122. SmallPlacesConfig lastSmallPlacesConfig =
  123. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  124. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  125. lastSmallPlacesData.completionEventCount <
  126. lastSmallPlacesConfig.CompletionEventCount))
  127. {
  128. return LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount);
  129. }
  130. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  131. {
  132. AccountFileInfo.EventList eventList =
  133. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  134. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  135. if (eventList == null || !eventList.isCompleted)
  136. {
  137. EventConfig eventConfig =
  138. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  139. return LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName));
  140. }
  141. }
  142. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  143. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  144. if (currentSmallPlacesData == null)
  145. {
  146. return LanguageManager.Instance.Text(10377);
  147. }
  148. return "";
  149. }
  150. private bool IsSmallPlacesDataUlock(int id)
  151. {
  152. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  153. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  154. SmallPlacesConfig lastSmallPlacesConfig =
  155. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  156. if (id > 1 && (lastSmallPlacesData == null ||
  157. lastSmallPlacesData.completionEventCount <
  158. lastSmallPlacesConfig.CompletionEventCount))
  159. {
  160. return false;
  161. }
  162. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  163. {
  164. AccountFileInfo.EventList eventList =
  165. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  166. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  167. if (eventList == null || !eventList.isCompleted)
  168. {
  169. return false;
  170. }
  171. }
  172. return true;
  173. }
  174. }
  175. }