diff --git a/GameEngine/src/main/java/gameEngine/GameEditor.java b/GameEngine/src/main/java/gameEngine/GameEditor.java index fb79bb4..c32c83e 100644 --- a/GameEngine/src/main/java/gameEngine/GameEditor.java +++ b/GameEngine/src/main/java/gameEngine/GameEditor.java @@ -1,8 +1,11 @@ package gameEngine; +import gameEngine.entites.EditorEntity; +import gameEngine.geometry.Transform; import gameEngine.scenes.EditorScene; import gameEngine.views.*; import gameEngine.scenes.Scene; +import org.joml.Vector3f; import java.util.ArrayList; import java.util.Collections; @@ -28,6 +31,7 @@ private Button createEntityViewButton; private Text createEntityViewButtonText; + public InputField[][] inspectorInputFields; public GameEditor(Scene scene, float windowWidth, float windowHeight) { this.scene = (EditorScene) scene; @@ -71,11 +75,13 @@ float labelOffsetX = -100; float labelOffsetY = 5; + InputField[][] inputFields = new InputField[3][3]; + for (int i = 0; i < labels.length; i++) { float labelX = startX + labelOffsetX; float labelY = startY + i * spacingY + labelOffsetY; - Text labelText = new Text(labelX, labelY-6, labels[i] + ":", 18); + Text labelText = new Text(labelX, labelY - 6, labels[i] + ":", 18); updatableviews.add(labelText); for (int j = 0; j < axes.length; j++) { @@ -85,10 +91,48 @@ Text axisText = new Text(fieldX - 20, fieldY, axes[j] + ":", 18); InputField field = new InputField(fieldX, fieldY, fieldWidth, fieldHeight, "0", 18); + inputFields[i][j] = field; + + int transformType = i; + int axisIndex = j; + + //InputFieldの値変更時 + field.setOnChangeListener(newValue -> { + EditorEntity clickedEntity = scene.getClickedEntity(); + + System.out.println("うおおお!" + clickedEntity); + + if (clickedEntity != null) { + Transform transform = clickedEntity.transform; + float value = Float.parseFloat(newValue); + + switch (transformType) { + case 0: + if (axisIndex == 0) transform.position.x = value; + if (axisIndex == 1) transform.position.y = value; + if (axisIndex == 2) transform.position.z = value; + break; + case 1: + if (axisIndex == 0) transform.rotation.x = value; + if (axisIndex == 1) transform.rotation.y = value; + if (axisIndex == 2) transform.rotation.z = value; + break; + case 2: + if (axisIndex == 0) transform.scale.x = value; + if (axisIndex == 1) transform.scale.y = value; + if (axisIndex == 2) transform.scale.z = value; + break; + } + + clickedEntity.transform = transform; + } + }); + updatableviews.add(axisText); updatableviews.add(field); } } + this.inspectorInputFields = inputFields; } private void setButtonListeners() { @@ -121,6 +165,20 @@ for (IUpdatable updatable : updatableviews) { updatable.update(); } + + if (scene.getClickedEntity() != null) { + Transform transform = scene.getClickedEntity().transform; + + updateInspectorField(inspectorInputFields[0], transform.position); // Position + updateInspectorField(inspectorInputFields[1], transform.rotation); // Rotation + updateInspectorField(inspectorInputFields[2], transform.scale); // Scale + } + } + + public void updateInspectorField(InputField[] fields, Vector3f values) { + fields[0].setText(String.valueOf(values.x)); + fields[1].setText(String.valueOf(values.y)); + fields[2].setText(String.valueOf(values.z)); } private void createFrame(){