Skip to content

Commit

Permalink
ItemWidget and a few changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Apr 19, 2024
1 parent beb3e02 commit 67fc7f0
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 19 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
public class ContextMenu {
private final List<Option<?>> 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();
Expand Down Expand Up @@ -134,16 +137,15 @@ public int getX() {
public int getY() {
return y;
}

public int getWidth() {
return width;
}

public List<Option<?>> getOptions() {
return options;
}

public int getHeight() {
return height;
}

public int getWidth() {
return finalWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public RunnableOption(String name, Supplier<Boolean> getter, Consumer<Boolean> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@ 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) {
// This essentially acts as a Z - layer where the widget first in the list is moved and dragged
// 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Builder,ItemWidget>{
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ public void readFromTag(NbtCompound tag) {
createMenu();
}

public enum Enum {
Enum1,
Enum2,
Enum3
}

public static class Builder extends WidgetBuilder<Builder, TextWidget> {
protected boolean shadow = false;
protected boolean rainbow = false;
Expand Down

0 comments on commit 67fc7f0

Please sign in to comment.