Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / GameEditor.java
NoranekoFelician 2 days ago 2 KB EntityViewとComponentViewをついか
package gameEngine;

import gameEngine.views.Button;
import gameEngine.scenes.Scene;
import gameEngine.views.Sprite;
import gameEngine.views.Text;
import gameEngine.views.Window;

public class GameEditor {
    private Scene scene;
    private final String frameImagePath = "GameEngine/resources/EditorFrame.png";

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

    private Button playButton;
    private Text playButtonText;

    private Button createObjectButton;
    private Text createObjectButtonText;

    private Button createComponentViewButton;
    private Text createComponentViewButtonText;

    private Button createEntityViewButton;
    private Text createEntityViewButtonText;

    public GameEditor(Scene scene) {
        this.scene = scene;
        initializeEditorComponents();
    }

    private void initializeEditorComponents() {
        createFrame();

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

        createObjectButton = new Button(20, 33, 3.2f, 0.5f);
        createObjectButtonText = new Text(20 +5.25f, 30.4f, "Add GameObject", 24);

        createComponentViewButton = new Button(20, 73, 3.2f, 0.5f);
        createComponentViewButtonText = new Text(20 +5.25f, 70.4f, "Add Component", 24);

        createEntityViewButton = new Button(20, 113, 3.2f, 0.5f);
        createEntityViewButtonText = new Text(20 +5.25f, 110.4f, "Add Entity", 24);

        setButtonListeners();
    }

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

        createObjectButton.clearListeners();
        createObjectButton.addListener(scene::addNewObject);

        createComponentViewButton.clearListeners();
        createComponentViewButton.addListener(scene::addNewComponent);

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

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

    public void update() {
        for(Sprite editorFrameSprites : EditorFrameSprite) editorFrameSprites.update();
        playButton.update();
        playButtonText.update();
        createObjectButton.update();
        createObjectButtonText.update();
        createComponentViewButton.update();
        createComponentViewButtonText.update();
        createEntityViewButton.update();
        createEntityViewButtonText.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, Window.get().width-16, 0, 0.25f, 20);
        EditorFrameSprite[3] = new Sprite(frameImagePath, 0, Window.get().height-16, 20, 0.5f);
    }
}