From 0d44b2d840965db61a766e718b89500656a838b2 Mon Sep 17 00:00:00 2001 From: Dogukan Date: Fri, 23 Oct 2020 11:30:06 +0200 Subject: [PATCH] [TRY] tried to bind the label data, doesn't work yet --- Client/Client.cs | 5 +++-- Client/ViewModels/ViewModelGame.cs | 24 ++++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index fc73ac8..0a1ea72 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -179,9 +179,10 @@ namespace Client case JSONConvert.RANDOMWORD: //Flag byte for receiving the random word. int lobbyId = JSONConvert.GetLobbyID(payload); + string randomWord = JSONConvert.GetRandomWord(payload); - if(data.Lobby?.ID == lobbyId) - ViewModels.ViewModelGame.HandleRandomWord(JSONConvert.GetRandomWord(payload)); + if (data.Lobby?.ID == lobbyId) + ViewModels.ViewModelGame.HandleRandomWord(randomWord); break; default: Debug.WriteLine("[CLIENT] Received weird identifier: " + id); diff --git a/Client/ViewModels/ViewModelGame.cs b/Client/ViewModels/ViewModelGame.cs index 224a1c8..67be443 100644 --- a/Client/ViewModels/ViewModelGame.cs +++ b/Client/ViewModels/ViewModelGame.cs @@ -1,5 +1,6 @@ using Client.Views; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using SharedClientServer; using System.Collections.Generic; @@ -24,19 +25,17 @@ namespace Client.ViewModels private Color color; public static ObservableCollection Messages { get; } = new ObservableCollection(); - public static ObservableCollection Players { get; } = new ObservableCollection(); private dynamic _payload; - public static string Word + private static string _randomWord; + public string RandomWord { - get; - set; + get { return _randomWord; } + set { _randomWord = value; } } - public string _username; - public string _message; public string Message { @@ -107,13 +106,13 @@ namespace Client.ViewModels Message = string.Empty; } - internal void AddMessage(string message) + internal void AddMessage(string incomingMessage) { - Messages.Add($"{data.User.Username}: {message}"); + Messages.Add($"{data.User.Username}: {incomingMessage}"); _payload = new { username = data.User.Username, - message = message + message = incomingMessage }; //Broadcast the message after adding it to the list! @@ -147,11 +146,8 @@ namespace Client.ViewModels */ public static void HandleRandomWord(string randomWord) { - Debug.WriteLine("[CLIENT] Reached the handle random word method!"); - Application.Current.Dispatcher.Invoke(delegate - { - Word = randomWord; - }); + _randomWord = randomWord; + Debug.WriteLine($"[CLIENT] The random word is: {_randomWord}"); } public static void HandleIncomingPlayer(Lobby lobby)