diff --git a/GameEngine/src/main/java/gameEngine/GameEditor.java b/GameEngine/src/main/java/gameEngine/GameEditor.java index f759374..fb79bb4 100644 --- a/GameEngine/src/main/java/gameEngine/GameEditor.java +++ b/GameEngine/src/main/java/gameEngine/GameEditor.java @@ -4,11 +4,17 @@ import gameEngine.views.*; import gameEngine.scenes.Scene; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class GameEditor { private EditorScene scene; private float windowWidth, windowHeight; private final String frameImagePath = Window.resourcePath + "EditorFrame.png"; + private List updatableviews = new ArrayList<>(); + private Sprite[] EditorFrameSprite = new Sprite[4]; private Button playButton; @@ -23,8 +29,6 @@ private Button createEntityViewButton; private Text createEntityViewButtonText; - private InputField inputField; - public GameEditor(Scene scene, float windowWidth, float windowHeight) { this.scene = (EditorScene) scene; this.windowWidth = windowWidth; @@ -47,9 +51,44 @@ createEntityViewButton = new Button(240, 33, 3.2f, 0.5f); createEntityViewButtonText = new Text(240 +5.25f, 30.4f, "Add Entity", 24); - inputField = new InputField(400,400,160,40,"InputField",32); - setButtonListeners(); + setInspector(); + } + + private void registerUpdatable(IUpdatable... components) { + Collections.addAll(updatableviews, components); + } + + private void setInspector() { + String[] labels = {"Position", "Rotation", "Scale"}; + String[] axes = {"x", "y", "z"}; + float startX = 900; + float startY = 40; + float fieldWidth = 70; + float fieldHeight = 22; + float spacingX = 100; + float spacingY = 40; + float labelOffsetX = -100; + float labelOffsetY = 5; + + 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); + updatableviews.add(labelText); + + for (int j = 0; j < axes.length; j++) { + float fieldX = startX + j * spacingX; + float fieldY = startY + i * spacingY; + + Text axisText = new Text(fieldX - 20, fieldY, axes[j] + ":", 18); + InputField field = new InputField(fieldX, fieldY, fieldWidth, fieldHeight, "0", 18); + + updatableviews.add(axisText); + updatableviews.add(field); + } + } } private void setButtonListeners() { @@ -64,6 +103,11 @@ createEntityViewButton.clearListeners(); createEntityViewButton.addListener(scene::addNewEntity); + + registerUpdatable(playButton, playButtonText, + createMeshComponentViewButton, createMeshComponentViewButtonText, + createMoveImageComponentViewButton, createMoveImageComponentViewButtonText, + createEntityViewButton, createEntityViewButtonText); } public void setScene(Scene newScene) { @@ -73,15 +117,10 @@ public void update() { for(Sprite editorFrameSprites : EditorFrameSprite) editorFrameSprites.update(); - playButton.update(); - playButtonText.update(); - createMeshComponentViewButton.update(); - createMeshComponentViewButtonText.update(); - createMoveImageComponentViewButton.update(); - createMoveImageComponentViewButtonText.update(); - createEntityViewButton.update(); - createEntityViewButtonText.update(); - inputField.update(); + + for (IUpdatable updatable : updatableviews) { + updatable.update(); + } } private void createFrame(){ @@ -89,5 +128,9 @@ EditorFrameSprite[1] = new Sprite(frameImagePath, 0, 0, 0.25f, 20); EditorFrameSprite[2] = new Sprite(frameImagePath, windowWidth-16, 0, 0.25f, 20); EditorFrameSprite[3] = new Sprite(frameImagePath, 0, windowHeight-16, 20, 0.5f); + + for (Sprite sprite : EditorFrameSprite) { + updatableviews.add(sprite); + } } }