The TournamentViewer is quite ready, just the score-handling is left to wire up

This commit is contained in:
2020-05-18 23:44:18 +02:00
parent 1207617a7c
commit 8040d47acb
5 changed files with 322 additions and 4 deletions

View File

@ -77,6 +77,7 @@
<Compile Include="ViewModels\CreateTeamViewModel.cs" />
<Compile Include="ViewModels\CreateTournamentViewModel.cs" />
<Compile Include="ViewModels\ShellViewModel.cs" />
<Compile Include="ViewModels\TournamentViewerViewModel.cs" />
<Compile Include="Views\CreatePersonView.xaml.cs">
<DependentUpon>CreatePersonView.xaml</DependentUpon>
</Compile>
@ -96,6 +97,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Views\TournamentViewerView.xaml.cs">
<DependentUpon>TournamentViewerView.xaml</DependentUpon>
</Compile>
<Page Include="Views\CreatePersonView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -116,6 +120,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\TournamentViewerView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@ -29,13 +29,23 @@ namespace TrackerWPFUI.ViewModels
ActivateItem(new CreateTournamentViewModel());
}
public void LoadTournament()
{
if (SelectedTournament !=null && !string.IsNullOrWhiteSpace(SelectedTournament.TournamentName))
{
ActivateItem(new TournamentViewerViewModel(SelectedTournament));
}
}
public void Handle(TournamentModel message)
{
// Open the tournamentViewer to the given tournament
throw new NotImplementedException();
ExistingTournaments.Add(message);
SelectedTournament = message;
}
private BindableCollection<TournamentModel> _existingTournaments;
private TournamentModel _SelectedTournament;
public BindableCollection<TournamentModel> ExistingTournaments
{
@ -43,7 +53,6 @@ namespace TrackerWPFUI.ViewModels
set { _existingTournaments = value; }
}
private TournamentModel _SelectedTournament;
public TournamentModel SelectedTournament
{
@ -52,9 +61,8 @@ namespace TrackerWPFUI.ViewModels
{
_SelectedTournament = value;
NotifyOfPropertyChange(() => SelectedTournament);
LoadTournament();
}
}
}
}

View File

@ -0,0 +1,206 @@
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackerLibrary.Models;
namespace TrackerWPFUI.ViewModels
{
public class TournamentViewerViewModel : Screen
{
public TournamentModel Tournament { get; set; }
private BindableCollection<int> _rounds = new BindableCollection<int>();
private BindableCollection<MatchupModel> _matchups = new BindableCollection<MatchupModel>();
private bool _unplayedOnly;
private string _teamOne;
private string _teamTwo;
private double _teamOneScore;
private double _teamTwoScore;
private MatchupModel _selectedMatchup;
private int _selectedRound = 0;
public TournamentViewerViewModel(TournamentModel model)
{
Tournament = model;
LoadRounds();
}
public int SelectedRound
{
get { return _selectedRound; }
set
{
_selectedRound = value;
NotifyOfPropertyChange(() => SelectedRound);
LoadMatchups();
}
}
public MatchupModel SelectedMatchup
{
get { return _selectedMatchup; }
set
{
_selectedMatchup = value;
NotifyOfPropertyChange(() => SelectedMatchup);
LoadMatchup();
}
}
public double TeamTwoScore
{
get { return _teamTwoScore; }
set { _teamTwoScore = value; }
}
public double TeamOneScore
{
get { return _teamOneScore; }
set { _teamOneScore = value; }
}
public string TeamTwo
{
get { return _teamTwo; }
set
{
_teamTwo = value;
NotifyOfPropertyChange(() => TeamTwo);
}
}
public string TeamOne
{
get { return _teamOne; }
set
{
_teamOne = value;
NotifyOfPropertyChange(() => TeamOne);
}
}
public bool UnplayedOnly
{
get { return _unplayedOnly; }
set
{
_unplayedOnly = value;
NotifyOfPropertyChange(() => UnplayedOnly);
LoadMatchups();
}
}
public BindableCollection<MatchupModel> Matchups
{
get { return _matchups; }
set { _matchups = value; }
}
public BindableCollection<int> Rounds
{
get { return _rounds; }
set { _rounds = value; }
}
private void LoadRounds()
{
Rounds.Clear();
Rounds.Add(1);
int currRound = 1;
foreach (List<MatchupModel> matchups in Tournament.Rounds)
{
if (matchups.First().MatchupRound > currRound)
{
currRound = matchups.First().MatchupRound;
Rounds.Add(currRound);
}
}
SelectedRound = 1;
}
private void LoadMatchups()
{
foreach (List<MatchupModel> matchups in Tournament.Rounds)
{
if (matchups.First().MatchupRound == SelectedRound)
{
//loading = true;
Matchups.Clear();
foreach (MatchupModel mm in matchups)
{
if (mm.Winner == null || !UnplayedOnly)
{
Matchups.Add(mm);
}
}
//loading = false;
}
}
if (Matchups.Count > 0)
{
SelectedMatchup = Matchups.First();
}
}
private void LoadMatchup()
{
//if (!loading)
//{
if (SelectedMatchup == null)
{
return;
}
for (int i = 0; i < SelectedMatchup.Entries.Count; i++)
{
if (i == 0)
{
if (SelectedMatchup.Entries[0].TeamCompeting != null)
{
TeamOne = SelectedMatchup.Entries[0].TeamCompeting.TeamName;
TeamOneScore = SelectedMatchup.Entries[0].Score;
TeamTwo = "<bye>";
TeamTwoScore = 0;
}
else
{
TeamOne = "Not Yet Set";
TeamOneScore = 0;
}
}
if (i == 1)
{
if (SelectedMatchup.Entries[1].TeamCompeting != null)
{
TeamTwo = SelectedMatchup.Entries[1].TeamCompeting.TeamName;
TeamTwoScore = SelectedMatchup.Entries[1].Score;
}
else
{
TeamTwo = "Not Yet Set";
TeamTwoScore = 0;
}
}
}
//}
}
}
}

