Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Lag when moving nodes. #420

Open
wants to merge 7 commits into
base: talos-3d
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.talosvfx.talos.editor.addons.scene.apps.routines;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand Down Expand Up @@ -42,74 +39,18 @@ public RoutineEditorApp() {
Notifications.registerObserver(this);
routineStage = new RoutineStage(this, SharedResources.skin);
routineStageWrapper = new GenericStageWrappedViewportWidget(routineStage.getRootActor()) {
private static final float AUTO_SCROLL_RANGE = 45.0f;
private static final float AUTO_SCROLL_SPEED = 200.0f;

@Override
protected boolean canMoveAround() {
return true;
}

private Vector2 tmp = new Vector2();

private static final float DELAY_BEFORE_MOVE = 0.3f;
private float delayBeforeMove = DELAY_BEFORE_MOVE;

@Override
public void act(float delta) {
super.act(delta);

tmp.set(Gdx.input.getX(), Gdx.input.getY());
screenToLocalCoordinates(tmp);

float dt = Gdx.graphics.getDeltaTime();
OrthographicCamera camera = (OrthographicCamera) routineStageWrapper.getViewportViewSettings().getCurrentCamera();

tmp.set(Gdx.input.getX(), Gdx.input.getY());
routineStageWrapper.screenToLocalCoordinates(tmp);

boolean shouldMove = routineStage.shouldAutoMove()
&& (isInTopZone(tmp) || isInBottomZone(tmp) || isInLeftZone(tmp) || isInRightZone(tmp));

if (shouldMove) {
delayBeforeMove -= delta;
} else {
delayBeforeMove = DELAY_BEFORE_MOVE;
}

if (delayBeforeMove < 0) {
if (isInTopZone(tmp)) {
camera.translate(0, camera.zoom * AUTO_SCROLL_SPEED * dt, 0);
} else if (isInBottomZone(tmp)) {
camera.translate(0, camera.zoom * -AUTO_SCROLL_SPEED * dt, 0);
}

if (isInLeftZone(tmp)) {
camera.translate(camera.zoom * AUTO_SCROLL_SPEED * dt, 0, 0);
} else if (isInRightZone(tmp)) {
camera.translate(camera.zoom * -AUTO_SCROLL_SPEED * dt, 0, 0);
}
}

routineStage.act();
}


private boolean isInRightZone(Vector2 mouse) {
return mouse.x > 0 && mouse.x < AUTO_SCROLL_RANGE;
}

private boolean isInLeftZone(Vector2 mouse) {
return mouse.x > routineStageWrapper.getWidth() - AUTO_SCROLL_RANGE && mouse.x < routineStageWrapper.getWidth();
}

private boolean isInBottomZone(Vector2 mouse) {
return mouse.y > 0 && mouse.y < AUTO_SCROLL_RANGE;
}

private boolean isInTopZone(Vector2 mouse) {
return mouse.y > routineStageWrapper.getHeight() - AUTO_SCROLL_RANGE && mouse.y < routineStageWrapper.getHeight();
}
};
routineStageWrapper.getDropdownForWorld().setVisible(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public RoutineStage (RoutineEditorApp routineEditorApp, Skin skin) {
protected void initActors () {
super.initActors();
nodeBoard.setTouchable(Touchable.enabled);
nodeBoard.getAutoMoveUtil().setViewportWidget(routineEditorApp.routineStageWrapper);
}

public void loadFrom (GameAsset<RoutineStageData> asset) {
Expand Down
10 changes: 0 additions & 10 deletions editor/src/com/talosvfx/talos/editor/nodes/DynamicNodeStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.talosvfx.talos.editor.utils.InputUtils.ctrlPressed;

public abstract class DynamicNodeStage<T extends DynamicNodeStageData> extends WorkplaceStage implements EventContextProvider<DynamicNodeStage<?>> {

private static final Logger logger = LoggerFactory.getLogger(DynamicNodeStage.class);
Expand All @@ -39,8 +37,6 @@ public abstract class DynamicNodeStage<T extends DynamicNodeStageData> extends W
public GameAsset<T> gameAsset;
public T data;

public boolean shouldAutoMove;

public DynamicNodeStage (Skin skin) {
super();
this.skin = skin;
Expand Down Expand Up @@ -235,9 +231,6 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
protected abstract void onBaseStageSelected ();

protected void initActors() {
// GridRendererWrapper gridRenderer = new GridRendererWrapper(stage);
// stage.addActor(gridRenderer);

nodeBoard = new NodeBoard<T>(skin, this);

getRootActor().addActor(nodeBoard);
Expand Down Expand Up @@ -279,7 +272,4 @@ public DynamicNodeStage<?> getContext () {

public abstract void onNodeSelectionChange ();

public boolean shouldAutoMove() {
return shouldAutoMove;
}
}
167 changes: 86 additions & 81 deletions editor/src/com/talosvfx/talos/editor/nodes/EmptyWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, int bu
}
});
this.addListener(new InputListener() {
float startX;
float startY;
float lastX;
float lastY;

private void updateEdge(float x, float y) {
float border = (float)EmptyWindow.this.resizeBorder / 2.0F;
Expand Down Expand Up @@ -103,10 +99,10 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, int bu
if (button == 0) {
this.updateEdge(x, y);
EmptyWindow.this.dragging = EmptyWindow.this.edge != 0;
this.startX = x;
this.startY = y;
this.lastX = x - EmptyWindow.this.getWidth();
this.lastY = y - EmptyWindow.this.getHeight();
touchDraggedStartX = x;
touchDraggedStartY = y;
touchDraggedLastX = x - EmptyWindow.this.getWidth();
touchDraggedLastY = y - EmptyWindow.this.getHeight();
}

return EmptyWindow.this.edge != 0 || EmptyWindow.this.isModal;
Expand All @@ -118,79 +114,7 @@ public void touchUp(InputEvent event, float x, float y, int pointer, int button)

public void touchDragged(InputEvent event, float x, float y, int pointer) {
if (EmptyWindow.this.dragging) {
float width = EmptyWindow.this.getWidth();
float height = EmptyWindow.this.getHeight();
float windowX = EmptyWindow.this.getX();
float windowY = EmptyWindow.this.getY();
float minWidth = EmptyWindow.this.getMinWidth();
float maxWidth = EmptyWindow.this.getMaxWidth();
float minHeight = EmptyWindow.this.getMinHeight();
float maxHeight = EmptyWindow.this.getMaxHeight();
Stage stage = EmptyWindow.this.getStage();
boolean clampPosition = stage != null && EmptyWindow.this.getParent() == stage.getRoot();
float amountY;
if ((EmptyWindow.this.edge & 32) != 0) {
amountY = x - this.startX;
float amountYx = y - this.startY;
windowX += amountY;
windowY += amountYx;
}

if ((EmptyWindow.this.edge & 8) != 0) {
amountY = x - this.startX;
if (width - amountY < minWidth) {
amountY = -(minWidth - width);
}

if (clampPosition && windowX + amountY < 0.0F) {
amountY = -windowX;
}

width -= amountY;
windowX += amountY;
}

if ((EmptyWindow.this.edge & 4) != 0) {
amountY = y - this.startY;
if (height - amountY < minHeight) {
amountY = -(minHeight - height);
}

if (clampPosition && windowY + amountY < 0.0F) {
amountY = -windowY;
}

height -= amountY;
windowY += amountY;
}

if ((EmptyWindow.this.edge & 16) != 0) {
amountY = x - this.lastX - width;
if (width + amountY < minWidth) {
amountY = minWidth - width;
}

if (clampPosition && windowX + width + amountY > stage.getWidth()) {
amountY = stage.getWidth() - windowX - width;
}

width += amountY;
}

if ((EmptyWindow.this.edge & 2) != 0) {
amountY = y - this.lastY - height;
if (height + amountY < minHeight) {
amountY = minHeight - height;
}

if (clampPosition && windowY + height + amountY > stage.getHeight()) {
amountY = stage.getHeight() - windowY - height;
}

height += amountY;
}

EmptyWindow.this.setBounds((float)Math.round(windowX), (float)Math.round(windowY), (float)Math.round(width), (float)Math.round(height));
EmptyWindow.this.touchDragged(x, y);
}
}

Expand Down Expand Up @@ -293,4 +217,85 @@ public float getPrefWidth() {
public abstract float getTitlePrefWidth();

public abstract float getDragPadTop();

private float touchDraggedStartX;
private float touchDraggedStartY;
private float touchDraggedLastX;
private float touchDraggedLastY;

public void touchDragged(float localX, float localY) {
float width = EmptyWindow.this.getWidth();
float height = EmptyWindow.this.getHeight();
float windowX = EmptyWindow.this.getX();
float windowY = EmptyWindow.this.getY();
float minWidth = EmptyWindow.this.getMinWidth();
float maxWidth = EmptyWindow.this.getMaxWidth();
float minHeight = EmptyWindow.this.getMinHeight();
float maxHeight = EmptyWindow.this.getMaxHeight();
Stage stage = EmptyWindow.this.getStage();
boolean clampPosition = stage != null && EmptyWindow.this.getParent() == stage.getRoot();
float amountY;
if ((EmptyWindow.this.edge & 32) != 0) {
amountY = localX - this.touchDraggedStartX;
float amountYx = localY - this.touchDraggedStartY;
windowX += amountY;
windowY += amountYx;
}

if ((EmptyWindow.this.edge & 8) != 0) {
amountY = localX - this.touchDraggedStartX;
if (width - amountY < minWidth) {
amountY = -(minWidth - width);
}

if (clampPosition && windowX + amountY < 0.0F) {
amountY = -windowX;
}

width -= amountY;
windowX += amountY;
}

if ((EmptyWindow.this.edge & 4) != 0) {
amountY = localY - this.touchDraggedStartY;
if (height - amountY < minHeight) {
amountY = -(minHeight - height);
}

if (clampPosition && windowY + amountY < 0.0F) {
amountY = -windowY;
}

height -= amountY;
windowY += amountY;
}

if ((EmptyWindow.this.edge & 16) != 0) {
amountY = localX - this.touchDraggedLastX - width;
if (width + amountY < minWidth) {
amountY = minWidth - width;
}

if (clampPosition && windowX + width + amountY > stage.getWidth()) {
amountY = stage.getWidth() - windowX - width;
}

width += amountY;
}

if ((EmptyWindow.this.edge & 2) != 0) {
amountY = localY - this.touchDraggedLastY - height;
if (height + amountY < minHeight) {
amountY = minHeight - height;
}

if (clampPosition && windowY + height + amountY > stage.getHeight()) {
amountY = stage.getHeight() - windowY - height;
}

height += amountY;
}

EmptyWindow.this.setBounds((float)Math.round(windowX), (float)Math.round(windowY), (float)Math.round(width), (float)Math.round(height));
}
}
Loading