Skip to content

Commit

Permalink
selection bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rpereira committed Nov 27, 2017
1 parent 7840744 commit a468ac9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.grillecube.client.renderer.gui.components;

import com.grillecube.client.opengl.GLH;
import com.grillecube.client.renderer.camera.CameraPerspectiveWorldCentered;
import com.grillecube.client.renderer.camera.CameraPerspectiveWorldEntity;
import com.grillecube.client.renderer.camera.CameraProjective;
import com.grillecube.client.renderer.camera.CameraProjectiveWorld;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class CameraToolPlace extends CameraTool implements Positioneable, Sizeab
private final Vector3i firstBlock;
private final Vector3i secondBlock;
private Vector3i face;
private int ySelected;
private int expansion;

public CameraToolPlace(GuiModelView guiModelView) {
super(guiModelView);
this.hovered = new Vector3i();
this.firstBlock = new Vector3i();
this.secondBlock = new Vector3i();
this.ySelected = 0;
this.expansion = 0;
}

@Override
Expand All @@ -58,9 +58,9 @@ public void onKeyPress(GuiEventKeyPress<GuiModelView> event) {
this.guiModelView.getToolbox().getSelectedModelPanels().getGuiToolboxModelPanelSkin().refresh();
}
} else if (event.getKey() == GLFW.GLFW_KEY_W) {
this.incYSelection(1);
this.expand(1);
} else if (event.getKey() == GLFW.GLFW_KEY_S) {
this.incYSelection(-1);
this.expand(-1);
}
}
}
Expand All @@ -71,7 +71,7 @@ public void onMouseMove() {

@Override
public void onLeftPressed() {
this.ySelected = 0;
this.expansion = 0;
}

@Override
Expand All @@ -94,7 +94,7 @@ public void onRightReleased() {

@Override
public void onLeftReleased() {
this.ySelected = 0;
this.expansion = 0;
}

private final void updateHoveredBlock() {
Expand Down Expand Up @@ -147,17 +147,28 @@ public boolean onRaycastCoordinates(int x, int y, int z, Vector3i theFace) {
@Override
public void onMouseScroll(GuiEventMouseScroll<GuiModelView> event) {
if (super.guiModelView.isLeftPressed()) {
int dy = -Maths.sign(event.getScrollY());
this.incYSelection(dy);
int d = -Maths.sign(event.getScrollY());
this.expand(d);
} else {
float speed = this.getCamera().getDistanceFromCenter() * 0.14f;
this.getCamera().increaseDistanceFromCenter((float) (-event.getScrollY() * speed));
}
}

private void incYSelection(int dy) {
this.ySelected += dy;
this.secondBlock.y += dy;
private void expand(int d) {
this.expansion += d;
this.updateSecondBlock();
}

private final void updateSecondBlock() {
if (this.face == null) {
this.secondBlock.set(this.hovered);
return;
}
int x = this.hovered.x + this.expansion * this.face.x;
int y = this.hovered.y + this.expansion * this.face.y;
int z = this.hovered.z + this.expansion * this.face.z;
this.secondBlock.set(x, y, z);
}

@Override
Expand All @@ -170,7 +181,7 @@ private final void updateSelection() {
if (!this.guiModelView.isLeftPressed()) {
this.firstBlock.set(this.hovered);
}
this.secondBlock.set(this.hovered.x, this.hovered.y + this.ySelected, this.hovered.z);
this.updateSecondBlock();
super.guiModelView.getWorldRenderer().getLineRendererFactory().addBox(this, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class CameraToolRemove extends CameraTool implements Positioneable, Sizea
private final Vector3i firstBlock;
private final Vector3i secondBlock;
private Vector3i face;
private int ySelected;
private int expansion;

public CameraToolRemove(GuiModelView guiModelView) {
super(guiModelView);
this.hovered = new Vector3i();
this.firstBlock = new Vector3i();
this.secondBlock = new Vector3i();
this.ySelected = 0;
this.expansion = 0;
}

@Override
Expand Down Expand Up @@ -65,18 +65,13 @@ public void onKeyPress(GuiEventKeyPress<GuiModelView> event) {
}
}
} else if (event.getKey() == GLFW.GLFW_KEY_W) {
this.incYSelection(1);
this.expand(1);
} else if (event.getKey() == GLFW.GLFW_KEY_S) {
this.incYSelection(-1);
this.expand(-1);
}
}
}

private void incYSelection(int dy) {
this.ySelected += dy;
this.secondBlock.y += dy;
}

@Override
public void onMouseMove() {
}
Expand All @@ -101,12 +96,12 @@ public void onRightReleased() {

@Override
public void onLeftPressed() {
this.ySelected = 0;
this.expansion = 0;
}

@Override
public void onLeftReleased() {
this.ySelected = 0;
this.expansion = 0;
}

private final void updateHoveredBlock() {
Expand Down Expand Up @@ -140,7 +135,7 @@ private final void updateHoveredBlock() {
@Override
public boolean onRaycastCoordinates(int x, int y, int z, Vector3i theFace) {
// System.out.println(x + " : " + y + " : " + z);
if (y <= model.getMiny() || model.getBlockData(pos.set(x, y, z)) != null) {
if (y < model.getMiny() || model.getBlockData(pos.set(x, y, z)) != null) {
hovered.set(x, y, z);
face = theFace;
return (true);
Expand All @@ -157,8 +152,8 @@ public boolean onRaycastCoordinates(int x, int y, int z, Vector3i theFace) {
@Override
public void onMouseScroll(GuiEventMouseScroll<GuiModelView> event) {
if (super.guiModelView.isLeftPressed()) {
int dy = -Maths.sign(event.getScrollY());
this.incYSelection(dy);
int d = -Maths.sign(event.getScrollY());
this.expand(d);
} else {
float speed = this.getCamera().getDistanceFromCenter() * 0.14f;
this.getCamera().increaseDistanceFromCenter((float) (-event.getScrollY() * speed));
Expand All @@ -171,11 +166,27 @@ public void onUpdate() {
this.updateSelection();
}

private void expand(int d) {
this.expansion += d;
this.updateSecondBlock();
}

private final void updateSecondBlock() {
if (this.face == null) {
this.secondBlock.set(this.hovered);
return;
}
int x = this.hovered.x + this.expansion * this.face.x;
int y = this.hovered.y + this.expansion * this.face.y;
int z = this.hovered.z + this.expansion * this.face.z;
this.secondBlock.set(x, y, z);
}

private final void updateSelection() {
if (!this.guiModelView.isLeftPressed()) {
this.firstBlock.set(this.hovered);
}
this.secondBlock.set(this.hovered.x, this.hovered.y + this.ySelected, this.hovered.z);
this.updateSecondBlock();
super.guiModelView.getWorldRenderer().getLineRendererFactory().addBox(this, this, Color.RED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public class CameraToolRigging extends CameraTool implements Positioneable, Size
private final Vector3i firstBlock;
private final Vector3i secondBlock;
private Vector3i face;
private int ySelected;
private int expansion;

public CameraToolRigging(GuiModelView guiModelView) {
super(guiModelView);
this.hovered = new Vector3i();
this.firstBlock = new Vector3i();
this.secondBlock = new Vector3i();
this.ySelected = 0;
this.expansion = 0;
}

@Override
Expand All @@ -49,9 +49,9 @@ public void onKeyPress(GuiEventKeyPress<GuiModelView> event) {
this.inputRiggingOnSelection(model);
}
} else if (event.getKey() == GLFW.GLFW_KEY_W) {
this.incYSelection(1);
this.expand(1);
} else if (event.getKey() == GLFW.GLFW_KEY_S) {
this.incYSelection(-1);
this.expand(-1);
}
}
}
Expand All @@ -60,9 +60,9 @@ private void inputRiggingOnSelection(EditableModel model) {
this.guiModelView.addChild(new GuiWindowRigging(this));
}

private void incYSelection(int dy) {
this.ySelected += dy;
this.secondBlock.y += dy;
private void expand(int d) {
this.expansion += d;
this.updateSecondBlock();
}

@Override
Expand All @@ -89,12 +89,12 @@ public void onRightReleased() {

@Override
public void onLeftPressed() {
this.ySelected = 0;
this.expansion = 0;
}

@Override
public void onLeftReleased() {
this.ySelected = 0;
this.expansion = 0;
}

private final void updateHoveredBlock() {
Expand Down Expand Up @@ -128,7 +128,7 @@ private final void updateHoveredBlock() {
@Override
public boolean onRaycastCoordinates(int x, int y, int z, Vector3i theFace) {
// System.out.println(x + " : " + y + " : " + z);
if (y <= model.getMiny() || model.getBlockData(pos.set(x, y, z)) != null) {
if (y < model.getMiny() || model.getBlockData(pos.set(x, y, z)) != null) {
hovered.set(x, y, z);
face = theFace;
return (true);
Expand All @@ -146,13 +146,24 @@ public boolean onRaycastCoordinates(int x, int y, int z, Vector3i theFace) {
public void onMouseScroll(GuiEventMouseScroll<GuiModelView> event) {
if (super.guiModelView.isLeftPressed()) {
int dy = -Maths.sign(event.getScrollY());
this.incYSelection(dy);
this.expand(dy);
} else {
float speed = this.getCamera().getDistanceFromCenter() * 0.14f;
this.getCamera().increaseDistanceFromCenter((float) (-event.getScrollY() * speed));
}
}

private final void updateSecondBlock() {
if (this.face == null) {
this.secondBlock.set(this.hovered);
return;
}
int x = this.hovered.x + this.expansion * this.face.x;
int y = this.hovered.y + this.expansion * this.face.y;
int z = this.hovered.z + this.expansion * this.face.z;
this.secondBlock.set(x, y, z);
}

@Override
public void onUpdate() {
this.updateCameraRotation();
Expand All @@ -163,8 +174,8 @@ private final void updateSelection() {
if (!this.guiModelView.isLeftPressed()) {
this.firstBlock.set(this.hovered);
}
this.secondBlock.set(this.hovered.x, this.hovered.y + this.ySelected, this.hovered.z);
super.guiModelView.getWorldRenderer().getLineRendererFactory().addBox(this, this, Color.RED);
this.updateSecondBlock();
super.guiModelView.getWorldRenderer().getLineRendererFactory().addBox(this, this, Color.GREEN);
}

private final void updateCameraRotation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@ private final void setBoneWeight() {
}
}
});

this.cancel = new GuiButton();
this.cancel.setText("Decline");
this.cancel.setBox(0.55f, 0.15f, w, h, 0.0f);
this.cancel.addTextParameter(txtSize);
this.cancel.addTextParameter(txtCenter);
this.cancel.addListener(new GuiListener<GuiEventPress<GuiButton>>() {
@Override
public void invoke(GuiEventPress<GuiButton> event) {
close();
}
});
this.addChild(this.cancel);
}
}

0 comments on commit a468ac9

Please sign in to comment.