Skip to content

Commit

Permalink
First round of tweaks based on covers feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Jan 11, 2024
1 parent 228be19 commit 785f905
Show file tree
Hide file tree
Showing 80 changed files with 883 additions and 1,283 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'

compileOnly(fg.deobf("mezz.jei:jei-${config.mc_version}-common-api:${config.jei_version}"))
compileOnly(fg.deobf("mezz.jei:jei-${config.mc_version}-forge-api:${config.jei_version}"))
compileOnly(fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}"))
compileOnly(fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}"))
}

test {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ org.gradle.daemon=false
mc_version=1.20.1
forge_version=47.1.65
mod_version=4.4.0
jei_version=15.2.0.27
72 changes: 72 additions & 0 deletions src/main/java/codechicken/lib/colour/Colour.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,78 @@ public Colour set(float[] floats) {
return set(floats[0], floats[1], floats[2], floats[3]);
}

public Colour r(float r) {
this.r = (byte) (255F * r);
return this;
}

public Colour g(float g) {
this.g = (byte) (255F * g);
return this;
}

public Colour b(float b) {
this.b = (byte) (255F * b);
return this;
}

public Colour a(float a) {
this.a = (byte) (255F * a);
return this;
}

public Colour r(int r) {
this.r = (byte) r;
return this;
}

public Colour g(int g) {
this.g = (byte) g;
return this;
}

public Colour b(int b) {
this.b = (byte) b;
return this;
}

public Colour a(int a) {
this.a = (byte) a;
return this;
}

public float r() {
return r / 255F;
}

public float g() {
return g / 255F;
}

public float b() {
return b / 255F;
}

public float a() {
return a / 255F;
}

public float rI() {
return r & 0xFF;
}

public float gI() {
return g & 0xFF;
}

public float bI() {
return b & 0xFF;
}

public float aI() {
return a & 0xFF;
}

/**
* Flips a color between ABGR and RGBA.
*
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/codechicken/lib/gui/modular/ModularGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import codechicken.lib.gui.modular.lib.geometry.Constraint;
import codechicken.lib.gui.modular.lib.geometry.GeoParam;
import codechicken.lib.gui.modular.lib.geometry.GuiParent;
import net.covers1624.quack.collection.FastStream;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -55,7 +56,6 @@ public class ModularGui implements GuiParent<ModularGui> {
private Screen parentScreen;

private Component guiTitle = Component.empty();
private GuiElement<?> focused;
private ResourceLocation newCursor = null;

private final Map<Slot, GuiElement<?>> slotHandlers = new HashMap<>();
Expand Down Expand Up @@ -492,17 +492,6 @@ public double ySize() {

//=== Other ===//

// @Override
// public void setFocused(@Nullable GuiElement<?> element) {
// focused = element;
// }
//
// @Nullable
// @Override
// public GuiElement<?> getFocused() {
// return focused;
// }

public double computeMouseX() {
return mc.mouseHandler.xpos() * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
}
Expand Down Expand Up @@ -552,8 +541,8 @@ public void removeJEIExclude(GuiElement<?> element) {
jeiExclusions.remove(element);
}

public Stream<GuiElement<?>> getJeiExclusions() {
return jeiExclusions.stream().filter(GuiElement::isEnabled);
public FastStream<GuiElement<?>> getJeiExclusions() {
return FastStream.of(jeiExclusions).filter(GuiElement::isEnabled);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float
imageWidth = (int) root.getValue(GeoParam.WIDTH);
imageHeight = (int) root.getValue(GeoParam.HEIGHT);

modularGui.setVanillaSlotRendering(false);
if (modularGui.renderBackground()) {
renderBackground(graphics);
}
Expand Down
200 changes: 100 additions & 100 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,106 @@ public GuiButton(@NotNull GuiParent<?> parent) {
super(parent);
}

/**
* Creates a new gui button that looks and acts exactly like a standard vanilla button.
*/
public static GuiButton vanilla(@NotNull GuiParent<?> parent, @Nullable Component label, Runnable onClick) {
return vanilla(parent, label).onClick(onClick);
}

/**
* Creates a new gui button that looks and acts exactly like a standard vanilla button.
*/
public static GuiButton vanilla(@NotNull GuiParent<?> parent, @Nullable Component label) {
GuiButton button = new GuiButton(parent);
GuiTexture texture = new GuiTexture(button, CCGuiTextures.getter(() -> button.toggleState() ? "dynamic/button_highlight" : "dynamic/button_vanilla"));
texture.dynamicTexture();
GuiRectangle highlight = new GuiRectangle(button).border(() -> button.hoverTime() > 0 ? 0xFFFFFFFF : 0);

Constraints.bind(texture, button);
Constraints.bind(highlight, button);

if (label != null) {
button.setLabel(new GuiText(button, label));
Constraints.bind(button.getLabel(), button, 0, 2, 0, 2);
}

return button;
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, Component label, Runnable onPress) {
return vanillaAnimated(parent, label == null ? null : () -> label, onPress);
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Runnable onPress) {
return vanillaAnimated(parent, label).onPress(onPress);
}

//TODO Could use a quad-sliced texture for this.

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, Component label) {
return vanillaAnimated(parent, label == null ? null : () -> label);
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label) {
GuiButton button = new GuiButton(parent);
GuiTexture texture = new GuiTexture(button, CCGuiTextures.getter(() -> button.toggleState() || button.isPressed() ? "dynamic/button_pressed" : "dynamic/button_vanilla"));
texture.dynamicTexture();
GuiRectangle highlight = new GuiRectangle(button).border(() -> button.isMouseOver() ? 0xFFFFFFFF : 0);

Constraints.bind(texture, button);
Constraints.bind(highlight, button);

if (label != null) {
button.setLabel(new GuiText(button, label)
.constrain(TOP, Constraint.relative(button.get(TOP), () -> button.isPressed() ? -0.5D : 0.5D).precise())
.constrain(LEFT, Constraint.relative(button.get(LEFT), () -> button.isPressed() ? 1.5D : 2.5D).precise())
.constrain(WIDTH, Constraint.relative(button.get(WIDTH), -4))
.constrain(HEIGHT, Constraint.match(button.get(HEIGHT)))
);
}

return button;
}

/**
* Super simple button that is just a coloured rectangle with a label.
*/
public static GuiButton flatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Function<Boolean, Integer> buttonColour) {
return flatColourButton(parent, label, buttonColour, null);
}

/**
* Super simple button that is just a coloured rectangle with a label.
*/
public static GuiButton flatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Function<Boolean, Integer> buttonColour, @Nullable Function<Boolean, Integer> borderColour) {
GuiButton button = new GuiButton(parent);
GuiRectangle background = new GuiRectangle(button)
.fill(() -> buttonColour.apply(button.isMouseOver() || button.toggleState() || button.isPressed()))
.border(borderColour == null ? null : () -> borderColour.apply(button.isMouseOver() || button.toggleState() || button.isPressed()));
Constraints.bind(background, button);

if (label != null) {
GuiText text = new GuiText(button, label);
button.setLabel(text);
Constraints.bind(text, button, 0, 2, 0, 2);
}

return button;
}

/**
* When creating buttons with labels, use this method to store a reference to the label in the button fore easy retrival later.
*
Expand Down Expand Up @@ -232,104 +332,4 @@ public boolean mouseReleased(double mouseX, double mouseY, int button, boolean c
pressed = false;
return consumed;
}

/**
* Creates a new gui button that looks and acts exactly like a standard vanilla button.
*/
public static GuiButton vanilla(@NotNull GuiParent<?> parent, @Nullable Component label, Runnable onClick) {
return vanilla(parent, label).onClick(onClick);
}

/**
* Creates a new gui button that looks and acts exactly like a standard vanilla button.
*/
public static GuiButton vanilla(@NotNull GuiParent<?> parent, @Nullable Component label) {
GuiButton button = new GuiButton(parent);
GuiTexture texture = new GuiTexture(button, CCGuiTextures.getter(() -> button.toggleState() ? "dynamic/button_highlight" : "dynamic/button_vanilla"));
texture.dynamicTexture();
GuiRectangle highlight = new GuiRectangle(button).border(() -> button.hoverTime() > 0 ? 0xFFFFFFFF : 0);

Constraints.bind(texture, button);
Constraints.bind(highlight, button);

if (label != null) {
button.setLabel(new GuiText(button, label));
Constraints.bind(button.getLabel(), button, 0, 2, 0, 2);
}

return button;
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, Component label, Runnable onPress) {
return vanillaAnimated(parent, label == null ? null : () -> label, onPress);
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Runnable onPress) {
return vanillaAnimated(parent, label).onPress(onPress);
}

//TODO Could use a quad-sliced texture for this.

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, Component label) {
return vanillaAnimated(parent, label == null ? null : () -> label);
}

/**
* Creates a vanilla button with a "press" animation.
*/
public static GuiButton vanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label) {
GuiButton button = new GuiButton(parent);
GuiTexture texture = new GuiTexture(button, CCGuiTextures.getter(() -> button.toggleState() || button.isPressed() ? "dynamic/button_pressed" : "dynamic/button_vanilla"));
texture.dynamicTexture();
GuiRectangle highlight = new GuiRectangle(button).border(() -> button.isMouseOver() ? 0xFFFFFFFF : 0);

Constraints.bind(texture, button);
Constraints.bind(highlight, button);

if (label != null) {
button.setLabel(new GuiText(button, label)
.constrain(TOP, Constraint.relative(button.get(TOP), () -> button.isPressed() ? -0.5D : 0.5D).precise())
.constrain(LEFT, Constraint.relative(button.get(LEFT), () -> button.isPressed() ? 1.5D : 2.5D).precise())
.constrain(WIDTH, Constraint.relative(button.get(WIDTH), -4))
.constrain(HEIGHT, Constraint.match(button.get(HEIGHT)))
);
}

return button;
}

/**
* Super simple button that is just a coloured rectangle with a label.
*/
public static GuiButton flatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Function<Boolean, Integer> buttonColour) {
return flatColourButton(parent, label, buttonColour, null);
}

/**
* Super simple button that is just a coloured rectangle with a label.
*/
public static GuiButton flatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<Component> label, Function<Boolean, Integer> buttonColour, @Nullable Function<Boolean, Integer> borderColour) {
GuiButton button = new GuiButton(parent);
GuiRectangle background = new GuiRectangle(button)
.fill(() -> buttonColour.apply(button.isMouseOver() || button.toggleState() || button.isPressed()))
.border(borderColour == null ? null : () -> borderColour.apply(button.isMouseOver() || button.toggleState() || button.isPressed()));
Constraints.bind(background, button);

if (label != null) {
GuiText text = new GuiText(button, label);
button.setLabel(text);
Constraints.bind(text, button, 0, 2, 0, 2);
}

return button;
}
}
Loading

0 comments on commit 785f905

Please sign in to comment.