Skip to content

Commit

Permalink
new: Option to improve visibility for text on HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Jul 21, 2022
1 parent c595a9a commit 9c2cddd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ public static OptionPage extra() {
.setBinding((opts, value) -> opts.extraSettings.overlayCorner = value, opts -> opts.extraSettings.overlayCorner)
.build()
)
.add(OptionImpl.createBuilder(SodiumExtraGameOptions.TextContrast.class, sodiumExtraOpts)
.setName(Text.translatable("sodium-extra.option.text_contrast"))
.setTooltip(Text.translatable("sodium-extra.option.text_contrast.tooltip"))
.setControl(option -> new CyclingControl<>(option, SodiumExtraGameOptions.TextContrast.class))
.setBinding((opts, value) -> opts.extraSettings.textContrast = value, opts -> opts.extraSettings.textContrast)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumExtraOpts)
.setName(Text.translatable("sodium-extra.option.show_fps"))
.setTooltip(Text.translatable("sodium-extra.option.show_fps.tooltip"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ public Text getLocalizedName() {
}
}

public enum TextContrast implements TextProvider {
NONE("sodium-extra.option.text_contrast.none"),
BACKGROUND("sodium-extra.option.text_contrast.background"),
SHADOW("sodium-extra.option.text_contrast.shadow");

private final Text text;

TextContrast(String text) {
this.text = Text.translatable(text);
}

@Override
public Text getLocalizedName() {
return this.text;
}
}

public static class AnimationSettings {
public boolean animation;
public boolean water;
Expand Down Expand Up @@ -173,6 +190,7 @@ public RenderSettings() {

public static class ExtraSettings {
public OverlayCorner overlayCorner;
public TextContrast textContrast;
public boolean showFps;
public boolean showFPSExtended;
public boolean showCoords;
Expand All @@ -185,6 +203,7 @@ public static class ExtraSettings {

public ExtraSettings() {
this.overlayCorner = OverlayCorner.TOP_LEFT;
this.textContrast = TextContrast.NONE;
this.showFps = false;
this.showFPSExtended = true;
this.showCoords = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.flashyreese.mods.sodiumextra.mixin.gui;

import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -37,7 +39,7 @@ public void render(MatrixStack matrices, float tickDelta, CallbackInfo callbackI
} else if (SodiumExtraClientMod.options().extraSettings.showCoords) {
this.renderCoords(matrices);
}
if (!SodiumExtraClientMod.options().renderSettings.lightUpdates){
if (!SodiumExtraClientMod.options().renderSettings.lightUpdates) {
this.renderLightUpdatesWarning(matrices);
}
}
Expand Down Expand Up @@ -71,10 +73,11 @@ private void renderFPS(MatrixStack matrices) {
x = this.scaledWidth - this.client.textRenderer.getWidth(text) - 2;
y = this.scaledHeight - this.client.textRenderer.fontHeight - 2;
}
default -> throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
default ->
throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
}

this.client.textRenderer.draw(matrices, text, x, y, 0xffffffff);
this.drawString(matrices, text, x, y);
}

private void renderCoords(MatrixStack matrices) {
Expand All @@ -101,13 +104,14 @@ private void renderCoords(MatrixStack matrices) {
x = this.scaledWidth - this.client.textRenderer.getWidth(text) - 2;
y = this.scaledHeight - this.client.textRenderer.fontHeight - 12;
}
default -> throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
default ->
throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
}

this.client.textRenderer.draw(matrices, text, x, y, 0xffffffff);
this.drawString(matrices, text, x, y);
}

private void renderLightUpdatesWarning(MatrixStack matrices){
private void renderLightUpdatesWarning(MatrixStack matrices) {
Text text = Text.translatable("sodium-extra.overlay.light_updates");

int x, y;
Expand All @@ -128,9 +132,21 @@ private void renderLightUpdatesWarning(MatrixStack matrices){
x = this.scaledWidth - this.client.textRenderer.getWidth(text) - 2;
y = this.scaledHeight - this.client.textRenderer.fontHeight - 22;
}
default -> throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
default ->
throw new IllegalStateException("Unexpected value: " + SodiumExtraClientMod.options().extraSettings.overlayCorner);
}

this.client.textRenderer.draw(matrices, text, x, y, 0xffffffff);
this.drawString(matrices, text, x, y);
}

private void drawString(MatrixStack matrices, Text text, int x, int y) {
if (SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.NONE) {
this.client.textRenderer.draw(matrices, text, x, y, 0xffffffff);
} else if (SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.BACKGROUND) {
DrawableHelper.fill(matrices, x - 1, y - 1, x + this.client.textRenderer.getWidth(text) + 1, y + this.client.textRenderer.fontHeight, -1873784752);
this.client.textRenderer.draw(matrices, text, x, y, 0xffffffff);
} else if (SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.SHADOW) {
this.client.textRenderer.drawWithShadow(matrices, text, x, y, 0xffffffff);
}
}
}
9 changes: 7 additions & 2 deletions src/main/resources/assets/sodium-extra/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"sodium-extra.option.overlay_corner.top_left": "Top Left",
"sodium-extra.option.overlay_corner.top_right": "Top Right",
"sodium-extra.option.paintings.tooltip": "If enabled, paintings are rendered.",
"sodium-extra.option.particles.tooltips": "If enabled, %s particles are processed.",
"sodium-extra.option.particles_all.tooltip": "If enabled, particles are processed.",
"sodium-extra.option.piston.tooltip": "If enabled, piston extending animations are processed.",
"sodium-extra.option.prevent_shaders": "Prevent Shaders",
Expand All @@ -57,6 +58,11 @@
"sodium-extra.option.stars.tooltip": "If enabled, the stars will be rendered.",
"sodium-extra.option.sun_moon": "Sun & Moon",
"sodium-extra.option.sun_moon.tooltip": "If enabled, the sun and moon will be rendered.",
"sodium-extra.option.text_contrast": "Text Contrast",
"sodium-extra.option.text_contrast.background": "Background",
"sodium-extra.option.text_contrast.none": "None",
"sodium-extra.option.text_contrast.shadow": "Shadow",
"sodium-extra.option.text_contrast.tooltip": "Adjusts the contrast of the FPS/Coordinates counter.\n- None: Default plain white text\n- Background: Renders a background to the text like the debug menu\n- Shadow: Plain white text without shadow",
"sodium-extra.option.toasts": "Toasts",
"sodium-extra.option.toasts.tooltip": "If enabled, advancement and crafting recipe popups will be displayed.",
"sodium-extra.option.use_adaptive_sync.name": "Use Adaptive Sync",
Expand All @@ -68,6 +74,5 @@
"sodium-extra.overlay.fps_extended": "(max. %s / avg. %s / min. %s)",
"sodium-extra.overlay.light_updates": "Light updates disabled",
"sodium-extra.suggestRSO.header": "Suggestion: Install Reese's Sodium Options",
"sodium-extra.suggestRSO.message": "It is highly recommended you install Reese's Sodium Options alongside Sodium Extra. Due to the growing amount of features, it no longer fits properly on Sodium's video options.",
"sodium-extra.option.particles.tooltips": "If enabled, %s particles are processed."
"sodium-extra.suggestRSO.message": "It is highly recommended you install Reese's Sodium Options alongside Sodium Extra. Due to the growing amount of features, it no longer fits properly on Sodium's video options."
}

0 comments on commit 9c2cddd

Please sign in to comment.