Merge pull request #4 from Fretuks/add-ui-bar-adjustment-and-resizing-options

Add configurable HUD bar sizing and offsets
This commit is contained in:
2026-01-24 09:16:30 +01:00
committed by GitHub
2 changed files with 68 additions and 23 deletions
@@ -27,6 +27,12 @@ public final class ConfigMM {
public final ForgeConfigSpec.BooleanValue DISABLE_SHADERS; public final ForgeConfigSpec.BooleanValue DISABLE_SHADERS;
public final ForgeConfigSpec.DoubleValue FLASH_STRENGTH_MULTIPLIER; public final ForgeConfigSpec.DoubleValue FLASH_STRENGTH_MULTIPLIER;
public final ForgeConfigSpec.DoubleValue SANITY_DESAT_MULTIPLIER; public final ForgeConfigSpec.DoubleValue SANITY_DESAT_MULTIPLIER;
public final ForgeConfigSpec.IntValue BAR_WIDTH;
public final ForgeConfigSpec.IntValue BAR_HEIGHT;
public final ForgeConfigSpec.IntValue TEMPO_BAR_X_OFFSET;
public final ForgeConfigSpec.IntValue TEMPO_BAR_Y_OFFSET;
public final ForgeConfigSpec.IntValue SANITY_BAR_X_OFFSET;
public final ForgeConfigSpec.IntValue SANITY_BAR_Y_OFFSET;
Client(ForgeConfigSpec.Builder b) { Client(ForgeConfigSpec.Builder b) {
b.push("visual"); b.push("visual");
@@ -43,6 +49,32 @@ public final class ConfigMM {
.comment("Intensity of desaturation from low sanity.") .comment("Intensity of desaturation from low sanity.")
.defineInRange("sanityDesaturationMultiplier", 1.0, 0.0, 3.0); .defineInRange("sanityDesaturationMultiplier", 1.0, 0.0, 3.0);
b.pop().push("hud");
BAR_WIDTH = b
.comment("Width of sanity/tempo bars in pixels.")
.defineInRange("barWidth", 102, 40, 240);
BAR_HEIGHT = b
.comment("Height of sanity/tempo bars in pixels.")
.defineInRange("barHeight", 9, 4, 30);
TEMPO_BAR_X_OFFSET = b
.comment("Horizontal offset for the tempo bar relative to its default position.")
.defineInRange("tempoBarXOffset", 0, -300, 300);
TEMPO_BAR_Y_OFFSET = b
.comment("Vertical offset for the tempo bar relative to its default position.")
.defineInRange("tempoBarYOffset", 0, -300, 300);
SANITY_BAR_X_OFFSET = b
.comment("Horizontal offset for the sanity bar relative to its default position.")
.defineInRange("sanityBarXOffset", 0, -300, 300);
SANITY_BAR_Y_OFFSET = b
.comment("Vertical offset for the sanity bar relative to its default position.")
.defineInRange("sanityBarYOffset", 0, -300, 300);
b.pop(); b.pop();
} }
} }
@@ -108,4 +140,4 @@ public final class ConfigMM {
@SubscribeEvent @SubscribeEvent
public static void onReload(ModConfigEvent.Reloading e) { public static void onReload(ModConfigEvent.Reloading e) {
} }
} }
@@ -1,6 +1,7 @@
package net.fretux.mindmotion.client; package net.fretux.mindmotion.client;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.fretux.mindmotion.ConfigMM;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@@ -12,8 +13,8 @@ import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(modid = "mindmotion", value = Dist.CLIENT) @Mod.EventBusSubscriber(modid = "mindmotion", value = Dist.CLIENT)
public class SanityTempoOverlay { public class SanityTempoOverlay {
private static final int BAR_WIDTH = 102; private static final int DEFAULT_LABEL_OFFSET = 10;
private static final int BAR_HEIGHT = 9; private static final int DEFAULT_VENT_OFFSET = 22;
@SubscribeEvent @SubscribeEvent
public static void onRenderOverlay(RenderGuiOverlayEvent.Post event) { public static void onRenderOverlay(RenderGuiOverlayEvent.Post event) {
@@ -22,21 +23,29 @@ public class SanityTempoOverlay {
GuiGraphics gui = event.getGuiGraphics(); GuiGraphics gui = event.getGuiGraphics();
int width = event.getWindow().getGuiScaledWidth(); int width = event.getWindow().getGuiScaledWidth();
int height = event.getWindow().getGuiScaledHeight(); int height = event.getWindow().getGuiScaledHeight();
int y = height - 48; int barWidth = ConfigMM.CLIENT.BAR_WIDTH.get();
int xTempo = 8; int barHeight = ConfigMM.CLIENT.BAR_HEIGHT.get();
int xSanity = width - BAR_WIDTH - 8; int labelOffset = Math.max(DEFAULT_LABEL_OFFSET, barHeight + 1);
int ventOffset = Math.max(DEFAULT_VENT_OFFSET, labelOffset + 12);
int baseY = height - 48;
int baseTempoX = 8;
int baseSanityX = width - barWidth - 8;
int xTempo = baseTempoX + ConfigMM.CLIENT.TEMPO_BAR_X_OFFSET.get();
int yTempo = baseY + ConfigMM.CLIENT.TEMPO_BAR_Y_OFFSET.get();
int xSanity = baseSanityX + ConfigMM.CLIENT.SANITY_BAR_X_OFFSET.get();
int ySanity = baseY + ConfigMM.CLIENT.SANITY_BAR_Y_OFFSET.get();
float sanity = ClientData.SANITY; float sanity = ClientData.SANITY;
float insanity = ClientData.INSANITY; float insanity = ClientData.INSANITY;
float tempo = ClientData.TEMPO; float tempo = ClientData.TEMPO;
float sanityPercent = sanity / ClientData.MAX_SANITY; float sanityPercent = sanity / ClientData.MAX_SANITY;
float insanityPercent = insanity / ClientData.MAX_SANITY; float insanityPercent = insanity / ClientData.MAX_SANITY;
float tempoPercent = (float) tempo / (float) ClientData.MAX_TEMPO; float tempoPercent = (float) tempo / (float) ClientData.MAX_TEMPO;
int sanityFill = (int) (BAR_WIDTH * sanityPercent); int sanityFill = (int) (barWidth * sanityPercent);
int tempoFill = (int) (BAR_WIDTH * tempoPercent); int tempoFill = (int) (barWidth * tempoPercent);
int insanityFill = (int) (BAR_WIDTH * insanityPercent); int insanityFill = (int) (barWidth * insanityPercent);
RenderSystem.enableBlend(); RenderSystem.enableBlend();
drawRoundedBar(gui, xTempo, y, BAR_WIDTH, BAR_HEIGHT, 0xFF33AFFF, tempoFill); drawRoundedBar(gui, xTempo, yTempo, barWidth, barHeight, 0xFF33AFFF, tempoFill);
gui.drawString(mc.font, Component.literal("Tempo"), xTempo, y - 10, 0x66CCFF, false); gui.drawString(mc.font, Component.literal("Tempo"), xTempo, yTempo - labelOffset, 0x66CCFF, false);
if (ClientData.VENT_COOLDOWN > 0) { if (ClientData.VENT_COOLDOWN > 0) {
int seconds = ClientData.VENT_COOLDOWN / 20; int seconds = ClientData.VENT_COOLDOWN / 20;
String ventText = "Vent: " + seconds + "s"; String ventText = "Vent: " + seconds + "s";
@@ -44,35 +53,39 @@ public class SanityTempoOverlay {
mc.font, mc.font,
Component.literal(ventText), Component.literal(ventText),
xTempo, xTempo,
y - 22, yTempo - ventOffset,
0x33AFFF, 0x33AFFF,
false false
); );
} }
boolean insaneMode = sanity <= 0; boolean insaneMode = sanity <= 0;
if (!insaneMode) { if (!insaneMode) {
drawRoundedBar(gui, xSanity, y, BAR_WIDTH, BAR_HEIGHT, 0xFFFFFFFF, sanityFill); drawRoundedBar(gui, xSanity, ySanity, barWidth, barHeight, 0xFFFFFFFF, sanityFill);
gui.drawString(mc.font, Component.literal("Sanity"), xSanity + BAR_WIDTH - 30, y - 10, 0xFFFFFF, false); int sanityLabelWidth = mc.font.width("Sanity");
int sanityLabelX = xSanity + barWidth - sanityLabelWidth;
gui.drawString(mc.font, Component.literal("Sanity"), sanityLabelX, ySanity - labelOffset, 0xFFFFFF, false);
} else { } else {
int purple = 0xFFAA33FF; int purple = 0xFFAA33FF;
int darkPurple = 0xFF6611AA; int darkPurple = 0xFF6611AA;
drawRoundedRect(gui, xSanity, y, BAR_WIDTH, BAR_HEIGHT, 0xDD000000); drawRoundedRect(gui, xSanity, ySanity, barWidth, barHeight, 0xDD000000);
drawRoundedRect(gui, xSanity, y, insanityFill, BAR_HEIGHT, purple, darkPurple); drawRoundedRect(gui, xSanity, ySanity, insanityFill, barHeight, purple, darkPurple);
gui.drawString(mc.font, Component.literal("Insanity"), xSanity + BAR_WIDTH - 42, y - 10, 0xCC66FF, false); int insanityLabelWidth = mc.font.width("Insanity");
int insanityLabelX = xSanity + barWidth - insanityLabelWidth;
gui.drawString(mc.font, Component.literal("Insanity"), insanityLabelX, ySanity - labelOffset, 0xCC66FF, false);
} }
double mouseX = mc.mouseHandler.xpos() * width / (double) event.getWindow().getScreenWidth(); double mouseX = mc.mouseHandler.xpos() * width / (double) event.getWindow().getScreenWidth();
double mouseY = mc.mouseHandler.ypos() * height / (double) event.getWindow().getScreenHeight(); double mouseY = mc.mouseHandler.ypos() * height / (double) event.getWindow().getScreenHeight();
if (isMouseOver(mouseX, mouseY, xTempo, y, BAR_WIDTH, BAR_HEIGHT)) { if (isMouseOver(mouseX, mouseY, xTempo, yTempo, barWidth, barHeight)) {
String text = String.format("%.0f%%", tempoPercent * 100f); String text = String.format("%.0f%%", tempoPercent * 100f);
gui.drawCenteredString(mc.font, text, xTempo + BAR_WIDTH / 2, y - 12, 0x66CCFF); gui.drawCenteredString(mc.font, text, xTempo + barWidth / 2, yTempo - (labelOffset + 2), 0x66CCFF);
} }
if (isMouseOver(mouseX, mouseY, xSanity, y, BAR_WIDTH, BAR_HEIGHT)) { if (isMouseOver(mouseX, mouseY, xSanity, ySanity, barWidth, barHeight)) {
if (!insaneMode) { if (!insaneMode) {
String text = String.format("%.0f%%", sanityPercent * 100f); String text = String.format("%.0f%%", sanityPercent * 100f);
gui.drawCenteredString(mc.font, text, xSanity + BAR_WIDTH / 2, y - 12, 0xFFFFFF); gui.drawCenteredString(mc.font, text, xSanity + barWidth / 2, ySanity - (labelOffset + 2), 0xFFFFFF);
} else { } else {
String text = String.format("%.0f%%", insanityPercent * 100f); String text = String.format("%.0f%%", insanityPercent * 100f);
gui.drawCenteredString(mc.font, text, xSanity + BAR_WIDTH / 2, y - 12, 0xCC66FF); gui.drawCenteredString(mc.font, text, xSanity + barWidth / 2, ySanity - (labelOffset + 2), 0xCC66FF);
} }
} }
} }
@@ -99,4 +112,4 @@ public class SanityTempoOverlay {
private static boolean isMouseOver(double mx, double my, int x, int y, int w, int h) { private static boolean isMouseOver(double mx, double my, int x, int y, int w, int h) {
return mx >= x && mx <= x + w && my >= y && my <= y + h; return mx >= x && mx <= x + w && my >= y && my <= y + h;
} }
} }