Skip to content

Commit

Permalink
Many refactors, renamed files, smoothened MinecraftSkin panel. Added …
Browse files Browse the repository at this point in the history
…a panel behind color option as well. Added color settings in YACL.
  • Loading branch information
tanishisherewithhh committed Oct 22, 2024
1 parent 5b7f7fb commit 3f93c11
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.tanishisherewith.dynamichud.config;

import com.tanishisherewith.dynamichud.helpers.ColorHelper;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
import dev.isxander.yacl3.api.controller.ColorControllerBuilder;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder;
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.config.v2.impl.autogen.ColorFieldImpl;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.awt.*;

public final class GlobalConfig {
public static final ConfigClassHandler<GlobalConfig> HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class)
.id(Identifier.of("dynamichud", "dynamichud_config"))
Expand All @@ -37,6 +42,12 @@ public final class GlobalConfig {
@SerialEntry
private int snapSize = 100;

@SerialEntry
private Color hudActiveColor = new Color(0, 0, 0, 128);

@SerialEntry
private Color hudInactiveColor = new Color(255, 0, 0, 128);

public static GlobalConfig get() {
return INSTANCE;
}
Expand Down Expand Up @@ -75,6 +86,18 @@ public Screen createYACLGUI() {
.controller(integerOption -> IntegerFieldControllerBuilder.create(integerOption).range(10, 500))
.build())
.build())
.option(Option.<Color>createBuilder()
.name(Text.literal("Widget HUD Active Background Color"))
.description(OptionDescription.of(Text.literal("Color of the background of the widget when it will be rendered")))
.binding(new Color(0, 0, 0, 128), () -> this.hudActiveColor, newVal -> this.hudActiveColor = newVal)
.controller(ColorControllerBuilder::create)
.build())
.option(Option.<Color>createBuilder()
.name(Text.literal("Widget HUD Inactive Background Color"))
.description(OptionDescription.of(Text.literal("Color of the background of the widget when it will NOT be rendered")))
.binding(new Color(255, 0, 0, 128), () -> this.hudInactiveColor, newVal -> this.hudInactiveColor = newVal)
.controller(ColorControllerBuilder::create)
.build())
.build())
.save(HANDLER::save)
.build()
Expand All @@ -96,4 +119,12 @@ public boolean shouldDisplayDescriptions() {
public int getSnapSize() {
return snapSize;
}

public Color getHudInactiveColor() {
return hudInactiveColor;
}

public Color getHudActiveColor() {
return hudActiveColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tanishisherewith.dynamichud.utils.Input;
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.ContextMenuScreenFactory;
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.DefaultContextMenuScreenFactory;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.math.MathHelper;
Expand All @@ -19,18 +20,18 @@ public class ContextMenu implements Input {
public final Color darkerBackgroundColor;
//The properties of a context menu
protected final ContextMenuProperties properties;
private final List<Option<?>> options = new ArrayList<>(); // The list of options in the context menu
private final ContextMenuScreenFactory screenFactory;
protected final List<Option<?>> options = new ArrayList<>(); // The list of options in the context menu
protected final ContextMenuScreenFactory screenFactory;
public int x, y;
// Width is counted while the options are being rendered.
// FinalWidth is the width at the end of the count.
private int width = 0;
private int finalWidth = 0;
private int height = 0, widgetHeight = 0;
private boolean shouldDisplay = false;
private float scale = 0.0f;
private Screen parentScreen = null;
private boolean newScreenFlag = false;
protected int width = 0;
protected int finalWidth = 0;
protected int height = 0, widgetHeight = 0;
protected boolean shouldDisplay = false;
protected float scale = 0.0f;
protected Screen parentScreen = null;
protected boolean newScreenFlag = false;

public ContextMenu(int x, int y, ContextMenuProperties properties) {
this(x, y, properties, new DefaultContextMenuScreenFactory());
Expand Down Expand Up @@ -85,16 +86,14 @@ public void update() {
}

public void close() {
if (properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null) {
shouldDisplay = false;
newScreenFlag = false;
DynamicHUD.MC.setScreen(parentScreen);
}
shouldDisplay = false;
newScreenFlag = false;
for (Option<?> option : options) {
option.onClose();
}
shouldDisplay = false;
newScreenFlag = false;
if (properties.getSkin().shouldCreateNewScreen() && scale <= 0 && parentScreen != null) {
DynamicHUD.MC.setScreen(parentScreen);
}
}

public void open() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
@Override
public void close() {
contextMenu.close();
contextMenu.setVisible(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.utils.BooleanPool;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption.ColorGradientPicker;
import net.minecraft.client.gui.DrawContext;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption.ColorGradient;

import java.awt.*;
import java.util.function.Consumer;
Expand All @@ -13,13 +11,13 @@ public class ColorOption extends Option<Color> {
public String name = "Empty";
public boolean isVisible = false;
private ContextMenu parentMenu = null;
private ColorGradientPicker colorPicker = null;
private ColorGradient colorGradient = null;

public ColorOption(String name, ContextMenu parentMenu, Supplier<Color> getter, Consumer<Color> setter) {
super(getter, setter);
this.name = name;
this.parentMenu = parentMenu;
colorPicker = new ColorGradientPicker(x + this.parentMenu.getFinalWidth(), y - 10, get(), this::set, 50, 100);
colorGradient = new ColorGradient(x + this.parentMenu.getFinalWidth(), y - 10, get(), this::set, 50, 100);
this.renderer.init(this);
}

Expand All @@ -28,36 +26,36 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isMouseOver(mouseX, mouseY)) {
isVisible = !isVisible;
if (isVisible) {
colorPicker.setPos(this.x + parentMenu.getFinalWidth() + 7, y - 10);
colorPicker.display();
colorGradient.setPos(this.x + parentMenu.getFinalWidth() + 7, y - 10);
colorGradient.display();
} else {
colorPicker.close();
colorGradient.close();
}
}
colorPicker.mouseClicked(mouseX, mouseY, button);
colorGradient.mouseClicked(mouseX, mouseY, button);
return super.mouseClicked(mouseX, mouseY, button);
}

@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
colorPicker.mouseReleased(mouseX, mouseY, button);
colorGradient.mouseReleased(mouseX, mouseY, button);
return super.mouseReleased(mouseX, mouseY, button);
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
colorPicker.mouseDragged(mouseX, mouseY, button);
colorGradient.mouseDragged(mouseX, mouseY, button);
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

public ColorGradientPicker getColorPicker() {
return colorPicker;
public ColorGradient getColorGradient() {
return colorGradient;
}

@Override
public void onClose() {
isVisible = false;
colorPicker.close();
colorGradient.close();
}

public ContextMenu getParentMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import org.apache.commons.lang3.Validate;
import org.lwjgl.glfw.GLFW;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

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

import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

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

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.tanishisherewith.dynamichud.utils.contextmenu;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.DynamicHUD;
import com.tanishisherewith.dynamichud.utils.Input;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.SkinRenderer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

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

import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.tanishisherewith.dynamichud.utils.BooleanPool;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;

import java.util.Objects;
import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public void setX(int x) {
this.x = x;
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

public boolean isMouseOver(double mouseX, double mouseY) {
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
import java.nio.ByteBuffer;
import java.util.function.Consumer;

public class ColorGradientPicker {
public class ColorGradient {
final MinecraftClient client = MinecraftClient.getInstance();
private final Consumer<Color> onColorSelected; // The callback to call when a color is selected
private final GradientSlider gradientSlider;
private final GradientBox gradientBox;
private final HueSlider gradientSlider;
private final SaturationHueBox gradientBox;
private final ColorPickerButton colorPickerButton;
private final AlphaSlider alphaSlider;
private final int boxSize;
private final Color initialColor;
private int x, y;
private boolean display = false;

public ColorGradientPicker(int x, int y, Color initialColor, Consumer<Color> onColorSelected, int boxSize, int colors) {
public ColorGradient(int x, int y, Color initialColor, Consumer<Color> onColorSelected, int boxSize, int colors) {
this.x = x;
this.y = y;
this.initialColor = initialColor;
this.onColorSelected = onColorSelected;
this.gradientSlider = new GradientSlider(x, y, colors, 10);
this.gradientBox = new GradientBox(x, y + 20, boxSize);
this.gradientSlider = new HueSlider(x, y, colors, 10);
this.gradientBox = new SaturationHueBox(x, y + 20, boxSize);
this.alphaSlider = new AlphaSlider(x, y, 10, boxSize, initialColor);

float[] hsv = new float[3];
Expand Down Expand Up @@ -182,4 +182,27 @@ public void mouseDragged(double mouseX, double mouseY, int button) {
onColorSelected.accept(alphaSlider.getColor());
}

public int getBoxSize() {
return boxSize;
}

public boolean isDisplay() {
return display;
}

public ColorPickerButton getColorPickerButton() {
return colorPickerButton;
}

public AlphaSlider getAlphaSlider() {
return alphaSlider;
}

public HueSlider getGradientSlider() {
return gradientSlider;
}

public SaturationHueBox getGradientBox() {
return gradientBox;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public void render(DrawContext drawContext, int x, int y) {
public int getHeight() {
return height;
}

public int getWidth() {
return width;
}
public boolean onClick(double mouseX, double mouseY, int button) {
if (button == 0) {
if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import java.awt.*;

public class GradientSlider {
public class HueSlider {
private final int width;
private final int height;
private int x;
private int y;
private float hue = 0.0f;
private boolean isDragging = false;

public GradientSlider(int x, int y, int width, int height) {
public HueSlider(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
Expand Down
Loading

0 comments on commit 3f93c11

Please sign in to comment.