PlacesInfoWidget.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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);
  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. callBack?.Invoke(true);
  84. callBack = null;
  85. });
  86. Btn_Jiesuo.onClick.AddListener(async () =>
  87. {
  88. if (smallPlacesConfig.ID == 0)
  89. return;
  90. //解锁下一个地图
  91. if (currentSmallPlacesData == null && IsSmallPlacesDataUlock(smallPlacesConfig.ID))
  92. {
  93. PlacesInfoPanel placesInfoPanel = UIManager.Instance.GetComponent<PlacesInfoPanel>();
  94. if (placesInfoPanel != null && !placesInfoPanel.IsClose)
  95. {
  96. placesInfoPanel.isChange = true;
  97. }
  98. await UIManager.Instance.HideUIUIPanel<LevelChoosePanel>();
  99. await UIManager.Instance.HideUIUIPanel<PlacesInfoPanel>();
  100. SmallPlacesConfig currentSmallPlacesConfig =
  101. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  102. //切换下一个地图
  103. await PlayerManager.Instance.ChangeMap(smallPlacesConfig.ID);
  104. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  105. {
  106. PlacesChangeInfoPanel placesChangeInfoPanel =
  107. await PlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.ID);
  108. await placesChangeInfoPanel.UIClosed();
  109. }
  110. else
  111. {
  112. BigPlacesChangeInfoPanel bigPlacesChangeInfoPanel =
  113. await BigPlacesChangeInfoPanel.OpenPanel(smallPlacesConfig.PlacesId);
  114. await bigPlacesChangeInfoPanel.UIClosed();
  115. }
  116. callBack?.Invoke(true);
  117. callBack = null;
  118. }
  119. });
  120. }
  121. public void CustomInit(int smallPlacesId, Action<bool> callBack)
  122. {
  123. this.callBack = callBack;
  124. smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesId);
  125. Text_Name.text = LanguageManager.Instance.Text(smallPlacesConfig.placeName);
  126. Text_Desc.text = LanguageManager.Instance.Text(smallPlacesConfig.placeDesc);
  127. lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  128. currentSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  129. Btn_Qianwang.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id != smallPlacesConfig.ID);
  130. Icon_DIdian.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id == smallPlacesConfig.ID);
  131. Icon_Places.icon_name = smallPlacesConfig.placeIcon;
  132. isUlock = IsSmallPlacesDataUlock(smallPlacesConfig.ID);
  133. if (currentSmallPlacesData == null && isUlock)
  134. {
  135. Text_Tips.text = "";
  136. Icon_Marsk.gameObject.SetActive(true);
  137. Btn_Jiesuo.gameObject.SetActive(true);
  138. }
  139. else if (!isUlock)
  140. {
  141. Icon_Marsk.gameObject.SetActive(true);
  142. Text_Tips.text = GetSmallPlacesDataTips(smallPlacesConfig.ID);
  143. Btn_Jiesuo.gameObject.SetActive(false);
  144. }
  145. else
  146. {
  147. Icon_Marsk.gameObject.SetActive(false);
  148. Btn_Jiesuo.gameObject.SetActive(false);
  149. }
  150. }
  151. private string GetSmallPlacesDataTips(int id)
  152. {
  153. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(id);
  154. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  155. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID-1);
  156. if (currentSmallPlacesData == null)
  157. {
  158. return LanguageManager.Instance.Text(10377);
  159. }
  160. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  161. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  162. SmallPlacesConfig lastSmallPlacesConfig =
  163. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  164. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  165. lastSmallPlacesData.completionEventCount <
  166. lastSmallPlacesConfig.CompletionEventCount))
  167. {
  168. return LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount);
  169. }
  170. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  171. {
  172. AccountFileInfo.EventList eventList =
  173. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  174. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  175. if (eventList == null || !eventList.isCompleted)
  176. {
  177. EventConfig eventConfig =
  178. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  179. return LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName));
  180. }
  181. }
  182. return "";
  183. }
  184. private bool IsSmallPlacesDataUlock(int id)
  185. {
  186. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  187. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  188. SmallPlacesConfig lastSmallPlacesConfig =
  189. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  190. if (id > 1 && (lastSmallPlacesData == null ||
  191. lastSmallPlacesData.completionEventCount <
  192. lastSmallPlacesConfig.CompletionEventCount))
  193. {
  194. return false;
  195. }
  196. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  197. {
  198. AccountFileInfo.EventList eventList =
  199. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  200. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  201. if (eventList == null || !eventList.isCompleted)
  202. {
  203. return false;
  204. }
  205. }
  206. return true;
  207. }
  208. }
  209. }