package gameEngine.scenes; import gameEngine.ConnectionManager; import gameEngine.GameEditor; import gameEngine.entites.Entity; import gameEngine.entites.GameObject; import gameEngine.entites.gameComponents.ComponentView; import gameEngine.entites.gameComponents.Draggable; import gameEngine.entites.gameComponents.EntityView; import gameEngine.entites.gameComponents.TextMesh; import gameEngine.views.Color; import gameEngine.views.Window; import org.joml.Vector3f; import java.util.HashMap; import static org.lwjgl.opengl.GL11.glClearColor; public class EditorScene extends Scene { private static GameEditor gameEditor; public HashMap<String, Entity> editorEntities = new HashMap<>(); private GameObject selectedObject = null; public ConnectionManager connectionManager = new ConnectionManager(); public EditorScene(float windowWidth, float windowHeight){ System.out.println("Active Editor scene"); gameEditor = new GameEditor(this, windowWidth, windowHeight); gameEditor.setScene(this); glClearColor(1, 1, 1, 0); } @Override public void update(float dt) { updateDraggable(); changeScene(1, dt); //Gameシーンへの以降処理 connectionManager.update(); for (Entity entity : editorEntities.values()) { if (entity instanceof GameObject) { GameObject gameObject = (GameObject) entity; gameObject.updateComponents(); } } gameEditor.update(); } public Entity getEditorEntity(String eid) { return editorEntities.get(eid); } public void addEditorEntity(String eid, Entity entity) { editorEntities.put(eid, entity); } public void removeEditorEntity(String eid) { editorEntities.remove(eid); } private GameObject createGameObject(){ int entitiesLength = editorEntities.size(); String newId = Integer.toString(entitiesLength); GameObject gameObject = new GameObject(newId); addEditorEntity(newId, gameObject); return gameObject; } public Runnable addNewEntity() { enqueueTask(this::addEntityView); return null; } private void addEntityView(){ GameObject object = createGameObject(); object.transform.setPosition((float) Window.get().width / 2 ,(float) Window.get().height /2, 0); object.addComponent(new EntityView(object)); object.addComponent(new TextMesh(object, "Entity", 16)); object.getComponent(TextMesh.class).setLocalPosition(new Vector3f(0,-20,0)); } public Runnable addNewMeshComponent() { enqueueTask(this::addMeshComponentView); return null; } private void addMeshComponentView(){ GameObject object = createGameObject(); object.transform.setPosition((float) Window.get().width / 2 ,(float) Window.get().height /2, 0); object.addComponent(new ComponentView(object, GameObject.Connectiontype.Mesh)); object.addComponent(new TextMesh(object, "Mesh", 20)); object.getComponent(TextMesh.class).setLocalPosition(new Vector3f(10,2,0)); } public Runnable addNewMoveImageComponent() { enqueueTask(this::addMoveImageComponentView); return null; } private void addMoveImageComponentView(){ GameObject object = createGameObject(); object.transform.setPosition((float) Window.get().width / 2 ,(float) Window.get().height /2, 0); object.addComponent(new ComponentView(object, GameObject.Connectiontype.MoveImage)); object.addComponent(new TextMesh(object, "MoveImage", 20)); object.getComponent(TextMesh.class).setLocalPosition(new Vector3f(10,2,0)); } ///---------------------------------------------------------------- /// 選択、ドラッグ処理 ///---------------------------------------------------------------- public GameObject getSelectedObject() { return selectedObject; } public void setSelectedObject(GameObject gameObject) { selectedObject = gameObject; System.out.println("Selected Entity: " + selectedObject); } public void clearSelectedObject() { selectedObject = null; } public void updateDraggable() { if (selectedObject != null) { if (selectedObject.getComponent(Draggable.class) != null) { selectedObject.getComponent(Draggable.class).handleDragging(); } } else { for (Entity entity : editorEntities.values()) { if (entity instanceof GameObject gameObject) { if (gameObject.getComponent(Draggable.class) != null) { gameObject.getComponent(Draggable.class).handleDragging(); } } } } } }