diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 01d4a8e..f9eeab1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -36,3 +36,11 @@ jobs: with: name: Dynamichud path: build/libs/ + - name: Release + uses: softprops/action-gh-release@v2 + with: + name: "DynamicHUD Pre-release" + prerelease: true + fail_on_unmatched_files: true + generate_release_notes: true; + files: Dynamichud.zip diff --git a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java index 9c3bc60..00f0885 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java +++ b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java @@ -1,5 +1,6 @@ package com.tanishisherewith.dynamichud.screens; +import com.tanishisherewith.dynamichud.widget.Widget; import com.tanishisherewith.dynamichud.widget.WidgetRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; @@ -32,7 +33,9 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - widgetRenderer.mouseClicked(mouseX, mouseY, button); + if(widgetRenderer.mouseClicked(mouseX, mouseY, button)){ + handleClickOnWidget(widgetRenderer.selectedWidget,mouseX,mouseY,button); + } return false; } @@ -79,6 +82,9 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) // Draw each widget widgetRenderer.renderWidgets(drawContext, mouseX, mouseY); } + public void handleClickOnWidget(Widget widget, double mouseX, double mouseY, int button){ + + } @Override public void close() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java index 17d58e4..272019c 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java @@ -10,7 +10,10 @@ public class ContextMenu { private final List> options = new ArrayList<>(); // The list of options in the context menu public int x, y; - public int width = 0, finalWidth = 0; + // Width is counted while the options are being rendered. + // FinalWidth is the width at the end of the count. + private int width = 0; + public int finalWidth = 0; public int height = 0; public Color backgroundColor = new Color(107, 112, 126, 124); private Color darkerBorderColor = backgroundColor.darker().darker().darker().darker().darker().darker(); @@ -134,11 +137,6 @@ public int getX() { public int getY() { return y; } - - public int getWidth() { - return width; - } - public List> getOptions() { return options; } @@ -146,4 +144,8 @@ public List> getOptions() { public int getHeight() { return height; } + + public int getWidth() { + return finalWidth; + } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java index a1b3497..883ef92 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java @@ -27,8 +27,6 @@ public RunnableOption(String name, Supplier getter, Consumer s } Color DARK_RED = new Color(116, 0, 0); Color DARK_GREEN = new Color(24, 132, 0, 226); - - @Override public void render(DrawContext drawContext, int x, int y) { super.render(drawContext, x, y); diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetBox.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetBox.java index cf2670d..aea7f75 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetBox.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetBox.java @@ -45,7 +45,7 @@ public boolean intersects(WidgetBox other) { return !(this.y + this.height < other.y); } - public void setSizeAndPosition(float x, float y, float width, float height) { + public void setSizeAndPositionNoScale(float x, float y, float width, float height) { this.x = x; this.y = y; this.height = height; diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java index db0c9c5..6b9f8a6 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java @@ -68,10 +68,10 @@ public void renderWidgets(DrawContext context, int mouseX, int mouseY) { } } - public void mouseClicked(double mouseX, double mouseY, int button) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { Screen currentScreen = DynamicHUD.MC.currentScreen; if (currentScreen == null) { - return; + return false; } if (currentScreen instanceof AbstractMoveableScreen) { for (Widget widget : widgets) { @@ -79,10 +79,11 @@ public void mouseClicked(double mouseX, double mouseY, int button) { // if they are overlapped on each other. if (widget.mouseClicked(mouseX, mouseY, button)) { selectedWidget = widget; - return; + return true; } } } + return false; } public void mouseDragged(double mouseX, double mouseY, int button, int snapSize) { diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java new file mode 100644 index 0000000..002e9c8 --- /dev/null +++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java @@ -0,0 +1,61 @@ +package com.tanishisherewith.dynamichud.widgets; + +import com.tanishisherewith.dynamichud.config.GlobalConfig; +import com.tanishisherewith.dynamichud.widget.Widget; +import com.tanishisherewith.dynamichud.widget.WidgetData; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; + +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) { + 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); + 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())); + } + + @Override + public void readFromTag(NbtCompound tag) { + super.readFromTag(tag); + item = Item.byRawId(tag.getInt("ItemID")).getDefaultStack(); + } + + public void setItemStack(ItemStack item) { + this.item = item; + } + public static class Builder extends WidgetBuilder{ + ItemStack itemStack; + public Builder setItemStack(ItemStack itemStack) { + this.itemStack = itemStack; + return self(); + } + + @Override + protected Builder self() { + return this; + } + + @Override + public ItemWidget build() { + 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 efdf1a4..9e6fa6a 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java @@ -169,12 +169,6 @@ public void readFromTag(NbtCompound tag) { createMenu(); } - public enum Enum { - Enum1, - Enum2, - Enum3 - } - public static class Builder extends WidgetBuilder { protected boolean shadow = false; protected boolean rainbow = false;