package gameEngine.entites.editorComponents; import gameEngine.ResourceManager; import gameEngine.entites.EditorEntity; import gameEngine.geometry.Transform; import gameEngine.input.Input; import gameEngine.input.MouseInput; import gameEngine.views.Sprite; import gameEngine.views.Text; import gameEngine.views.Window; import org.joml.Vector3f; public class ComponentView extends DraggableComponent { public EditorEntity.Connectiontype connectionType; private final PortView portview; public int meshId = 0; public Sprite meshSprite; ResourceManager resourceManager; public ComponentView(EditorEntity parent, EditorEntity.Connectiontype connectionType, String text){ this.parent = parent; this.sprite = new Sprite(Window.resourcePath + "ComponentView.png"); sprite.updateSpriteDimensions(); this.text = new Text(parent.screenTransform.position.x, parent.screenTransform.position.y, text, 14); portview = new PortView(PortView.PortType.OUT, parent); this.connectionType = connectionType; } public ComponentView(EditorEntity parent, EditorEntity.Connectiontype connectionType, ResourceManager resourceManager, String text){ this(parent, connectionType, text); this.resourceManager = resourceManager; meshSprite = new Sprite(resourceManager.getPath(meshId)); } @Override protected void updatePortView(Vector3f actualPosition, Transform transform) { Vector3f adjustedPos = new Vector3f(actualPosition.x + 92, actualPosition.y, actualPosition.z); portview.update(adjustedPos, transform.rotation, transform.scale); portview.handleDragging(); } @Override protected void additionalUpdate(Vector3f actualPosition, Transform transform, Vector3f cameraPosition) { if (meshSprite != null) { meshSprite.setPosition(new Vector3f(actualPosition.x, actualPosition.y + 30, actualPosition.z)); meshSprite.setRotation(transform.rotation); meshSprite.setScale(transform.scale); meshSprite.update(); float mouseX = MouseInput.getX(); float mouseY = MouseInput.getY(); if (Input.GetMouseButtonDown(0) && meshSprite.isMouseOver(mouseX, mouseY)) { changeMeshSprite(); } } } private void changeMeshSprite() { meshId = (meshId + 1) % resourceManager.getPathList().size(); // 新しいスプライトを設定 String newPath = resourceManager.getPath(meshId); if (newPath != null) { meshSprite.setTexturePath(newPath); } } @Override public EditorComponent copy() { return this; } public String getSpritePath(){ if(meshId == 0) return null; return resourceManager.getPath(meshId); } }