Skip to content

Commit

Permalink
* add group box style
Browse files Browse the repository at this point in the history
* GoldDifferenceWindow is no longer closed and then re-opened when a new game is started
  • Loading branch information
Johannes-Schneider committed Oct 27, 2020
1 parent 3fee0f6 commit a6020d8
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 25 deletions.
3 changes: 2 additions & 1 deletion GoldDiff.Playground/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
Margin="0, 0, 0, 12"
CanClose="True"
CanMaximize="True"
CanMinimize="True" />
CanMinimize="True"
CanOpenSettings="True"/>

<StackPanel Grid.Row="1">

Expand Down
1 change: 1 addition & 0 deletions GoldDiff.Shared/GoldDiff.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Page Include="View\Resource\VectorIcons.xaml" />
<Page Include="View\Style\DefaultDialogStyle.xaml" />
<Page Include="View\Style\DefaultGoldDiffCheckBoxStyle.xaml" />
<Page Include="View\Style\DefaultGroupBoxStyle.xaml" />
<Page Include="View\Style\DefaultIconButtonStyle.xaml" />
<Page Include="View\Style\DefaultIconControlStyle.xaml" />
<Page Include="View\Style\DefaultProgressBarStyle.xaml" />
Expand Down
9 changes: 9 additions & 0 deletions GoldDiff.Shared/View/ControlElement/WindowControlBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
<StackPanel HorizontalAlignment="Right"
Orientation="Horizontal"
VerticalAlignment="Center">

<controlElement:IconButton Icon="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.IconSettings}}"
BackgroundWhenHovered="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.ForegroundRegular}}"
BackgroundWhenPressed="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.ForegroundDark}}"
ForegroundWhenHovered="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.BackgroundRegular}}"
ForegroundWhenPressed="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.BackgroundRegular}}"
Visibility="{Binding ElementName=This, Path=CanOpenSettings, Converter={StaticResource BoolToVisibilityConverter}}"
Command="{Binding ElementName=This, Path=OpenSettingsCommand}"
CommandParameter="{Binding ElementName=This, Path=OpenSettingsCommandParameter}" />

