[CHANGED] Static function for handling to callbacks
This commit is contained in:
@@ -13,6 +13,8 @@ namespace Client
|
||||
public delegate void LobbyCallback(int id);
|
||||
public delegate void LobbyJoinCallback(bool isHost);
|
||||
public delegate void RandomWord(string word);
|
||||
public delegate void HandleIncomingMsg(string username, string msg);
|
||||
internal delegate void HandleIncomingPlayer(Lobby lobby);
|
||||
class Client : ObservableObject
|
||||
{
|
||||
private TcpClient tcpClient;
|
||||
@@ -32,6 +34,8 @@ namespace Client
|
||||
public LobbyCallback OnLobbyCreated;
|
||||
public LobbyCallback OnLobbyLeave;
|
||||
public RandomWord RandomWord;
|
||||
public HandleIncomingMsg IncomingMsg;
|
||||
public HandleIncomingPlayer IncomingPlayer;
|
||||
private ClientData data = ClientData.Instance;
|
||||
public Lobby[] Lobbies { get; set; }
|
||||
|
||||
@@ -124,7 +128,7 @@ namespace Client
|
||||
|
||||
if(textUsername != data.User.Username)
|
||||
{
|
||||
ViewModels.ViewModelGame.HandleIncomingMsg(textUsername, textMsg);
|
||||
IncomingMsg?.Invoke(textUsername, textMsg);
|
||||
}
|
||||
|
||||
//TODO display username and message in chat window
|
||||
@@ -160,7 +164,7 @@ namespace Client
|
||||
{
|
||||
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
||||
if (item.ID == data.Lobby.ID)
|
||||
ViewModels.ViewModelGame.HandleIncomingPlayer(item);
|
||||
IncomingPlayer(item);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace Client.ViewModels
|
||||
private Point currentPoint = new Point();
|
||||
private Color color;
|
||||
|
||||
public static ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
||||
public static ObservableCollection<string> Players { get; } = new ObservableCollection<string>();
|
||||
public ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
||||
public ObservableCollection<string> Players { get; } = new ObservableCollection<string>();
|
||||
|
||||
private dynamic _payload;
|
||||
|
||||
@@ -99,6 +99,8 @@ namespace Client.ViewModels
|
||||
{
|
||||
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
||||
data.Client.RandomWord = HandleRandomWord;
|
||||
data.Client.IncomingMsg = HandleIncomingMsg;
|
||||
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
||||
}
|
||||
|
||||
private void ChatBox_KeyDown()
|
||||
@@ -125,7 +127,7 @@ namespace Client.ViewModels
|
||||
* MISC make this a callback
|
||||
* Handles the incoming chat message from another client.
|
||||
*/
|
||||
public static void HandleIncomingMsg(string username, string message)
|
||||
public void HandleIncomingMsg(string username, string message)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
@@ -143,7 +145,6 @@ namespace Client.ViewModels
|
||||
}
|
||||
|
||||
/*
|
||||
* MISC make this a callback
|
||||
* Handles the random word that has been received from the server.
|
||||
*/
|
||||
public void HandleRandomWord(string randomWord)
|
||||
@@ -152,7 +153,7 @@ namespace Client.ViewModels
|
||||
Debug.WriteLine($"[CLIENT] The random word is: {_randomWord}");
|
||||
}
|
||||
|
||||
public static void HandleIncomingPlayer(Lobby lobby)
|
||||
public void HandleIncomingPlayer(Lobby lobby)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Text;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
class Lobby : INotifyPropertyChanged
|
||||
internal class Lobby : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user