Spelrundebilden påbörjad , kommunikation mellan bilder fungerar

This commit is contained in:
2025-09-17 12:21:11 +02:00
parent a955218c7a
commit 12002b65dd
13 changed files with 134 additions and 33 deletions

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
using GreadyPoang.EntityLayer;
namespace GreadyPoang.Services;
public class ObjectMessageService : IObjectMessageService
{
public RoundBuilderGroup CurrentGroup { get; set; }
}

View File

@ -0,0 +1,9 @@
using GreadyPoang.EntityLayer;
namespace GreadyPoang.Services;
public interface IObjectMessageService
{
RoundBuilderGroup CurrentGroup { get; set; }
}

View File

@ -10,6 +10,7 @@
<ProjectReference Include="..\Common.Library\Common.Library.csproj" /> <ProjectReference Include="..\Common.Library\Common.Library.csproj" />
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.Services\GreadyPoang.Services.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,7 +1,9 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
namespace GreadyPoang.ViewModelLayer; namespace GreadyPoang.ViewModelLayer;
@ -17,23 +19,54 @@ public class RoundRunningViewModel : ViewModelBase
IRepository<GameRound> roundsRepo, IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined ICombinedRepository combined,
IObjectMessageService objectMessage
) : base() ) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
_pointsRepo = pointsRepo; _pointsRepo = pointsRepo;
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined; _combined = combined;
_objectMessage = objectMessage;
_roundElements = new ObservableCollection<RoundBuilderElement>();
} }
private readonly IRepository<GameRound>? _roundsRepo; private readonly IRepository<GameRound>? _roundsRepo;
private readonly IRepository<GamePoint> _pointsRepo; private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined; private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private ObservableCollection<RoundBuilderElement> _roundElements;
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new(); private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new(); private ObservableCollection<Participant> _ParticipantList = new();
private ObservableCollection<RoundBuilderElement> _roundElements;
public ObservableCollection<RoundBuilderElement> RoundElements
{
get { return _roundElements; }
set
{
_roundElements = value;
RaisePropertyChanged(nameof(RoundElements));
} }
}
public ObservableCollection<RoundBuilderElement> Get()
{
if (_objectMessage.CurrentGroup != null)
{
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
if (RoundElements.Count > 0)
{
RoundElements.Clear();
}
foreach (var item in _objectMessage.CurrentGroup.Elements)
{
_roundElements.Add(item);
}
}
return RoundElements;
}
}

View File

@ -1,6 +1,7 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -18,12 +19,14 @@ public class RoundStartingViewModel : ViewModelBase
IRepository<GameRound> roundsRepo, IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base() ICombinedRepository combined,
IObjectMessageService objectMessage) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
_pointsRepo = pointsRepo; _pointsRepo = pointsRepo;
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined; _combined = combined;
_objectMessage = objectMessage;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
} }
@ -36,6 +39,7 @@ public class RoundStartingViewModel : ViewModelBase
private readonly IRepository<GamePoint> _pointsRepo; private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined; private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private Participant _selectedItem; private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements; private ObservableCollection<RoundBuilderElement> _roundElements;
@ -228,7 +232,13 @@ public class RoundStartingViewModel : ViewModelBase
public void RoundSelected(RoundBuilderElement element) public void RoundSelected(RoundBuilderElement element)
{ {
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}"); Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
if (rbGroup != null)
{
_objectMessage.CurrentGroup = rbGroup;
Shell.Current.GoToAsync("//RoundRunningView");
}
} }
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)

View File

