private void sendMessage_Click(object sender, RoutedEventArgs e) { MessageObject tmpMsg = new MessageObject() { Who = userNameHidden, Type = "text", Data = chattTextBox.Text }; CurrentChatMessages.Add(tmpMsg); db.addToDB(tmpMsg); chattBox.SelectedIndex = CurrentChatMessages.Count - 1; chattBox.ScrollIntoView(chattBox.SelectedItem); try { try { CurrentClient.send_message("{'type': 'message', 'message': '" + chattTextBox.Text + "'}"); } catch (NullReferenceException n) { Console.WriteLine("NullReferenceException: {0}", e); throw new ConnectionException(); } } catch (ConnectionException ce) { Console.WriteLine("connectionException: {0}", ce); System.Windows.MessageBox.Show("Can't send message if not connected", "Connection Error"); } chattTextBox.Text = ""; chattTextBox.Focus(); }
private void sendImage_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|GIF Files (*.gif)|*.gif"; dlg.DefaultExt = ".png"; Nullable <bool> result = dlg.ShowDialog(); if (result.HasValue && result.Value) { string filename = dlg.SafeFileName; byte[] imageArray = System.IO.File.ReadAllBytes(dlg.FileName); System.IO.File.Copy(dlg.FileName, System.AppDomain.CurrentDomain.BaseDirectory + "/assets/img/" + dlg.SafeFileName, true); MessageObject tmpMsg = new MessageObject() { Who = userNameHidden, Type = "image", Data = dlg.SafeFileName }; CurrentChatMessages.Add(tmpMsg); db.addToDB(tmpMsg); CurrentClient.send_image(imageArray, filename); } chattBox.SelectedIndex = CurrentChatMessages.Count - 1; chattBox.ScrollIntoView(chattBox.SelectedItem); }
protected override void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); if (World.GameState == GameState.Uninitialized) { return; } else if (World.GameState == GameState.PregameMenu && !Components.Contains(preGameMenuPanel)) { Components.Clear(); Components.Add(preGameMenuPanel); KeyboardDispatcher.Subscriber = null; usernameTextbox.OnEnterPressed -= loginTBEvent; passwordTextbox.OnEnterPressed -= loginTBEvent; confirmPasswordTextbox.OnEnterPressed -= registerTBEvent; if (!FXCollection.Songs[Songs.PreGame].Playing) { FXCollection.Songs[Songs.PreGame].Play(); } if (FXCollection.Songs[Songs.InGame].Playing) { FXCollection.Songs[Songs.InGame].Stop(); } if (!backgroundPanel.Components.Contains(background)) { backgroundPanel.Components.Add(background); } if (!backgroundPanel.Components.Contains(PreGameMenu)) { backgroundPanel.Components.Add(PreGameMenu); } } else if (World.GameState == GameState.Login && !Components.Contains(loginPanel)) { loginPanel.ClearTextBoxes(); //if going back to the login screen clear the previously typed data out of the text boxes Components.Clear(); Components.Add(loginPanel); KeyboardDispatcher.Subscriber = usernameTextbox; cancelHyperlink.DrawLocation = new Vector2(cancelHyperlink.DrawLocation.X, GraphicsDevice.Viewport.Height / 2 + 30); usernameTextbox.OnEnterPressed -= registerTBEvent; passwordTextbox.OnEnterPressed -= registerTBEvent; passwordTextbox.OnTabPressed -= subscribeToConfirmBox; confirmPasswordTextbox.OnEnterPressed -= registerTBEvent; usernameTextbox.OnEnterPressed += loginTBEvent; passwordTextbox.OnEnterPressed += loginTBEvent; passwordTextbox.OnTabPressed += subscribeToUsernameBox; if (!FXCollection.Songs[Songs.PreGame].Playing) { FXCollection.Songs[Songs.PreGame].Play(); } if (FXCollection.Songs[Songs.InGame].Playing) { FXCollection.Songs[Songs.InGame].Stop(); } if (backgroundPanel.Components.Contains(PreGameMenu)) { backgroundPanel.Components.Remove(PreGameMenu); } } else if (World.GameState == GameState.InGame && !Components.Contains(inGamePanel)) { InputHandler.PreviousState = state; Components.Clear(); Components.Add(inGamePanel); //the text boxes are ALWAYS listening (because the subscriber listening for an enter keypress works outside of the game component model) usernameTextbox.OnEnterPressed -= loginTBEvent; passwordTextbox.OnEnterPressed -= loginTBEvent; confirmPasswordTextbox.OnEnterPressed -= registerTBEvent; if (FXCollection.Songs[Songs.PreGame].Playing) { FXCollection.Songs[Songs.PreGame].Stop(); } if (!FXCollection.Songs[Songs.InGame].Playing) { FXCollection.Songs[Songs.InGame].Play(); } } else if (World.GameState == GameState.Register && !Components.Contains(registerPanel)) { Components.Clear(); Components.Add(registerPanel); KeyboardDispatcher.Subscriber = usernameTextbox; cancelHyperlink.DrawLocation = new Vector2(cancelHyperlink.DrawLocation.X, GraphicsDevice.Viewport.Height / 2 + 80); usernameTextbox.OnEnterPressed -= loginTBEvent; passwordTextbox.OnEnterPressed -= loginTBEvent; passwordTextbox.OnTabPressed -= subscribeToUsernameBox; confirmPasswordTextbox.OnEnterPressed += registerTBEvent; usernameTextbox.OnEnterPressed += registerTBEvent; passwordTextbox.OnEnterPressed += registerTBEvent; passwordTextbox.OnTabPressed += subscribeToConfirmBox; if (!FXCollection.Songs[Songs.PreGame].Playing) { FXCollection.Songs[Songs.PreGame].Play(); } if (FXCollection.Songs[Songs.InGame].Playing) { FXCollection.Songs[Songs.InGame].Stop(); } if (backgroundPanel.Components.Contains(PreGameMenu)) { backgroundPanel.Components.Remove(PreGameMenu); } } else if (World.GameState == GameState.HowToPlay && !Components.Contains(howToPlayPanel)) { Components.Clear(); Components.Add(howToPlayPanel); if (backgroundPanel.Components.Contains(PreGameMenu)) { backgroundPanel.Components.Remove(PreGameMenu); } } if (state.IsKeyDown(Keys.Escape) && !previousState.IsKeyDown(Keys.Escape)) { if (World.GameState == GameState.Login || World.GameState == GameState.Register || World.GameState == GameState.HowToPlay) { FXCollection.SoundEffects[SoundEffects.Select].Play(); usernameTextbox.Text = ""; passwordTextbox.Text = ""; confirmPasswordTextbox.Text = ""; World.GameState = GameState.PregameMenu; } } // Render new text messages if (World.GameState == GameState.InGame) { if (untexturedChatMessages.Count > 0) { foreach (var pair in untexturedChatMessages) { CurrentChatMessages.Add(pair.Key, chatRenderer.GenerateTexture(pair.Value)); } untexturedChatMessages.Clear(); } } //We have an in-game dialog (for teh winz) change the mouse visibility. If a dialog is open, DON'T CHANGE IT BACK! if (XNADialog.ModalDialogs != null && XNADialog.ModalDialogs.Count == 0) { IsMouseVisible = World.GameState == GameState.Login || World.GameState == GameState.Register || World.GameState == GameState.LoggingIn || World.GameState == GameState.Registering || World.GameState == GameState.PregameMenu || World.GameState == GameState.HowToPlay; } previousState = state; foreach (LoopedSoundPlayer player in FXCollection.Songs) { player.Update(); } base.Update(gameTime); }