| New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using Cysharp.Threading.Tasks; |
| | | using UnityEngine; |
| | | |
| | | /// <summary> |
| | | /// 公会日志界面 |
| | | /// </summary> |
| | | public class GuildNoteWin : UIBase |
| | | { |
| | | [SerializeField] Color32 nameColor; |
| | | [SerializeField] Transform noNote; |
| | | [SerializeField] Transform hasNote; |
| | | [SerializeField] GuildNoteNormalCell guildNoteNormalCell; |
| | | [SerializeField] ScrollerController scroller; |
| | | [SerializeField] TextEx maxCount; |
| | | protected override void OnPreOpen() |
| | | { |
| | | GuildManager.Instance.EnterOrQuitGuildEvent += OnEnterOrQuitGuildEvent; |
| | | GuildManager.Instance.FamilyActionInfoEvent += OnFamilyActionInfoEvent; |
| | | scroller.OnGetDynamicSize += OnGetChatDynamicSize; |
| | | scroller.OnRefreshCell += OnRefreshCell; |
| | | |
| | | maxCount.text = Language.Get("Guild_82", GuildManager.Instance.familyRecordMaxCount); |
| | | |
| | | GuildManager.Instance.QueryFamilyAction(PlayerDatas.Instance.fairyData.fairy.FamilyID, GuildManager.MemberChangeActionType); |
| | | } |
| | | |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | GuildManager.Instance.EnterOrQuitGuildEvent -= OnEnterOrQuitGuildEvent; |
| | | GuildManager.Instance.FamilyActionInfoEvent -= OnFamilyActionInfoEvent; |
| | | scroller.OnGetDynamicSize -= OnGetChatDynamicSize; |
| | | scroller.OnRefreshCell -= OnRefreshCell; |
| | | } |
| | | |
| | | private void OnEnterOrQuitGuildEvent(bool isEnter) |
| | | { |
| | | DelayCloseWindow().Forget(); |
| | | } |
| | | |
| | | private bool OnGetChatDynamicSize(ScrollerDataType type, int index, out float height) |
| | | { |
| | | height = 0; |
| | | if (list.IsNullOrEmpty() || index < 0 || index >= list.Count) |
| | | return false; |
| | | var data = list[index]; |
| | | switch (type) |
| | | { |
| | | case ScrollerDataType.Header: |
| | | height = 19; |
| | | return true; |
| | | case ScrollerDataType.Normal: |
| | | height = guildNoteNormalCell.GetHeight(data.Info); |
| | | return true; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private void OnRefreshCell(ScrollerDataType type, CellView cell) |
| | | { |
| | | if (type == ScrollerDataType.Header) |
| | | { |
| | | var _cell = cell.GetComponent<GuildNoteHeaderCell>(); |
| | | _cell?.Display(cell.index, list); |
| | | } |
| | | else |
| | | { |
| | | var _cell = cell.GetComponent<GuildNoteNormalCell>(); |
| | | _cell?.Display(cell.index, list); |
| | | } |
| | | } |
| | | |
| | | private void OnFamilyActionInfoEvent(int familyID, int actionType) |
| | | { |
| | | if (familyID != PlayerDatas.Instance.fairyData.fairy.FamilyID) |
| | | return; |
| | | if (actionType != GuildManager.MemberChangeActionType) |
| | | return; |
| | | Display(); |
| | | } |
| | | |
| | | List<GuildNoteData> list; |
| | | private void Display() |
| | | { |
| | | if (!GuildManager.Instance.TryGetFamilyActions(GuildManager.MemberChangeActionType, out var actions)) |
| | | { |
| | | hasNote.SetActive(false); |
| | | noNote.SetActive(true); |
| | | return; |
| | | } |
| | | |
| | | list = GetShowGuildNoteDataList(actions); |
| | | bool isNullOrEmpty = list.IsNullOrEmpty(); |
| | | if (isNullOrEmpty) |
| | | { |
| | | hasNote.SetActive(false); |
| | | noNote.SetActive(true); |
| | | return; |
| | | } |
| | | |
| | | scroller.Refresh(); |
| | | if (!isNullOrEmpty) |
| | | { |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | if (list[i].ShowType == 0) |
| | | { |
| | | scroller.AddCell(ScrollerDataType.Header, i); |
| | | } |
| | | else |
| | | { |
| | | scroller.AddCell(ScrollerDataType.Normal, i); |
| | | } |
| | | } |
| | | } |
| | | scroller.Restart(); |
| | | |
| | | noNote.SetActive(isNullOrEmpty); |
| | | hasNote.SetActive(!isNullOrEmpty); |
| | | |
| | | } |
| | | |
| | | |
| | | private List<GuildNoteData> GetShowGuildNoteDataList(HA513_tagMCFamilyActionInfo.tagMCFamilyAction[] actions) |
| | | { |
| | | List<GuildNoteData> list = GetGuildNoteDataList(actions); |
| | | if (list.IsNullOrEmpty()) |
| | | return null; |
| | | |
| | | var result = new List<GuildNoteData>(); |
| | | |
| | | int lastDay = -1; |
| | | |
| | | foreach (var noteData in list) |
| | | { |
| | | // 获取当前条目所属日期 |
| | | DateTime currentTime = TimeUtility.GetTime(noteData.Time); |
| | | int currentDay = TimeUtility.GetPassDays((int)noteData.Time); |
| | | |
| | | // 检查是否需要插入日期标题 |
| | | if (lastDay == -1 || currentDay != lastDay) |
| | | { |
| | | // 获取目标天的凌晨时间戳 |
| | | DateTime dayStartTime = TimeUtility.GetDayStartTime(currentTime.Year, currentTime.Month, currentTime.Day); |
| | | int dayStartSeconds = (int)(dayStartTime - TimeUtility.OriginalTime).TotalSeconds; |
| | | |
| | | result.Add(new GuildNoteData |
| | | { |
| | | ShowType = 0, // 标题类型 |
| | | Time = (uint)dayStartSeconds, |
| | | Info = currentTime.ToString("yyyy-MM-dd"), |
| | | }); |
| | | } |
| | | |
| | | result.Add(noteData); |
| | | lastDay = currentDay; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private List<GuildNoteData> GetGuildNoteDataList(HA513_tagMCFamilyActionInfo.tagMCFamilyAction[] actions) |
| | | { |
| | | if (actions.IsNullOrEmpty()) |
| | | return null; |
| | | |
| | | var result = new List<GuildNoteData>(); |
| | | int maxCount = GuildManager.Instance.familyRecordMaxCount; |
| | | // 倒序遍历actions,并限制数量 |
| | | int count = 0; |
| | | for (int i = actions.Length - 1; i >= 0 && count < maxCount; i--) |
| | | { |
| | | var action = actions[i]; |
| | | string info = GetInfo(action); |
| | | result.Add(new GuildNoteData |
| | | { |
| | | ShowType = 1, // 内容类型 |
| | | Time = action.Time, |
| | | Info = info, |
| | | }); |
| | | count++; |
| | | } |
| | | return result.OrderBy(a => a.Time).ToList(); |
| | | } |
| | | |
| | | private string GetInfo(HA513_tagMCFamilyActionInfo.tagMCFamilyAction data) |
| | | { |
| | | if (data == null || data.Value1 != 2) |
| | | return string.Empty; |
| | | switch (data.Value2) |
| | | { |
| | | case 0: |
| | | return Language.Get("Guild_52", GetColorStr(data.Name)); |
| | | case 1: |
| | | return Language.Get("Guild_53", GetColorStr(data.Name)); |
| | | case 2: |
| | | return Language.Get("Guild_55", GetColorStr(data.Name)); |
| | | case 4: |
| | | if (data.Value3 > data.Value4) |
| | | { |
| | | return Language.Get("Guild_54", GetColorStr(data.Name), GetColorStr(RichTextMsgReplaceConfig.GetRichReplace("FAMILY", (int)data.Value3))); |
| | | } |
| | | else |
| | | { |
| | | return Language.Get("Guild_83", GetColorStr(data.Name), GetColorStr(RichTextMsgReplaceConfig.GetRichReplace("FAMILY", (int)data.Value3))); |
| | | } |
| | | case 3: |
| | | default: |
| | | return string.Empty; |
| | | } |
| | | } |
| | | |
| | | private string GetColorStr(string name) |
| | | { |
| | | return UIHelper.AppendColor(nameColor, name); |
| | | } |
| | | } |
| | | |
| | | public class GuildNoteData |
| | | { |
| | | public uint Time; //时间戳 |
| | | public int ShowType; //显示用途类型 0-标题(年-月-日) 1-内容 |
| | | public string Info; //信息 |
| | | } |