aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-08-09 07:02:36 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-08-09 07:02:36 +1000
commitf729d5199a2acd9264f9e4244d598debdc53cbcc (patch)
treebbc3d3017c5283174eb55a1300ce4e26bf52e5ec /src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java
parent1b2b38531242d2f3862f5594199bd55d0bf00539 (diff)
downloadnotenoughupdates-f729d5199a2acd9264f9e4244d598debdc53cbcc.tar.gz
notenoughupdates-f729d5199a2acd9264f9e4244d598debdc53cbcc.tar.bz2
notenoughupdates-f729d5199a2acd9264f9e4244d598debdc53cbcc.zip
1.1.1
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java
index 91cca2d7..6bdd25fd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java
@@ -1,5 +1,9 @@
package io.github.moulberry.notenoughupdates.mbgui;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.inventory.GuiContainer;
import org.lwjgl.util.vector.Vector2f;
import java.util.*;
@@ -7,6 +11,8 @@ import java.util.*;
public class MBGuiGroupFloating extends MBGuiGroup {
private LinkedHashMap<MBGuiElement, MBAnchorPoint> children;
+ private GuiContainer lastContainer = null;
+ private HashMap<MBGuiElement, Vector2f> childrenPositionOffset = new HashMap<>();
public MBGuiGroupFloating(int width, int height, LinkedHashMap<MBGuiElement, MBAnchorPoint> children) {
this.width = width;
@@ -20,7 +26,53 @@ public class MBGuiGroupFloating extends MBGuiGroup {
}
@Override
+ public Map<MBGuiElement, Vector2f> getChildrenPosition() {
+ GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
+
+ if(currentScreen instanceof GuiContainer) {
+ GuiContainer currentContainer = (GuiContainer) currentScreen;
+ if(lastContainer != currentContainer) {
+ lastContainer = currentContainer;
+ for(Map.Entry<MBGuiElement, MBAnchorPoint> entry : children.entrySet()) {
+ MBGuiElement child = entry.getKey();
+ MBAnchorPoint anchorPoint = entry.getValue();
+
+ Vector2f childPos;
+ if(childrenPosition.containsKey(child)) {
+ childPos = new Vector2f(childrenPosition.get(child));
+ } else {
+ childPos = new Vector2f();
+ }
+
+ if(anchorPoint.anchorPoint == MBAnchorPoint.AnchorPoint.INV_BOTMID) {
+ try {
+ int xSize = (int) Utils.getField(GuiContainer.class, currentContainer, "xSize", "field_146999_f");
+ int ySize = (int) Utils.getField(GuiContainer.class, currentContainer, "ySize", "field_147000_g");
+ int guiLeft = (int) Utils.getField(GuiContainer.class, currentContainer, "guiLeft", "field_147003_i");
+ int guiTop = (int) Utils.getField(GuiContainer.class, currentContainer, "guiTop", "field_147009_r");
+
+ int defGuiLeft = (this.width - xSize) / 2;
+ int defGuiTop = (this.height - ySize) / 2;
+
+ childPos.x += guiLeft-defGuiLeft + (anchorPoint.anchorPoint.x-0.5f)*xSize;
+ childPos.y += guiTop-defGuiTop + (anchorPoint.anchorPoint.y-0.5f)*ySize;
+ } catch(Exception ignored) {
+ }
+ }
+
+ childrenPositionOffset.put(child, childPos);
+ }
+ }
+ return Collections.unmodifiableMap(childrenPositionOffset);
+ } else {
+ return Collections.unmodifiableMap(childrenPosition);
+ }
+ }
+
+ @Override
public void recalculate() {
+ lastContainer = null;
+
for(MBGuiElement child : children.keySet()) {
child.recalculate();
}
@@ -30,6 +82,12 @@ public class MBGuiGroupFloating extends MBGuiGroup {
MBAnchorPoint anchorPoint = entry.getValue();
float x = anchorPoint.anchorPoint.x * width - anchorPoint.anchorPoint.x * child.getWidth() + anchorPoint.offset.x;
float y = anchorPoint.anchorPoint.y * height - anchorPoint.anchorPoint.y * child.getHeight() + anchorPoint.offset.y;
+
+ if(anchorPoint.anchorPoint == MBAnchorPoint.AnchorPoint.INV_BOTMID) {
+ x = width*0.5f + anchorPoint.offset.x;
+ y = height*0.5f + anchorPoint.offset.y;
+ }
+
childrenPosition.put(child, new Vector2f(x, y));
}
}