<controlElement:IconButton Icon="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.IconMinimize}}"
BackgroundWhenHovered="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.ForegroundRegular}}"
Expand Down
22 changes: 22 additions & 0 deletions GoldDiff.Shared/View/ControlElement/WindowControlBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace GoldDiff.Shared.View.ControlElement
{
Expand All @@ -9,6 +10,9 @@ public partial class WindowControlBar : UserControl
public static readonly DependencyProperty CanMinimizeProperty = DependencyProperty.Register(nameof(CanMinimize), typeof(bool), MethodBase.GetCurrentMethod().DeclaringType);
public static readonly DependencyProperty CanMaximizeProperty = DependencyProperty.Register(nameof(CanMaximize), typeof(bool), MethodBase.GetCurrentMethod().DeclaringType);
public static readonly DependencyProperty CanCloseProperty = DependencyProperty.Register(nameof(CanClose), typeof(bool), MethodBase.GetCurrentMethod().DeclaringType);
public static readonly DependencyProperty CanOpenSettingsProperty = DependencyProperty.Register(nameof(CanOpenSettings), typeof(bool), MethodBase.GetCurrentMethod().DeclaringType);
public static readonly DependencyProperty OpenSettingsCommandProperty = DependencyProperty.Register(nameof(OpenSettingsCommand), typeof(ICommand), MethodBase.GetCurrentMethod().DeclaringType);
public static readonly DependencyProperty OpenSettingsCommandParameterProperty = DependencyProperty.Register(nameof(OpenSettingsCommandParameter), typeof(object), MethodBase.GetCurrentMethod().DeclaringType);

public bool CanMinimize
{
Expand All @@ -27,6 +31,24 @@ public bool CanClose
get => (bool) GetValue(CanCloseProperty);
set => SetValue(CanCloseProperty, value);
}

public bool CanOpenSettings
{
get => (bool) GetValue(CanOpenSettingsProperty);
set => SetValue(CanOpenSettingsProperty, value);
}

public ICommand? OpenSettingsCommand
{
get => GetValue(OpenSettingsCommandProperty) as ICommand;
set => SetValue(OpenSettingsCommandProperty, value);
}

public object? OpenSettingsCommandParameter
{
get => GetValue(OpenSettingsCommandParameterProperty);
set => SetValue(OpenSettingsCommandParameterProperty, value);
}

public WindowControlBar()
{
Expand Down
1 change: 1 addition & 0 deletions GoldDiff.Shared/View/GoldDiffSharedResourceKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static class GoldDiffSharedResourceKeys
public const string DefaultProgressBarStyle = nameof(DefaultProgressBarStyle);
public const string DefaultGoldDiffCheckBoxStyle = nameof(DefaultGoldDiffCheckBoxStyle);
public const string DefaultDialogStyle = nameof(DefaultDialogStyle);
public const string DefaultGroupBoxStyle = nameof(DefaultGroupBoxStyle);

#endregion
}
Expand Down
50 changes: 50 additions & 0 deletions GoldDiff.Shared/View/Style/DefaultGroupBoxStyle.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace:GoldDiff.Shared.View"
xmlns:controlElement="clr-namespace:GoldDiff.Shared.View.ControlElement">

<Style TargetType="{x:Type GroupBox}" x:Key="{x:Static view:GoldDiffSharedResourceKeys.DefaultGroupBoxStyle}">
<Setter Property="Background" Value="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.BackgroundRegular}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.ForegroundRegular}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static view:GoldDiffSharedResourceKeys.ForegroundDisabled}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>


<Border Grid.Row="0"
Grid.RowSpan="2"
BorderThickness="1"
CornerRadius="2"
Margin="0, 9, 0, 0"
SnapsToDevicePixels="True"
BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"
Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />

<ContentPresenter Grid.Row="1"
Margin="6" />

<Border Grid.Row="0"
Margin="6, 0, 6, 0"
BorderThickness="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Padding="3, 0, 3, 0"
SnapsToDevicePixels="True"
Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}">

<ContentPresenter ContentSource="Header"
RecognizesAccessKey="True" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
3 changes: 3 additions & 0 deletions GoldDiff/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultIconButtonStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultIconControlStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultProgressBarStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultGoldDiffCheckBoxStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultDialogStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff.Shared;component/View/Style/DefaultGroupBoxStyle.xaml" />

<ResourceDictionary Source="pack://application:,,,/GoldDiff;component/View/Style/DefaultGoldDifferenceStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/GoldDiff;component/View/Style/DefaultLoLPositionStyle.xaml" />
Expand Down
23 changes: 19 additions & 4 deletions GoldDiff/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,28 @@ private void Game_OnInitialized(object sender, EventArgs e)
{
Current.Dispatcher.Invoke(() =>
{
_goldDifferenceWindow?.Close();
_goldDifferenceWindow = new GoldDifferenceWindow(_game);
_goldDifferenceWindow.Show();
if (_goldDifferenceWindow != null)
{
_goldDifferenceWindow.Model.Game = _game;
if (_goldDifferenceWindow.WindowState == WindowState.Minimized)
{
_goldDifferenceWindow.WindowState = WindowState.Normal;
}
}
else
{
_goldDifferenceWindow = new GoldDifferenceWindow(_game);
_goldDifferenceWindow.Closed += GoldDifferenceWindow_OnClosed;
_goldDifferenceWindow.Show();
}
});
}

private void GoldDifferenceWindow_OnClosed(object sender, EventArgs e)
{
_goldDifferenceWindow = null;
}

private void TargetProcessStopped()
{
_clientDataPollService?.Dispose();
Expand Down
47 changes: 29 additions & 18 deletions GoldDiff/View/Controller/GoldDifferenceWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,42 @@ public class GoldDifferenceWindowController
};

public GoldDifferenceWindowViewModel Model { get; }

public LoLGame Game { get; }

