yyl
4 天以前 5a4e34c8a85737c0fa5b5775122da31155cbaef3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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();
        
        if (!isNullOrEmpty)
        {
            scroller.JumpIndex(list.Count - 1);
        }
 
        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;        //信息
}