Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / GameEditor.java
NoranekoFelician on 19 Nov 3 KB ・InputFieldを作成
package gameEngine;

import gameEngine.scenes.EditorScene;
import gameEngine.views.*;
import gameEngine.scenes.Scene;

public class GameEditor {
    private EditorScene scene;
    private float windowWidth, windowHeight;
    private final String frameImagePath = Window.resourcePath + "EditorFrame.png";

    private Sprite[] EditorFrameSprite = new Sprite[4];

    private Button playButton;
    private Text playButtonText;

    private Button createMeshComponentViewButton;
    private Text createMeshComponentViewButtonText;

    private Button createMoveImageComponentViewButton;
    private Text createMoveImageComponentViewButtonText;

    private Button createEntityViewButton;
    private Text createEntityViewButtonText;

    private InputField inputField;

    public GameEditor(Scene scene, float windowWidth, float windowHeight) {
        this.scene = (EditorScene) scene;
        this.windowWidth = windowWidth;
        this.windowHeight = windowHeight;
        initializeEditorComponents();
    }

    private void initializeEditorComponents() {
        createFrame();

        playButton = new Button(windowWidth/ 2 -16 , 3, 1, 0.4f);
        playButtonText = new Text(windowWidth/ 2 - 11.25f, 1, "Play", 24);

        createMeshComponentViewButton = new Button(20, 33, 3.2f, 0.5f);
        createMeshComponentViewButtonText = new Text(20 +5.25f, 30.4f, "Add Mesh", 24);

        createMoveImageComponentViewButton = new Button(20, 73, 3.2f, 0.5f);
        createMoveImageComponentViewButtonText = new Text(20 +5.25f, 70.4f, "Add MoveImage", 24);

        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();
    }

    private void setButtonListeners() {
        playButton.clearListeners();
        playButton.addListener(scene::changeSceneStart);

        createMeshComponentViewButton.clearListeners();
        createMeshComponentViewButton.addListener(scene::addNewMeshComponent);

        createMoveImageComponentViewButton.clearListeners();
        createMoveImageComponentViewButton.addListener(scene::addNewMoveImageComponent);

        createEntityViewButton.clearListeners();
        createEntityViewButton.addListener(scene::addNewEntity);
    }

    public void setScene(Scene newScene) {
        this.scene = (EditorScene) newScene;
        setButtonListeners();
    }

    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();
    }

    private void createFrame(){
        EditorFrameSprite[0] = new Sprite(frameImagePath, 0, 0, 20, 0.5f);
        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);
    }
}