XianTuLogInfoPanel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using UnityEngine;
  8. using Utility;
  9. namespace Fort23.Mono
  10. {
  11. public class XianTuLogInfoData
  12. {
  13. /// <summary>
  14. /// 1.大标题 2.标题 3.描述
  15. /// </summary>
  16. public int type;
  17. public string message;
  18. public int id;
  19. }
  20. [UIBinding(prefab = "XianTuLogInfoPanel")]
  21. public partial class XianTuLogInfoPanel : UIPanel, IScrollListContent
  22. {
  23. private EventLogTitleWidget eventLogTitleWidget;
  24. private XianTuLogConfig _xianTuLogConfig;
  25. List<XianTuLogInfoData> showXianTuLogInfoData = new List<XianTuLogInfoData>();
  26. List<UIComponent> components = new List<UIComponent>();
  27. // List<EventLogTitleWidget> titleWidgets = new List<EventLogTitleWidget>();
  28. private int type;
  29. private void Init()
  30. {
  31. isAddStack = true;
  32. }
  33. public async override CTask GetFocus()
  34. {
  35. await AppBarPanel.OpenPanel(this);
  36. base.GetFocus();
  37. }
  38. protected override void AddEvent()
  39. {
  40. }
  41. protected override void DelEvent()
  42. {
  43. }
  44. public override void AddButtonEvent()
  45. {
  46. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  47. Sr.onValueChanged.AddListener(OnValueChanged);
  48. }
  49. private void OnValueChanged(Vector2 arg0)
  50. {
  51. UpdateTitleWidget();
  52. }
  53. public async override CTask<bool> AsyncInit(object[] uiData)
  54. {
  55. CustomInit((int)uiData[0], (int)uiData[1]);
  56. return await base.AsyncInit(uiData);
  57. }
  58. public async CTask CustomInit(int type, int id)
  59. {
  60. this.type = type;
  61. eventLogTitleWidget = await UIManager.Instance.CreateGComponentForObject<EventLogTitleWidget>(EventLogTitleWidget, null);
  62. Map<int, List<EventConfig>> eventConfigMap = new Map<int, List<EventConfig>>();
  63. showXianTuLogInfoData.Clear();
  64. _xianTuLogConfig = ConfigComponent.Instance.Get<XianTuLogConfig>(id);
  65. var configs = EventSystemManager.Instance.eventConfigsMap[_xianTuLogConfig.ID];
  66. foreach (var @c in configs)
  67. {
  68. EventConfig eventConfig = c;
  69. if (!eventConfigMap.ContainsKey(eventConfig.placeID))
  70. {
  71. eventConfigMap.Add(eventConfig.placeID, new List<EventConfig>());
  72. }
  73. eventConfigMap[eventConfig.placeID].Add(eventConfig);
  74. }
  75. foreach (var keyValuePair in eventConfigMap)
  76. {
  77. if (type == 1)
  78. {
  79. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(keyValuePair.Key);
  80. XianTuLogInfoData xianTuLogInfoData3 = new XianTuLogInfoData();
  81. xianTuLogInfoData3.type = 1;
  82. xianTuLogInfoData3.id = keyValuePair.Value[0].ID;
  83. xianTuLogInfoData3.message = LanguageManager.Instance.Text(placesConfig.placeName);
  84. showXianTuLogInfoData.Add(xianTuLogInfoData3);
  85. }
  86. foreach (var eventConfig in keyValuePair.Value)
  87. {
  88. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(cl => cl.eventID == eventConfig.ID);
  89. if (eventList == null)
  90. {
  91. //主线没有做不显示问好
  92. if (_xianTuLogConfig.EventType == 2)
  93. {
  94. XianTuLogInfoData xianTuLogInfoData = new XianTuLogInfoData();
  95. xianTuLogInfoData.type = 2;
  96. xianTuLogInfoData.id = eventConfig.ID;
  97. xianTuLogInfoData.message = "????????";
  98. XianTuLogInfoData xianTuLogInfoData1 = new XianTuLogInfoData();
  99. xianTuLogInfoData1.type = 3;
  100. xianTuLogInfoData1.id = eventConfig.ID;
  101. xianTuLogInfoData1.message = "?????????????????????????????????";
  102. showXianTuLogInfoData.Add(xianTuLogInfoData);
  103. showXianTuLogInfoData.Add(xianTuLogInfoData1);
  104. }
  105. }
  106. else
  107. {
  108. XianTuLogInfoData xianTuLogInfoData = new XianTuLogInfoData();
  109. xianTuLogInfoData.type = 2;
  110. xianTuLogInfoData.id = eventConfig.ID;
  111. xianTuLogInfoData.message = LanguageManager.Instance.Text(eventConfig.EventName);
  112. showXianTuLogInfoData.Add(xianTuLogInfoData);
  113. for (var i = 0; i < eventList.selectEventLinkIds.Count; i++)
  114. {
  115. EventLinkConfig eventLinkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(eventList.selectEventLinkIds[i]);
  116. if (eventLinkConfig.LanID != null)
  117. {
  118. for (var i1 = 0; i1 < eventLinkConfig.LanID.Length; i1++)
  119. {
  120. XianTuLogInfoData xianTuLogInfoData1 = new XianTuLogInfoData();
  121. xianTuLogInfoData1.type = 3;
  122. xianTuLogInfoData1.id = eventConfig.ID;
  123. if (eventLinkConfig.NPCID != 0)
  124. {
  125. xianTuLogInfoData1.message = $"<color=#A6A6A6>{LanguageManager.Instance.Text(eventLinkConfig.LanID[i1])}</color>";
  126. }
  127. else
  128. {
  129. xianTuLogInfoData1.message = $"<color=#867169>{LanguageManager.Instance.Text(eventLinkConfig.LanID[i1])}</color>";
  130. }
  131. showXianTuLogInfoData.Add(xianTuLogInfoData1);
  132. }
  133. }
  134. //选项文本
  135. if (eventLinkConfig.optionType == 1 && eventList.selectEventLinkIds.Count > i + 1)
  136. {
  137. XianTuLogInfoData xianTuLogInfoData1 = new XianTuLogInfoData();
  138. xianTuLogInfoData1.type = 3;
  139. xianTuLogInfoData1.id = eventConfig.ID;
  140. int index = eventLinkConfig.optionPara1.ToList().IndexOf(eventList.selectEventLinkIds[i + 1]);
  141. if (eventLinkConfig.NPCID != 0)
  142. {
  143. xianTuLogInfoData1.message = $"<color=#A6A6A6>选项:{LanguageManager.Instance.Text(eventLinkConfig.optionPara2[index])}</color>";
  144. }
  145. else
  146. {
  147. xianTuLogInfoData1.message = $"<color=#867169>选项:{LanguageManager.Instance.Text(eventLinkConfig.optionPara2[index])}</color>";
  148. }
  149. showXianTuLogInfoData.Add(xianTuLogInfoData1);
  150. }
  151. }
  152. }
  153. }
  154. }
  155. if (type == 1)
  156. {
  157. // eventLogTitleWidget.SetActive(true);
  158. Sv.SetParent(Marsk1, false);
  159. eventLogTitleWidget.CustomInit(showXianTuLogInfoData[0]);
  160. eventLogTitleWidget.own.SetActive(true);
  161. }
  162. else if (type == 2)
  163. {
  164. Sv.SetParent(Marsk2, false);
  165. eventLogTitleWidget.own.SetActive(false);
  166. }
  167. await Content.Init(this, showXianTuLogInfoData.Count);
  168. }
  169. public async CTask<IScorllListWidget> GetIScorllListWidget(int index, RectTransform root)
  170. {
  171. if (index < 0 || index >= showXianTuLogInfoData.Count)
  172. {
  173. return null;
  174. }
  175. XianTuLogInfoData xianTuLogInfoData = showXianTuLogInfoData[index];
  176. if (xianTuLogInfoData.type == 1)
  177. {
  178. EventLogTitleWidget eventLogTitleWidget = await UIManager.Instance.CreateGComponent<EventLogTitleWidget>(null, ContentRoot);
  179. eventLogTitleWidget.CustomInit(xianTuLogInfoData);
  180. // titleWidgets.Add(eventLogTitleWidget);
  181. components.Add(eventLogTitleWidget);
  182. return eventLogTitleWidget;
  183. }
  184. else if (xianTuLogInfoData.type == 2)
  185. {
  186. EventLogInfoWidget eventLogInfoWidget = await UIManager.Instance.CreateGComponent<EventLogInfoWidget>(null, ContentRoot);
  187. eventLogInfoWidget.CustomInit(xianTuLogInfoData);
  188. components.Add(eventLogInfoWidget);
  189. return eventLogInfoWidget;
  190. }
  191. else if (xianTuLogInfoData.type == 3)
  192. {
  193. EventLogMessageWidget eventLogInfoWidget = await UIManager.Instance.CreateGComponent<EventLogMessageWidget>(null, ContentRoot);
  194. eventLogInfoWidget.CustomInit(xianTuLogInfoData);
  195. components.Add(eventLogInfoWidget);
  196. return eventLogInfoWidget;
  197. }
  198. return null;
  199. }
  200. public void HindIScorllListWidget(IScorllListWidget widget)
  201. {
  202. UIManager.Instance.DormancyGComponent(widget as UIComponent);
  203. if (components.Contains(widget as UIComponent))
  204. {
  205. components.Remove(widget as UIComponent);
  206. }
  207. // if (titleWidgets.Contains(widget as EventLogTitleWidget))
  208. // {
  209. // titleWidgets.Remove(widget as EventLogTitleWidget);
  210. // }
  211. }
  212. public override void Close()
  213. {
  214. showXianTuLogInfoData.Clear();
  215. foreach (var uiComponent in components)
  216. {
  217. UIManager.Instance.DormancyGComponent(uiComponent);
  218. }
  219. components.Clear();
  220. // titleWidgets.Clear();
  221. base.Close();
  222. }
  223. List<UIComponent> _components = new List<UIComponent>();
  224. private float maxY;
  225. private float minY;
  226. public void UpdateTitleWidget()
  227. {
  228. if (type != 1)
  229. return;
  230. UIComponent highestItem = null;
  231. maxY = float.MinValue;
  232. minY = float.MaxValue;
  233. _components.Clear();
  234. foreach (var xianTuTitleWidget in components)
  235. {
  236. float itemY = xianTuTitleWidget.own.transform.position.y; // 使用世界坐标的 Y 值
  237. if (itemY > eventLogTitleWidget.own.transform.position.y)
  238. {
  239. maxY = itemY;
  240. // highestItem = xianTuTitleWidget;
  241. _components.Add(xianTuTitleWidget);
  242. }
  243. }
  244. foreach (var uiComponent in _components)
  245. {
  246. float itemY = uiComponent.own.transform.position.y; // 使用世界坐标的 Y 值
  247. if (itemY < minY)
  248. {
  249. minY = itemY;
  250. highestItem = uiComponent;
  251. }
  252. }
  253. if (highestItem != null)
  254. {
  255. float outsideY = eventLogTitleWidget.own.transform.position.y;
  256. if (maxY > outsideY)
  257. {
  258. EventConfig eventConfig = default;
  259. if (highestItem is EventLogTitleWidget)
  260. {
  261. EventLogTitleWidget eventLogTitleWidget = highestItem as EventLogTitleWidget;
  262. eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventLogTitleWidget.data.id);
  263. }
  264. else if (highestItem is EventLogInfoWidget)
  265. {
  266. EventLogInfoWidget eventLogTitleWidget = highestItem as EventLogInfoWidget;
  267. eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventLogTitleWidget.data.id);
  268. }
  269. else if (highestItem is EventLogMessageWidget)
  270. {
  271. EventLogMessageWidget eventLogTitleWidget = highestItem as EventLogMessageWidget;
  272. eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventLogTitleWidget.data.id);
  273. }
  274. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(eventConfig.placeID);
  275. eventLogTitleWidget.CustomInit(LanguageManager.Instance.Text(placesConfig.placeName));
  276. }
  277. }
  278. }
  279. public async static CTask OpenPanel(int type, int id)
  280. {
  281. XianTuLogInfoPanel xianTuLogInfoPanel = await UIManager.Instance.LoadAndOpenPanel<XianTuLogInfoPanel>(null, uiData: new object[] { type, id });
  282. // xianTuLogInfoPanel.CustomInit(type, id);
  283. }
  284. }
  285. }