Files
Csharp-eindproject/Client/ViewModels/LoginViewModel.cs
2020-10-23 21:05:05 +02:00

38 lines
1.1 KiB
C#

using SharedClientServer;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
namespace Client.ViewModels
{
class LoginViewModel
{
ClientData data = ClientData.Instance;
private Window window;
public LoginViewModel(Window window)
{
this.window = window;
}
public void UsernameEntered(string name) {
User user = new User(name);
Client client = new Client(user.Username);
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();
window.Close();
});
};
}
}
}