XianTuLogInfoPanel.cs 13 KB

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