diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2019-10-06 08:24:39 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2019-10-06 08:28:09 +0900 |
commit | bb7f4c331aab6539067e4f932718e70f8f0ac004 (patch) | |
tree | 0600dfb8696b18ac6294709c3d8b397705c081d0 | |
parent | cfa77571c6656a4d1a4ad830de877a2edf05421a (diff) | |
download | wf-clock-bb7f4c331aab6539067e4f932718e70f8f0ac004.tar.gz |
add initial standalone mode implementation
-rw-r--r-- | WarframeClock/App.xaml | 3 | ||||
-rw-r--r-- | WarframeClock/App.xaml.cs | 33 | ||||
-rw-r--r-- | WarframeClock/OverlayWindow.xaml.cs | 36 | ||||
-rw-r--r-- | WarframeClock/OverlayWindowViewModel.cs | 10 | ||||
-rw-r--r-- | WarframeClock/Settings.cs | 8 | ||||
-rw-r--r-- | WarframeClock/SettingsWindow.xaml | 37 | ||||
-rw-r--r-- | WarframeClock/StandaloneOverlayWindow.xaml | 19 | ||||
-rw-r--r-- | WarframeClock/StandaloneOverlayWindow.xaml.cs | 44 | ||||
-rw-r--r-- | WarframeClock/WarframeClock.csproj | 7 |
9 files changed, 162 insertions, 35 deletions
diff --git a/WarframeClock/App.xaml b/WarframeClock/App.xaml index 8a9ad4d..81105bc 100644 --- a/WarframeClock/App.xaml +++ b/WarframeClock/App.xaml @@ -1,8 +1,7 @@ <Application x:Class="WarframeClock.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="clr-namespace:WarframeClock" - StartupUri="OverlayWindow.xaml"> + xmlns:local="clr-namespace:WarframeClock"> <Application.Resources> </Application.Resources> </Application> diff --git a/WarframeClock/App.xaml.cs b/WarframeClock/App.xaml.cs index 500efd1..6dbbda5 100644 --- a/WarframeClock/App.xaml.cs +++ b/WarframeClock/App.xaml.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Windows; +using System.Windows.Threading; namespace WarframeClock { @@ -22,6 +23,10 @@ namespace WarframeClock public static readonly AppData AppData = new AppData(); private string _debugTracePath; + private OverlayWindowViewModel _vm; + private DispatcherTimer _updateTimer; + private System.Windows.Forms.NotifyIcon _notifyIcon; + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); @@ -31,10 +36,38 @@ namespace WarframeClock Trace.Listeners.Add(new TextWriterTraceListener(File.Create(_debugTracePath))); } + // Prepare ViewModel(?) and a timer updating it + _vm = new OverlayWindowViewModel(); + _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Background, + (_, __) => _vm.Refresh(), Dispatcher.CurrentDispatcher); + _updateTimer.Start(); + + // Prepare System Tray icon + var iconMenu = new System.Windows.Forms.ContextMenu(); + iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(App.VersionString) { Enabled = false }); + iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Configure", + (_, __) => new SettingsWindow(_vm).Show())); + iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", + (_, __) => ((App)Application.Current).Terminate())); + + _notifyIcon = new System.Windows.Forms.NotifyIcon + { + ContextMenu = iconMenu, + Icon = WarframeClock.Properties.Resources.TrayIcon, + Text = $"Warframe Clock - {App.VersionString}", + Visible = true + }; + + // Last, start the main window + if (Settings.Standalone) + new StandaloneOverlayWindow(_vm).Show(); + else + new OverlayWindow(_vm).Show(); } internal void Terminate() { + _updateTimer.Stop(); MainWindow?.Close(); if (DEBUG) { diff --git a/WarframeClock/OverlayWindow.xaml.cs b/WarframeClock/OverlayWindow.xaml.cs index dbfe7cf..e469d6f 100644 --- a/WarframeClock/OverlayWindow.xaml.cs +++ b/WarframeClock/OverlayWindow.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Windows; using System.Windows.Input; using System.Windows.Threading; @@ -11,31 +12,16 @@ namespace WarframeClock public partial class OverlayWindow : OverlayWindowBase { private readonly OverlayWindowViewModel _vm; - private readonly System.Windows.Forms.NotifyIcon _notifyIcon; private readonly DispatcherTimer _updateTimer; - public OverlayWindow() + public OverlayWindow(OverlayWindowViewModel vm) { InitializeComponent(); - DataContext = _vm = new OverlayWindowViewModel(); - - var iconMenu = new System.Windows.Forms.ContextMenu(); - iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(App.VersionString) { Enabled = false }); - iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Configure", - (_, __) => new SettingsWindow(_vm).Show())); - iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", - (_, __) => ((App)Application.Current).Terminate())); - - _notifyIcon = new System.Windows.Forms.NotifyIcon - { - ContextMenu = iconMenu, - Icon = Properties.Resources.TrayIcon, - Text = $"Warframe Clock - {App.VersionString}", - Visible = true - }; + DataContext = _vm = vm; + _vm.PropertyChanged += OnVmPropertyChanged; _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Background, - UpdateTimerTick, Dispatcher.CurrentDispatcher); + (_, __) => AdjustOverlay(), Dispatcher.CurrentDispatcher); } protected override void OnSourceInitialized(EventArgs e) @@ -47,15 +33,17 @@ namespace WarframeClock protected override void OnClosed(EventArgs e) { base.OnClosed(e); - _notifyIcon.Dispose(); _updateTimer.Stop(); + _vm.PropertyChanged -= OnVmPropertyChanged; } - private void UpdateTimerTick(object sender, EventArgs e) + private void OnVmPropertyChanged(object sender, PropertyChangedEventArgs e) { - _vm.Refresh(); - - AdjustOverlay(); + if (e.PropertyName == nameof(OverlayWindowViewModel.Standalone) && _vm.Standalone) + { + new StandaloneOverlayWindow(_vm).Show(); + Close(); + } } private Point _dragOriginalPosition; diff --git a/WarframeClock/OverlayWindowViewModel.cs b/WarframeClock/OverlayWindowViewModel.cs index 5862ab8..e43c72f 100644 --- a/WarframeClock/OverlayWindowViewModel.cs +++ b/WarframeClock/OverlayWindowViewModel.cs @@ -77,6 +77,16 @@ namespace WarframeClock NotifyPropertyChanged(); } } + + public bool Standalone + { + get => Settings.Standalone; + set + { + Settings.Standalone = value; + NotifyPropertyChanged(); + } + } #endregion public void Refresh() diff --git a/WarframeClock/Settings.cs b/WarframeClock/Settings.cs index d400a7b..eb63875 100644 --- a/WarframeClock/Settings.cs +++ b/WarframeClock/Settings.cs @@ -75,6 +75,13 @@ namespace WarframeClock set => SetValue((_showKuvaFlood = value).ToString()); } + private static bool _standalone; + public static bool Standalone + { + get => _standalone; + set => SetValue((_standalone = value).ToString()); + } + private static readonly Configuration ExeConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); @@ -89,6 +96,7 @@ namespace WarframeClock _fontSize = double.TryParse(s.Get(nameof(FontSize)), out var fontSize) ? fontSize : 13; _showArbitration = bool.TryParse(s.Get(nameof(ShowArbitration)), out var showArbitration) && showArbitration; _showKuvaFlood = bool.TryParse(s.Get(nameof(ShowKuvaFlood)), out var showKuvaFlood) && showKuvaFlood; + _standalone = bool.TryParse(s.Get(nameof(Standalone)), out var standalone) && standalone; } private static void SetValue(string value, [CallerMemberName] string key = null) diff --git a/WarframeClock/SettingsWindow.xaml b/WarframeClock/SettingsWindow.xaml index 6f32432..89e454c 100644 --- a/WarframeClock/SettingsWindow.xaml +++ b/WarframeClock/SettingsWindow.xaml @@ -10,7 +10,7 @@ <GroupBox Header="Settings"> <Grid> <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="100" /> <ColumnDefinition Width="5" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> @@ -20,14 +20,33 @@ <RowDefinition MinHeight="20" /> <RowDefinition MinHeight="20" /> </Grid.RowDefinitions> - <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Font Settings:</TextBlock> - <Button Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Click="FontSettingsButton_Click">...</Button> - <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">Arbitration:</TextBlock> - <CheckBox Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding ShowArbitration}"/> - <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Kuva Flood:</TextBlock> - <CheckBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding ShowKuvaFlood}"/> - <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center">Position:</TextBlock> - <TextBlock Grid.Row="3" Grid.Column="2" VerticalAlignment="Center">Drag the clock overlay to reposition it.</TextBlock> + <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Standalone Mode:</TextBlock> + <CheckBox Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding Standalone}"/> + <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">Font Settings:</TextBlock> + <Button Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" Click="FontSettingsButton_Click">...</Button> + <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Arbitration:</TextBlock> + <CheckBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding ShowArbitration}"/> + <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center">Kuva Flood:</TextBlock> + <CheckBox Grid.Row="3" Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding ShowKuvaFlood}"/> + </Grid> + </GroupBox> + <GroupBox Header="Standalone Mode" IsEnabled="{Binding Standalone}"> + <StackPanel> + <TextBlock>Nothing to configure, currently.</TextBlock> + </StackPanel> + </GroupBox> + <GroupBox Header="Overlay Mode"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="100" /> + <ColumnDefinition Width="5" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition MinHeight="20" /> + </Grid.RowDefinitions> + <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Position:</TextBlock> + <TextBlock Grid.Row="0" Grid.Column="2" VerticalAlignment="Center">Drag the clock overlay to reposition it.</TextBlock> </Grid> </GroupBox> <GroupBox Header="About"> diff --git a/WarframeClock/StandaloneOverlayWindow.xaml b/WarframeClock/StandaloneOverlayWindow.xaml new file mode 100644 index 0000000..7369d40 --- /dev/null +++ b/WarframeClock/StandaloneOverlayWindow.xaml @@ -0,0 +1,19 @@ +<Window x:Class="WarframeClock.StandaloneOverlayWindow" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WarframeClock" + mc:Ignorable="d" + Title="WarframeClock StandaloneOverlayWindow" + Background="Black" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight" + d:DataContext="{d:DesignInstance local:OverlayWindowViewModel, IsDesignTimeCreatable=True}" + MouseDown="Window_MouseDown"> + <StackPanel Orientation="Horizontal"> + <local:PlainsTimeOverlayItem DataContext="{Binding PlainsTimeOverlayItemViewModel}"/> + <local:ArbitrationOverlayItem DataContext="{Binding ArbitrationOverlayItemViewModel}" + Margin="10,0,0,0"/> + <local:KuvaFloodOverlayItem DataContext="{Binding KuvaFloodOverlayItemViewModel}" + Margin="10,0,0,0"/> + </StackPanel> +</Window> diff --git a/WarframeClock/StandaloneOverlayWindow.xaml.cs b/WarframeClock/StandaloneOverlayWindow.xaml.cs new file mode 100644 index 0000000..00be945 --- /dev/null +++ b/WarframeClock/StandaloneOverlayWindow.xaml.cs @@ -0,0 +1,44 @@ +using System; +using System.ComponentModel; +using System.Windows; +using System.Windows.Input; + +namespace WarframeClock +{ + /// <summary> + /// Interaction logic for StandaloneOverlayWindow.xaml + /// </summary> + public partial class StandaloneOverlayWindow : Window + { + private readonly OverlayWindowViewModel _vm; + + public StandaloneOverlayWindow(OverlayWindowViewModel vm) + { + InitializeComponent(); + DataContext = _vm = vm; + + _vm.PropertyChanged += OnVmPropertyChanged; + } + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + _vm.PropertyChanged -= OnVmPropertyChanged; + } + + private void OnVmPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(OverlayWindowViewModel.Standalone) && !_vm.Standalone) + { + new OverlayWindow(_vm).Show(); + Close(); + } + } + + private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + if (e.LeftButton == MouseButtonState.Pressed) + DragMove(); + } + } +} diff --git a/WarframeClock/WarframeClock.csproj b/WarframeClock/WarframeClock.csproj index 7e08100..789df22 100644 --- a/WarframeClock/WarframeClock.csproj +++ b/WarframeClock/WarframeClock.csproj @@ -97,6 +97,9 @@ <Compile Include="SettingsWindow.xaml.cs"> <DependentUpon>SettingsWindow.xaml</DependentUpon> </Compile> + <Compile Include="StandaloneOverlayWindow.xaml.cs"> + <DependentUpon>StandaloneOverlayWindow.xaml</DependentUpon> + </Compile> <Compile Include="WorldState.cs" /> <Compile Include="WfcdWorldStateData.cs" /> <Page Include="OverlayWindow.xaml"> @@ -128,6 +131,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="StandaloneOverlayWindow.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs"> |