ResizableHudComponent: Fixed resize logic

This commit is contained in:
noil 2021-01-09 00:56:40 -05:00
parent 003b1e5217
commit f45438c590
8 changed files with 41 additions and 32 deletions

View File

@ -17,13 +17,17 @@ public class ResizableHudComponent extends DraggableHudComponent {
private float initialWidth; private float initialWidth;
private float initialHeight; private float initialHeight;
private float maxWidth;
private float maxHeight;
protected final float CLICK_ZONE = 2; protected final float CLICK_ZONE = 2;
public ResizableHudComponent(String name, float initialWidth, float initialHeight) { public ResizableHudComponent(String name, float initialWidth, float initialHeight, float maxWidth, float maxHeight) {
super(name); super(name);
this.initialWidth = initialWidth; this.initialWidth = initialWidth;
this.initialHeight = initialHeight; this.initialHeight = initialHeight;
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
} }
@Override @Override
@ -53,14 +57,13 @@ public class ResizableHudComponent extends DraggableHudComponent {
this.clampMaxs(); this.clampMaxs();
} }
final boolean inside = mouseX >= this.getX() + this.getW() - CLICK_ZONE && mouseX <= this.getX() + this.getW() + CLICK_ZONE && mouseY >= this.getY() + this.getH() - CLICK_ZONE && mouseY <= this.getY() + this.getH() + CLICK_ZONE; if (Minecraft.getMinecraft().currentScreen instanceof GuiHudEditor) {
RenderUtil.drawRect(this.getX() + this.getW() - CLICK_ZONE, this.getY() + this.getH() - CLICK_ZONE, this.getX() + this.getW() + CLICK_ZONE, this.getY() + this.getH() + CLICK_ZONE, 0x90202020);
if (inside) {
RenderUtil.drawRect(this.getX() + this.getW() - CLICK_ZONE, this.getY() + this.getH() - CLICK_ZONE, this.getX() + this.getW() + CLICK_ZONE, this.getY() + this.getH() + CLICK_ZONE, 0x45FFFFFF);
} }
if (Minecraft.getMinecraft().currentScreen instanceof GuiHudEditor) { final boolean insideClickZone = mouseX >= this.getX() + this.getW() - CLICK_ZONE && mouseX <= this.getX() + this.getW() + CLICK_ZONE && mouseY >= this.getY() + this.getH() - CLICK_ZONE && mouseY <= this.getY() + this.getH() + CLICK_ZONE;
RenderUtil.drawRect(this.getX() + this.getW() - CLICK_ZONE, this.getY() + this.getH() - CLICK_ZONE, this.getX() + this.getW() + CLICK_ZONE, this.getY() + this.getH() + CLICK_ZONE, 0x75101010); if (insideClickZone) {
RenderUtil.drawRect(this.getX() + this.getW() - CLICK_ZONE, this.getY() + this.getH() - CLICK_ZONE, this.getX() + this.getW() + CLICK_ZONE, this.getY() + this.getH() + CLICK_ZONE, 0x45FFFFFF);
} }
this.clampMaxs(); this.clampMaxs();
@ -85,6 +88,14 @@ public class ResizableHudComponent extends DraggableHudComponent {
if (this.getH() <= this.getInitialHeight()) { if (this.getH() <= this.getInitialHeight()) {
this.setH(this.getInitialHeight()); this.setH(this.getInitialHeight());
} }
if (this.getW() >= this.getMaxWidth()) {
this.setW(this.getMaxWidth());
}
if (this.getH() >= this.getMaxHeight()) {
this.setH(this.getMaxHeight());
}
} }
public boolean isResizeDragging() { public boolean isResizeDragging() {
@ -126,4 +137,20 @@ public class ResizableHudComponent extends DraggableHudComponent {
public void setInitialHeight(float initialHeight) { public void setInitialHeight(float initialHeight) {
this.initialHeight = initialHeight; this.initialHeight = initialHeight;
} }
public float getMaxWidth() {
return maxWidth;
}
public void setMaxWidth(float maxWidth) {
this.maxWidth = maxWidth;
}
public float getMaxHeight() {
return maxHeight;
}
public void setMaxHeight(float maxHeight) {
this.maxHeight = maxHeight;
}
} }

View File

@ -28,7 +28,6 @@ public final class ColorsComponent extends ResizableHudComponent {
private int totalHeight; private int totalHeight;
private final int MAX_WIDTH = 215;
private final int SCROLL_WIDTH = 5; private final int SCROLL_WIDTH = 5;
private final int BORDER = 2; private final int BORDER = 2;
private final int TEXT_GAP = 1; private final int TEXT_GAP = 1;
@ -37,7 +36,7 @@ public final class ColorsComponent extends ResizableHudComponent {
private ColorComponent currentColorComponent = null; private ColorComponent currentColorComponent = null;
public ColorsComponent() { public ColorsComponent() {
super("Colors", 100, 120); super("Colors", 100, 120, 215, 1000);
this.setSnappable(false); this.setSnappable(false);
this.setW(120); this.setW(120);
@ -76,11 +75,6 @@ public final class ColorsComponent extends ResizableHudComponent {
this.setH(this.getTotalHeight()); this.setH(this.getTotalHeight());
this.setResizeDragging(false); this.setResizeDragging(false);
} }
if (this.getW() > MAX_WIDTH) {
this.setW(MAX_WIDTH);
this.setResizeDragging(false);
}
} }
// Background & title // Background & title

View File

@ -21,7 +21,6 @@ public final class HubComponent extends ResizableHudComponent {
private int totalHeight; private int totalHeight;
private final int MAX_WIDTH = 125;
private final int SCROLL_WIDTH = 5; private final int SCROLL_WIDTH = 5;
private final int BORDER = 2; private final int BORDER = 2;
private final int TEXT_GAP = 1; private final int TEXT_GAP = 1;
@ -31,7 +30,7 @@ public final class HubComponent extends ResizableHudComponent {
private final Texture texture; private final Texture texture;
public HubComponent() { public HubComponent() {
super("Hub", 100, 120); super("Hub", 100, 120, 125, 1000);
this.texture = new Texture("module-hub.png"); this.texture = new Texture("module-hub.png");
this.setVisible(true); this.setVisible(true);
@ -72,11 +71,6 @@ public final class HubComponent extends ResizableHudComponent {
this.setH(this.getTotalHeight()); this.setH(this.getTotalHeight());
this.setResizeDragging(false); this.setResizeDragging(false);
} }
if (this.getW() > MAX_WIDTH) {
this.setW(MAX_WIDTH);
this.setResizeDragging(false);
}
} }
// Background & title // Background & title

View File

@ -27,7 +27,7 @@ public final class MovementGraphComponent extends ResizableHudComponent {
private final Timer timer = new Timer(); private final Timer timer = new Timer();
public MovementGraphComponent() { public MovementGraphComponent() {
super("MovementGraph", 60, 27); super("MovementGraph", 60, 27, 600, 400);
this.setW(60); this.setW(60);
this.setH(27); this.setH(27);
} }

View File

@ -21,7 +21,7 @@ public final class OverViewComponent extends ResizableHudComponent {
private float distance = 35.0f; private float distance = 35.0f;
public OverViewComponent() { public OverViewComponent() {
super("OverView", 120, 120); super("OverView", 120, 120, 400, 400);
Seppuku.INSTANCE.getCameraManager().addCamera(overviewCamera); Seppuku.INSTANCE.getCameraManager().addCamera(overviewCamera);
this.setW(120); this.setW(120);
this.setH(120); this.setH(120);

View File

@ -14,7 +14,7 @@ public final class RearViewComponent extends ResizableHudComponent {
private final Camera rearviewCamera = new Camera(); private final Camera rearviewCamera = new Camera();
public RearViewComponent() { public RearViewComponent() {
super("RearView", 120, 120); super("RearView", 120, 120, 400, 400);
Seppuku.INSTANCE.getCameraManager().addCamera(rearviewCamera); Seppuku.INSTANCE.getCameraManager().addCamera(rearviewCamera);
this.setW(120); this.setW(120);
this.setH(120); this.setH(120);

View File

@ -25,7 +25,7 @@ public final class TpsGraphComponent extends ResizableHudComponent {
private final Timer timer = new Timer(); private final Timer timer = new Timer();
public TpsGraphComponent() { public TpsGraphComponent() {
super("TpsGraph", 60, 27); super("TpsGraph", 60, 27, 600, 400);
this.setW(60); this.setW(60);
this.setH(27); this.setH(27);
} }

View File

@ -35,7 +35,6 @@ public final class ModuleListComponent extends ResizableHudComponent {
private int oldScroll = 0; private int oldScroll = 0;
private int totalHeight; private int totalHeight;
private final int MAX_WIDTH = 150;
private final int SCROLL_WIDTH = 5; private final int SCROLL_WIDTH = 5;
private final int BORDER = 2; private final int BORDER = 2;
private final int TEXT_GAP = 1; private final int TEXT_GAP = 1;
@ -53,7 +52,7 @@ public final class ModuleListComponent extends ResizableHudComponent {
private ModuleSettingsComponent currentSettings; private ModuleSettingsComponent currentSettings;
public ModuleListComponent(Module.ModuleType type) { public ModuleListComponent(Module.ModuleType type) {
super(StringUtils.capitalize(type.name().toLowerCase()), 100, 100); super(StringUtils.capitalize(type.name().toLowerCase()), 100, 100, 150, 1000);
this.type = type; this.type = type;
this.originalName = StringUtils.capitalize(type.name().toLowerCase()); this.originalName = StringUtils.capitalize(type.name().toLowerCase());
this.hudEditorModule = (HudEditorModule) Seppuku.INSTANCE.getModuleManager().find(HudEditorModule.class); this.hudEditorModule = (HudEditorModule) Seppuku.INSTANCE.getModuleManager().find(HudEditorModule.class);
@ -95,11 +94,6 @@ public final class ModuleListComponent extends ResizableHudComponent {
this.setH(this.getTotalHeight()); this.setH(this.getTotalHeight());
this.setResizeDragging(false); this.setResizeDragging(false);
} }
if (this.getW() > MAX_WIDTH) {
this.setW(MAX_WIDTH);
this.setResizeDragging(false);
}
} else if (!this.isLocked() && this.currentSettings == null && this.getH() > this.getTotalHeight()) { } else if (!this.isLocked() && this.currentSettings == null && this.getH() > this.getTotalHeight()) {
this.setH(this.getTotalHeight()); this.setH(this.getTotalHeight());
} else if (this.currentSettings == null && this.getH() > this.getTotalHeight() && this.getTotalHeight() > this.getInitialHeight()) { } else if (this.currentSettings == null && this.getH() > this.getTotalHeight() && this.getTotalHeight() > this.getInitialHeight()) {