View File

@ -0,0 +1,68 @@
<UserControl x:Class="TrackerWPFUI.Views.TournamentViewerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TrackerWPFUI.Views"
mc:Ignorable="d" Background="White"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--Row 0-->
<TextBlock x:Name="TournamentName" FontSize="28" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
<!--Row 1-->
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" >
<TextBlock Margin="0 10 5 0" >Round</TextBlock>
<ComboBox x:Name="Rounds" Margin="5 10 0 0"
SelectedItem="{Binding Path=SelectedRound, Mode=TwoWay}"/>
</StackPanel>
<!--Row 2-->
<CheckBox x:Name="UnplayedOnly" Grid.Row="2" Grid.Column="0" Margin="0 10 0 0">
Unplayed Only
</CheckBox>
<!--Row 3-->
<ListBox x:Name="Matchups" Grid.Row="3" Grid.Column="0"
DisplayMemberPath="DisplayName" Grid.RowSpan="3"
Margin="0 0 5 0"
SelectedItem="{Binding Path=SelectedMatchup , Mode=TwoWay}"/>
<StackPanel Grid.Column="1" Grid.Row="3" Orientation="Vertical" >
<TextBlock x:Name="TeamOne" Margin="0 0 0 5"/>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 0">Score</TextBlock>
<TextBox x:Name="TeamOneScore" MinWidth="50"/>
</StackPanel>
</StackPanel>
<!--Row 4-->
<TextBlock Margin="0 10 0 10" Grid.Row="4" Grid.Column="1"
HorizontalAlignment="Center">
- VS -
</TextBlock>
<Button x:Name="ScoreMatch" Grid.Row="4" Grid.Column="2"
Margin="10 0 0 0" Padding="15 5" >
Score
</Button>
<!--Row 5-->
<StackPanel Grid.Column="1" Grid.Row="5" Orientation="Vertical" >
<TextBlock x:Name="TeamTwo" Margin="0 0 0 5"/>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 0">Score</TextBlock>
<TextBox x:Name="TeamTwoScore" MinWidth="50"/>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TrackerWPFUI.Views
{
/// <summary>
/// Interaction logic for TournamentViewerView.xaml
/// </summary>
public partial class TournamentViewerView : UserControl
{
public TournamentViewerView()
{
InitializeComponent();
}
}
}