From 2d64accf09e6599dc42551ca11328f6b428bbed0 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Fri, 23 Oct 2020 17:35:33 +0200 Subject: [PATCH] [EDIT] made loginviewmodel kinda mvvm --- Client/Views/LoginScreen.xaml.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Client/Views/LoginScreen.xaml.cs b/Client/Views/LoginScreen.xaml.cs index f40641a..ac92080 100644 --- a/Client/Views/LoginScreen.xaml.cs +++ b/Client/Views/LoginScreen.xaml.cs @@ -20,8 +20,10 @@ namespace Client.Views public partial class LoginScreen : Window { ClientData data = ClientData.Instance; + private LoginViewModel loginViewModel; public LoginScreen() { + loginViewModel = new LoginViewModel(this); InitializeComponent(); } @@ -29,22 +31,8 @@ namespace Client.Views { string name = usernameTextbox.Text; if (name == string.Empty) return; - User user = new User(name); - - Client client = new Client(user.Username); LoginButton.IsEnabled = false; - client.OnSuccessfullConnect = () => - { - // because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread - Application.Current.Dispatcher.Invoke(delegate { - data.User = user; - data.Client = client; - client.SendMessage(JSONConvert.ConstructLobbyRequestMessage()); - MainWindow startWindow = new MainWindow(); - startWindow.Show(); - this.Close(); - }); - }; + loginViewModel.UsernameEntered(name); }