From d575d7ea674246153e055ee29cc6cf952aa3ceec Mon Sep 17 00:00:00 2001 From: Tom Martin Date: Mon, 18 Jul 2022 16:28:15 +0100 Subject: [PATCH 1/2] Add entity position fields to allow user to position the entity --- .../chunky/ui/render/tabs/EntitiesTab.java | 80 +++++++++++++------ .../chunky/ui/render/tabs/EntitiesTab.fxml | 41 ++++++++++ 2 files changed, 95 insertions(+), 26 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/EntitiesTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/EntitiesTab.java index d2d28b3eed..0be0f4478e 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/EntitiesTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/EntitiesTab.java @@ -28,12 +28,12 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.*; -import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import javafx.stage.FileChooser; import se.llbit.chunky.entity.ArmorStand; import se.llbit.chunky.entity.BeaconBeam; @@ -45,6 +45,7 @@ import se.llbit.chunky.entity.Poseable; import se.llbit.chunky.renderer.scene.PlayerModel; import se.llbit.chunky.renderer.scene.Scene; +import se.llbit.chunky.ui.DoubleTextField; import se.llbit.chunky.ui.dialogs.DialogUtils; import se.llbit.chunky.ui.dialogs.ValidatingTextInputDialog; import se.llbit.chunky.ui.elements.AngleAdjuster; @@ -52,6 +53,7 @@ import se.llbit.chunky.ui.IntegerAdjuster; import se.llbit.chunky.ui.IntegerTextField; import se.llbit.chunky.ui.controller.RenderControlsFxController; +import se.llbit.chunky.ui.elements.TextFieldLabelWrapper; import se.llbit.chunky.ui.render.RenderControlsTab; import se.llbit.chunky.world.material.BeaconBeamMaterial; import se.llbit.fx.LuxColorPicker; @@ -117,28 +119,21 @@ public String getKind() { } } - @FXML - private TableView entityTable; - @FXML - private TableColumn nameCol; - @FXML - private TableColumn kindCol; - @FXML - private Button delete; - @FXML - private Button add; - @FXML - private Button cameraToPlayer; - @FXML - private Button playerToCamera; - @FXML - private Button playerToTarget; - @FXML - private Button faceCamera; - @FXML - private Button faceTarget; - @FXML - private VBox controls; + @FXML private TableView entityTable; + @FXML private TableColumn nameCol; + @FXML private TableColumn kindCol; + @FXML private Button delete; + @FXML private Button add; + @FXML private Button cameraToPlayer; + @FXML private Button playerToCamera; + @FXML private Button playerToTarget; + @FXML private Button faceCamera; + @FXML private Button faceTarget; + @FXML private GridPane position; + @FXML private DoubleTextField posX; + @FXML private DoubleTextField posY; + @FXML private DoubleTextField posZ; + @FXML private VBox controls; public EntitiesTab() throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("EntitiesTab.fxml")); @@ -422,6 +417,32 @@ else if(entity instanceof BeaconBeam) { controls.getChildren().add(beamColor); } + updatePositionFields(entity); + posX.valueProperty().addListener((observable, oldValue, newValue) -> { + withEntity(e -> { + Vector3 currentPosition = e.getPosition(); + e.setPosition(new Vector3(newValue.doubleValue(), currentPosition.y, currentPosition.z)); + }); + scene.rebuildActorBvh(); + }); + posY.valueProperty().addListener((observable, oldValue, newValue) -> { + withEntity(e -> { + Vector3 currentPosition = e.getPosition(); + e.setPosition(new Vector3(currentPosition.x, newValue.doubleValue(), currentPosition.z)); + }); + scene.rebuildActorBvh(); + }); + posZ.valueProperty().addListener((observable, oldValue, newValue) -> { + withEntity(e -> { + Vector3 currentPosition = e.getPosition(); + e.setPosition(new Vector3(currentPosition.x, currentPosition.y, newValue.doubleValue())); + }); + scene.rebuildActorBvh(); + }); + + controls.getChildren().add(position); + position.setVisible(true); + DoubleAdjuster scale = new DoubleAdjuster(); scale.setName("Scale"); scale.setTooltip("Modifies entity scale."); @@ -588,6 +609,7 @@ public void initialize(URL location, ResourceBundle resources) { playerToCamera.setTooltip(new Tooltip("Move the selected player to the camera position.")); playerToCamera.setOnAction(e -> withEntity(entity -> { entity.setPosition(scene.camera().getPosition()); + updatePositionFields(entity); scene.rebuildActorBvh(); })); playerToTarget.setTooltip(new Tooltip("Move the selected player to the current target.")); @@ -595,6 +617,7 @@ public void initialize(URL location, ResourceBundle resources) { Vector3 target = scene.getTargetPosition(); if (target != null) { player.position.set(target); + updatePositionFields(player); scene.rebuildActorBvh(); } })); @@ -606,8 +629,7 @@ public void initialize(URL location, ResourceBundle resources) { scene.rebuildActorBvh(); } })); - faceTarget - .setTooltip(new Tooltip("Makes the selected player look at the current view target.")); + faceTarget.setTooltip(new Tooltip("Makes the selected player look at the current view target.")); faceTarget.setOnAction(e -> withEntity(entity -> { Vector3 target = scene.getTargetPosition(); if (target != null && entity instanceof Poseable) { @@ -649,6 +671,12 @@ private void withPose(Entity entity, String part, Consumer consumer) } } + private void updatePositionFields(Entity entity) { + posX.valueProperty().set(entity.position.x); + posY.valueProperty().set(entity.position.y); + posZ.valueProperty().set(entity.position.z); + } + @Override public void setController(RenderControlsFxController controller) { scene = controller.getRenderController().getSceneManager().getScene(); diff --git a/chunky/src/res/se/llbit/chunky/ui/render/tabs/EntitiesTab.fxml b/chunky/src/res/se/llbit/chunky/ui/render/tabs/EntitiesTab.fxml index 27b2853376..c77f308373 100644 --- a/chunky/src/res/se/llbit/chunky/ui/render/tabs/EntitiesTab.fxml +++ b/chunky/src/res/se/llbit/chunky/ui/render/tabs/EntitiesTab.fxml @@ -8,6 +8,13 @@ + + + + + + + @@ -33,6 +40,40 @@