PlacesInfoWidget.cs 9.6 KB

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