Skip to content

Commit

Permalink
Removed unnecessary methods and reverted TextWidget to use the Classi…
Browse files Browse the repository at this point in the history
…cSkin
  • Loading branch information
tanishisherewithhh committed Oct 22, 2024
1 parent 05da4c7 commit 5b7f7fb
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ public class ContextMenuProperties {
private boolean enableAnimations = true;
private Skin skin = new ClassicSkin();

private ContextMenuProperties() {
}
private ContextMenuProperties() {}

public static Builder builder() {
return new ContextMenuProperties().new Builder();
}

public static ContextMenuProperties createGenericSimplified() {
return new ContextMenuProperties().new Builder().build();
return new ContextMenuProperties();
}

// Getters for all properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public void updateProperties(ContextMenuProperties properties) {
this.properties = properties;
this.renderer = properties.getSkin().getRenderer((Class<Option<T>>) this.getClass());
if (renderer == null) {
DynamicHUD.logger.error("Renderer not found for class: {}", this.getClass().getName());
DynamicHUD.logger.error("Renderer not found for class: {} in the following skin: {}", this.getClass().getName(), properties.getSkin());
throw new RuntimeException();
}
}

public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
this.x = x;
this.y = y;
this.value = get();

// Retrieve the renderer and ensure it is not null
renderer.render(drawContext, this, x, y, mouseX, mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ public BooleanOption(String name, boolean defaultValue, BooleanType type) {
BooleanPool.put(name, defaultValue);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
value = get();
super.render(drawContext, x, y, mouseX, mouseY);

// properties.getSkin().getRenderer(BooleanOption.class).render(drawContext,this,x,y,mouseX,mouseY);
/*
int color = value ? Color.GREEN.getRGB() : Color.RED.getRGB();
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);
this.height = mc.textRenderer.fontHeight;
this.width = mc.textRenderer.getWidth(name) + 1;
*/
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ColorOption extends Option<Color> {
public String name = "Empty";
public boolean isVisible = false;
public ContextMenu parentMenu = null;
private ContextMenu parentMenu = null;
private ColorGradientPicker colorPicker = null;

public ColorOption(String name, ContextMenu parentMenu, Supplier<Color> getter, Consumer<Color> setter) {
Expand All @@ -23,35 +23,6 @@ public ColorOption(String name, ContextMenu parentMenu, Supplier<Color> getter,
this.renderer.init(this);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
super.render(drawContext, x, y, mouseX, mouseY);

// properties.getSkin().getRenderer(ColorOption.class).render(drawContext,this,x,y,mouseX,mouseY);

/*
int color = isVisible ? Color.GREEN.getRGB() : Color.RED.getRGB();
this.height = mc.textRenderer.fontHeight;
this.width = mc.textRenderer.getWidth(name) + 8;
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);
int shadowOpacity = Math.min(value.getAlpha(),90);
DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
x + width - 4,
y - 1,
8,
8,
2,
value.getRGB(),
shadowOpacity,
1,
1);
colorPicker.render(drawContext, this.x + parentMenu.finalWidth + 7, y - 10);
*/
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY)) {
Expand Down Expand Up @@ -88,4 +59,8 @@ public void onClose() {
isVisible = false;
colorPicker.close();
}

public ContextMenu getParentMenu() {
return parentMenu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,6 @@ public DoubleOption(String name, double minValue, double maxValue, float step, S
this.renderer.init(this);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
value = get();
super.render(drawContext, x, y, mouseX, mouseY);

//properties.getSkin().getRenderer(DoubleOption.class).render(drawContext,this,x,y,mouseX,mouseY);

/*
this.width = 35;
this.height = 16;
// Draw the label
TextRenderer textRenderer = mc.textRenderer;
DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, 0.7f);
String labelText = name + ": " + String.format("%.1f", value);
int labelWidth = textRenderer.getWidth(labelText);
this.width = Math.max(this.width, labelWidth);
drawContext.drawTextWithShadow(textRenderer, labelText, x, y + 1, 0xFFFFFFFF);
DrawHelper.stopScaling(drawContext.getMatrices());
float handleWidth = 3;
float handleHeight = 8;
double handleX = x + (value - minValue) / (maxValue - minValue) * (width - handleWidth);
double handleY = y + textRenderer.fontHeight + 1 + ((2 - handleHeight) / 2);
// Draw the slider
drawSlider(drawContext, x, y + textRenderer.fontHeight + 1, width, handleX);
// Draw the handle
DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
(float) handleX,
(float) handleY,
handleWidth,
handleHeight,
1,
0xFFFFFFFF,
90,
0.6f,
0.6f);
*/
}

public void drawSlider(DrawContext drawContext, int sliderX, int sliderY, int sliderWidth, double handleX) {
DrawHelper.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), sliderX, sliderY, sliderWidth, 2, 0xFFFFFFFF);
if (handleX - sliderX > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ public EnumOption(String name, Supplier<E> getter, Consumer<E> setter, E[] value
this.renderer.init(this);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
value = get();
super.render(drawContext, x, y, mouseX, mouseY);

// properties.getSkin().getRenderer(EnumOption.class).render(drawContext,this,x,y,mouseX,mouseY);

/*
this.height = mc.textRenderer.fontHeight + 1;
this.width = mc.textRenderer.getWidth(name + ": " + value.name()) + 1;
drawContext.drawText(mc.textRenderer, Text.of(name + ": "), x, y, Color.WHITE.getRGB(), false);
drawContext.drawText(mc.textRenderer, Text.of(value.name()), x + mc.textRenderer.getWidth(name + ": ") + 1, y, Color.CYAN.getRGB(), false);
*/
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ public ListOption(String name, Supplier<T> getter, Consumer<T> setter, List<T> v
this.renderer.init(this);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
value = get();
super.render(drawContext, x, y, mouseX, mouseY);

// properties.getSkin().getRenderer(ListOption.class).render(drawContext,this,x,y,mouseX,mouseY);
/*
this.height = mc.textRenderer.fontHeight + 1;
this.width = mc.textRenderer.getWidth(name + ": " + value.toString()) + 1;
drawContext.drawText(mc.textRenderer, Text.of(name + ": "), x, y, Color.WHITE.getRGB(), false);
drawContext.drawText(mc.textRenderer, Text.of(value.toString()), x + mc.textRenderer.getWidth(name + ": ") + 1, y, Color.CYAN.getRGB(), false);
*/
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ public RunnableOption(String name, boolean defaultValue, Runnable task) {
BooleanPool.put(name, defaultValue);
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
value = get();
super.render(drawContext, x, y, mouseX, mouseY);

//properties.getSkin().getRenderer(RunnableOption.class).render(drawContext,this,x,y,mouseX,mouseY);

/*
this.height = mc.textRenderer.fontHeight;
this.width = mc.textRenderer.getWidth("Run: " + name);
int color = value ? DARK_GREEN.getRGB() : DARK_RED.getRGB();
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);
*/
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public SubMenuOption(String name, ContextMenu parentMenu) {
this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value), parentMenu.getProperties().copy());
}

@Override
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
super.render(drawContext, x, y, mouseX, mouseY);
// properties.getSkin().getRenderer(SubMenuOption.class).render(drawContext,this,x,y,mouseX,mouseY);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in
1,
1);

option.getColorPicker().render(drawContext, x + option.parentMenu.getFinalWidth() + 7, y - 10);
option.getColorPicker().render(drawContext, x + option.getParentMenu().getFinalWidth() + 7, y - 10);
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i
}
}

public class ClassicListRenderer<E> implements SkinRenderer<ListOption<E>> {
public static class ClassicListRenderer<E> implements SkinRenderer<ListOption<E>> {
@Override
public void render(DrawContext drawContext, ListOption<E> option, int x, int y, int mouseX, int mouseY) {
option.setHeight(mc.textRenderer.fontHeight + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem;

import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import net.minecraft.client.gui.DrawContext;

public class ModernSkin extends Skin{
@Override
public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public TextWidget(DynamicValueRegistry dynamicValueRegistry, String dynamicRegis
}

public void createMenu() {
ContextMenuProperties properties = ContextMenuProperties.builder()
.skin(new MinecraftSkin(MinecraftSkin.PanelColor.DARK_PANEL))
.build();
ContextMenuProperties properties = ContextMenuProperties.createGenericSimplified();

menu = new ContextMenu(getX(), getY(), properties);
menu.getProperties().getSkin().setContextMenu(menu);
Expand Down

0 comments on commit 5b7f7fb

Please sign in to comment.