[ADDED] the inlog screen and a data singleton for the client
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Client.Views;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -17,9 +18,9 @@ namespace Client
|
|||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
MainWindow startWindow = new MainWindow();
|
LoginScreen startWindow = new LoginScreen();
|
||||||
ViewModel VM = new ViewModel();
|
//ViewModel VM = new ViewModel();
|
||||||
startWindow.DataContext = VM;
|
//startWindow.DataContext = VM;
|
||||||
startWindow.Show();
|
startWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
59
Client/ClientData.cs
Normal file
59
Client/ClientData.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace Client
|
|||||||
ButtonCommand = new RelayCommand(() =>
|
ButtonCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
_lobbies = new List<Lobby>();
|
_lobbies = new List<Lobby>();
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Client.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class GameWindow : Window
|
public partial class GameWindow : Window
|
||||||
{
|
{
|
||||||
|
ClientData data = ClientData.Instance;
|
||||||
public GameWindow()
|
public GameWindow()
|
||||||
{
|
{
|
||||||
DataContext = new ViewModelGame();
|
DataContext = new ViewModelGame();
|
||||||
@@ -110,7 +110,7 @@ namespace Client.Views
|
|||||||
*/
|
*/
|
||||||
private void WriteToChat(string message)
|
private void WriteToChat(string message)
|
||||||
{
|
{
|
||||||
string user = "Monkey";
|
string user = data.User.Username;
|
||||||
SentMessage.AppendText($"{user}: {message}\n");
|
SentMessage.AppendText($"{user}: {message}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
Client/Views/LoginScreen.xaml
Normal file
29
Client/Views/LoginScreen.xaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<Window x:Class="Client.Views.LoginScreen"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Client.Views"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="LoginScreen" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="60"/>
|
||||||
|
<RowDefinition Height="50"/>
|
||||||
|
<RowDefinition Height="30"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition />
|
||||||
|
<ColumnDefinition />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<Label Grid.Row="0" FontSize="40" Content="Welcome to Scrubl.io"/>
|
||||||
|
<Label Grid.Row="1" FontSize="30" Content="Enter a username:"/>
|
||||||
|
<Label Grid.Row="2" FontSize="15" Content="(max amount of characters for the username is 10)"/>
|
||||||
|
|
||||||
|
<TextBox Name="usernameTextbox" Grid.Row="1" Grid.Column="1" MaxLength="10" FontSize="30" VerticalAlignment="Center" HorizontalAlignment="Left" Width="250"/>
|
||||||
|
<Button Content="ENTER" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="100" Height="40" Click="Button_EnterUsername"/>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
40
Client/Views/LoginScreen.xaml.cs
Normal file
40
Client/Views/LoginScreen.xaml.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace Client.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for LoginScreen.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class LoginScreen : Window
|
||||||
|
{
|
||||||
|
ClientData data = ClientData.Instance;
|
||||||
|
public LoginScreen()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_EnterUsername(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
User user = new User(usernameTextbox.Text, 0, false);
|
||||||
|
Client client = new Client();
|
||||||
|
|
||||||
|
data.User = user;
|
||||||
|
data.Client = client;
|
||||||
|
|
||||||
|
MainWindow startWindow = new MainWindow();
|
||||||
|
startWindow.Show();
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,9 +21,13 @@ namespace Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
ClientData data = ClientData.Instance;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
this.DataContext = new ViewModel();
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
usernameTextbox.Text = data.User.Username;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace Server.Models
|
|||||||
{
|
{
|
||||||
foreach(ServerClient sc in serverClients)
|
foreach(ServerClient sc in serverClients)
|
||||||
{
|
{
|
||||||
if (sc.Username == username)
|
if (sc.Username == user.Username)
|
||||||
{
|
{
|
||||||
serverClientsInlobbies[l].Add(sc);
|
serverClientsInlobbies[l].Add(sc);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Client
|
|||||||
succes = false;
|
succes = false;
|
||||||
if (_users.Count < _maxPlayers)
|
if (_users.Count < _maxPlayers)
|
||||||
{
|
{
|
||||||
_users.Add(new User(username, 0));
|
_users.Add(new User(username, 0, false));
|
||||||
succes = true;
|
succes = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user