Skip to content

Commit d3dbcf8

Browse files
committed
Readded GamePage with PegSelectionComponent to WinUI
1 parent 3465e69 commit d3dbcf8

6 files changed

Lines changed: 207 additions & 2 deletions

File tree

src/Codebreaker.WinUI/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public partial class App : Application
4848

4949
services.AddSingleton<IActivationService, ActivationService>();
5050
services.AddPageService(builder => builder
51-
.Configure<SettingsPage>("GamePage")
52-
//.Configure<SettingsPage>("SettingsPage")
51+
.Configure<GamePage>("GamePage")
52+
.Configure<SettingsPage>("SettingsPage")
5353
.Configure<ShellPage>("ShellPage"));
5454
services.AddSingleton<IWinUINavigationService, WinUINavigationService>();
5555
services.AddSingleton<INavigationService>(x => x.GetRequiredService<IWinUINavigationService>());

src/Codebreaker.WinUI/Styles/Thickness.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@
3232
<Thickness x:Key="MenuBarContentMargin">36,24,0,0</Thickness>
3333

3434
<Thickness x:Key="SettingsPageHyperlinkButtonMargin">-12,4,0,0</Thickness>
35+
36+
<x:Double x:Key="Spacing1">4</x:Double>
37+
<x:Double x:Key="Spacing2">8</x:Double>
38+
<x:Double x:Key="Spacing3">12</x:Double>
39+
<x:Double x:Key="Spacing4">16</x:Double>
40+
<x:Double x:Key="Spacing5">20</x:Double>
3541

