[EDIT] made loginviewmodel kinda mvvm

This commit is contained in:
Sem van der Hoeven
2020-10-23 17:35:33 +02:00
parent 1d8963ec60
commit 2d64accf09

View File

@@ -20,8 +20,10 @@ namespace Client.Views
public partial class LoginScreen : Window public partial class LoginScreen : Window
{ {
ClientData data = ClientData.Instance; ClientData data = ClientData.Instance;
private LoginViewModel loginViewModel;
public LoginScreen() public LoginScreen()
{ {
loginViewModel = new LoginViewModel(this);
InitializeComponent(); InitializeComponent();
} }
@@ -29,22 +31,8 @@ namespace Client.Views
{ {
string name = usernameTextbox.Text; string name = usernameTextbox.Text;
if (name == string.Empty) return; if (name == string.Empty) return;
User user = new User(name);
Client client = new Client(user.Username);
LoginButton.IsEnabled = false; LoginButton.IsEnabled = false;
client.OnSuccessfullConnect = () => loginViewModel.UsernameEntered(name);
{
// 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();
});
};
} }