| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class PrivateChatHUDView : ChatHUDView |
| | 6 | | { |
| 9 | 7 | | string ENTRY_PATH_SENT = "ChatEntrySent"; |
| 9 | 8 | | string ENTRY_PATH_RECEIVED = "ChatEntryReceived"; |
| 9 | 9 | | string ENTRY_PATH_SEPARATOR = "ChatEntrySeparator"; |
| | 10 | |
|
| | 11 | | public override void AddEntry(ChatEntry.Model chatEntryModel, bool setScrollPositionToBottom = false) |
| | 12 | | { |
| 7 | 13 | | AddSeparatorEntryIfNeeded(chatEntryModel); |
| | 14 | |
|
| 7 | 15 | | var chatEntryGO = Instantiate(Resources.Load(chatEntryModel.subType == ChatEntry.Model.SubType.PRIVATE_TO ? ENTR |
| 7 | 16 | | ChatEntry chatEntry = chatEntryGO.GetComponent<ChatEntry>(); |
| | 17 | |
|
| 7 | 18 | | chatEntry.SetFadeout(false); |
| 7 | 19 | | chatEntry.Populate(chatEntryModel); |
| | 20 | |
|
| 7 | 21 | | chatEntry.OnTriggerHover += OnMessageTriggerHover; |
| 7 | 22 | | chatEntry.OnCancelHover += OnMessageCancelHover; |
| | 23 | |
|
| 7 | 24 | | entries.Add(chatEntry); |
| 7 | 25 | | Utils.ForceUpdateLayout(transform as RectTransform, delayed: false); |
| | 26 | |
|
| 7 | 27 | | if (setScrollPositionToBottom && scrollRect.verticalNormalizedPosition > 0) |
| 0 | 28 | | scrollRect.verticalNormalizedPosition = 0; |
| 7 | 29 | | } |
| | 30 | |
|
| | 31 | | protected override void OnMessageTriggerHover(ChatEntry chatEntry) |
| | 32 | | { |
| 0 | 33 | | (messageHoverPanel.transform as RectTransform).pivot = new Vector2(chatEntry.model.subType == ChatEntry.Model.Su |
| | 34 | |
|
| 0 | 35 | | base.OnMessageTriggerHover(chatEntry); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | private void AddSeparatorEntryIfNeeded(ChatEntry.Model chatEntryModel) |
| | 39 | | { |
| 7 | 40 | | DateTime entryDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); |
| 7 | 41 | | entryDateTime = GetDateTimeFromUnixTimestampMilliseconds(chatEntryModel.timestamp); |
| | 42 | |
|
| 7 | 43 | | if (!dateSeparators.Exists(separator => |
| 4 | 44 | | separator.model.date.Year == entryDateTime.Year && |
| | 45 | | separator.model.date.Month == entryDateTime.Month && |
| | 46 | | separator.model.date.Day == entryDateTime.Day)) |
| | 47 | | { |
| 3 | 48 | | var chatEntrySeparatorGO = Instantiate(Resources.Load(ENTRY_PATH_SEPARATOR) as GameObject, chatEntriesContai |
| 3 | 49 | | DateSeparatorEntry dateSeparatorEntry = chatEntrySeparatorGO.GetComponent<DateSeparatorEntry>(); |
| 3 | 50 | | dateSeparatorEntry.Populate(new DateSeparatorEntry.Model |
| | 51 | | { |
| | 52 | | date = entryDateTime |
| | 53 | | }); |
| 3 | 54 | | dateSeparators.Add(dateSeparatorEntry); |
| | 55 | | } |
| 7 | 56 | | } |
| | 57 | |
|
| | 58 | | private DateTime GetDateTimeFromUnixTimestampMilliseconds(ulong milliseconds) |
| | 59 | | { |
| 7 | 60 | | System.DateTime result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 7 | 61 | | return result.AddMilliseconds(milliseconds); |
| | 62 | | } |
| | 63 | | } |