Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.4 kB
1
Indexable
Never
using DartApp.AppLogic.Contracts;
using DartApp.Domain.Contracts;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace DartApp.Presentation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private IPlayer _selectedPlayer;
        //private Visibility _showSelectedPlayer;
        private IPlayerService _playerService;
        public MainWindow(IPlayerService playerService)
        {
            InitializeComponent();
            AllPlayers = new ObservableCollection<IPlayer>();
            foreach (IPlayer player in playerService.GetAllPlayers())
            {
                AllPlayers.Add(player);
            }
            _playerService = playerService;
            DataContext = this;
        }
        public ObservableCollection<IPlayer> AllPlayers { get; set; }

        public Visibility ShowSelectedPlayer =>  SelectedPlayer == null ? Visibility.Hidden : Visibility.Visible;

        public IPlayer? SelectedPlayer 
        { 
            get => _selectedPlayer;
            set
            {
                _selectedPlayer = value;
                OnPropertyChanged(nameof(SelectedPlayer));
                OnPropertyChanged(nameof(ShowSelectedPlayer));
            }
        }

        public IPlayerStats? PlayerStats { get; set; }



        private void OnPlayerSelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void OnAddPlayerClick(object sender, RoutedEventArgs e)
        {
            var player = _playerService.AddPlayer(PlayerNameTextBox.Text);
            AllPlayers.Add(player);
            SelectedPlayer = player;
            PlayerNameTextBox.Text = "";
        }

        private void OnAddGameResultClick(object sender, RoutedEventArgs e)
        {
            
        }

        private void OnCalculateStats(object sender, RoutedEventArgs e)
        {

        }

        public event PropertyChangedEventHandler? PropertyChanged;


        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}