diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
| commit | b09f774d422263ce15b97d6d0804beddf856176d (patch) | |
| tree | e542258481d7496b15679f3c329ef9e087c7d8fc /src/main/java/io/github/moulberry/notenoughupdates/mbgui | |
| parent | 22cb02adbeb24b7ec98f843bcaba99cebe3e4f03 (diff) | |
| download | notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.gz notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.bz2 notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.zip | |
feat: improve formating :)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/mbgui')
6 files changed, 280 insertions, 277 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBAnchorPoint.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBAnchorPoint.java index 7d4b3b11..eaf41ba6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBAnchorPoint.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBAnchorPoint.java @@ -5,51 +5,51 @@ import org.lwjgl.util.vector.Vector2f; import java.io.Serializable; public class MBAnchorPoint implements Serializable { - public enum AnchorPoint { - TOPLEFT(0, 0), TOPMID(0.5f, 0), TOPRIGHT(1, 0), - MIDRIGHT(1, 0.5f), BOTRIGHT(1, 1), BOTMID(0.5f, 1), - BOTLEFT(0, 1), MIDLEFT(0, 0.5f), MIDMID(0.5f, 0.5f); - - public final float x; - public final float y; - - AnchorPoint(float x, float y) { - this.x = x; - this.y = y; - } - } - - public AnchorPoint anchorPoint; - public Vector2f offset; - public boolean inventoryRelative; - - public MBAnchorPoint(AnchorPoint anchorPoint, Vector2f offset) { - this(anchorPoint, offset, false); - } - - public MBAnchorPoint(AnchorPoint anchorPoint, Vector2f offset, boolean inventoryRelative) { - this.anchorPoint = anchorPoint; - this.offset = offset; - this.inventoryRelative = inventoryRelative; - } - - public static MBAnchorPoint createFromString(String str) { - if (str == null || str.split(":").length != 4) { - return null; - } - - try { - String[] split = str.split(":"); - AnchorPoint point = AnchorPoint.valueOf(split[0].toUpperCase()); - Vector2f pos = new Vector2f(Float.parseFloat(split[1]), Float.parseFloat(split[2])); - return new MBAnchorPoint(point, pos, Boolean.parseBoolean(split[3])); - } catch (Exception e) { - return null; - } - } - - @Override - public String toString() { - return anchorPoint.toString() + ":" + offset.x + ":" + offset.y + ":" + inventoryRelative; - } + public enum AnchorPoint { + TOPLEFT(0, 0), TOPMID(0.5f, 0), TOPRIGHT(1, 0), + MIDRIGHT(1, 0.5f), BOTRIGHT(1, 1), BOTMID(0.5f, 1), + BOTLEFT(0, 1), MIDLEFT(0, 0.5f), MIDMID(0.5f, 0.5f); + + public final float x; + public final float y; + + AnchorPoint(float x, float y) { + this.x = x; + this.y = y; + } + } + + public AnchorPoint anchorPoint; + public Vector2f offset; + public boolean inventoryRelative; + + public MBAnchorPoint(AnchorPoint anchorPoint, Vector2f offset) { + this(anchorPoint, offset, false); + } + + public MBAnchorPoint(AnchorPoint anchorPoint, Vector2f offset, boolean inventoryRelative) { + this.anchorPoint = anchorPoint; + this.offset = offset; + this.inventoryRelative = inventoryRelative; + } + + public static MBAnchorPoint createFromString(String str) { + if (str == null || str.split(":").length != 4) { + return null; + } + + try { + String[] split = str.split(":"); + AnchorPoint point = AnchorPoint.valueOf(split[0].toUpperCase()); + Vector2f pos = new Vector2f(Float.parseFloat(split[1]), Float.parseFloat(split[2])); + return new MBAnchorPoint(point, pos, Boolean.parseBoolean(split[3])); + } catch (Exception e) { + return null; + } + } + + @Override + public String toString() { + return anchorPoint.toString() + ":" + offset.x + ":" + offset.y + ":" + inventoryRelative; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBDeserializer.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBDeserializer.java index 06a7f5aa..b9e858ef 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBDeserializer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBDeserializer.java @@ -5,14 +5,14 @@ import com.google.gson.JsonObject; import java.io.IOException; public class MBDeserializer { - public static MBGuiElement deserialize(JsonObject json) { - return null; - } + public static MBGuiElement deserialize(JsonObject json) { + return null; + } - public static void serializeAndSave(MBGuiElement element, String filename) throws IOException { + public static void serializeAndSave(MBGuiElement element, String filename) throws IOException { /*JsonObject json = element.serialize(); File file = new File(NotEnoughUpdates.INSTANCE.manager.configLocation, filename+".json"); NotEnoughUpdates.INSTANCE.manager.writeJson(json, file);*/ - } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiElement.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiElement.java index b0750d1c..ad836097 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiElement.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiElement.java @@ -1,17 +1,17 @@ package io.github.moulberry.notenoughupdates.mbgui; public abstract class MBGuiElement { - public abstract int getWidth(); + public abstract int getWidth(); - public abstract int getHeight(); + public abstract int getHeight(); - public abstract void recalculate(); + public abstract void recalculate(); - public abstract void mouseClick(float x, float y, int mouseX, int mouseY); + public abstract void mouseClick(float x, float y, int mouseX, int mouseY); - public abstract void mouseClickOutside(); + public abstract void mouseClickOutside(); - public abstract void render(float x, float y); + public abstract void render(float x, float y); - //public abstract JsonObject serialize(); + //public abstract JsonObject serialize(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java index 3582a549..4540b146 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java @@ -8,56 +8,56 @@ import java.util.HashMap; import java.util.Map; public abstract class MBGuiGroup extends MBGuiElement { - public int width; - public int height; - protected HashMap<MBGuiElement, Vector2f> childrenPosition = new HashMap<>(); - - public MBGuiGroup() {} - - public abstract Collection<MBGuiElement> getChildren(); - - public Map<MBGuiElement, Vector2f> getChildrenPosition() { - return Collections.unmodifiableMap(childrenPosition); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public void mouseClick(float x, float y, int mouseX, int mouseY) { - Map<MBGuiElement, Vector2f> childrenPos = getChildrenPosition(); - - for (MBGuiElement child : getChildren()) { - Vector2f childPos = childrenPos.get(child); - if (mouseX > x + childPos.x && mouseX < x + childPos.x + child.getWidth()) { - if (mouseY > y + childPos.y && mouseY < y + childPos.y + child.getHeight()) { - child.mouseClick(x + childPos.x, y + childPos.y, mouseX, mouseY); - } - } - } - } - - @Override - public void mouseClickOutside() { - for (MBGuiElement child : getChildren()) { - child.mouseClickOutside(); - } - } - - @Override - public void render(float x, float y) { - Map<MBGuiElement, Vector2f> childrenPos = getChildrenPosition(); - - for (MBGuiElement child : getChildren()) { - Vector2f childPos = childrenPos.get(child); - child.render(x + childPos.x, y + childPos.y); - } - } + public int width; + public int height; + protected HashMap<MBGuiElement, Vector2f> childrenPosition = new HashMap<>(); + + public MBGuiGroup() {} + + public abstract Collection<MBGuiElement> getChildren(); + + public Map<MBGuiElement, Vector2f> getChildrenPosition() { + return Collections.unmodifiableMap(childrenPosition); + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + Map<MBGuiElement, Vector2f> childrenPos = getChildrenPosition(); + + for (MBGuiElement child : getChildren()) { + Vector2f childPos = childrenPos.get(child); + if (mouseX > x + childPos.x && mouseX < x + childPos.x + child.getWidth()) { + if (mouseY > y + childPos.y && mouseY < y + childPos.y + child.getHeight()) { + child.mouseClick(x + childPos.x, y + childPos.y, mouseX, mouseY); + } + } + } + } + + @Override + public void mouseClickOutside() { + for (MBGuiElement child : getChildren()) { + child.mouseClickOutside(); + } + } + + @Override + public void render(float x, float y) { + Map<MBGuiElement, Vector2f> childrenPos = getChildrenPosition(); + + for (MBGuiElement child : getChildren()) { + Vector2f childPos = childrenPos.get(child); + child.render(x + childPos.x, y + childPos.y); + } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java index c6a9e8ee..eef4b5e5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java @@ -6,59 +6,59 @@ import java.util.Collection; import java.util.List; public abstract class MBGuiGroupAligned extends MBGuiGroup { - //Serialized - private final List<MBGuiElement> children; - private final boolean vertical; + //Serialized + private final List<MBGuiElement> children; + private final boolean vertical; - public MBGuiGroupAligned(List<MBGuiElement> children, boolean vertical) { - this.children = children; - this.vertical = vertical; - recalculate(); - } + public MBGuiGroupAligned(List<MBGuiElement> children, boolean vertical) { + this.children = children; + this.vertical = vertical; + recalculate(); + } - public abstract int getPadding(); + public abstract int getPadding(); - public Collection<MBGuiElement> getChildren() { - return children; - } + public Collection<MBGuiElement> getChildren() { + return children; + } - public void recalculate() { - for (MBGuiElement child : children) { - child.recalculate(); - } + public void recalculate() { + for (MBGuiElement child : children) { + child.recalculate(); + } - if (vertical) { - height = 0; - for (int i = 0; i < children.size(); i++) { - MBGuiElement child = children.get(i); - childrenPosition.put(child, new Vector2f(0, height)); - height += child.getHeight(); - if (i != children.size() - 1) height += getPadding(); - } + if (vertical) { + height = 0; + for (int i = 0; i < children.size(); i++) { + MBGuiElement child = children.get(i); + childrenPosition.put(child, new Vector2f(0, height)); + height += child.getHeight(); + if (i != children.size() - 1) height += getPadding(); + } - width = 0; - for (MBGuiElement child : children) { - int childWidth = child.getWidth(); - if (childWidth > width) { - width = childWidth; - } - } - } else { - width = 0; - for (int i = 0; i < children.size(); i++) { - MBGuiElement child = children.get(i); - childrenPosition.put(child, new Vector2f(width, 0)); - width += child.getWidth(); - if (i != children.size() - 1) width += getPadding(); - } + width = 0; + for (MBGuiElement child : children) { + int childWidth = child.getWidth(); + if (childWidth > width) { + width = childWidth; + } + } + } else { + width = 0; + for (int i = 0; i < children.size(); i++) { + MBGuiElement child = children.get(i); + childrenPosition.put(child, new Vector2f(width, 0)); + width += child.getWidth(); + if (i != children.size() - 1) width += getPadding(); + } - height = 0; - for (MBGuiElement child : children) { - int childHeight = child.getHeight(); - if (childHeight > height) { - height = childHeight; - } - } - } - } + height = 0; + for (MBGuiElement child : children) { + int childHeight = child.getHeight(); + if (childHeight > height) { + height = childHeight; + } + } + } + } } 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 125d2f99..24697cc6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java @@ -13,122 +13,125 @@ import org.lwjgl.util.vector.Vector2f; import java.util.*; public class MBGuiGroupFloating extends MBGuiGroup { - private GuiScreen lastScreen = null; - private final HashMap<MBGuiElement, Vector2f> childrenPositionOffset = new HashMap<>(); - - //Serialized - private final LinkedHashMap<MBGuiElement, MBAnchorPoint> children; - - public MBGuiGroupFloating(int width, int height, LinkedHashMap<MBGuiElement, MBAnchorPoint> children) { - this.width = width; - this.height = height; - this.children = children; - recalculate(); - } - - public Map<MBGuiElement, MBAnchorPoint> getChildrenMap() { - return Collections.unmodifiableMap(children); - } - - @Override - public Map<MBGuiElement, Vector2f> getChildrenPosition() { - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - - if (currentScreen instanceof GuiContainer || currentScreen instanceof GuiItemRecipe - || currentScreen instanceof CustomAHGui || NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.isRenderOverAuctionView()) { - - if (lastScreen != currentScreen) { - lastScreen = currentScreen; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int screenWidth = scaledResolution.getScaledWidth(); - int screenHeight = scaledResolution.getScaledHeight(); - - int xSize = -1; - int ySize = -1; - int guiLeft = -1; - int guiTop = -1; - - if (currentScreen instanceof GuiContainer) { - GuiContainer currentContainer = (GuiContainer) currentScreen; - - try { - xSize = (int) Utils.getField(GuiContainer.class, currentContainer, "xSize", "field_146999_f"); - ySize = (int) Utils.getField(GuiContainer.class, currentContainer, "ySize", "field_147000_g"); - guiLeft = (int) Utils.getField(GuiContainer.class, currentContainer, "guiLeft", "field_147003_i"); - guiTop = (int) Utils.getField(GuiContainer.class, currentContainer, "guiTop", "field_147009_r"); - } catch (Exception ignored) {} - } else if (currentScreen instanceof GuiItemRecipe) { - xSize = ((GuiItemRecipe) currentScreen).xSize; - ySize = ((GuiItemRecipe) currentScreen).ySize; - guiLeft = ((GuiItemRecipe) currentScreen).guiLeft; - guiTop = ((GuiItemRecipe) currentScreen).guiTop; - } else if (currentScreen instanceof CustomAHGui || - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.isRenderOverAuctionView()) { - xSize = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.getXSize(); - ySize = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.getYSize(); - guiLeft = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.guiLeft; - guiTop = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.guiTop; - } - - if (xSize <= 0 && ySize <= 0 && guiLeft <= 0 && guiTop <= 0) { - lastScreen = null; - return Collections.unmodifiableMap(childrenPosition); - } - - 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.inventoryRelative) { - int defGuiLeft = (screenWidth - xSize) / 2; - int defGuiTop = (screenHeight - ySize) / 2; - - childPos.x += guiLeft - defGuiLeft + (0.5f - anchorPoint.anchorPoint.x) * xSize; - childPos.y += guiTop - defGuiTop + (0.5f - anchorPoint.anchorPoint.y) * ySize; - } - - childrenPositionOffset.put(child, childPos); - } - } - return Collections.unmodifiableMap(childrenPositionOffset); - } else { - return Collections.unmodifiableMap(childrenPosition); - } - } - - @Override - public void recalculate() { - lastScreen = null; - - for (MBGuiElement child : children.keySet()) { - child.recalculate(); - } - - for (Map.Entry<MBGuiElement, MBAnchorPoint> entry : children.entrySet()) { - MBGuiElement child = entry.getKey(); - 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.inventoryRelative) { - x = width * 0.5f + anchorPoint.offset.x; - y = height * 0.5f + anchorPoint.offset.y; - } - - childrenPosition.put(child, new Vector2f(x, y)); - } - } - - @Override - public Collection<MBGuiElement> getChildren() { - return children.keySet(); - } + private GuiScreen lastScreen = null; + private final HashMap<MBGuiElement, Vector2f> childrenPositionOffset = new HashMap<>(); + + //Serialized + private final LinkedHashMap<MBGuiElement, MBAnchorPoint> children; + + public MBGuiGroupFloating(int width, int height, LinkedHashMap<MBGuiElement, MBAnchorPoint> children) { + this.width = width; + this.height = height; + this.children = children; + recalculate(); + } + + public Map<MBGuiElement, MBAnchorPoint> getChildrenMap() { + return Collections.unmodifiableMap(children); + } + + @Override + public Map<MBGuiElement, Vector2f> getChildrenPosition() { + GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; + + if (currentScreen instanceof GuiContainer || currentScreen instanceof GuiItemRecipe + || currentScreen instanceof CustomAHGui || + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.isRenderOverAuctionView()) { + + if (lastScreen != currentScreen) { + lastScreen = currentScreen; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int screenWidth = scaledResolution.getScaledWidth(); + int screenHeight = scaledResolution.getScaledHeight(); + + int xSize = -1; + int ySize = -1; + int guiLeft = -1; + int guiTop = -1; + + if (currentScreen instanceof GuiContainer) { + GuiContainer currentContainer = (GuiContainer) currentScreen; + + try { + xSize = (int) Utils.getField(GuiContainer.class, currentContainer, "xSize", "field_146999_f"); + ySize = (int) Utils.getField(GuiContainer.class, currentContainer, "ySize", "field_147000_g"); + guiLeft = (int) Utils.getField(GuiContainer.class, currentContainer, "guiLeft", "field_147003_i"); + guiTop = (int) Utils.getField(GuiContainer.class, currentContainer, "guiTop", "field_147009_r"); + } catch (Exception ignored) { + } + } else if (currentScreen instanceof GuiItemRecipe) { + xSize = ((GuiItemRecipe) currentScreen).xSize; + ySize = ((GuiItemRecipe) currentScreen).ySize; + guiLeft = ((GuiItemRecipe) currentScreen).guiLeft; + guiTop = ((GuiItemRecipe) currentScreen).guiTop; + } else if (currentScreen instanceof CustomAHGui || + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.isRenderOverAuctionView()) { + xSize = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.getXSize(); + ySize = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.getYSize(); + guiLeft = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.guiLeft; + guiTop = NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.guiTop; + } + + if (xSize <= 0 && ySize <= 0 && guiLeft <= 0 && guiTop <= 0) { + lastScreen = null; + return Collections.unmodifiableMap(childrenPosition); + } + + 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.inventoryRelative) { + int defGuiLeft = (screenWidth - xSize) / 2; + int defGuiTop = (screenHeight - ySize) / 2; + + childPos.x += guiLeft - defGuiLeft + (0.5f - anchorPoint.anchorPoint.x) * xSize; + childPos.y += guiTop - defGuiTop + (0.5f - anchorPoint.anchorPoint.y) * ySize; + } + + childrenPositionOffset.put(child, childPos); + } + } + return Collections.unmodifiableMap(childrenPositionOffset); + } else { + return Collections.unmodifiableMap(childrenPosition); + } + } + + @Override + public void recalculate() { + lastScreen = null; + + for (MBGuiElement child : children.keySet()) { + child.recalculate(); + } + + for (Map.Entry<MBGuiElement, MBAnchorPoint> entry : children.entrySet()) { + MBGuiElement child = entry.getKey(); + 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.inventoryRelative) { + x = width * 0.5f + anchorPoint.offset.x; + y = height * 0.5f + anchorPoint.offset.y; + } + + childrenPosition.put(child, new Vector2f(x, y)); + } + } + + @Override + public Collection<MBGuiElement> getChildren() { + return children.keySet(); + } } |
