diff --git a/TODO.md b/TODO.md index 1c930214..774284ab 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ # 1 * new InputComponent interacting with MapComponent - * (map) zooming + * (map) zooming (<<<<<<<--------------------------------) * add sortable physics modifier components * NULLImplementations -> Optionals ... * @@ -12,8 +12,6 @@ * add pre-click-event (preclick, click, doublecklic) events * * UI/MAP: - * panning - * zooming (scaling) * add scale bar * add measurement tool * add menu diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java index 27f75ec5..720354f5 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicComponent.java @@ -19,7 +19,7 @@ public void update(final long elapsedNanoTime) { physicsCoreComponent.setPositionX(newPositionX); physicsCoreComponent.setPositionY(newPositionY); - final double restoringForce = physicsCoreComponent.getRestoringForce(); + final double restoringForce = physicsCoreComponent.getFrictionForce(); if (restoringForce != 0) { double newVelocityX = applyRestoringForce(physicsCoreComponent.getVelocityXComponent(), restoringForce); double newVelocityY = applyRestoringForce(physicsCoreComponent.getVelocityYComponent(), restoringForce); diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java index a55a13ec..5c75a85b 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/entitycomponentsystem/component/PhysicCoreComponent.java @@ -17,7 +17,7 @@ public class PhysicCoreComponent extends ComponentTemplate { private double dragInNewton = 1.0; - private double restoringForce = 0; + private double frictionForce = 0; public PhysicCoreComponent() { diff --git a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/JavaFxMouseButtonCommandMapper.java b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/JavaFxMouseButtonCommandMapper.java index 3d1f6c0e..94294019 100644 --- a/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/JavaFxMouseButtonCommandMapper.java +++ b/libs/tacviewfx/src/main/java/com/recom/tacview/engine/input/mapper/mousebutton/JavaFxMouseButtonCommandMapper.java @@ -39,7 +39,6 @@ private void startMachines() { mouseButtonEventFSMs.forEach(IsMouseButtonEventFSM::start); } - @Override @SuppressWarnings("unchecked") public boolean mapEvents(@NonNull final Stream> timedMouseEventStream) { diff --git a/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java b/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java index 5309c0e1..0f1f1eac 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java +++ b/services/recom-commander/src/main/java/com/recom/commander/configuration/RECOMMapEntityConfiguration.java @@ -17,7 +17,7 @@ public RECOMMapEntity getRECOMMapEntity(@NonNull final RECOMMapComponent recomMa final RECOMMapEntity recomMapEntity = new RECOMMapEntity(); final PhysicCoreComponent component = new PhysicCoreComponent(); - component.setRestoringForce(100); + component.setFrictionForce(100); recomMapEntity.addComponent(recomMapComponent); recomMapEntity.addComponent(new RECOMMapInputComponent()); diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java index 3c5d3b3a..09931779 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapComponent.java @@ -39,6 +39,8 @@ public class RECOMMapComponent extends RenderableComponent implements AutoClosea @Nullable private ReactiveObserver mapTopographyDataReactiveObserver; + private int pixelFactor = 1; + public RECOMMapComponent( @NonNull final MapsOverviewService mapsOverviewService, @@ -52,7 +54,6 @@ public RECOMMapComponent( this.setZIndex(0); } - @PostConstruct public void init() { mapOverviewReactiveObserver = ReactiveObserver.reactWith(onReloadMapOverviewReaction()); @@ -115,4 +116,26 @@ public void close() { } } + public void zoomIn() { + if (pixelFactor == 1) { + return; + } else { + pixelFactor--; + swapBuffer(); + } + } + + public void zoomOut() { + pixelFactor++; + swapBuffer(); + } + + private void swapBuffer() { + // @TODO <<<<--------------------------------------------------------------------------------------------------- + // swap buffer this.pixelBuffer = new PixelBuffer(dimension, pixelBufferArray); + + // create LinkedList pixelBufferList + // init first element with actual buffer! + } + } diff --git a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java index bc3e5014..fc076a09 100644 --- a/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java +++ b/services/recom-commander/src/main/java/com/recom/commander/enginemodule/entity/recommapentity/component/RECOMMapInputComponent.java @@ -15,60 +15,85 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.util.Optional; + @Slf4j @Component public class RECOMMapInputComponent extends InputComponent { - private static final float velocityX = 140f; + private static final float MOVING_FORCE = 140f; private static final int DRAG_SPEED_COEFFICIENT = 4; + @NonNull + private Optional maybeMapComponent = Optional.empty(); + @Override public void handleInputCommand(@NonNull final IsCommand inputCommand) { switch (inputCommand) { - case KeyboardCommand keyboardCommand -> { - this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { - if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.LEFT)) { - physicsCoreComponent.addVelocityXComponent(velocityX); - } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.RIGHT)) { - physicsCoreComponent.addVelocityXComponent(-velocityX); - } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.UP)) { - physicsCoreComponent.addVelocityYComponent(velocityX); - } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.DOWN)) { - physicsCoreComponent.addVelocityYComponent(-velocityX); - } - }); + case KeyboardCommand keyboardCommand -> handleKeyboardCommand(keyboardCommand); + case ScrollCommand scrollCommand -> handleScrollCommand(scrollCommand); + case MouseDragCommand mouseDragCommand -> handleMouseDragCommand(inputCommand, mouseDragCommand); + default -> logInputCommand(inputCommand); + } + } + + private void handleKeyboardCommand(@NonNull final KeyboardCommand keyboardCommand) { + this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { + if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.LEFT)) { + physicsCoreComponent.addVelocityXComponent(MOVING_FORCE); + } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.RIGHT)) { + physicsCoreComponent.addVelocityXComponent(-MOVING_FORCE); + } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.UP)) { + physicsCoreComponent.addVelocityYComponent(MOVING_FORCE); + } else if (keyboardCommand.getNanoTimedEvent().getEvent().getCode().equals(KeyCode.DOWN)) { + physicsCoreComponent.addVelocityYComponent(-MOVING_FORCE); } - case ScrollCommand scrollCommand -> { - // log.info("ScrollCommand received: {} ({})", inputCommand.getClass().getSimpleName(), mapToScrollDirection(scrollCommand.getNanoTimedEvent().getEvent())); - // code to zoom in/out - this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { - if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() > 0) { - // todo - } else if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() < 0) { - // todo - } - }); + }); + } + + private void handleScrollCommand(@NonNull final ScrollCommand scrollCommand) { + this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { + if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() > 0) { + locateRecomMapComponent().ifPresent(RECOMMapComponent::zoomIn); + } else if (scrollCommand.getNanoTimedEvent().getEvent().getDeltaY() < 0) { + locateRecomMapComponent().ifPresent(RECOMMapComponent::zoomOut); } - case MouseDragCommand mouseDragCommand -> { - if (mouseDragCommand.getMouseButton().equals(MouseButton.SECONDARY)) { - this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { - if (mouseDragCommand.isInOriginPosition()) { - physicsCoreComponent.setVelocityXComponent(0); - physicsCoreComponent.setVelocityYComponent(0); - } else { - physicsCoreComponent.setVelocityXComponent(-1 * mouseDragCommand.getDistanceX() * DRAG_SPEED_COEFFICIENT); - physicsCoreComponent.setVelocityYComponent(-1 * mouseDragCommand.getDistanceY() * DRAG_SPEED_COEFFICIENT); - } - }); + }); + } + + private void handleMouseDragCommand( + @NonNull final IsCommand inputCommand, + @NonNull final MouseDragCommand mouseDragCommand + ) { + if (mouseDragCommand.getMouseButton().equals(MouseButton.SECONDARY)) { + this.getEntity().locateComponent(ComponentType.PhysicsCoreComponent).ifPresent(physicsCoreComponent -> { + if (mouseDragCommand.isInOriginPosition()) { + physicsCoreComponent.setVelocityXComponent(0); + physicsCoreComponent.setVelocityYComponent(0); } else { - log.info("MouseDragCommand received: {} ({})", inputCommand.getClass().getSimpleName(), mouseDragCommand.getMouseButton()); + physicsCoreComponent.setVelocityXComponent(-1 * mouseDragCommand.getDistanceX() * DRAG_SPEED_COEFFICIENT); + physicsCoreComponent.setVelocityYComponent(-1 * mouseDragCommand.getDistanceY() * DRAG_SPEED_COEFFICIENT); } - } - default -> logInputCommand(inputCommand); + }); + } else { + log.info("MouseDragCommand received: {} ({})", inputCommand.getClass().getSimpleName(), mouseDragCommand.getMouseButton()); } } + // @TODO; kann man das generalisieren? + @NonNull + private Optional locateRecomMapComponent() { + if (maybeMapComponent.isEmpty()) { + maybeMapComponent = this.getEntity().locateComponents(ComponentType.RenderableComponent).stream() + .filter(component -> component instanceof RECOMMapComponent) + .map(component -> (RECOMMapComponent) component) + .findFirst(); + } + + return maybeMapComponent; + } + private void logInputCommand(@NonNull final IsCommand inputCommand) { switch (inputCommand) { case MouseButtonCommand mouseButtonCommand ->