PlacesInfoWidget.cs 10 KB

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