3642
</ResourceDictionary>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<UserControl
3+
x:Class="CodeBreaker.WinUI.Views.Components.PegSelectionComponent"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:CodeBreaker.WinUI.Views.Components"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:vmComponents="using:Codebreaker.ViewModels.Components"
10+
xmlns:toolkitConverters="using:CommunityToolkit.WinUI.UI.Converters"
11+
xmlns:cme="using:CodeBreaker.WinUI.CustomMarkupExtensions"
12+
mc:Ignorable="d"
13+
x:Name="ThisControl">
14+
15+
<UserControl.Resources>
16+
<toolkitConverters:BoolToVisibilityConverter x:Key="BoolToVisibility" />
17+
<DataTemplate x:Key="SelectColorTemplate">
18+
<Grid>
19+
<Ellipse Fill="{Binding Mode=OneWay, Converter={StaticResource ColorConverter}}" Width="60" Height="60" />
20+
</Grid>
21+
</DataTemplate>
22+
<DataTemplate x:Key="SelectColorItemTemplate" x:DataType="vmComponents:SelectedFieldViewModel">
23+
<ComboBox
24+
Margin="04" Width="112"
25+
Height="92"
26+
ItemsSource="{Binding ElementName=ThisControl, Path=DataContext.Game.FieldValues[colors], Mode=OneWay}"
27+
SelectedItem="{x:Bind Path=Value, Mode=TwoWay}"
28+
ItemTemplate="{StaticResource SelectColorTemplate}"
29+
PlaceholderText="" HorizontalContentAlignment="Center" FontSize="40" />
30+
</DataTemplate>
31+
</UserControl.Resources>
32+
33+
<Grid>
34+
<Grid.ColumnDefinitions>
35+
<ColumnDefinition Width="auto" />
36+
<ColumnDefinition Width="auto" />
37+
</Grid.ColumnDefinitions>
38+
<ItemsControl
39+
Grid.Column="0"
40+
ItemsSource="{x:Bind Path=ViewModel.Fields, Mode=OneWay}"
41+
ItemTemplate="{StaticResource SelectColorItemTemplate}">
42+
<ItemsControl.ItemsPanel>
43+
<ItemsPanelTemplate>
44+
<StackPanel Orientation="Horizontal" Margin="15,0,15,10" />
45+
</ItemsPanelTemplate>
46+
</ItemsControl.ItemsPanel>
47+
</ItemsControl>
48+
<Button Command="{x:Bind ViewModel.SetMoveCommand, Mode=OneTime}" Grid.Column="1" Margin="4" VerticalAlignment="Top" Height="92" Width="100">
49+
<StackPanel Orientation="Vertical" Spacing="5">
50+
<SymbolIcon Symbol="Send" Visibility="{x:Bind ViewModel.SetMoveCommand.IsRunning, Mode=OneWay, Converter={StaticResource BoolToVisibility}, ConverterParameter=True}" />
51+
<ProgressRing Visibility="{x:Bind ViewModel.SetMoveCommand.IsRunning, Mode=OneWay}" />
52+
<TextBlock Text="{cme:ResourceString Name=PegSelection_MakeMove}" />
53+
</StackPanel>
54+
</Button>
55+
</Grid>
56+
</UserControl>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Codebreaker.ViewModels;
2+
3+
namespace CodeBreaker.WinUI.Views.Components;
4+
5+
internal sealed partial class PegSelectionComponent : UserControl
6+
{
7+
public PegSelectionComponent()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
public GamePageViewModel ViewModel
13+
{
14+
get => (GamePageViewModel)GetValue(ViewModelProperty);
15+
set
16+
{
17+
SetValue(ViewModelProperty, value);
18+
DataContext = ViewModel;
19+
}
20+
}
21+
22+
public static readonly DependencyProperty ViewModelProperty =
23+
DependencyProperty.Register("ViewModel", typeof(GamePageViewModel), typeof(PegSelectionComponent), new PropertyMetadata(null));
24+
25+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="CodeBreaker.WinUI.Views.Pages.GamePage"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:CodeBreaker.WinUI.Views.Pages"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:components="using:CodeBreaker.WinUI.Views.Components"
10+
xmlns:conv="using:CodeBreaker.WinUI.Converters"
11+
xmlns:toolkitConverters="using:CommunityToolkit.WinUI.UI.Converters"
12+
xmlns:ca="using:CodeBreaker.WinUI.CustomAttachedProperties"
13+
xmlns:cme="using:CodeBreaker.WinUI.CustomMarkupExtensions"
14+
mc:Ignorable="d">
15+
<Page.Resources>
16+
<conv:GameStatusToVisibilityConverter x:Key="GameStatusVisibility" />
17+
<toolkitConverters:BoolToVisibilityConverter x:Key="BoolToVisibility" />
18+
<Style TargetType="InfoBar">
19+
<Setter Property="Margin" Value="0,0,0,30" />
20+
</Style>
21+
</Page.Resources>
22+
<Grid x:Name="ContentArea">
23+
<Grid.RowDefinitions>
24+
<RowDefinition Height="auto" />
25+
<RowDefinition Height="auto" />
26+
<RowDefinition Height="auto" />
27+
<RowDefinition Height="*" />
28+
</Grid.RowDefinitions>
29+
<!--Startgame section-->
30+
<Grid
31+
Grid.Row="1"
32+
ColumnSpacing="25"
33+
Visibility="{x:Bind ViewModel.GameStatus, Mode=OneWay, Converter={StaticResource GameStatusVisibility}, ConverterParameter=Start}">
34+
<Grid.ColumnDefinitions>
35+
<ColumnDefinition />
36+
<ColumnDefinition Width="Auto" />
37+
</Grid.ColumnDefinitions>
38+
<Grid Grid.Column="0">
39+
<!-- The extra grid and the empy (enabled) TextBlock are necessary for showing the tooltip over the (disabled) TextBox. -->
40+
<TextBlock />
41+
<TextBox
42+
IsEnabled="{x:Bind ViewModel.IsNameEnterable, Mode=OneWay}"
43+
Header="{cme:ResourceString Name=GamePage_NameInputHeader}"
44+
PlaceholderText="{cme:ResourceString Name=GamePage_NameInputPlaceholder}"
45+
VerticalAlignment="Center"
46+
Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
47+
<ToolTipService.ToolTip>
48+
<ToolTip
49+
Content="{cme:ResourceString Name=GamePage_NameAlreadyProvidedTooltip}"
50+
IsEnabled="{x:Bind Path=ViewModel.IsNamePredefined, Mode=OneWay}"
51+
Placement="Bottom" />
52+
</ToolTipService.ToolTip>
53+
</Grid>
54+
<Button
55+
Grid.Column="1"
56+
VerticalAlignment="Bottom"
57+
HorizontalAlignment="Stretch"
58+
Padding="35,8"
59+
Command="{x:Bind Path=ViewModel.StartGameCommand, Mode=OneTime}">
60+
<StackPanel Orientation="Vertical" Spacing="5">
61+
<SymbolIcon Symbol="Play" Visibility="{x:Bind Path=ViewModel.StartGameCommand.IsRunning, Mode=OneWay, Converter={StaticResource BoolToVisibility}, ConverterParameter=True}" />
62+
<ProgressRing Visibility="{x:Bind Path=ViewModel.StartGameCommand.IsRunning, Mode=OneWay}" Width="20" Height="20" />
63+
<TextBlock Text="{cme:ResourceString Name=GamePage_StartButtonText}" />
64+
</StackPanel>
65+
</Button>
66+
</Grid>
67+
<!--Gamebar section-->
68+
<StackPanel
69+
Orientation="Horizontal"
70+
Grid.Row="1"
71+
Visibility="{x:Bind ViewModel.GameStatus, Mode=OneWay, Converter={StaticResource GameStatusVisibility}, ConverterParameter=Cancelable}">
72+
<!--
73+
Cancelling the game is not yet implemented in the VM
74+
<Button
75+
Height="92" Margin="0,-6,4,0" Width="100"
76+
ca:Confirm.Enabled="True"
77+
ca:Confirm.Title="{cme:ResourceString Name=GamePage_CancelConfirmTitle}"
78+
ca:Confirm.Content="{cme:ResourceString Name=GamePage_CancelConfirmContent}"
79+
ca:Confirm.PrimaryCommand="{x:Bind ViewModel.CancelGameCommand, Mode=OneTime}"
80+
ca:Confirm.PrimaryText="{cme:ResourceString Name=Yes}"
81+
ca:Confirm.CloseText="{cme:ResourceString Name=No}">
82+
<StackPanel Orientation="Vertical" Spacing="05">
83+
<SymbolIcon Symbol="Cancel" Visibility="{x:Bind ViewModel.CancelGameCommand.IsRunning, Mode=OneWay,Converter={StaticResource BoolToVisibility},ConverterParameter=True}" />
84+
<ProgressRing Visibility="{x:Bind ViewModel.CancelGameCommand.IsRunning, Mode=OneWay}" />
85+
<TextBlock Text="{cme:ResourceString Name=GamePage_CancelButtonText}" />
86+
</StackPanel>
87+
</Button>-->
88+
<components:PegSelectionComponent
89+
Grid.Row="2"
90+
ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
91+
</StackPanel>
92+
<!--Move section-->
93+
<ListBox
94+
x:Name="listGameMoves"
95+
Grid.Row="3"
96+
Background="Transparent"
97+
Visibility="{x:Bind ViewModel.GameStatus, Mode=OneWay, Converter={StaticResource GameStatusVisibility}, ConverterParameter=Running}"
98+
ItemsSource="{x:Bind ViewModel.GameMoves, Mode=OneWay}"
99+
ItemTemplate="{StaticResource PegsTemplate}" />
100+
</Grid>
101+
</Page>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Codebreaker.ViewModels;
2+
3+
namespace CodeBreaker.WinUI.Views.Pages;
4+
5+
/// <summary>
6+
/// An empty page that can be used on its own or navigated to within a Frame.
7+
/// </summary>
8+
public sealed partial class GamePage : Page
9+
{
10+
public GamePageViewModel ViewModel { get; }
11+
12+
public GamePage()
13+
{
14+
ViewModel = App.GetService<GamePageViewModel>();
15+
InitializeComponent();
16+
}
17+
}

0 commit comments

Comments
 (0)