-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from CodebreakerApp/92-animations-and-infomess…
…ages 92 animations and infomessages
- Loading branch information
Showing
6 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace System.Linq; | ||
|
||
internal static class LinqExtensions | ||
{ | ||
public static IEnumerable<T> Foreach<T>(this IEnumerable<T> enumerable, Action<T> action) | ||
{ | ||
foreach (var item in enumerable) | ||
action(item); | ||
|
||
return enumerable; | ||
} | ||
|
||
public static IEnumerable<T> Foreach<T>(this IEnumerable<T> enumerable, Action<T, int> action) | ||
{ | ||
int i = 0; | ||
|
||
foreach (var item in enumerable) | ||
action(item, i++); | ||
|
||
return enumerable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,45 @@ | ||
using Codebreaker.ViewModels; | ||
using CommunityToolkit.Mvvm.Messaging; | ||
using Microsoft.UI.Xaml.Media.Animation; | ||
using Microsoft.UI.Xaml.Shapes; | ||
|
||
namespace CodeBreaker.WinUI.Views.Pages; | ||
|
||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class GamePage : Page | ||
public sealed partial class GamePage : Page, IRecipient<GameMoveMessage> | ||
{ | ||
public GamePageViewModel ViewModel { get; } | ||
|
||
public GamePage() | ||
{ | ||
ViewModel = App.GetService<GamePageViewModel>(); | ||
InitializeComponent(); | ||
WeakReferenceMessenger.Default.Register(this); | ||
WeakReferenceMessenger.Default.UnregisterAllOnUnloaded(this); | ||
} | ||
|
||
public void Receive(GameMoveMessage message) | ||
{ | ||
if (message.GameMoveValue is not GameMoveValue.Completed) | ||
return; | ||
|
||
var selectionAndKeyPegs = message.SelectionAndKeyPegs ?? throw new InvalidOperationException(); | ||
var animationService = ConnectedAnimationService.GetForCurrentView(); | ||
animationService.DefaultDuration = TimeSpan.FromMilliseconds(500); | ||
var container = listGameMoves.ItemContainerGenerator.ContainerFromItem(selectionAndKeyPegs); | ||
this.FindItemsOfType<Ellipse>(container) | ||
.Foreach((ellipse, i) => | ||
{ | ||
ConnectedAnimation? animation = animationService.GetAnimation($"guess{i}"); | ||
|
||
// No animation found for this ellipxe -> the ellipse is most likely a key-peg | ||
if (animation is null) | ||
return; | ||
|
||
animation.Configuration = new BasicConnectedAnimationConfiguration(); | ||
animation.TryStart(ellipse); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters