optionClass, SkinRenderer super T> renderer) {
+ renderers.put(optionClass, renderer);
}
@SuppressWarnings("unchecked")
@@ -50,9 +50,14 @@ public boolean mouseDragged(ContextMenu menu, double mouseX, double mouseY, int
return false;
}
- public void keyPressed(ContextMenu menu, int key,int scanCode, int modifiers) {}
- public void keyReleased(ContextMenu menu, int key,int scanCode, int modifiers) {}
- public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double horizontalAmount, double verticalAmount){}
+ public void keyPressed(ContextMenu menu, int key, int scanCode, int modifiers) {
+ }
+
+ public void keyReleased(ContextMenu menu, int key, int scanCode, int modifiers) {
+ }
+
+ public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
+ }
public boolean shouldCreateNewScreen() {
return createNewScreen;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java
index fc498de..8e7775f 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/SkinRenderer.java
@@ -18,9 +18,15 @@ default boolean mouseDragged(T option, double mouseX, double mouseY, int button,
return option.isMouseOver(mouseX, mouseY);
}
- default void keyPressed(T option, int key) {}
+ default void keyPressed(T option, int key, int scanCode, int modifiers) {
+ }
+
+ default void keyReleased(T option, int key, int scanCode, int modifiers) {
+ }
- default void keyReleased(T option, int key) {}
- default void mouseScrolled(T option, double mouseX, double mouseY, double horizontalAmount, double verticalAmount){}
- default void init(T option){}
+ default void mouseScrolled(T option, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
+ }
+
+ default void init(T option) {
+ }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
index 2e34341..ab3821a 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java
@@ -6,17 +6,12 @@
import com.tanishisherewith.dynamichud.utils.UID;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.option.VideoOptionsScreen;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.glfw.GLFW;
-import java.util.Properties;
-import java.util.Set;
-
public abstract class Widget {
- public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER }
-
+ private final Anchor anchor; // The chosen anchor point
public WidgetData> DATA;
/**
* This is the UID of the widget used to identify during loading and saving.
@@ -26,23 +21,13 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER }
* @see #modId
*/
public UID uid = UID.generate();
- protected boolean isInEditor = false;
-
// Whether the widget is enabled and should be displayed.
public boolean display = true;
public boolean isDraggable = true;
-
- private int offsetX, offsetY; // Offset from the anchor point
-
//Boolean to check if the widget is being dragged
public boolean dragging;
-
//To enable/disable snapping
public boolean shiftDown = false;
-
- // Absolute position of the widget on screen in pixels.
- protected int x, y;
- protected boolean shouldScale = true;
/**
* An identifier for widgets to group them under one ID.
*
@@ -52,6 +37,10 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER }
* @see #uid
*/
public String modId = "unknown";
+ protected boolean isInEditor = false;
+ // Absolute position of the widget on screen in pixels.
+ protected int x, y;
+ protected boolean shouldScale = true;
protected MinecraftClient mc = MinecraftClient.getInstance();
/**
* Scale of the current widget.
@@ -62,12 +51,12 @@ public enum Anchor { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER }
//Dimensions of the widget
protected WidgetBox widgetBox;
int startX, startY;
- private final Anchor anchor; // The chosen anchor point
-
+ private int offsetX, offsetY; // Offset from the anchor point
public Widget(WidgetData> DATA, String modId) {
- this(DATA,modId,Anchor.CENTER);
+ this(DATA, modId, Anchor.CENTER);
}
- public Widget(WidgetData> DATA, String modId,Anchor anchor) {
+
+ public Widget(WidgetData> DATA, String modId, Anchor anchor) {
this.DATA = DATA;
widgetBox = new WidgetBox(0, 0, 0, 0);
this.modId = modId;
@@ -75,7 +64,6 @@ public Widget(WidgetData> DATA, String modId,Anchor anchor) {
init();
}
-
/**
* This method is called at the end of the {@link Widget#Widget(WidgetData, String)} constructor.
*/
@@ -133,8 +121,8 @@ private int getAnchorY(int screenHeight) {
// Update position based on anchor and offset
void updatePosition(int screenWidth, int screenHeight) {
- if(offsetX == 0 || offsetY == 0){
- calculateOffset(x,y,screenWidth,screenHeight);
+ if (offsetX == 0 || offsetY == 0) {
+ calculateOffset(x, y, screenWidth, screenHeight);
}
int anchorX = getAnchorX(screenWidth);
@@ -148,10 +136,10 @@ void updatePosition(int screenWidth, int screenHeight) {
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
- if(mc.getWindow() != null){
+ if (mc.getWindow() != null) {
//updatePercentages();
calculateOffset(x, y, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Set initial offset
- updatePosition( mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Initial placement
+ updatePosition(mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Initial placement
}
}
@@ -185,7 +173,7 @@ public final void render(DrawContext drawContext, int mouseX, int mouseY) {
* Renders the widget on the editor screen.
*/
public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY) {
- if(!isInEditor) return;
+ if (!isInEditor) return;
displayBg(drawContext);
@@ -200,7 +188,6 @@ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY
clampPosition();
}
-
/**
* Renders the widget on the screen
*
@@ -213,12 +200,10 @@ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY
*/
public abstract void renderWidget(DrawContext context, int mouseX, int mouseY);
-
/**
* Renders the widget in the editor screen with a background.
* Override this method without super call to remove the background.
* Could also be used to display placeholder values.
- *
*/
private void renderWidgetInEditor(DrawContext context, int mouseX, int mouseY) {
//displayBg(context);
@@ -226,12 +211,10 @@ private void renderWidgetInEditor(DrawContext context, int mouseX, int mouseY) {
renderWidget(context, mouseX, mouseY);
}
- /* Input related methods. Override with super call to add your own input-based code like contextMenu */
-
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (widgetBox.isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
toggle();
- if(isDraggable) {
+ if (isDraggable) {
startX = (int) (mouseX - x);
startY = (int) (mouseY - y);
dragging = true;
@@ -240,13 +223,16 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}
return false;
}
- public void clampPosition(){
+
+ /* Input related methods. Override with super call to add your own input-based code like contextMenu */
+
+ public void clampPosition() {
this.x = (int) MathHelper.clamp(this.x, 0, mc.getWindow().getScaledWidth() - getWidth());
this.y = (int) MathHelper.clamp(this.y, 0, mc.getWindow().getScaledHeight() - getHeight());
}
public boolean mouseDragged(double mouseX, double mouseY, int button, int snapSize) {
- if(!isDraggable) return false;
+ if (!isDraggable) return false;
if (dragging && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
int newX = (int) (mouseX - startX);
int newY = (int) (mouseY - startY);
@@ -287,7 +273,6 @@ public void mouseReleased(double mouseX, double mouseY, int button) {
public void mouseScrolled(double mouseX, double mouseY, double vAmount, double hAmount) {
}
-
public boolean toggle() {
return this.display = !this.display;
}
@@ -299,7 +284,6 @@ public void onClose() {
/**
* Displays a faint grayish background if enabled or faint reddish background if disabled.
* Drawn with 2 pixel offset to all sides
- *
*/
protected void displayBg(DrawContext context) {
int backgroundColor = this.shouldDisplay() ? ColorHelper.getColor(0, 0, 0, 128) : ColorHelper.getColor(255, 0, 0, 128);
@@ -372,6 +356,8 @@ public String toString() {
'}';
}
+ public enum Anchor {TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER}
+
public abstract static class WidgetBuilder {
protected int x;
protected int y;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
index d3afbcc..489a799 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
@@ -6,7 +6,6 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtList;
-import net.minecraft.util.math.MathHelper;
import java.io.DataOutputStream;
import java.io.File;
@@ -182,7 +181,7 @@ public static void loadWidgets(File file) throws IOException {
widgets.clear();
if (file.exists() || (file = new File(file.getAbsolutePath() + ".backup")).exists()) {
- if(!file.exists()){
+ if (!file.exists()) {
printWarn("Main file " + file.getAbsolutePath() + " was not found... Loading from a found backup file");
}
@@ -205,7 +204,7 @@ public static void loadWidgets(File file) throws IOException {
}
}
- public static boolean doesWidgetFileExist(File file){
+ public static boolean doesWidgetFileExist(File file) {
return file.exists() || new File(file.getAbsolutePath() + ".backup").exists();
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
index 7b570ba..11d46e4 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
@@ -12,27 +12,26 @@
* This is just an example widget, not supposed to be used.
*/
public class ItemWidget extends Widget {
- public static WidgetData> DATA = new WidgetData<>("ItemWidget","Displays item texture", ItemWidget::new);
- public ItemStack item;
-
- public ItemWidget(ItemStack itemStack,String modId) {
+ public ItemStack item; public static WidgetData> DATA = new WidgetData<>("ItemWidget", "Displays item texture", ItemWidget::new);
+ public ItemWidget(ItemStack itemStack, String modId) {
super(DATA, modId);
this.item = itemStack;
}
+
public ItemWidget() {
this(ItemStack.EMPTY, "empty");
}
@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY) {
- context.drawItem(item,x,y);
+ context.drawItem(item, x, y);
widgetBox.setSizeAndPosition(getX(), getY(), 16, 16, this.shouldScale, GlobalConfig.get().getScale());
}
@Override
public void writeToTag(NbtCompound tag) {
super.writeToTag(tag);
- tag.putInt("ItemID",Item.getRawId(item.getItem()));
+ tag.putInt("ItemID", Item.getRawId(item.getItem()));
}
@Override
@@ -45,8 +44,9 @@ public void setItemStack(ItemStack item) {
this.item = item;
}
- public static class Builder extends WidgetBuilder{
- ItemStack itemStack;
+ public static class Builder extends WidgetBuilder {
+ ItemStack itemStack;
+
public Builder setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
return self();
@@ -59,7 +59,9 @@ protected Builder self() {
@Override
public ItemWidget build() {
- return new ItemWidget(itemStack,modID);
+ return new ItemWidget(itemStack, modID);
}
}
+
+
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
index 4db69cb..b14a296 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
@@ -7,7 +7,9 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuManager;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProvider;
-import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.BooleanOption;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.ColorOption;
+import com.tanishisherewith.dynamichud.utils.contextmenu.options.DoubleOption;
import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.MinecraftSkin;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.widget.WidgetData;
@@ -16,26 +18,22 @@
import org.lwjgl.glfw.GLFW;
import java.awt.*;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
public class TextWidget extends Widget implements ContextMenuProvider {
public Color textColor;
protected boolean shadow; // Whether to draw a shadow behind the text
- public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new);
protected boolean rainbow; // Whether to apply a rainbow effect to the text
+ public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new);
protected int rainbowSpeed = 2; //Speed of the rainbow effect
Supplier textSupplier;
String dynamicRegistryKey;
DynamicValueRegistry dynamicValueRegistry = null;
private ContextMenu menu;
-
public TextWidget() {
this(null, null, false, false, Color.WHITE, "unknown");
}
+
/**
* Searches for the supplier within the {@link DynamicValueRegistry#globalRegistry} using the given registryKey
*
@@ -85,7 +83,7 @@ public void createMenu() {
menu.addOption(new BooleanOption("Shadow", () -> this.shadow, value -> this.shadow = value, BooleanOption.BooleanType.ON_OFF));
menu.addOption(new BooleanOption("Rainbow", () -> this.rainbow, value -> this.rainbow = value, BooleanOption.BooleanType.ON_OFF));
menu.addOption(new ColorOption("TextColor", menu, () -> this.textColor, value -> this.textColor = value));
- menu.addOption(new DoubleOption("RainbowSpeed", 1, 5.0f, 1, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(),menu));
+ menu.addOption(new DoubleOption("RainbowSpeed", 1, 5.0f, 1, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(), menu));
/* TEST
AtomicReference option = new AtomicReference<>("Enum1");
@@ -111,7 +109,7 @@ public void renderWidget(DrawContext drawContext, int mouseX, int mouseY) {
drawContext.drawText(mc.textRenderer, text, getX() + 2, getY() + 2, color, shadow);
widgetBox.setSizeAndPosition(getX(), getY(), mc.textRenderer.getWidth(text) + 3, mc.textRenderer.fontHeight + 2, this.shouldScale, GlobalConfig.get().getScale());
}
- menu.set(getX(),getY(),(int) Math.ceil(getHeight()));
+ menu.set(getX(), getY(), (int) Math.ceil(getHeight()));
}
@Override
@@ -173,7 +171,7 @@ public void readFromTag(NbtCompound tag) {
dynamicValueRegistry = dvr;
return;
}
- createMenu();
+ createMenu();
}
@Override
@@ -232,4 +230,6 @@ public TextWidget build() {
return widget;
}
}
+
+
}