package gameEngine.entites.editorComponents; import gameEngine.entites.EditorEntity; import gameEngine.input.Input; import gameEngine.input.MouseInput; import gameEngine.scenes.EditorScene; import gameEngine.views.Window; public abstract class Draggable extends EditorComponent { protected EditorEntity parent; protected boolean isDraggable = true; protected boolean isLeftDragging = false; protected boolean isRightDragging = false; protected float dragOffsetX = 0.0f; protected float dragOffsetY = 0.0f; public void setDraggable(boolean draggable) { this.isDraggable = draggable; } public void handleDragging() { if (!isDraggable) return; float mouseX = MouseInput.getX(); float mouseY = MouseInput.getY(); EditorScene scene = (EditorScene) Window.get().getScene(); if (scene.getSelectedEntity() == null) { if (Input.GetMouseButtonDown(0) && isMouseOver(mouseX, mouseY)) { isLeftDragging = true; scene.setSelectedEntity(parent); scene.setClickedEntity(parent); leftDragStartAction(mouseX, mouseY); // ドラッグ開始時の処理 } if (Input.GetMouseButtonDown(1) && isMouseOver(mouseX, mouseY)) { isRightDragging = true; scene.setSelectedEntity(parent); scene.setClickedEntity(parent); rightDragStartAction(mouseX, mouseY); } } if (isLeftDragging && Input.GetMouseButton(0)) { leftDraggingAction(mouseX, mouseY); // ドラッグ中の処理 } if (isRightDragging && Input.GetMouseButton(1)) { rightDraggingAction(mouseX, mouseY); // ドラッグ中の処理 } if (Input.GetMouseButtonUp(0)) { isLeftDragging = false; scene.clearSelectedObject(); } if (Input.GetMouseButtonUp(1)) { isRightDragging = false; scene.clearSelectedObject(); } } protected abstract boolean isMouseOver(float mouseX, float mouseY); protected abstract void leftDragStartAction(float mouseX, float mouseY); protected abstract void leftDraggingAction(float mouseX, float mouseY); protected abstract void rightDragStartAction(float mouseX, float mouseY); protected abstract void rightDraggingAction(float mouseX, float mouseY); }