Skip to content

Commit

Permalink
select points on the field when they're clicked on timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
varun7654 committed Nov 6, 2023
1 parent 07d5fc8 commit bd7f37a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
12 changes: 11 additions & 1 deletion core/src/main/com/dacubeking/autobuilder/gui/AutoBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ private void draw() {
@Nullable ClosePoint lastSelectedPoint = null;
boolean somethingMoved = false;

public void selectPoint(TrajectoryPathRenderer trajectoryPathRenderer, int index) {
removeLastSelectedPoint();
var point = new ClosePoint(0, trajectoryPathRenderer, index);
trajectoryPathRenderer.selectPoint(
point, cameraHandler, AutoBuilder.getInstance().pathGui.guiItems
);

lastSelectedPoint = point;
}

private void update() {
MouseUtil.update();
undoHandler.update(pathGui);
Expand Down Expand Up @@ -518,7 +528,7 @@ private void update() {
pointAdded = true;
somethingMoved = false;
} else {
trajectoryPathRenderer.selectPoint(closestPoint, cam, mousePos, mouseDiff,
trajectoryPathRenderer.selectPoint(closestPoint, cameraHandler,
pathGui.guiItems);
lastSelectedPoint = closestPoint;
somethingMoved = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,8 @@ public void ensureOnScreen(Vector3 worldPos) {
targetX = cam.position.x + worldPos.x - worldPosOfTargetScreenPos.x;
targetY = cam.position.y + worldPos.y - worldPosOfTargetScreenPos.y;
}

public float getZoom() {
return zoom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public String onTextBoxClick(String text, int row, int column, NumberTextBox num
}

cameraHandler.ensureOnScreen(trajectoryPathRenderer.getPointList().get(row).getRenderPos3());
AutoBuilder.getInstance().selectPoint(trajectoryPathRenderer, row);
return text;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.badlogic.gdx.math.Vector3;
import com.dacubeking.AutoBuilder.robot.serialization.TimedRotation;
import com.dacubeking.autobuilder.gui.AutoBuilder;
import com.dacubeking.autobuilder.gui.CameraHandler;
import com.dacubeking.autobuilder.gui.config.Config;
import com.dacubeking.autobuilder.gui.events.movablepoint.MovablePointEventHandler;
import com.dacubeking.autobuilder.gui.events.movablepoint.PointMoveEvent;
Expand Down Expand Up @@ -448,14 +449,12 @@ public double distToClosestPointNotMainPoint(Vector3 mousePos) {
}

/**
* @param closePoint object that was created by {@link TrajectoryPathRenderer#getClosePoints(float, Vector3)}
* @param camera the camera
* @param mousePos the current mouse position
* @param mouseDiff the difference between the current and last mouse position
* @param itemList the list of gui items that contains all the path items
* @param closePoint object that was created by {@link TrajectoryPathRenderer#getClosePoints(float, Vector3)}
* @param cameraHandler the cameraHandler
* @param itemList the list of gui items that contains all the path items
*/
public void selectPoint(@NotNull ClosePoint closePoint, @NotNull OrthographicCamera camera, @NotNull Vector3 mousePos,
@NotNull Vector3 mouseDiff, @NotNull List<AbstractGuiItem> itemList) {
public void selectPoint(@NotNull ClosePoint closePoint, @NotNull CameraHandler cameraHandler,
@NotNull List<AbstractGuiItem> itemList) {
selectionPointIndex = closePoint.index();
attachedPath = null;

Expand Down Expand Up @@ -499,7 +498,7 @@ public void selectPoint(@NotNull ClosePoint closePoint, @NotNull OrthographicCam
}

if (Math.abs(selectedPoint.getPos2().sub((float) otherPathPose2d.x[0], (float) otherPathPose2d.y[0]).len2())
< Math.pow((20 / AutoBuilder.getConfig().getPointScaleFactor() * camera.zoom), 2)) {
< Math.pow((20 / AutoBuilder.getConfig().getPointScaleFactor() * cameraHandler.getZoom()), 2)) {
updateConnectedPath(selectedPoint);
} else {
attachedPath = null;
Expand Down

0 comments on commit bd7f37a

Please sign in to comment.