PlacesInfoWidget.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. public SmallPlacesConfig smallPlacesConfig;
  14. private Action<bool> callBack;
  15. public bool isUlock;
  16. private void Init()
  17. {
  18. }
  19. public override void AddEvent()
  20. {
  21. }
  22. public override void DelEvent()
  23. {
  24. }
  25. public override void AddButtonEvent()
  26. {
  27. Btn_Qianwang.onClick.AddListener(async () =>
  28. {
  29. if (smallPlacesConfig.ID == 0)
  30. return;
  31. SmallPlacesConfig lastSmallPlacesConfig =
  32. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  33. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  34. lastSmallPlacesData.completionEventCount <
  35. lastSmallPlacesConfig.CompletionEventCount))
  36. {
  37. TipMessagePanel.OpenTipMessagePanel(
  38. LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount));
  39. return;
  40. }
  41. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  42. {
  43. AccountFileInfo.EventList eventList =
  44. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  45. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  46. EventConfig eventConfig =
  47. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  48. if (eventList == null || !eventList.isCompleted)
  49. {
  50. TipMessagePanel.OpenTipMessagePanel(
  51. LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName)));
  52. return;
  53. }
  54. }
  55. if (smallPlacesConfig.ID == PlayerManager.Instance.CurrentsmallPlaces.id)
  56. {
  57. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  58. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  59. return;
  60. }
  61. PlacesInfoPanel placesInfoPanel = UIManager.Instance.GetComponent<PlacesInfoPanel>();
  62. if (placesInfoPanel != null && !placesInfoPanel.IsClose)
  63. {
  64. placesInfoPanel.isChange = true;
  65. }
  66. SmallPlacesConfig currentSmallPlacesConfig =
  67. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  68. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  69. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  70. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID, false);
  71. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  72. {
  73. PlacesChangeInfoPanel placesChangeInfoPanel =
  74. await PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.ID);
  75. await placesChangeInfoPanel.UIClosed();
  76. }
  77. else
  78. {
  79. BigPlacesChangeInfoPanel bigPlacesChangeInfoPanel =
  80. await BigPlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  81. await bigPlacesChangeInfoPanel.UIClosed();
  82. }
  83. UIManager.Instance.ShowLastHindAllShowPanel();
  84. callBack?.Invoke(true);
  85. callBack = null;
  86. });
  87. Btn_Jiesuo.onClick.AddListener(async () =>
  88. {
  89. if (smallPlacesConfig.ID == 0)
  90. return;
  91. //解锁下一个地图
  92. if (currentSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID))
  93. {
  94. PlacesInfoPanel placesInfoPanel = UIManager.Instance.GetComponent<PlacesInfoPanel>();
  95. if (placesInfoPanel != null && !placesInfoPanel.IsClose)
  96. {
  97. placesInfoPanel.isChange = true;
  98. }
  99. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  100. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  101. SmallPlacesConfig currentSmallPlacesConfig =
  102. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  103. //切换下一个地图
  104. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID, false);
  105. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  106. {
  107. PlacesChangeInfoPanel placesChangeInfoPanel =
  108. await PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.ID);
  109. await placesChangeInfoPanel.UIClosed();
  110. }
  111. else
  112. {
  113. BigPlacesChangeInfoPanel bigPlacesChangeInfoPanel =
  114. await BigPlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  115. await bigPlacesChangeInfoPanel.UIClosed();
  116. }
  117. UIManager.Instance.ShowLastHindAllShowPanel();
  118. callBack?.Invoke(true);
  119. callBack = null;
  120. }
  121. });
  122. }
  123. public void CustomInit(int smallPlacesId, Action<bool> callBack)
  124. {
  125. this.callBack = callBack;
  126. smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesId);
  127. Text_Name.text = LanguageManager.Instance.Text(smallPlacesConfig.placeName);
  128. Text_Desc.text = LanguageManager.Instance.Text(smallPlacesConfig.placeDesc);
  129. lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  130. currentSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  131. Btn_Qianwang.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id != smallPlacesConfig.ID);
  132. Icon_DIdian.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id == smallPlacesConfig.ID);
  133. Icon_Places.icon_name = smallPlacesConfig.placeIcon;
  134. isUlock = IsSmallPlacesDataUlock(smallPlacesConfig.ID);
  135. if (currentSmallPlacesData == null && isUlock)
  136. {
  137. Text_Tips.text = "";
  138. Icon_Marsk.gameObject.SetActive(true);
  139. Btn_Jiesuo.gameObject.SetActive(true);
  140. }
  141. else if (!isUlock)
  142. {
  143. Icon_Marsk.gameObject.SetActive(true);
  144. Text_Tips.text = GetSmallPlacesDataTips(smallPlacesConfig.ID);
  145. Btn_Jiesuo.gameObject.SetActive(false);
  146. }
  147. else
  148. {
  149. Icon_Marsk.gameObject.SetActive(false);
  150. Btn_Jiesuo.gameObject.SetActive(false);
  151. }
  152. }
  153. private string GetSmallPlacesDataTips(int id)
  154. {
  155. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(id);
  156. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  157. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  158. if (currentSmallPlacesData == null)
  159. {
  160. return LanguageManager.Instance.Text(10377);
  161. }
  162. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  163. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  164. SmallPlacesConfig lastSmallPlacesConfig =
  165. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  166. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  167. lastSmallPlacesData.completionEventCount <
  168. lastSmallPlacesConfig.CompletionEventCount))
  169. {
  170. return LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount);
  171. }
  172. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  173. {
  174. AccountFileInfo.EventList eventList =
  175. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  176. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  177. if (eventList == null || !eventList.isCompleted)
  178. {
  179. EventConfig eventConfig =
  180. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  181. return LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName));
  182. }
  183. }
  184. return "";
  185. }
  186. private bool IsSmallPlacesDataUlock(int id)
  187. {
  188. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  189. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  190. SmallPlacesConfig lastSmallPlacesConfig =
  191. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  192. if (id > 1 && (lastSmallPlacesData == null ||
  193. lastSmallPlacesData.completionEventCount <
  194. lastSmallPlacesConfig.CompletionEventCount))
  195. {
  196. return false;
  197. }
  198. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  199. {
  200. AccountFileInfo.EventList eventList =
  201. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  202. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  203. if (eventList == null || !eventList.isCompleted)
  204. {
  205. return false;
  206. }
  207. }
  208. return true;
  209. }
  210. }
  211. }