Ordning på spelarnas poängsummor + popup i participant och i RoundRunning när någon är på väg att vinna

This commit is contained in:
2025-10-18 09:52:49 +02:00
parent bb8f4bd5ed
commit a8ca07a1bf
7 changed files with 78 additions and 7 deletions

View File

@ -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)] = " ",
};

View File

@ -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<GamePoint> pointsRepo,
IMethodSharingService<Participant> 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<RoundBuilderElement>();
BuilderObject = new();
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
PopupVisad = false;
}
private readonly IRepository<GameRound>? _roundsRepo;
@ -41,6 +48,8 @@ public partial class RoundRunningViewModel : ObservableObject
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
//private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
//private ObservableCollection<Participant> _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<string, object>
{
[nameof(InfoPopupViewModel.Title)] = ppTitle,
[nameof(InfoPopupViewModel.Message)] = ppMessage,
[nameof(InfoPopupViewModel.Name)] = ppName,
};
_popupService.ShowPopup<InfoPopupViewModel>(
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<RoundBuilderElement> 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;