Skip to content

Commit 5159908

Browse files
committed
Adapted PegSelectionComponent for the new vm lib
1 parent bb47289 commit 5159908

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/Codebreaker.WinUI/Views/Components/PegSelectionComponent.xaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
xmlns:vmComponents="using:Codebreaker.ViewModels.Components"
10+
xmlns:models="using:Codebreaker.ViewModels.Models"
1011
xmlns:toolkitConverters="using:CommunityToolkit.WinUI.UI.Converters"
1112
xmlns:cme="using:CodeBreaker.WinUI.CustomMarkupExtensions"
1213
mc:Ignorable="d"
1314
x:Name="ThisControl">
1415

1516
<UserControl.Resources>
1617
<toolkitConverters:BoolToVisibilityConverter x:Key="BoolToVisibility" />
17-
<DataTemplate x:Key="SelectColorTemplate">
18+
<DataTemplate x:Key="SelectColorTemplate" x:DataType="x:String">
1819
<Grid>
19-
<Ellipse Fill="{Binding Mode=OneWay, Converter={StaticResource ColorConverter}}" Width="60" Height="60" />
20+
<Ellipse Fill="{x:Bind Mode=OneWay, Converter={StaticResource ColorConverter}}" Width="60" Height="60" />
2021
</Grid>
2122
</DataTemplate>
22-
<DataTemplate x:Key="SelectColorItemTemplate" x:DataType="vmComponents:SelectedFieldViewModel">
23+
<DataTemplate x:Key="SelectColorItemTemplate" x:DataType="models:Field">
2324
<ComboBox
2425
Margin="04" Width="112"
2526
Height="92"
26-
ItemsSource="{Binding ElementName=ThisControl, Path=DataContext.Game.FieldValues[colors], Mode=OneWay}"
27-
SelectedItem="{x:Bind Path=Value, Mode=TwoWay}"
27+
ItemsSource="{x:Bind PossibleColors, Mode=OneTime}"
28+
SelectedItem="{x:Bind Color, Mode=TwoWay}"
2829
ItemTemplate="{StaticResource SelectColorTemplate}"
2930
PlaceholderText="" HorizontalContentAlignment="Center" FontSize="40" />
3031
</DataTemplate>
@@ -37,18 +38,18 @@
3738
</Grid.ColumnDefinitions>
3839
<ItemsControl
3940
Grid.Column="0"
40-
ItemsSource="{x:Bind Path=ViewModel.Fields, Mode=OneWay}"
41+
ItemsSource="{x:Bind Path=ViewModel.SelectedFields, Mode=OneWay}"
4142
ItemTemplate="{StaticResource SelectColorItemTemplate}">
4243
<ItemsControl.ItemsPanel>
4344
<ItemsPanelTemplate>
4445
<StackPanel Orientation="Horizontal" Margin="15,0,15,10" />
4546
</ItemsPanelTemplate>
4647
</ItemsControl.ItemsPanel>
4748
</ItemsControl>
48-
<Button Command="{x:Bind ViewModel.SetMoveCommand, Mode=OneTime}" Grid.Column="1" Margin="4" VerticalAlignment="Top" Height="92" Width="100">
49+
<Button Command="{x:Bind ViewModel.MakeMoveCommand, Mode=OneTime}" Grid.Column="1" Margin="4" VerticalAlignment="Top" Height="92" Width="100">
4950
<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}" />
51+
<SymbolIcon Symbol="Send" Visibility="{x:Bind ViewModel.MakeMoveCommand.IsRunning, Mode=OneWay, Converter={StaticResource BoolToVisibility}, ConverterParameter=True}" />
52+
<ProgressRing Visibility="{x:Bind ViewModel.MakeMoveCommand.IsRunning, Mode=OneWay}" />
5253
<TextBlock Text="{cme:ResourceString Name=PegSelection_MakeMove}" />
5354
</StackPanel>
5455
</Button>

src/Codebreaker.WinUI/Views/Components/PegSelectionComponent.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using Codebreaker.ViewModels;
2+
using Codebreaker.ViewModels.Messages;
23
using CommunityToolkit.Mvvm.Messaging;
34
using Microsoft.UI.Xaml.Media.Animation;
45

56
namespace CodeBreaker.WinUI.Views.Components;
67

7-
internal sealed partial class PegSelectionComponent : UserControl, IRecipient<GameMoveMessage>
8+
internal sealed partial class PegSelectionComponent : UserControl, IRecipient<MakeMoveMessage>
89
{
910
public PegSelectionComponent()
1011
{
@@ -26,13 +27,14 @@ public GamePageViewModel ViewModel
2627
public static readonly DependencyProperty ViewModelProperty =
2728
DependencyProperty.Register("ViewModel", typeof(GamePageViewModel), typeof(PegSelectionComponent), new PropertyMetadata(null));
2829

29-
public void Receive(GameMoveMessage message)
30+
public void Receive(MakeMoveMessage message)
3031
{
31-
if (message.GameMoveValue is not GameMoveValue.Started)
32+
// Move must be completed already
33+
if (message.IsSet)
3234
return;
3335

3436
var animationService = ConnectedAnimationService.GetForCurrentView();
35-
this.FindItemsOfType<ComboBox>(this)
37+
this.FindChildrenRecursively<ComboBox>()
3638
.Foreach((comboBox, i) => animationService.PrepareToAnimate($"guess{i}", comboBox));
3739
}
3840
}

0 commit comments

Comments
 (0)