[ADD] added buttons reenabled when leaving
This commit is contained in:
@@ -8,7 +8,7 @@ using static SharedClientServer.JSONConvert;
|
|||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
public delegate void OnLobbyCreated(int id);
|
public delegate void LobbyCallback(int id);
|
||||||
class Client : ObservableObject
|
class Client : ObservableObject
|
||||||
{
|
{
|
||||||
private TcpClient tcpClient;
|
private TcpClient tcpClient;
|
||||||
@@ -23,7 +23,8 @@ namespace Client
|
|||||||
public Callback OnLobbiesListReceived;
|
public Callback OnLobbiesListReceived;
|
||||||
public Callback OnLobbyJoinSuccess;
|
public Callback OnLobbyJoinSuccess;
|
||||||
public Callback OnLobbiesReceivedAndWaitingForHost;
|
public Callback OnLobbiesReceivedAndWaitingForHost;
|
||||||
public OnLobbyCreated OnLobbyCreated;
|
public LobbyCallback OnLobbyCreated;
|
||||||
|
public LobbyCallback OnLobbyLeave;
|
||||||
public Lobby[] Lobbies { get; set; }
|
public Lobby[] Lobbies { get; set; }
|
||||||
|
|
||||||
public Client(string username)
|
public Client(string username)
|
||||||
@@ -118,6 +119,10 @@ namespace Client
|
|||||||
case LobbyIdentifier.JOIN_SUCCESS:
|
case LobbyIdentifier.JOIN_SUCCESS:
|
||||||
OnLobbyJoinSuccess?.Invoke();
|
OnLobbyJoinSuccess?.Invoke();
|
||||||
break;
|
break;
|
||||||
|
case LobbyIdentifier.LEAVE:
|
||||||
|
int lobbyLeaveID = JSONConvert.GetLobbyID(payload);
|
||||||
|
OnLobbyLeave?.Invoke(lobbyLeaveID);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
//TODO fill lobby with the data received
|
//TODO fill lobby with the data received
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace Client
|
|||||||
_lobbies = new ObservableCollection<Lobby>();
|
_lobbies = new ObservableCollection<Lobby>();
|
||||||
client = ClientData.Instance.Client;
|
client = ClientData.Instance.Client;
|
||||||
client.OnLobbiesListReceived = updateLobbies;
|
client.OnLobbiesListReceived = updateLobbies;
|
||||||
|
client.OnLobbyLeave = leaveLobby;
|
||||||
|
|
||||||
|
|
||||||
OnHostButtonClick = new RelayCommand(hostGame);
|
OnHostButtonClick = new RelayCommand(hostGame);
|
||||||
@@ -41,6 +42,13 @@ namespace Client
|
|||||||
JoinSelectedLobby = new RelayCommand(joinLobby, true);
|
JoinSelectedLobby = new RelayCommand(joinLobby, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void leaveLobby(int id)
|
||||||
|
{
|
||||||
|
_model.CanStartGame = true;
|
||||||
|
ClientData.Instance.Lobby = null;
|
||||||
|
SelectedLobby = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void hostGame()
|
private void hostGame()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
||||||
@@ -96,19 +104,6 @@ namespace Client
|
|||||||
Lobby[] lobbiesArr = client.Lobbies;
|
Lobby[] lobbiesArr = client.Lobbies;
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
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();
|
_lobbies.Clear();
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ namespace Server.Models
|
|||||||
case LobbyIdentifier.LEAVE:
|
case LobbyIdentifier.LEAVE:
|
||||||
id = JSONConvert.GetLobbyID(payload);
|
id = JSONConvert.GetLobbyID(payload);
|
||||||
ServerCommunication.INSTANCE.LeaveLobby(User, id);
|
ServerCommunication.INSTANCE.LeaveLobby(User, id);
|
||||||
|
sendMessage(JSONConvert.ConstructLobbyLeaveMessage(id));
|
||||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user