aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-24 21:53:19 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-24 21:53:19 +0100
commitba619ccebe7a313bac3b59e7f7e2085bb9cb74ee (patch)
tree59e431a7b9f95da1c409f96a4ce4bcfdedcf5db1 /src/main
parent7d7b2aaf85592840da824c6ce29c992cd669c84c (diff)
downloadskyhanni-ba619ccebe7a313bac3b59e7f7e2085bb9cb74ee.tar.gz
skyhanni-ba619ccebe7a313bac3b59e7f7e2085bb9cb74ee.tar.bz2
skyhanni-ba619ccebe7a313bac3b59e7f7e2085bb9cb74ee.zip
Code cleanup
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java58
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt45
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt12
4 files changed, 63 insertions, 77 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
index 65bb35996..edaae7d0f 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
@@ -35,8 +35,6 @@ public class Position {
private boolean clicked = false;
public String internalName = null;
- private static final int EDGE_OFFSET = 0;
-
public Position(int x, int y) {
this(x, y, false, false);
}
@@ -65,10 +63,6 @@ public class Position {
// return ;
// }
- public boolean isCenterY() {
- return false;
- }
-
public int getRawX() {
return x;
}
@@ -84,7 +78,7 @@ public class Position {
return clicked;
}
- public int getAbsX(ScaledResolution scaledResolution, int objWidth) {
+ public int getAbsX0(ScaledResolution scaledResolution, int objWidth) {
int width = scaledResolution.getScaledWidth();
int ret = x;
@@ -98,7 +92,7 @@ public class Position {
return ret;
}
- public int getAbsY(ScaledResolution scaledResolution, int objHeight) {
+ public int getAbsY0(ScaledResolution scaledResolution, int objHeight) {
int height = scaledResolution.getScaledHeight();
int ret = y;
@@ -118,22 +112,22 @@ public class Position {
this.x += deltaX;
if (wasPositiveX) {
- if (this.x < EDGE_OFFSET) {
- deltaX += EDGE_OFFSET - this.x;
- this.x = EDGE_OFFSET;
+ if (this.x < 0) {
+ deltaX += -this.x;
+ this.x = 0;
}
- if (this.x > screenWidth - EDGE_OFFSET) {
- deltaX += screenWidth - EDGE_OFFSET - this.x;
- this.x = screenWidth - EDGE_OFFSET;
+ if (this.x > screenWidth) {
+ deltaX += screenWidth - this.x;
+ this.x = screenWidth;
}
} else {
- if (this.x + 1 > -EDGE_OFFSET) {
- deltaX += -EDGE_OFFSET - 1 - this.x;
- this.x = -EDGE_OFFSET - 1;
+ if (this.x + 1 > 0) {
+ deltaX += -1 - this.x;
+ this.x = -1;
}
- if (this.x + screenWidth < EDGE_OFFSET) {
- deltaX += EDGE_OFFSET - screenWidth - this.x;
- this.x = EDGE_OFFSET - screenWidth;
+ if (this.x + screenWidth < 0) {
+ deltaX += -screenWidth - this.x;
+ this.x = -screenWidth;
}
}
@@ -152,22 +146,22 @@ public class Position {
this.y += deltaY;
if (wasPositiveY) {
- if (this.y < EDGE_OFFSET) {
- deltaY += EDGE_OFFSET - this.y;
- this.y = EDGE_OFFSET;
+ if (this.y < 0) {
+ deltaY += -this.y;
+ this.y = 0;
}
- if (this.y > screenHeight - EDGE_OFFSET) {
- deltaY += screenHeight - EDGE_OFFSET - this.y;
- this.y = screenHeight - EDGE_OFFSET;
+ if (this.y > screenHeight) {
+ deltaY += screenHeight - this.y;
+ this.y = screenHeight;
}
} else {
- if (this.y + 1 > -EDGE_OFFSET) {
- deltaY += -EDGE_OFFSET - 1 - this.y;
- this.y = -EDGE_OFFSET - 1;
+ if (this.y + 1 > -0) {
+ deltaY += -1 - this.y;
+ this.y = -1;
}
- if (this.y + screenHeight < EDGE_OFFSET) {
- deltaY += EDGE_OFFSET - screenHeight - this.y;
- this.y = EDGE_OFFSET - screenHeight;
+ if (this.y + screenHeight < 0) {
+ deltaY += -screenHeight - this.y;
+ this.y = -screenHeight;
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt
index a2eea8f3a..1cbb8a137 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt
@@ -20,10 +20,9 @@ package at.hannibal2.skyhanni.config.core.config.gui
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.core.config.Position
-import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX_
-import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY_
+import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX
+import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize
-import at.hannibal2.skyhanni.data.GuiEditManager.Companion.isCenterX_
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
@@ -68,12 +67,10 @@ class GuiPositionEditor(
var mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1
for (i in positions.indices.reversed()) {
val position = positions[i]
- val elementWidth = position.getDummySize().x.toInt()
- val elementHeight = position.getDummySize().y.toInt()
- var x = position.getAbsX_()
- var y = position.getAbsY_()
- if (position.isCenterX_()) x -= elementWidth / 2
- if (position.isCenterY) y -= elementHeight / 2
+ val elementWidth = position.getDummySize().x
+ val elementHeight = position.getDummySize().y
+ val x = position.getAbsX()
+ val y = position.getAbsY()
if (mouseX >= x - border && mouseY >= y - border && mouseX <= x + elementWidth + border * 2 && mouseY <= y + elementHeight + border * 2) {
hoveredPos = i
break
@@ -93,18 +90,17 @@ class GuiPositionEditor(
mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth
mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1
for (position in positions) {
- var elementWidth = position.getDummySize(true).x.toInt()
- var elementHeight = position.getDummySize(true).y.toInt()
+ var elementWidth = position.getDummySize(true).x
+ var elementHeight = position.getDummySize(true).y
if (position.clicked) {
grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution)
grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution)
}
- var x = position.getAbsX_()
- val y = position.getAbsY_()
- if (position.isCenterX_()) x -= elementWidth / 2
+ val x = position.getAbsX()
+ val y = position.getAbsY()
- elementWidth = position.getDummySize().x.toInt()
- elementHeight = position.getDummySize().y.toInt()
+ elementWidth = position.getDummySize().x
+ elementHeight = position.getDummySize().y
drawRect(x - border, y - border, x + elementWidth + border * 2, y + elementHeight + border * 2, -0x7fbfbfc0)
@@ -135,11 +131,10 @@ class GuiPositionEditor(
mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1
for (i in positions.indices.reversed()) {
val position = positions[i]
- val elementWidth = position.getDummySize().x.toInt()
- val elementHeight = position.getDummySize().y.toInt()
- var x = position.getAbsX_()
- val y = position.getAbsY_()
- if (position.isCenterX_()) x -= elementWidth / 2
+ val elementWidth = position.getDummySize().x
+ val elementHeight = position.getDummySize().y
+ val x = position.getAbsX()
+ val y = position.getAbsY()
if (!position.clicked) {
if (mouseX >= x && mouseY >= y && mouseX <= x + elementWidth && mouseY <= y + elementHeight) {
clickedPos = i
@@ -157,8 +152,8 @@ class GuiPositionEditor(
override fun keyTyped(typedChar: Char, keyCode: Int) {
if (clickedPos != -1) {
val position = positions[clickedPos]
- val elementWidth = position.getDummySize(true).x.toInt()
- val elementHeight = position.getDummySize(true).y.toInt()
+ val elementWidth = position.getDummySize(true).x
+ val elementHeight = position.getDummySize(true).y
if (keyCode == SkyHanniMod.feature.gui.keyBindReset) {
position.set(originalPositions[positions.indexOf(position)])
@@ -200,8 +195,8 @@ class GuiPositionEditor(
var mouseX: Int
var mouseY: Int
for (position in positions) {
- val elementWidth = position.getDummySize(true).x.toInt()
- val elementHeight = position.getDummySize(true).y.toInt()
+ val elementWidth = position.getDummySize(true).x
+ val elementHeight = position.getDummySize(true).y
if (position.clicked) {
val scaledResolution = Utils.pushGuiScale(-1)
mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
index d20605a6c..b68271c78 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
@@ -14,7 +14,6 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.input.Keyboard
-import org.lwjgl.util.vector.Vector2f
import java.util.*
class GuiEditManager {
@@ -89,27 +88,25 @@ class GuiEditManager {
fun isInGui() = Minecraft.getMinecraft().currentScreen is GuiPositionEditor
- fun Position.getDummySize(random: Boolean = false): Vector2f {
+ fun Position.getDummySize(random: Boolean = false): Vector2i {
if (random) {
- return Vector2f(15f, 15f)
+ return Vector2i(15, 15)
} else {
- val (x, y) = currentBorderSize[internalName] ?: return Vector2f(1f, 1f)
- return Vector2f(x.toFloat(), y.toFloat())
+ val (x, y) = currentBorderSize[internalName] ?: return Vector2i(1, 1)
+ return Vector2i(x, y)
}
}
- fun Position.getAbsX_(): Int {
+ fun Position.getAbsX(): Int {
val width = getDummySize(true).x
- return getAbsX(ScaledResolution(Minecraft.getMinecraft()), width.toInt())
+ return getAbsX0(ScaledResolution(Minecraft.getMinecraft()), width)
}
- fun Position.getAbsY_(): Int {
+ fun Position.getAbsY(): Int {
val height = getDummySize(true).y
- return getAbsY(ScaledResolution(Minecraft.getMinecraft()), height.toInt())
- }
-
- fun Position.isCenterX_(): Boolean {
- return false
+ return getAbsY0(ScaledResolution(Minecraft.getMinecraft()), height)
}
}
-} \ No newline at end of file
+}
+
+class Vector2i(val x: Int, val y: Int) \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 42509da79..1d24ff1e9 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -3,8 +3,8 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils.drawStringScaled
import at.hannibal2.skyhanni.data.GuiEditManager
-import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX_
-import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY_
+import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX
+import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY
import at.hannibal2.skyhanni.utils.NEUItems.renderOnScreen
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
@@ -443,8 +443,8 @@ object RenderUtils {
val minecraft = Minecraft.getMinecraft()
val renderer = minecraft.renderManager.fontRenderer
- val x = getAbsX_() + offsetX
- val y = getAbsY_() + offsetY
+ val x = getAbsX() + offsetX
+ val y = getAbsY() + offsetY
GlStateManager.translate(x + 1.0, y + 1.0, 0.0)
renderer.drawStringWithShadow(display, 0f, 0f, 0)
@@ -529,8 +529,8 @@ object RenderUtils {
val width = renderer.getStringWidth(any)
offsetX += width
} else if (any is ItemStack) {
- val isX = getAbsX_() + offsetX
- val isY = getAbsY_() + offsetY
+ val isX = getAbsX() + offsetX
+ val isY = getAbsY() + offsetY
any.renderOnScreen(isX.toFloat(), isY.toFloat(), itemScale)
offsetX += 12