Add a snappable check to fix interference with the hud snap logic

This commit is contained in:
noil 2019-11-04 16:15:01 -05:00
parent ed0bd8c187
commit 2dab44227a
4 changed files with 14 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import org.lwjgl.input.Keyboard;
*/
public class DraggableHudComponent extends HudComponent {
private boolean snappable;
private boolean dragging;
private float deltaX;
private float deltaY;
@ -27,6 +28,7 @@ public class DraggableHudComponent extends HudComponent {
public DraggableHudComponent(String name) {
this.setName(name);
this.setVisible(false);
this.setSnappable(true);
this.setX(Minecraft.getMinecraft().displayWidth / 2.0f);
this.setY(Minecraft.getMinecraft().displayHeight / 2.0f);
}
@ -155,7 +157,7 @@ public class DraggableHudComponent extends HudComponent {
if (button == 0) {
if (this.isDragging()) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || !this.isSnappable()) {
this.setDragging(false);
return;
}
@ -165,7 +167,7 @@ public class DraggableHudComponent extends HudComponent {
for (HudComponent component : Seppuku.INSTANCE.getHudManager().getComponentList()) {
if (component instanceof DraggableHudComponent) {
DraggableHudComponent draggable = (DraggableHudComponent) component;
if (draggable != this && this.collidesWith(draggable) && draggable.isVisible()) {
if (draggable != this && this.collidesWith(draggable) && draggable.isVisible() && draggable.isSnappable()) {
if ((this.getY() + (this.getH() / 2)) < (draggable.getY() + (draggable.getH() / 2))) { // top
this.setY(draggable.getY() - this.getH());
this.glueSide = GlueSide.TOP;
@ -226,8 +228,12 @@ public class DraggableHudComponent extends HudComponent {
}
}
public boolean collides() {
return false;
public boolean isSnappable() {
return snappable;
}
public void setSnappable(boolean snappable) {
this.snappable = snappable;
}
public boolean isDragging() {

View File

@ -26,6 +26,7 @@ public final class HubComponent extends DraggableHudComponent {
public HubComponent() {
super("Hub");
this.setVisible(true);
this.setSnappable(false);
this.setW(100);
this.setH(100);
this.setX((Minecraft.getMinecraft().displayWidth / 2) - (this.getW() / 2));

View File

@ -22,6 +22,8 @@ public final class TutorialComponent extends PopupComponent {
"- Both top and bottom parts of a component are able to be glued to.";
this.setTextData(tutorialData);
this.setSnappable(false);
this.setW(200);
this.setH(173);
this.setX((Minecraft.getMinecraft().displayWidth / 2) - (this.getW() / 2));

View File

@ -29,6 +29,7 @@ public final class ModuleListComponent extends DraggableHudComponent {
public ModuleListComponent(Module.ModuleType type) {
super(StringUtils.capitalize(type.name().toLowerCase()));
this.type = type;
this.setSnappable(false);
this.setW(100);
this.setH(100);
this.setX((Minecraft.getMinecraft().displayWidth / 2) - (this.getW() / 2));