aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java43
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java37
3 files changed, 38 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index 33068bf..5f944e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,5 @@ build
eclipse
run
build - Copy.gradle
+.vscode
+.devauth
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
index cfd6a9d..884a1bb 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
@@ -24,8 +24,8 @@ public class HudGui extends GuiScreen {
HudCore.editing = true;
Keyboard.enableRepeatEvents(true);
for (BasicHud hud : HudCore.huds) {
- hud.childRight = new TestHud();
- hud.childRight.parent = hud;
+ hud.childBottom = new TestHud();
+ hud.childBottom.parent = hud;
}
}
@@ -44,8 +44,10 @@ public class HudGui extends GuiScreen {
float pos = getXSnapping(mouseX, true);
float newWidth = pos - xFloat;
float newScale = newWidth / ((hud.getWidth(hud.scale) + hud.paddingX * hud.scale) / hud.scale);
- if (newScale > 20) newScale = 20;
- else if (newScale < 0.3) newScale = 0.3f;
+ if (newScale > 20)
+ newScale = 20;
+ else if (newScale < 0.3)
+ newScale = 0.3f;
hud.scale = newScale;
if (xFloat / this.width > 0.5)
@@ -54,8 +56,8 @@ public class HudGui extends GuiScreen {
editingHud.yUnscaled = (yFloat + (hud.getHeight(hud.scale) + hud.paddingY * hud.scale)) / (double) this.height;
}
- int width = (int) (hud.getTotalWidth(hud.scale) + hud.paddingX * hud.scale);
- int height = (int) (hud.getTotalHeight(hud.scale) + hud.paddingY * hud.scale);
+ int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale);
+ int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale);
int x = (int) hud.getXScaled(this.width);
int y = (int) hud.getYScaled(this.height);
@@ -63,7 +65,8 @@ public class HudGui extends GuiScreen {
int color = new Color(215, 224, 235).getRGB();
if (editingHud == hud) {
color = new Color(43, 159, 235).getRGB();
- if (isDragging) Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
+ if (isDragging)
+ Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
}
int finalColor = color;
RenderManager.setupAndDraw(true, (vg) -> {
@@ -84,20 +87,28 @@ public class HudGui extends GuiScreen {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
- if (newX < 0) newX = 0;
- else if (newX + width > this.width) newX = this.width - width;
- if (newY < 0) newY = 0;
- else if (newY + height > this.height) newY = this.height - height;
+ if (newX < 0)
+ newX = 0;
+ else if (newX + width > this.width)
+ newX = this.width - width;
+ if (newY < 0)
+ newY = 0;
+ else if (newY + height > this.height)
+ newY = this.height - height;
if (snap) {
newX = getXSnapping(newX, false);
newY = getYSnapping(newY);
}
- if (newX / this.width <= 0.5) editingHud.xUnscaled = newX / (double) this.width;
- else editingHud.xUnscaled = (newX + width) / (double) this.width;
- if (newY / this.height <= 0.5) editingHud.yUnscaled = newY / (double) this.height;
- else editingHud.yUnscaled = (newY + height) / (double) this.height;
+ if (newX / this.width <= 0.5)
+ editingHud.xUnscaled = newX / (double) this.width;
+ else
+ editingHud.xUnscaled = (newX + width) / (double) this.width;
+ if (newY / this.height <= 0.5)
+ editingHud.yUnscaled = newY / (double) this.height;
+ else
+ editingHud.yUnscaled = (newY + height) / (double) this.height;
}
private float getXSnapping(float pos, boolean rightOnly) {
@@ -231,4 +242,4 @@ public class HudGui extends GuiScreen {
public boolean doesGuiPauseGame() {
return false;
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
index f69bff4..e4bfd65 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
@@ -12,11 +12,9 @@ public abstract class BasicHud {
public int paddingY = 5;
public boolean background = true;
public boolean rounded = false;
- public BasicHud childLeft;
+ public BasicHud parent;
public BasicHud childRight;
public BasicHud childBottom;
- public BasicHud childTop;
- public BasicHud parent;
public abstract int getWidth(float scale);
@@ -33,29 +31,22 @@ public abstract class BasicHud {
}
public void drawAll(float x, float y, float scale) {
- if (parent == null) drawBackground(x, y, scale);
+ drawBackground(x, y, getWidth(scale), getHeight(scale), scale);
draw((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale);
- if (childLeft != null)
- childLeft.drawAll((int) (x + paddingX * scale / 2f) - childRight.getWidth(scale), (int) (y + paddingY * scale / 2f), scale);
- if (childRight != null)
- childRight.drawAll((int) (x + paddingX * scale / 2f) + getWidth(scale), (int) (y + paddingY * scale / 2f), scale);
}
public void drawExampleAll(float x, float y, float scale) {
- if (parent == null) drawBackground(x, y, scale);
+ drawBackground(x, y, getExampleWidth(scale), getExampleHeight(scale), scale);
drawExample((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale);
- if (childLeft != null)
- childLeft.drawExampleAll((int) (x + paddingX * scale / 2f) - childRight.getWidth(scale), (int) (y + paddingY * scale / 2f), scale);
- if (childRight != null)
- childRight.drawExampleAll((int) (x + paddingX * scale / 2f) + getWidth(scale), (int) (y + paddingY * scale / 2f), scale);
}
public void drawExample(int x, int y, float scale) {
draw(x, y, scale);
}
- private void drawBackground(float x, float y, float scale) {
- RenderManager.setupAndDraw((vg) -> RenderManager.drawRoundedRect(vg, x, y, getTotalWidth(scale) + paddingX * scale, getTotalHeight(scale) + paddingY * scale, new Color(0, 0, 0, 120).getRGB(), 2 * scale));
+ private void drawBackground(float x, float y, float width, float height, float scale) {
+ RenderManager.setupAndDraw((vg) -> RenderManager.drawRoundedRect(vg, x, y, width + paddingX * scale,
+ height + paddingY * scale, new Color(0, 0, 0, 120).getRGB(), 2 * scale));
}
public float getXScaled(int screenWidth) {
@@ -72,17 +63,7 @@ public abstract class BasicHud {
return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale));
}
- public int getTotalWidth(float scale) {
- int width = getWidth(scale);
- if (childLeft != null) width += childLeft.getWidth(scale);
- if (childRight != null) width += childRight.getWidth(scale);
- return width;
- }
-
- public int getTotalHeight(float scale) {
- int height = getHeight(scale);
- if (childBottom != null) height += childBottom.getHeight(scale);
- if (childTop != null) height += childTop.getHeight(scale);
- return height;
+ public float getTotalWidth(float scale) {
+ return 0;
}
-}
+} \ No newline at end of file