From 950915eb9f6a915dac412737d0eb2c00471c00f5 Mon Sep 17 00:00:00 2001 From: bixilon Date: Mon, 15 Jun 2020 13:37:26 +0200 Subject: [PATCH] debugUi: send chat messages --- .../bixilon/minosoft/debug/DebugWindow.java | 1 + .../minosoft/debug/gui/DebugMainWindow.java | 23 +++++++++++++------ src/main/resources/layout/debug/main.fxml | 9 ++++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java b/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java index 4e0ba9d1f..49569ef65 100644 --- a/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java +++ b/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java @@ -37,6 +37,7 @@ public class DebugWindow { // start gui uiThread = new Thread(() -> { DebugMainWindow.setHandler(handler); + DebugMainWindow.setConnection(connection); DebugMainWindow.initAndShow(); }); uiThread.start(); diff --git a/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java b/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java index b342bfb49..a44b38cb6 100644 --- a/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java +++ b/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java @@ -14,12 +14,14 @@ package de.bixilon.minosoft.debug.gui; import de.bixilon.minosoft.debug.handling.DebugUIHandler; +import de.bixilon.minosoft.protocol.network.Connection; import javafx.application.Application; import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; import javafx.scene.layout.VBox; import javafx.stage.Stage; @@ -29,6 +31,7 @@ public class DebugMainWindow extends Application { static DebugUIHandler handler; static Stage stage; static boolean initialized = false; + private static Connection connection; public static void initAndShow() { launch(); @@ -46,6 +49,10 @@ public class DebugMainWindow extends Application { return initialized; } + public static void setConnection(Connection connection) { + DebugMainWindow.connection = connection; + } + @Override public void start(Stage stage) throws IOException { @@ -56,15 +63,17 @@ public class DebugMainWindow extends Application { stage.show(); // autoscroll for chat - ((TextArea) scene.lookup("#chat")).textProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observableValue, Object o, Object t1) { - ((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE); //this will scroll to the bottom - + ((TextArea) scene.lookup("#chat")).textProperty().addListener((ChangeListener) (observableValue, o, t1) -> ((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE)); + // listen for enter in text field + TextField chatToSend = ((TextField) scene.lookup("#chatToSend")); + chatToSend.setOnKeyPressed(event -> { + if (event.getCode().equals(KeyCode.ENTER)) { + // send chat message + connection.sendChatMessage(chatToSend.getText()); + chatToSend.setText(""); } }); - DebugMainWindow.stage = stage; initialized = true; handler.initializedCallback(); diff --git a/src/main/resources/layout/debug/main.fxml b/src/main/resources/layout/debug/main.fxml index 08887e62e..0b8e1239b 100644 --- a/src/main/resources/layout/debug/main.fxml +++ b/src/main/resources/layout/debug/main.fxml @@ -2,16 +2,21 @@ + - + -