Merge branch 'master' into feature/handleChatData
This commit is contained in:
@@ -8,7 +8,7 @@ using static SharedClientServer.JSONConvert;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
public delegate void OnLobbyCreated(int id);
|
||||
public delegate void LobbyCallback(int id);
|
||||
class Client : ObservableObject
|
||||
{
|
||||
private TcpClient tcpClient;
|
||||
@@ -23,7 +23,8 @@ namespace Client
|
||||
public Callback OnLobbiesListReceived;
|
||||
public Callback OnLobbyJoinSuccess;
|
||||
public Callback OnLobbiesReceivedAndWaitingForHost;
|
||||
public OnLobbyCreated OnLobbyCreated;
|
||||
public LobbyCallback OnLobbyCreated;
|
||||
public LobbyCallback OnLobbyLeave;
|
||||
private ClientData data = ClientData.Instance;
|
||||
public Lobby[] Lobbies { get; set; }
|
||||
|
||||
@@ -125,6 +126,10 @@ namespace Client
|
||||
case LobbyIdentifier.JOIN_SUCCESS:
|
||||
OnLobbyJoinSuccess?.Invoke();
|
||||
break;
|
||||
case LobbyIdentifier.LEAVE:
|
||||
int lobbyLeaveID = JSONConvert.GetLobbyID(payload);
|
||||
OnLobbyLeave?.Invoke(lobbyLeaveID);
|
||||
break;
|
||||
}
|
||||
//TODO fill lobby with the data received
|
||||
break;
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Client
|
||||
_lobbies = new ObservableCollection<Lobby>();
|
||||
client = ClientData.Instance.Client;
|
||||
client.OnLobbiesListReceived = updateLobbies;
|
||||
client.OnLobbyLeave = leaveLobby;
|
||||
|
||||
|
||||
OnHostButtonClick = new RelayCommand(hostGame);
|
||||
@@ -41,6 +42,13 @@ namespace Client
|
||||
JoinSelectedLobby = new RelayCommand(joinLobby, true);
|
||||
}
|
||||
|
||||
private void leaveLobby(int id)
|
||||
{
|
||||
_model.CanStartGame = true;
|
||||
ClientData.Instance.Lobby = null;
|
||||
SelectedLobby = null;
|
||||
}
|
||||
|
||||
private void hostGame()
|
||||
{
|
||||
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
||||
@@ -96,19 +104,6 @@ namespace Client
|
||||
Lobby[] lobbiesArr = client.Lobbies;
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
|
||||
//for (int i = 0; i < lobbiesArr.Length; i++)
|
||||
//{
|
||||
// Lobby lobby = lobbiesArr[i];
|
||||
// Debug.WriteLine(lobby.PlayersIn);
|
||||
// if (i < _lobbies.Count && _lobbies[i].ID == lobby.ID)
|
||||
// {
|
||||
// _lobbies[i].Set(lobby);
|
||||
// } else
|
||||
// {
|
||||
// _lobbies.Add(lobbiesArr[i]);
|
||||
// }
|
||||
//}
|
||||
|
||||
_lobbies.Clear();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using GalaSoft.MvvmLight.Command;
|
||||
using SharedClientServer;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
@@ -127,6 +128,13 @@ namespace Client.ViewModels
|
||||
Messages.Add($"{username}: {message}");
|
||||
});
|
||||
}
|
||||
public void LeaveGame(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Debug.WriteLine("Leaving...");
|
||||
data.Client.SendMessage(JSONConvert.ConstructLobbyLeaveMessage(data.Lobby.ID));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
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"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
mc:Ignorable="d"
|
||||
Title="Scrubl.io" Height="600" Width="1200">
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
using Client.ViewModels;
|
||||
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
|
||||
{
|
||||
@@ -24,6 +17,7 @@ namespace Client.Views
|
||||
{
|
||||
this.viewModel = new ViewModelGame();
|
||||
DataContext = this.viewModel;
|
||||
Closing += this.viewModel.LeaveGame;
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
@@ -58,5 +52,6 @@ namespace Client.Views
|
||||
{
|
||||
viewModel.Color_Picker(e, this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user