| | 1 | | using System; |
| | 2 | | using System.Globalization; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Special type of entry to be used as date separator in chat conversations. |
| | 8 | | /// </summary> |
| | 9 | | public class DateSeparatorEntry : ChatEntry |
| | 10 | | { |
| | 11 | | [SerializeField] internal TextMeshProUGUI title; |
| | 12 | |
|
| | 13 | | private DateTime timestamp; |
| | 14 | | private ChatEntryModel chatEntryModel; |
| | 15 | |
|
| 0 | 16 | | public override ChatEntryModel Model => chatEntryModel; |
| | 17 | |
|
| | 18 | | public override void Populate(ChatEntryModel model) |
| | 19 | | { |
| 2 | 20 | | chatEntryModel = model; |
| 2 | 21 | | title.text = GetDateFormat(GetDateTimeFromUnixTimestampMilliseconds(model.timestamp)); |
| 2 | 22 | | } |
| | 23 | |
|
| | 24 | | public override void SetFadeout(bool enabled) |
| | 25 | | { |
| 0 | 26 | | if (!enabled) |
| | 27 | | { |
| 0 | 28 | | group.alpha = 1; |
| 0 | 29 | | fadeEnabled = false; |
| 0 | 30 | | return; |
| | 31 | | } |
| | 32 | |
|
| 0 | 33 | | fadeEnabled = true; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public override void FadeOut() |
| | 37 | | { |
| 0 | 38 | | if (!gameObject.activeInHierarchy) |
| | 39 | | { |
| 0 | 40 | | group.alpha = 0; |
| 0 | 41 | | return; |
| | 42 | | } |
| | 43 | |
|
| 0 | 44 | | if (previewInterpolationAlphaRoutine != null) |
| 0 | 45 | | StopCoroutine(previewInterpolationAlphaRoutine); |
| | 46 | |
|
| 0 | 47 | | previewInterpolationAlphaRoutine = StartCoroutine(InterpolateAlpha(0, 0.5f)); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | private string GetDateFormat(DateTime date) |
| | 51 | | { |
| 2 | 52 | | string result = string.Empty; |
| | 53 | |
|
| 2 | 54 | | if (date.Year == DateTime.Now.Year && |
| | 55 | | date.Month == DateTime.Now.Month && |
| | 56 | | date.Day == DateTime.Now.Day) |
| | 57 | | { |
| 1 | 58 | | result = "Today"; |
| 1 | 59 | | } |
| | 60 | | else |
| | 61 | | { |
| 1 | 62 | | result = date.ToString("D", DateTimeFormatInfo.InvariantInfo); |
| | 63 | | } |
| | 64 | |
|
| 2 | 65 | | return result; |
| | 66 | | } |
| | 67 | |
|
| | 68 | | private DateTime GetDateTimeFromUnixTimestampMilliseconds(ulong milliseconds) |
| | 69 | | { |
| 2 | 70 | | DateTime result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 2 | 71 | | return result.AddMilliseconds(milliseconds); |
| | 72 | | } |
| | 73 | | } |