@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang.DataLayer", "Gr
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang.Migrations", "GreadyPoang.Migrations\GreadyPoang.Migrations.csproj", "{56EB8207-E108-4498-82AC-BAC8966D3D2D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang.Migrations", "GreadyPoang.Migrations\GreadyPoang.Migrations.csproj", "{56EB8207-E108-4498-82AC-BAC8966D3D2D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang.Services", "GreadyPoang.Services\GreadyPoang.Services.csproj", "{1C70F0EC-370D-4F48-AEDD-DB171D71EA2A}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -46,6 +48,10 @@ Global
{56EB8207-E108-4498-82AC-BAC8966D3D2D}.Debug|Any CPU.Build.0 = Debug|Any CPU {56EB8207-E108-4498-82AC-BAC8966D3D2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56EB8207-E108-4498-82AC-BAC8966D3D2D}.Release|Any CPU.ActiveCfg = Release|Any CPU {56EB8207-E108-4498-82AC-BAC8966D3D2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56EB8207-E108-4498-82AC-BAC8966D3D2D}.Release|Any CPU.Build.0 = Release|Any CPU {56EB8207-E108-4498-82AC-BAC8966D3D2D}.Release|Any CPU.Build.0 = Release|Any CPU
{1C70F0EC-370D-4F48-AEDD-DB171D71EA2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C70F0EC-370D-4F48-AEDD-DB171D71EA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C70F0EC-370D-4F48-AEDD-DB171D71EA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C70F0EC-370D-4F48-AEDD-DB171D71EA2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,6 +1,7 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using System.Windows.Input; using System.Windows.Input;
@ -16,7 +17,13 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
IRepository<GameRound> roundsRepo, IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base(roundsRepo, pointsRepo, sharingService, combined) ICombinedRepository combined,
IObjectMessageService objectMessage)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage)
{ {
} }

View File

@ -1,6 +1,7 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using System.Windows.Input; using System.Windows.Input;
@ -16,7 +17,13 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
IRepository<GameRound> roundsRepo, IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base(roundsRepo, pointsRepo, sharingService, combined) ICombinedRepository combined,
IObjectMessageService objectMessage)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage)
{ {
} }

View File

@ -69,6 +69,7 @@
<ProjectReference Include="..\Common.Library\Common.Library.csproj" /> <ProjectReference Include="..\Common.Library\Common.Library.csproj" />
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.Services\GreadyPoang.Services.csproj" />
<ProjectReference Include="..\GreadyPoang.ViewModelLayer\GreadyPoang.ViewModelLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.ViewModelLayer\GreadyPoang.ViewModelLayer.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -3,6 +3,7 @@ using GreadyPoang.CommandClasses;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.DataLayer.Database; using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using GreadyPoang.Views; using GreadyPoang.Views;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -45,6 +46,8 @@ public static class MauiProgram
builder.Services.AddScoped<RoundStartingViewModelCommands>(); builder.Services.AddScoped<RoundStartingViewModelCommands>();
builder.Services.AddScoped<RoundStartingView>(); builder.Services.AddScoped<RoundStartingView>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddScoped<RoundRunningViewModelCommands>(); builder.Services.AddScoped<RoundRunningViewModelCommands>();
builder.Services.AddScoped<RoundRunningView>(); builder.Services.AddScoped<RoundRunningView>();

View File

@ -2,11 +2,12 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
x:Class="GreadyPoang.Views.RoundRunningView" x:Class="GreadyPoang.Views.RoundRunningView"
Title="RoundRunningView" xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
x:DataType="vm:RoundRunningViewModel"> xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModelCommands"
Title="RoundRunningView">
<Border Style="{StaticResource Border.Page}" StrokeThickness="4"> <Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
@ -20,20 +21,20 @@
ViewTitle="Starta eller fortsätt en registrerad Runda" ViewTitle="Starta eller fortsätt en registrerad Runda"
ViewDescription="Deltagarna visas först!" /> ViewDescription="Deltagarna visas först!" />
<CollectionView Grid.Row="1" <CollectionView Grid.Row="1"
ItemsSource="{Binding Participants}" ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList" ItemsLayout="HorizontalList"
Margin="5" Margin="5">
Padding="3">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement"> <DataTemplate x:DataType="model:RoundBuilderElement">
<Border BorderColor="Gray" Padding="10" Margin="5"> <Border Stroke="Gray" Padding="10" Margin="5">
<Border.GestureRecognizers> <Border.GestureRecognizers>
<TapGestureRecognizer <TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}" Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
CommandParameter="{Binding .}" /> CommandParameter="{Binding .}" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
<VerticalStackLayout> <VerticalStackLayout VerticalOptions="FillAndExpand">
<Label Text="Spelare" />
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" /> <Label Text="{Binding ParticipantName}" FontAttributes="Bold" />
<Label Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" /> <Label Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" />
<Label Text="{Binding Status}" /> <Label Text="{Binding Status}" />
@ -43,6 +44,7 @@
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<Label Text="{Binding RoundElements.Count, StringFormat='Antal: {0}'}" />
</Grid> </Grid>
</Border> </Border>

View File

@ -14,7 +14,8 @@ public partial class RoundRunningView : ContentPage
{ {
base.OnAppearing(); base.OnAppearing();
BindingContext = ViewModel; BindingContext = ViewModel;
ViewModel.Get();
} }
public RoundRunningViewModelCommands ViewModel { get; set; } public RoundRunningViewModelCommands ViewModel { get; set; }
public int GameRoundId { get; set; } //public int GameRoundId { get; set; }
} }