public GoldDifferenceWindowController(GoldDifferenceWindowViewModel? model, LoLGame? game)
public GoldDifferenceWindowController(GoldDifferenceWindowViewModel? model)
{
Model = model ?? throw new ArgumentNullException(nameof(model));
Model.PropertyChanged += ModelOnPropertyChanged;

TryInitializeModel();
}

Game = game ?? throw new ArgumentNullException(nameof(game));
if (Game.IsInitialized)
private void ModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals(nameof(Model.Game)))
{
InitializeBlueSidePlayers();
InitializeRedSidePlayers();
TryInitializeModel();
}
else
else if (string.IsNullOrEmpty(e.PropertyName) || PlayerPropertyNames.Contains(e.PropertyName))
{
Game.Initialized += Game_OnInitialized;
UpdateActivePlayerBackground();
}
}

private void ModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
private void TryInitializeModel()
{
if (string.IsNullOrEmpty(e.PropertyName) || PlayerPropertyNames.Contains(e.PropertyName))
if (Model.Game == null)
{
UpdateActivePlayerBackground();
return;
}

if (Model.Game.IsInitialized)
{
InitializeBlueSidePlayers();
InitializeRedSidePlayers();
}
else
{
Model.Game.Initialized += Game_OnInitialized;
}
}

Expand Down Expand Up @@ -121,14 +132,14 @@ private void Game_OnInitialized(object sender, EventArgs e)

private void InitializeBlueSidePlayers()
{
if (Game.TeamBlueSide == null)
if (Model.Game?.TeamBlueSide == null)
{
return;
}

Model.TeamBlueSide = Game.TeamBlueSide;
Model.TeamBlueSide = Model.Game.TeamBlueSide;

var orderedPlayers = OrderPlayers(Game.TeamBlueSide);
var orderedPlayers = OrderPlayers(Model.TeamBlueSide);
if (orderedPlayers.TryGetValue(LoLPositionType.Top, out var topPlayer))
{
Model.TopPlayerBlueSide = topPlayer;
Expand Down Expand Up @@ -157,14 +168,14 @@ private void InitializeBlueSidePlayers()

private void InitializeRedSidePlayers()
{
if (Game.TeamRedSide == null)
if (Model.Game?.TeamRedSide == null)
{
return;
}

Model.TeamRedSide = Game.TeamRedSide;
Model.TeamRedSide = Model.Game.TeamRedSide;

var orderedPlayers = OrderPlayers(Game.TeamRedSide);
var orderedPlayers = OrderPlayers(Model.TeamRedSide);
if (orderedPlayers.TryGetValue(LoLPositionType.Top, out var topPlayer))
{
Model.TopPlayerRedSide = topPlayer;
Expand Down
3 changes: 2 additions & 1 deletion GoldDiff/View/GoldDifferenceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public GoldDifferenceWindow(LoLGame? game)

Model = new GoldDifferenceWindowViewModel
{
Game = game,
ActivePlayerOnBlueSideBackground = Resources[ActivePlayerOnBlueSideBackground] as Brush,
ActivePlayerOnRedSideBackground = Resources[ActivePlayerOnRedSideBackground] as Brush,
InactivePlayerBackground = null,
};
Controller = new GoldDifferenceWindowController(Model, game);
Controller = new GoldDifferenceWindowController(Model);

PrivateModel = Model;
}
Expand Down
3 changes: 2 additions & 1 deletion GoldDiff/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
Grid.Row="0"
CanClose="True"
CanMinimize="True"
CanMaximize="False" />
CanMaximize="False"
CanOpenSettings="True" />

<TextBlock Grid.Column="0"
Grid.Row="1"
Expand Down
8 changes: 8 additions & 0 deletions GoldDiff/View/Model/GoldDifferenceWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class GoldDifferenceWindowViewModel : ViewModel
}
},
};

private LoLGame? _game;

public LoLGame? Game
{
get => _game;
set => MutateVerboseIfNotNull(ref _game, value);
}

#region Blue Side

Expand Down

0 comments on commit a6020d8

Please sign in to comment.