diff --git a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs index 4d01f3c..e94fa36 100644 --- a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs @@ -52,14 +52,14 @@ public class CombinedRepository : ICombinedRepository gp.GamePointId, gp.GameRoundId, gp.GameRoundRegNr, - gp.GameRegPoints, + latest.totPoints as GameRegPoints, gr.GameRoundStartDate, gr.GameStatus AS Status, p.ParticipantId, (p.LastName || ' ' || p.FirstName) AS ParticipantName FROM GamePoints gp INNER JOIN ( - SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId + SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId, sum(GameRegPoints) AS totPoints FROM GamePoints GROUP BY ParticipantId, GameRoundId ) latest ON gp.GamePointId = latest.MaxGamePointId diff --git a/GreadyPoang.EntityLayer/Enums/GamePointStatus.cs b/GreadyPoang.EntityLayer/Enums/GamePointStatus.cs index 8b2f684..c2700de 100644 --- a/GreadyPoang.EntityLayer/Enums/GamePointStatus.cs +++ b/GreadyPoang.EntityLayer/Enums/GamePointStatus.cs @@ -5,5 +5,7 @@ public enum GamePointStatus New = 0, InProgress = 1, Completed = 2, - Cancelled = 3 + Cancelled = 3, + Winning = 4, + Winner = 5 } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs index d49ab72..33a3e1d 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs @@ -73,7 +73,7 @@ public partial class ParticipantViewModel : BaseViewModel { [nameof(InfoPopupViewModel.Title)] = "Deltagar bildens infopopup", [nameof(InfoPopupViewModel.Message)] = "Deltagare laddade", - [nameof(InfoPopupViewModel.Name)] = "Urban", + [nameof(InfoPopupViewModel.Name)] = " ", }; diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index b0adc92..6fcfac7 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -1,4 +1,5 @@ using Common.Library; +using CommunityToolkit.Maui; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using GreadyPoang.DataLayer; @@ -24,7 +25,9 @@ public partial class RoundRunningViewModel : ObservableObject IRepository pointsRepo, IMethodSharingService sharingService, ICombinedRepository combined, - IObjectMessageService objectMessage + IObjectMessageService objectMessage, + IPopupService popupService, + IPopupEventHub popupEvent ) : base() { _roundsRepo = roundsRepo; @@ -32,8 +35,12 @@ public partial class RoundRunningViewModel : ObservableObject _sharingService = sharingService; _combined = combined; _objectMessage = objectMessage; + _popupService = popupService; + _popupEvent = popupEvent; RoundElements = new ObservableCollection(); BuilderObject = new(); + _popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested; + PopupVisad = false; } private readonly IRepository? _roundsRepo; @@ -41,6 +48,8 @@ public partial class RoundRunningViewModel : ObservableObject private readonly IMethodSharingService _sharingService; private readonly ICombinedRepository _combined; private readonly IObjectMessageService _objectMessage; + private readonly IPopupService _popupService; + private readonly IPopupEventHub _popupEvent; //private ObservableCollection _GameRoundList = new(); //private ObservableCollection _ParticipantList = new(); @@ -52,6 +61,9 @@ public partial class RoundRunningViewModel : ObservableObject [ObservableProperty] private RoundBuilderElement builderObject; + public bool PopupVisad { get; set; } + + public void TriggerRebuild() { // Trigga eventet @@ -164,6 +176,30 @@ public partial class RoundRunningViewModel : ObservableObject return -1; } + private void Show_a_Popup(string ppName, string ppTitle, string ppMessage) + { + if (!PopupVisad) + { + var queryAttributes = new Dictionary + { + [nameof(InfoPopupViewModel.Title)] = ppTitle, + [nameof(InfoPopupViewModel.Message)] = ppMessage, + [nameof(InfoPopupViewModel.Name)] = ppName, + + }; + + _popupService.ShowPopup( + Shell.Current, + options: PopupOptions.Empty, + shellParameters: queryAttributes); + } + } + + private async void infoPopupViewModel_ClosePopupRequested(object? sender, EventArgs e) + { + PopupVisad = true; + await _popupService.ClosePopupAsync(Shell.Current); + } private void FillupResultTable(IEnumerable elements) @@ -199,7 +235,27 @@ public partial class RoundRunningViewModel : ObservableObject if (element.GameRegPoints > 0) { player.Values.Add(element.GameRegPoints.ToString()); + var playerPointsOld = player.PlayerPoints; player.PlayerPoints += element.GameRegPoints; + if (player.PlayerPoints > 10000) + { + var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId); + winner.Status = GamePointStatus.Winning; + if (playerPointsOld < 10000) + { + Show_a_Popup( + player.PlayerName, + "Se upp för denne spelare !", + $"Du har nått en poängnivå över 10000 ({player.PlayerPoints})\r" + + $"Alla övriga får nu en chans att överträffa\r" + + $"om någon kommer till samma poäng som\r" + + $"{player.PlayerName}\r" + + $"får hen försvara sig med nytt kast\r" + + $"Om kastet inte blir godkänt (ger poäng)\r" + + $"Vinner den upphinnande spelaren" + ); + } + } } //oldPart = element.ParticipantId; diff --git a/GreadyPoang/Popups/InfoPopup.xaml b/GreadyPoang/Popups/InfoPopup.xaml index 16fcddc..e87647c 100644 --- a/GreadyPoang/Popups/InfoPopup.xaml +++ b/GreadyPoang/Popups/InfoPopup.xaml @@ -10,8 +10,9 @@ x:DataType="viewModels:InfoPopupViewModel" BackgroundColor="Transparent"> -