PlacesInfoWidget.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. Icon_DIdian.gameObject.SetActive(PlayerManager.Instance.CurrentsmallPlaces.id != smallPlacesConfig.ID);
  99. Icon_Places.icon_name = smallPlacesConfig.placeIcon;
  100. bool isUlock = IsSmallPlacesDataUlock(smallPlacesConfig.ID);
  101. if (currentSmallPlacesData == null && isUlock)
  102. {
  103. Text_Tips.text = "";
  104. Icon_Marsk.gameObject.SetActive(true);
  105. Btn_Jiesuo.gameObject.SetActive(true);
  106. }
  107. else if (!isUlock)
  108. {
  109. Icon_Marsk.gameObject.SetActive(true);
  110. Text_Tips.text = GetSmallPlacesDataTips(smallPlacesConfig.ID);
  111. Btn_Jiesuo.gameObject.SetActive(false);
  112. }
  113. else
  114. {
  115. Icon_Marsk.gameObject.SetActive(false);
  116. Btn_Jiesuo.gameObject.SetActive(false);
  117. }
  118. }
  119. private string GetSmallPlacesDataTips(int id)
  120. {
  121. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(id);
  122. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  123. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  124. SmallPlacesConfig lastSmallPlacesConfig =
  125. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  126. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  127. lastSmallPlacesData.completionEventCount <
  128. lastSmallPlacesConfig.CompletionEventCount))
  129. {
  130. return LanguageManager.Instance.Text(10375, lastSmallPlacesConfig.CompletionEventCount);
  131. }
  132. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  133. {
  134. AccountFileInfo.EventList eventList =
  135. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  136. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  137. if (eventList == null || !eventList.isCompleted)
  138. {
  139. EventConfig eventConfig =
  140. ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  141. return LanguageManager.Instance.Text(10376, LanguageManager.Instance.Text(eventConfig.EventName));
  142. }
  143. }
  144. AccountFileInfo.SmallPlacesData currentSmallPlacesData =
  145. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  146. if (currentSmallPlacesData == null)
  147. {
  148. return LanguageManager.Instance.Text(10377);
  149. }
  150. return "";
  151. }
  152. private bool IsSmallPlacesDataUlock(int id)
  153. {
  154. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  155. PlayerManager.Instance.GetSmallPlacesData(id - 1);
  156. SmallPlacesConfig lastSmallPlacesConfig =
  157. ConfigComponent.Instance.Get<SmallPlacesConfig>(id - 1);
  158. if (id > 1 && (lastSmallPlacesData == null ||
  159. lastSmallPlacesData.completionEventCount <
  160. lastSmallPlacesConfig.CompletionEventCount))
  161. {
  162. return false;
  163. }
  164. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  165. {
  166. AccountFileInfo.EventList eventList =
  167. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  168. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  169. if (eventList == null || !eventList.isCompleted)
  170. {
  171. return false;
  172. }
  173. }
  174. return true;
  175. }
  176. }
  177. }