aboutsummaryrefslogtreecommitdiffstats
path: root/WarframeClock/OverlayWindowViewModel.cs
blob: 0abeb3058d92912a8caa504bcfdb2417c64fc54d (plain)
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
using System;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace WarframeClock
{
    public class OverlayWindowViewModel : BindableBase
    {
        public DateTime NextBountiesResetByWorldState { get; set; } =
            new DateTime(1970, 1, 1).AddMilliseconds(1548159123053);
        public DateTime NextBountiesReset { get; set; } =
            new DateTime(1970, 1, 1);

        private string _overlayText = "!!!PLACEHOLDER!!!";
        public string OverlayText
        {
            get => _overlayText;
            set
            {
                _overlayText = value;
                NotifyPropertyChanged();
            }
        }

        public void RefreshOverlayText()
        {
            var currentTime = DateTime.UtcNow;
            const double bountiesLen = 8998.8748, plainsNightLen = bountiesLen * 1 / 3;

            string FormatPlainsText(DateTime cetusEnd)
            {
                var plainsDayEnd = cetusEnd.AddSeconds(-plainsNightLen);
                string sign;
                TimeSpan time;
                if (currentTime < plainsDayEnd)
                {
                    sign = "☀";
                    time = plainsDayEnd.Subtract(currentTime);
                }
                else
                {
                    sign = "🌙";
                    time = cetusEnd.Subtract(currentTime);
                }
                return $"{sign} {Math.Floor(time.TotalMinutes)}m{Math.Floor(time.TotalSeconds % 60)}s";
            }

            var wsReset = NextBountiesResetByWorldState;
            wsReset = wsReset.AddSeconds(
                (Math.Floor(currentTime.Subtract(wsReset).TotalSeconds / bountiesLen) + 1) * bountiesLen);

            var ret = new StringBuilder();
            if (NextBountiesReset > currentTime)
            {
                var eeReset = NextBountiesReset;
                ret.Append(FormatPlainsText(eeReset));
                var diff = eeReset.Subtract(wsReset).TotalSeconds;
                if (diff > bountiesLen / 2)
                    diff -= bountiesLen;
                else if (diff < -bountiesLen / 2)
                    diff += bountiesLen;
                ret.Append($" [{Math.Abs(diff):0.0}s {(diff > 0 ? "late" : "early")}]");
            }
            else
            {
                ret.Append($"({FormatPlainsText(wsReset)})");
            }

            OverlayText = ret.ToString();
        }

        private bool _settingsMode;
        public bool SettingsMode
        {
            get => _settingsMode;
            set
            {
                _settingsMode = value;
                NotifyPropertyChanged();
                NotifyPropertyChanged(nameof(SettingsControlVisibility));
            }
        }

        public Visibility SettingsControlVisibility =>
            SettingsMode ? Visibility.Visible : Visibility.Collapsed;

        #region "App Settings"
        public FontFamily FontFamily => new FontFamily(Settings.FontFamilyName);

        public double FontSize => Settings.FontSize;

        public HorizontalAlignment HorizontalAlignment =>
            Settings.DockToX == Settings.AlignmentX.Left ? HorizontalAlignment.Left : HorizontalAlignment.Right;

        public VerticalAlignment VerticalAlignment =>
            Settings.DockToY == Settings.AlignmentY.Top ? VerticalAlignment.Top : VerticalAlignment.Bottom;

        public Thickness Margin =>
            new Thickness(
                Settings.DockToX == Settings.AlignmentX.Left ? Settings.MarginX : 0.0,
                Settings.DockToY == Settings.AlignmentY.Top ? Settings.MarginY : 0.0,
                Settings.DockToX == Settings.AlignmentX.Right ? Settings.MarginX : 0.0,
                Settings.DockToY == Settings.AlignmentY.Bottom ? Settings.MarginY : 0.0);

        public void RefreshPosition()
        {
            NotifyPropertyChanged(nameof(HorizontalAlignment));
            NotifyPropertyChanged(nameof(VerticalAlignment));
            NotifyPropertyChanged(nameof(Margin));
        }

        public void RefreshFont()
        {
            NotifyPropertyChanged(nameof(FontFamily));
            NotifyPropertyChanged(nameof(FontSize));
        }
        #endregion
    }
}