Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CodeBreaker.WPF.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.7.33927.210
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codebreaker.WPF", "Codebreaker.WPF\Codebreaker.WPF.csproj", "{10FD3CBC-D263-49B3-9320-49AA2D522C0E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0F0847C3-59CA-4C02-87B7-C37A161BC067}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions src/Codebreaker.WPF/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Application x:Class="CodeBreaker.WPF.App"
<Application x:Class="Codebreaker.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CodeBreaker.WPF"
xmlns:local="clr-namespace:Codebreaker.WPF"
StartupUri="Views/Pages/GameWindow.xaml">
<Application.Resources>
<ResourceDictionary>
Expand Down
18 changes: 3 additions & 15 deletions src/Codebreaker.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
using CodeBreaker.Services;
using CodeBreaker.Services.Authentication;
using CodeBreaker.ViewModels;
using CodeBreaker.ViewModels.Services;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using System.Configuration;
using System.Windows;

namespace CodeBreaker.WPF;
namespace Codebreaker.WPF;

/// <summary>
/// Interaction logic for App.xaml
Expand All @@ -34,11 +23,10 @@ public App()
})
.ConfigureServices((context, services) =>
{
services.Configure<GamePageViewModelOptions>(options => options.EnableDialogs = false);
services.Configure<GamePageViewModelOptions>(options => options.EnableDialogs = true);
services.AddTransient<IDialogService, Services.WPFDialogService>();
services.AddScoped<GamePageViewModel>();
services.AddScoped<IAuthService, AuthService>();
services.AddHttpClient<IGameClient, GameClient>(client =>
services.AddHttpClient<IGamesClient, GamesClient>(client =>
{
string uriString = context.Configuration["ApiBase"] ?? throw new ConfigurationErrorsException("ApiBase not configured");
client.BaseAddress = new Uri(uriString);
Expand Down
3 changes: 2 additions & 1 deletion src/Codebreaker.WPF/Codebreaker.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<Company>CN innovation</Company>
<StartupObject>Codebreaker.WPF.App</StartupObject>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CNInnovation.Codebreaker.ViewModels" Version="2.0.0-beta1.12" />
<PackageReference Include="CNInnovation.Codebreaker.ViewModels" Version="3.5.0-beta.22" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions src/Codebreaker.WPF/Converters/BoolToVisibilityConverter.cs

This file was deleted.

29 changes: 12 additions & 17 deletions src/Codebreaker.WPF/Converters/ColorNameToBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

using static CodeBreaker.Shared.Models.Data.Colors;

namespace CodeBreaker.WPF.Converters;
namespace Codebreaker.WPF.Converters;

public class ColorNameToBrushConverter : IValueConverter
{
private static readonly Brush s_blackBrush = new SolidColorBrush(Colors.Black);
private static readonly Brush s_whiteBrush = new SolidColorBrush(Colors.White);
private static readonly Brush s_orangeBrush = new SolidColorBrush(Colors.Orange);
private static readonly Brush s_PurpleBrush = new SolidColorBrush(Colors.Purple);
private static readonly Brush s_redBrush = new SolidColorBrush(Color.FromRgb(209, 52, 56));
private static readonly Brush s_greenBrush = new SolidColorBrush(Color.FromRgb(0, 173, 86));
private static readonly Brush s_blueBrush = new SolidColorBrush(Color.FromRgb(79, 107, 237));
private static readonly Brush s_yellowBrush = new SolidColorBrush(Color.FromRgb(252, 225, 0));
private static readonly Brush s_emptyBrush = new SolidColorBrush(Color.FromRgb(160, 174, 178));

public Brush BlackBrush { get; set; } = s_blackBrush;
public Brush WhiteBrush { get; set; } = s_whiteBrush;
public Brush OrangeBrush { get; set; } = s_orangeBrush;
public Brush PurpleBrush { get; set; } = s_PurpleBrush;
public Brush RedBrush { get; set; } = s_redBrush;
public Brush GreenBrush { get; set; } = s_greenBrush;
public Brush BlueBrush { get; set; } = s_blueBrush;
Expand All @@ -26,14 +20,15 @@ public class ColorNameToBrushConverter : IValueConverter

public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{

return value switch
{
Black => BlackBrush,
White => WhiteBrush,
Red => RedBrush,
Green => GreenBrush,
Blue => BlueBrush,
Yellow => YellowBrush,
"Purple" => OrangeBrush,
"Orange" => PurpleBrush,
"Red" => RedBrush,
"Green" => GreenBrush,
"Blue" => BlueBrush,
"Yellow" => YellowBrush,
_ => EmptyBrush
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/Codebreaker.WPF/Converters/FieldValuesToColorsConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Codebreaker.WPF.Converters;

public class FieldValuesToColorsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IDictionary<string, string[]> data)
{
return data["colors"];
}
else
{
return value;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using CodeBreaker.ViewModels;

using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace CodeBreaker.WPF.Converters;
namespace Codebreaker.WPF.Converters;

internal class GameStatusToVisibilityConverter : IValueConverter
{
Expand Down
5 changes: 1 addition & 4 deletions src/Codebreaker.WPF/Converters/IntToEnumerableConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Globalization;
using System.Windows.Data;

namespace CodeBreaker.WPF.Converters;
namespace Codebreaker.WPF.Converters;

internal class IntToEnumerableConverter : IValueConverter
{
Expand Down
18 changes: 18 additions & 0 deletions src/Codebreaker.WPF/Converters/KeyPegColorNameToBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Codebreaker.WPF.Converters;

public class KeyPegColorNameToBrushConverter : IValueConverter
{
public Brush BlackBrush { get; set; } = new SolidColorBrush(Colors.Black);
public Brush WhiteBrush { get; set; } = new SolidColorBrush(Colors.White);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value switch
{
"Black" => BlackBrush,
"White" => WhiteBrush,
_ => value
};
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
using CodeBreaker.Shared.Models.Extensions;
using CodeBreaker.ViewModels;
namespace Codebreaker.WPF.Converters;

using System.Globalization;
using System.Windows;
using System.Windows.Data;
//public class SelectionAndKeyPegToKeyVisibilityConverter : IValueConverter
//{
// public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
// {
// ArgumentNullException.ThrowIfNull(parameter);

namespace CodeBreaker.WPF.Converters;
// if (value is SelectionAndKeyPegs selection && int.TryParse(parameter.ToString(), out int ix))
// {
// return (ix < selection.KeyPegs.ToModel().Total)
// ? Visibility.Visible
// : Visibility.Collapsed;
// }
// else
// {
// return Visibility.Hidden;
// }
// }

public class SelectionAndKeyPegToKeyVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ArgumentNullException.ThrowIfNull(parameter);

if (value is SelectionAndKeyPegs selection && int.TryParse(parameter.ToString(), out int ix))
{
return (ix < selection.KeyPegs.ToModel().Total)
? Visibility.Visible
: Visibility.Collapsed;
}
else
{
return Visibility.Hidden;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
// {
// throw new NotImplementedException();
// }
//}
14 changes: 14 additions & 0 deletions src/Codebreaker.WPF/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global using Codebreaker.GameAPIs.Client;
global using Codebreaker.ViewModels;
global using Codebreaker.ViewModels.Services;

global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;

global using System.Configuration;
global using System.Globalization;
global using System.Windows;
global using System.Windows.Data;
global using System.Windows.Media;

global using System.Windows.Controls;
6 changes: 2 additions & 4 deletions src/Codebreaker.WPF/Services/WPFDialogService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CodeBreaker.ViewModels.Services;


using System.Windows;

namespace CodeBreaker.WPF.Services;
namespace Codebreaker.WPF.Services;

public class WPFDialogService : IDialogService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Codebreaker.WPF/Views/Components/KeyPegsView.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="CodeBreaker.WPF.Views.Components.KeyPegsView"
<UserControl x:Class="Codebreaker.WPF.Views.Components.KeyPegsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down
4 changes: 1 addition & 3 deletions src/Codebreaker.WPF/Views/Components/KeyPegsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Windows.Controls;

namespace CodeBreaker.WPF.Views.Components;
namespace Codebreaker.WPF.Views.Components;

/// <summary>
/// Interaction logic for KeyPegs.xaml
Expand Down
7 changes: 5 additions & 2 deletions src/Codebreaker.WPF/Views/Components/PegSelectionView.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<UserControl x:Class="CodeBreaker.WPF.Views.Components.PegSelectionView"
<UserControl x:Class="Codebreaker.WPF.Views.Components.PegSelectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:Codebreaker.WPF.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
x:Name="PegSelectionViewControl">
<UserControl.Resources>
<conv:FieldValuesToColorsConverter x:Key="FieldValuesToColorsConverter" />
<conv:ColorNameToBrushConverter x:Key="ColorConverter" />
<DataTemplate x:Key="SelectColorTemplate">
<Ellipse Fill="{Binding Mode=OneWay, Converter={StaticResource ColorConverter}}" Width="60" Height="60" />
</DataTemplate>
Expand All @@ -15,7 +18,7 @@
Margin="0,0,8,0"
MinWidth="88"
MinHeight="60"
ItemsSource="{Binding ElementName=PegSelectionViewControl, Path=ViewModel.Game.Type.Fields, Mode=OneWay}"
ItemsSource="{Binding ElementName=PegSelectionViewControl, Path=ViewModel.Game.FieldValues, Converter={StaticResource FieldValuesToColorsConverter}, Mode=OneWay}"
ItemTemplate="{StaticResource SelectColorTemplate}"
SelectedItem="{Binding Value, Mode=TwoWay}" />
</DataTemplate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using CodeBreaker.ViewModels;

using System.Windows;
using System.Windows.Controls;

namespace CodeBreaker.WPF.Views.Components;
namespace Codebreaker.WPF.Views.Components;

public partial class PegSelectionView : UserControl
{
Expand Down
24 changes: 12 additions & 12 deletions src/Codebreaker.WPF/Views/Pages/GameWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Window x:Class="CodeBreaker.WPF.Views.Pages.GameWindow"
<Window x:Class="Codebreaker.WPF.Views.Pages.GameWindow"
x:Name="Self"
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:components="clr-namespace:CodeBreaker.WPF.Views.Components"
xmlns:conv="clr-namespace:CodeBreaker.WPF.Converters"
xmlns:components="clr-namespace:Codebreaker.WPF.Views.Components"
xmlns:conv="clr-namespace:Codebreaker.WPF.Converters"
mc:Ignorable="d"
Title="CodeBreaker" Height="450" Width="800">
Title="Codebreaker" Height="450" Width="800">
<Window.Resources>
<conv:GameStatusToVisibilityConverter x:Key="GameStatusVisibilityConverter" />
<conv:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<conv:SelectionAndKeyPegToKeyVisibilityConverter x:Key="KeyPegVisibilityConverter" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<!--<conv:SelectionAndKeyPegToKeyVisibilityConverter x:Key="KeyPegVisibilityConverter" />-->
<conv:ColorNameToBrushConverter x:Key="ColorConverter" />
</Window.Resources>

Expand All @@ -23,9 +23,9 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel Orientation="Vertical" Grid.Row="0">
<!-- TODO: Create component for this, to make it (more) generic. -->
<Grid Visibility="{Binding Path=ViewModel.InfoMessage.IsVisible, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
<!--<StackPanel Orientation="Vertical" Grid.Row="0">
--><!-- TODO: Create component for this, to make it (more) generic. --><!--
<Grid Visibility="{Binding Path=ViewModel.InfoMessage.IsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand All @@ -39,7 +39,7 @@
Content="{Binding ViewModel.InfoMessage.ActionTitle, Mode=OneWay}" Padding="30,8"
Command="{Binding ViewModel.InfoMessage.ActionCommand, Mode=OneWay}" />
</Grid>
<Grid Visibility="{Binding Path=ViewModel.ErrorMessage.IsVisible, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
<Grid Visibility="{Binding Path=ViewModel.ErrorMessage.IsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand All @@ -53,7 +53,7 @@
Content="{Binding ViewModel.ErrorMessage.ActionTitle, Mode=OneWay}" Padding="30,8"
Command="{Binding ViewModel.ErrorMessage.ActionCommand, Mode=OneWay}" />
</Grid>
</StackPanel>
</StackPanel>-->

<Grid Grid.Row="1" Margin="8" Visibility="{Binding ViewModel.GameStatus, Mode=OneWay, Converter={StaticResource GameStatusVisibilityConverter}, ConverterParameter=Start}">
<Grid.RowDefinitions>
Expand Down Expand Up @@ -101,6 +101,6 @@
Grid.Row="3"
Height="15"
Minimum="0" Maximum="100" IsIndeterminate="True"
Visibility="{Binding ViewModel.InProgress, Converter={StaticResource BoolToVisibilityConverter}}" />
Visibility="{Binding ViewModel.InProgress, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
</Window>
Loading