Checkar in innan funktionen är klar
This commit is contained in:
@ -42,7 +42,7 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
RoundElements = new ObservableCollection<RoundBuilderElement>();
|
RoundElements = new ObservableCollection<RoundBuilderElement>();
|
||||||
BuilderObject = new();
|
BuilderObject = new();
|
||||||
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
|
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
|
||||||
PopupVisad = false;
|
//PopupVisad = false;
|
||||||
OnLoadedCommand = new AsyncRelayCommand(OnLoadedAsync, () => true);
|
OnLoadedCommand = new AsyncRelayCommand(OnLoadedAsync, () => true);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
|
|
||||||
private string _activePopupId;
|
private string _activePopupId;
|
||||||
|
|
||||||
public bool PopupVisad { get; set; }
|
//public bool PopupVisad { get; set; }
|
||||||
|
|
||||||
private async Task OnLoadedAsync()
|
private async Task OnLoadedAsync()
|
||||||
{
|
{
|
||||||
@ -182,24 +182,24 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
|
|
||||||
private void Show_a_Popup(string ppName, string ppTitle, string ppMessage)
|
private void Show_a_Popup(string ppName, string ppTitle, string ppMessage)
|
||||||
{
|
{
|
||||||
if (!PopupVisad)
|
//if (!PopupVisad)
|
||||||
|
//{
|
||||||
|
var queryAttributes = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
var queryAttributes = new Dictionary<string, object>
|
[nameof(InfoPopupViewModel.Title)] = ppTitle,
|
||||||
{
|
[nameof(InfoPopupViewModel.Message)] = ppMessage,
|
||||||
[nameof(InfoPopupViewModel.Title)] = ppTitle,
|
[nameof(InfoPopupViewModel.Name)] = ppName,
|
||||||
[nameof(InfoPopupViewModel.Message)] = ppMessage,
|
|
||||||
[nameof(InfoPopupViewModel.Name)] = ppName,
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_popupService.ShowPopup<InfoPopupViewModel>(
|
_popupService.ShowPopup<InfoPopupViewModel>(
|
||||||
Shell.Current,
|
Shell.Current,
|
||||||
options: PopupOptions.Empty,
|
options: PopupOptions.Empty,
|
||||||
shellParameters: queryAttributes);
|
shellParameters: queryAttributes);
|
||||||
|
|
||||||
_activePopupId = LatestPopup.valueGuid;
|
_activePopupId = LatestPopup.valueGuid;
|
||||||
|
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
|
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
|
||||||
@ -208,7 +208,7 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PopupVisad = true;
|
//PopupVisad = true;
|
||||||
await _popupService.ClosePopupAsync(Shell.Current);
|
await _popupService.ClosePopupAsync(Shell.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,10 +229,12 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
PlayerColumn player = new PlayerColumn();
|
PlayerColumn player = new PlayerColumn();
|
||||||
|
|
||||||
|
var regMax = elements.Max(e => e.GameRoundRegNr);
|
||||||
|
var existingWinning = elements.FirstOrDefault(e => e.Status == GamePointStatus.Winning);
|
||||||
|
|
||||||
foreach (var element in elements)
|
foreach (var element in elements)
|
||||||
{
|
{
|
||||||
player = PlayerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
|
player = PlayerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId)!;
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
player = new PlayerColumn
|
player = new PlayerColumn
|
||||||
@ -250,23 +252,7 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
player.PlayerPoints += element.GameRegPoints;
|
player.PlayerPoints += element.GameRegPoints;
|
||||||
if (player.PlayerPoints > 10000)
|
if (player.PlayerPoints > 10000)
|
||||||
{
|
{
|
||||||
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
|
HandlePlayerReachedWinningThreshold(player, regMax, element, playerPointsOld, existingWinning);
|
||||||
var oldStatus = winner.Status;
|
|
||||||
winner.Status = GamePointStatus.Winning;
|
|
||||||
if (playerPointsOld < 10000 && oldStatus != winner.Status)
|
|
||||||
{
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,6 +285,47 @@ public partial class RoundRunningViewModel : ObservableObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandlePlayerReachedWinningThreshold(
|
||||||
|
PlayerColumn player,
|
||||||
|
int regMax,
|
||||||
|
RoundBuilderElement element,
|
||||||
|
int playerPointsOld,
|
||||||
|
RoundBuilderElement existingWinning
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
var nextPlayer = RoundElements[AfterNext()].ParticipantName;
|
||||||
|
Debug.WriteLine($"Spelare {nextPlayer} samma som {player.PlayerName} ???.");
|
||||||
|
// Om det redan finns en vinnare, sätt dennes status tillbaka till InProgress, kanske
|
||||||
|
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
|
||||||
|
var oldStatus = winner.Status;
|
||||||
|
winner.Status = GamePointStatus.Winning;
|
||||||
|
if (playerPointsOld < 10000 && oldStatus != winner.Status && regMax == element.GameRoundRegNr)
|
||||||
|
{
|
||||||
|
//PopupVisad = false;
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int AfterNext()
|
||||||
|
{
|
||||||
|
var comingUp = nextPlayerElement();
|
||||||
|
if (RoundElements.Count - 1 == comingUp)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return comingUp;
|
||||||
|
}
|
||||||
|
|
||||||
public void BuildScore(IEnumerable<PlayerColumn> columns)
|
public void BuildScore(IEnumerable<PlayerColumn> columns)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -33,10 +33,10 @@ public static class MauiProgram
|
|||||||
builder.Services.AddDbContext<DataContext>(options =>
|
builder.Services.AddDbContext<DataContext>(options =>
|
||||||
{
|
{
|
||||||
var MauiDataPath = FileSystem.Current.AppDataDirectory;
|
var MauiDataPath = FileSystem.Current.AppDataDirectory;
|
||||||
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
|
//if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
|
||||||
{
|
//{
|
||||||
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
|
// File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
|
||||||
}
|
//}
|
||||||
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
|
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
|
||||||
options.UseSqlite($"Data Source={dbPath}");
|
options.UseSqlite($"Data Source={dbPath}");
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,10 +8,6 @@
|
|||||||
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||||
x:DataType="vm:RoundRunningViewModel"
|
x:DataType="vm:RoundRunningViewModel"
|
||||||
Title="RoundRunningView">
|
Title="RoundRunningView">
|
||||||
<!--xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"-->
|
|
||||||
<!--<ContentPage.Behaviors>
|
|
||||||
<behaviors:LoadedBehavior Command="{Binding OnLoadedCommand}" />
|
|
||||||
</ContentPage.Behaviors>-->
|
|
||||||
<Border
|
<Border
|
||||||
behaviors:LoadedBehavior.Command="{Binding OnLoadedCommand}"
|
behaviors:LoadedBehavior.Command="{Binding OnLoadedCommand}"
|
||||||
Style="{StaticResource Border.Page}" StrokeThickness="4">
|
Style="{StaticResource Border.Page}" StrokeThickness="4">
|
||||||
@ -31,6 +27,7 @@
|
|||||||
<CollectionView Grid.Row="1"
|
<CollectionView Grid.Row="1"
|
||||||
ItemsSource="{Binding RoundElements}"
|
ItemsSource="{Binding RoundElements}"
|
||||||
ItemsLayout="HorizontalList"
|
ItemsLayout="HorizontalList"
|
||||||
|
HeightRequest="110"
|
||||||
Margin="2">
|
Margin="2">
|
||||||
<CollectionView.ItemTemplate>
|
<CollectionView.ItemTemplate>
|
||||||
<DataTemplate x:DataType="model:RoundBuilderElement">
|
<DataTemplate x:DataType="model:RoundBuilderElement">
|
||||||
|
|||||||
@ -25,15 +25,15 @@
|
|||||||
ViewDescription="Välj deltagare och initiera spel" />
|
ViewDescription="Välj deltagare och initiera spel" />
|
||||||
<Border Grid.Row="1" Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" >
|
<Border Grid.Row="1" Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" >
|
||||||
<ScrollView Orientation="Horizontal">
|
<ScrollView Orientation="Horizontal">
|
||||||
<StackLayout x:Name="ResponsiveStack" Spacing="5" Style="{StaticResource ResponsiveStackStyle}" >
|
<StackLayout x:Name="ResponsiveStack" Spacing="5" HeightRequest="125" Style="{StaticResource ResponsiveStackStyle}" >
|
||||||
<Border Stroke="Gray"
|
<Border Stroke="Gray"
|
||||||
StrokeThickness="2"
|
StrokeThickness="2"
|
||||||
BackgroundColor="LightGray"
|
BackgroundColor="LightGray"
|
||||||
Padding="10"
|
Padding="10"
|
||||||
Margin="2"
|
Margin="2"
|
||||||
HorizontalOptions="Start"
|
HorizontalOptions="Start"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
WidthRequest="250">
|
WidthRequest="250">
|
||||||
<Picker ItemsSource="{Binding ParticipantList}"
|
<Picker ItemsSource="{Binding ParticipantList}"
|
||||||
ItemDisplayBinding="{Binding LastNameFirstName}"
|
ItemDisplayBinding="{Binding LastNameFirstName}"
|
||||||
SelectedItem="{Binding SelectedItem}"
|
SelectedItem="{Binding SelectedItem}"
|
||||||
@ -80,16 +80,16 @@
|
|||||||
</CollectionView>
|
</CollectionView>
|
||||||
</Border>
|
</Border>
|
||||||
<Border
|
<Border
|
||||||
HorizontalOptions="Start"
|
HorizontalOptions="Start"
|
||||||
Padding="2"
|
Padding="2"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
WidthRequest="150"
|
WidthRequest="150"
|
||||||
HeightRequest="100"
|
HeightRequest="100"
|
||||||
Stroke="LightGray"
|
Stroke="LightGray"
|
||||||
StrokeThickness="1"
|
StrokeThickness="1"
|
||||||
x:Name="RoundElementBorder"
|
x:Name="RoundElementBorder"
|
||||||
BackgroundColor="BlanchedAlmond"
|
BackgroundColor="BlanchedAlmond"
|
||||||
StrokeShape="RoundRectangle 10">
|
StrokeShape="RoundRectangle 10">
|
||||||
<VerticalStackLayout Spacing="5" Padding="4">
|
<VerticalStackLayout Spacing="5" Padding="4">
|
||||||
<Button Text="Spara omgång" WidthRequest="130"
|
<Button Text="Spara omgång" WidthRequest="130"
|
||||||
Style="{StaticResource HoverButtonBlueStyle}"
|
Style="{StaticResource HoverButtonBlueStyle}"
|
||||||
@ -119,6 +119,7 @@
|
|||||||
ItemsLayout="HorizontalList"
|
ItemsLayout="HorizontalList"
|
||||||
x:Name="InnerList"
|
x:Name="InnerList"
|
||||||
Margin="0,10,0,10"
|
Margin="0,10,0,10"
|
||||||
|
HeightRequest="90"
|
||||||
ItemSizingStrategy="MeasureAllItems">
|
ItemSizingStrategy="MeasureAllItems">
|
||||||
<CollectionView.ItemTemplate>
|
<CollectionView.ItemTemplate>
|
||||||
<DataTemplate x:DataType="model:RoundBuilderElement">
|
<DataTemplate x:DataType="model:RoundBuilderElement">
|
||||||
|
|||||||
Reference in New Issue
Block a user