From 84bf1b3e6445bf3828f0b588ec726275f054737e Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 20 Oct 2020 16:36:34 +0200 Subject: [PATCH] [ADDED] the inlog screen and a data singleton for the client --- Client/App.xaml.cs | 9 +++-- Client/ClientData.cs | 59 ++++++++++++++++++++++++++++ Client/ViewModels/ViewModel.cs | 2 +- Client/Views/GameWindow.xaml.cs | 4 +- Client/Views/LoginScreen.xaml | 29 ++++++++++++++ Client/Views/LoginScreen.xaml.cs | 40 +++++++++++++++++++ Client/Views/MainWindow.xaml.cs | 4 ++ Server/Models/ServerCommunication.cs | 2 +- SharedClientServer/Lobby.cs | 2 +- 9 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 Client/ClientData.cs create mode 100644 Client/Views/LoginScreen.xaml create mode 100644 Client/Views/LoginScreen.xaml.cs diff --git a/Client/App.xaml.cs b/Client/App.xaml.cs index 30a075c..9f2324b 100644 --- a/Client/App.xaml.cs +++ b/Client/App.xaml.cs @@ -1,4 +1,5 @@ -using System; +using Client.Views; +using System; using System.Collections.Generic; using System.Configuration; using System.Data; @@ -17,9 +18,9 @@ namespace Client protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); - MainWindow startWindow = new MainWindow(); - ViewModel VM = new ViewModel(); - startWindow.DataContext = VM; + LoginScreen startWindow = new LoginScreen(); + //ViewModel VM = new ViewModel(); + //startWindow.DataContext = VM; startWindow.Show(); } diff --git a/Client/ClientData.cs b/Client/ClientData.cs new file mode 100644 index 0000000..9442e8d --- /dev/null +++ b/Client/ClientData.cs @@ -0,0 +1,59 @@ +using SharedClientServer; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace Client +{ + class ClientData + { + private static ClientData _instance; + private static readonly object padlock = new object(); + + public static ClientData Instance + { + get + { + lock (padlock) + { + if (_instance == null) + { + _instance = new ClientData(); + } + return _instance; + } + } + } + + + private User _user; + private Client _client; + private Lobby _lobby; + + private ClientData() + { + + } + + + public User User + { + get { return _user; } + set { _user = value; } + } + + public Client Client + { + get { return _client; } + set { _client = value; } + } + + public Lobby Lobby + { + get { return _lobby; } + set { _lobby = value; } + } + + } +} diff --git a/Client/ViewModels/ViewModel.cs b/Client/ViewModels/ViewModel.cs index 241b520..fb310bf 100644 --- a/Client/ViewModels/ViewModel.cs +++ b/Client/ViewModels/ViewModel.cs @@ -18,7 +18,7 @@ namespace Client ButtonCommand = new RelayCommand(() => { Client client = new Client(); - }); + }, true); _lobbies = new List(); diff --git a/Client/Views/GameWindow.xaml.cs b/Client/Views/GameWindow.xaml.cs index 0b609ba..aacc67e 100644 --- a/Client/Views/GameWindow.xaml.cs +++ b/Client/Views/GameWindow.xaml.cs @@ -18,7 +18,7 @@ namespace Client.Views /// public partial class GameWindow : Window { - + ClientData data = ClientData.Instance; public GameWindow() { DataContext = new ViewModelGame(); @@ -110,7 +110,7 @@ namespace Client.Views */ private void WriteToChat(string message) { - string user = "Monkey"; + string user = data.User.Username; SentMessage.AppendText($"{user}: {message}\n"); } } diff --git a/Client/Views/LoginScreen.xaml b/Client/Views/LoginScreen.xaml new file mode 100644 index 0000000..e011780 --- /dev/null +++ b/Client/Views/LoginScreen.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + +