Skip to content

Commit

Permalink
fix: some issues that occurred while testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Morazzer committed Nov 21, 2024
1 parent f60ea24 commit 171835f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public Text getName() {

@Override
public void buildSettings(HudElementSettingBuilder builder) {
super.buildSettings(builder);
addBasicSetting(builder);
addConfigSetting(builder);
}

public DungeonInstance getMockInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean shouldRender() {
return this.hudEditAction == HudEditAction.SHOW_ALL;
}

if (this.hudEditAction == HudEditAction.ALL_ENABLED) {
if (this.hudEditAction == HudEditAction.ALL_ENABLED || this.hudEditAction == HudEditAction.SHOW_ALL) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import codes.cookies.mod.services.mining.CrystalStatusService;
import codes.cookies.mod.utils.items.ItemUtils;
import codes.cookies.mod.utils.skyblock.LocationUtils;

import org.apache.commons.lang3.StringUtils;

import net.minecraft.text.MutableText;
Expand Down Expand Up @@ -158,7 +159,11 @@ public boolean shouldRender() {

@Override
public int getWidth() {
return 170;
if (this.hudEditAction != HudEditAction.NONE) {
return 170;
}

return super.lastWidth;
}

@Override
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/codes/cookies/mod/render/hud/HudEditScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ private void renderElement(DrawContext context, HudElement hudElement, float del
context.cm$withMatrix(stack -> {
stack.translate(elementX, elementY, 0);
stack.scale(hudElement.getScale(), hudElement.getScale(), 0);
if (currentlyHovered == hudElement) {
hudElement.getNormalizedBoundingBox().fill(context, 0xFFABABAB);
} else {
hudElement.getNormalizedBoundingBox().fill(context, 0xAB000000);
if (!hudElement.getPosition().isBackground()) {
if (currentlyHovered == hudElement) {
hudElement.getNormalizedBoundingBox().fill(context, 0xFFABABAB);
} else {
hudElement.getNormalizedBoundingBox().fill(context, 0xAB000000);
}
}
hudElement.renderChecks(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import codes.cookies.mod.render.hud.settings.ValueSetting;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.MustBeInvokedByOverriders;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -39,7 +38,7 @@ public HudElement(Identifier identifier) {

public void renderBackground(DrawContext drawContext) {
if (this.position.isBackground()) {
this.getBoundingBox().fill(drawContext, this.position.getBackgroundColor());
this.getNormalizedBoundingBox().fill(drawContext, this.position.getBackgroundColor());
}
}

Expand All @@ -58,8 +57,7 @@ public final void renderChecks(DrawContext drawContext, TextRenderer textRendere

public abstract Text getName();

@MustBeInvokedByOverriders
public void buildSettings(HudElementSettingBuilder builder) {
protected void addBasicSetting(HudElementSettingBuilder builder) {
builder.prependSetting(new EnumCycleSetting<>(
Text.literal("Alignment"),
Text.literal(""),
Expand All @@ -70,14 +68,36 @@ public void buildSettings(HudElementSettingBuilder builder) {
builder.prependSetting(new ValueSetting(Text.literal("Y: " + this.getY())));
builder.prependSetting(new ValueSetting(Text.literal("X: " + this.getX())));
builder.prependSetting(new LiteralSetting(getName(), HudElementSettingType.METADATA));
}

builder.addSetting(new BooleanSetting(Text.literal("test"), Text.literal("Test"), this.position::isBackground, this.position::setBackground));
builder.addSetting(new ColorSetting(Text.literal("test2"), Text.literal("Test3"), this.position::getColorValue, this.position::setColorValue, true));

protected void addConfigSetting(HudElementSettingBuilder builder) {
final List<Option<?, ?>> hudSettings = ConfigManager.getConfigReader().getHudSettings(this);
hudSettings.forEach(builder::addOption);
}

protected void addBackgroundSetting(HudElementSettingBuilder builder) {
builder.addSetting(new BooleanSetting(
Text.literal("Enable Background"),
Text.literal("Enables a background for the hud element"),
this.position::isBackground, this.position::setBackground)
);
builder.addSetting(
new ColorSetting(
Text.literal("Background Color"),
Text.literal("The background color for the hud element"),
this.position::getColorValue,
this.position::setColorValue,
true
)
);
}

public void buildSettings(HudElementSettingBuilder builder) {
addBasicSetting(builder);
addBackgroundSetting(builder);
addConfigSetting(builder);
}

public int getX() {
return this.position.clampX(getWidth());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import java.util.List;

import codes.cookies.mod.render.hud.internal.HudEditAction;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public abstract class MultiLineTextHudElement extends HudElement {
protected int lastWidth;
protected int lastHeight;
public MultiLineTextHudElement(Identifier identifier) {
super(identifier);
}
Expand All @@ -18,9 +22,20 @@ public void render(DrawContext drawContext, TextRenderer textRenderer, float tic
this.renderBackground(drawContext);
int yOffset = 0;
lastWidth = 0;
for (Text text : getText()) {
lastHeight = MinecraftClient.getInstance().textRenderer.fontHeight;
final List<Text> lines = getText();
if (lines.isEmpty()) {
if (hudEditAction != HudEditAction.NONE) {
renderSingleText(drawContext, textRenderer, getName(), yOffset);
lastWidth += 10;
}

return;
}
for (Text text : lines) {
renderSingleText(drawContext, textRenderer, text, yOffset);
yOffset += 10;
lastWidth += 10;
}
}

Expand All @@ -31,6 +46,10 @@ protected void renderSingleText(DrawContext drawContext, TextRenderer textRender

@Override
public int getHeight() {
if (hudEditAction == HudEditAction.NONE) {
return lastHeight;
}

return getMaxRows() * 10;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class HudElementSettings {
Codec.FLOAT.fieldOf("y").forGetter(HudElementSettings::getRelativeY),
Codec.FLOAT.fieldOf("scale").forGetter(HudElementSettings::getScale),
Alignment.CODEC.fieldOf("alignment").forGetter(HudElementSettings::getAlignment),
Codec.BOOL.fieldOf("background").forGetter(HudElementSettings::isBackground),
Codec.INT.fieldOf("background_color").forGetter(HudElementSettings::getBackgroundColor)
Codec.BOOL.optionalFieldOf("background", false).forGetter(HudElementSettings::isBackground),
Codec.INT.optionalFieldOf("background_color", 0xFFFFFFFF).forGetter(HudElementSettings::getBackgroundColor)
).apply(instance, HudElementSettings::new));

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraft.text.Text;

public class ColorInputWidget extends TextFieldWidget {
private final boolean canHaveAlpha = false;
private final boolean canHaveAlpha;
private Color color;
@Setter
private Consumer<Color> callback = Consumers.nop();
Expand All @@ -29,6 +29,7 @@ public ColorInputWidget(
) {
super(textRenderer, 10, height, Text.literal(toText(text, canHaveAlpha)));
this.update();
this.canHaveAlpha = canHaveAlpha;
}
private int getBackgroundColor() {
return 0xFF << 24 | ~this.color.getRGB() & 0xFFFFFF;
Expand Down

0 comments on commit 171835f

Please sign in to comment.