Skip to content

Commit

Permalink
new: Add translation for Sodium's video settings screen (#717)
Browse files Browse the repository at this point in the history
* new: Add translation for Sodium's video settings screen

Co-Authored-By: AMereBagatelle <56981737+AMereBagatelle@users.noreply.github.com>
Co-authored-by: Bytzo <bytzo@bytzo.net>

* fix: Update "Enable Memory Tracing" option to use translation system

Co-authored-by: AMereBagatelle <56981737+AMereBagatelle@users.noreply.github.com>
Co-authored-by: Bytzo <bytzo@bytzo.net>
Co-authored-by: JellySquid <jellysquid3@users.noreply.github.com>
  • Loading branch information
4 people committed Jul 15, 2021
1 parent 5d24d24 commit 5306c9c
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 133 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
modIncludeImplementation(fabricApi.module("fabric-api-base", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version))
}

if (project.use_third_party_mods) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gui.options.TextProvider;
import net.minecraft.client.option.GraphicsMode;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;

import java.io.FileReader;
import java.io.IOException;
Expand Down Expand Up @@ -43,18 +45,18 @@ public static class NotificationSettings {
}

public enum GraphicsQuality implements TextProvider {
DEFAULT("Default"),
FANCY("Fancy"),
FAST("Fast");
DEFAULT("generator.default"),
FANCY("options.clouds.fancy"),
FAST("options.clouds.fast");

private final String name;
private final Text name;

GraphicsQuality(String name) {
this.name = name;
this.name = new TranslatableText(name);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ private void rebuildGUI() {
this.rebuildGUIPages();
this.rebuildGUIOptions();

this.undoButton = new FlatButtonWidget(new Dim2i(this.width - 211, this.height - 26, 65, 20), "Undo", this::undoChanges);
this.applyButton = new FlatButtonWidget(new Dim2i(this.width - 142, this.height - 26, 65, 20), "Apply", this::applyChanges);
this.closeButton = new FlatButtonWidget(new Dim2i(this.width - 73, this.height - 26, 65, 20), "Close", this::onClose);
this.donateButton = new FlatButtonWidget(new Dim2i(this.width - 128, 6, 100, 20), "Buy us a coffee!", this::openDonationPage);
this.hideDonateButton = new FlatButtonWidget(new Dim2i(this.width - 26, 6, 20, 20), "x", this::hideDonationButton);
this.undoButton = new FlatButtonWidget(new Dim2i(this.width - 211, this.height - 30, 65, 20), new TranslatableText("sodium.options.buttons.undo"), this::undoChanges);
this.applyButton = new FlatButtonWidget(new Dim2i(this.width - 142, this.height - 30, 65, 20), new TranslatableText("sodium.options.buttons.apply"), this::applyChanges);
this.closeButton = new FlatButtonWidget(new Dim2i(this.width - 73, this.height - 30, 65, 20), new TranslatableText("sodium.options.buttons.close"), this::onClose);
this.donateButton = new FlatButtonWidget(new Dim2i(this.width - 128, 6, 100, 20), new TranslatableText("sodium.options.buttons.donate"), this::openDonationPage);
this.hideDonateButton = new FlatButtonWidget(new Dim2i(this.width - 26, 6, 20, 20), new LiteralText("x"), this::hideDonationButton);

if (SodiumClientMod.options().notifications.hideDonationButton) {
this.setDonationButtonVisibility(false);
Expand Down Expand Up @@ -219,7 +219,7 @@ private void renderOptionTooltip(MatrixStack matrixStack, ControlElement<?> elem
OptionImpact impact = option.getImpact();

if (impact != null) {
tooltip.add(Language.getInstance().reorder(new LiteralText(Formatting.GRAY + "Performance Impact: " + impact.toDisplayString())));
tooltip.add(Language.getInstance().reorder(new TranslatableText("sodium.options.performance_impact_string", impact.getLocalizedName()).formatted(Formatting.GRAY)));
}

int boxHeight = (tooltip.size() * 12) + boxPadding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Collection;

public interface Option<T> {
String getName();
Text getName();

Text getTooltip();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package me.jellysquid.mods.sodium.client.gui.options;

import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;

public enum OptionImpact {
LOW(Formatting.GREEN, "Low"),
MEDIUM(Formatting.YELLOW, "Medium"),
HIGH(Formatting.GOLD, "High"),
VARIES(Formatting.WHITE, "Varies");
public enum OptionImpact implements TextProvider {
LOW(Formatting.GREEN, "sodium.option_impact.low"),
MEDIUM(Formatting.YELLOW, "sodium.option_impact.medium"),
HIGH(Formatting.GOLD, "sodium.option_impact.high"),
VARIES(Formatting.WHITE, "sodium.option_impact.varies");

private final Formatting color;
private final String text;
private final Text text;

OptionImpact(Formatting color, String text) {
this.color = color;
this.text = text;
this.text = new TranslatableText(text).formatted(color);
}

public String toDisplayString() {
return this.color + this.text;
@Override
public Text getLocalizedName() {
return this.text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

Expand All @@ -22,7 +21,7 @@ public class OptionImpl<S, T> implements Option<T> {

private final EnumSet<OptionFlag> flags;

private final String name;
private final Text name;
private final Text tooltip;

private final OptionImpact impact;
Expand All @@ -33,16 +32,16 @@ public class OptionImpl<S, T> implements Option<T> {
private final boolean enabled;

private OptionImpl(OptionStorage<S> storage,
String name,
String tooltip,
Text name,
Text tooltip,
OptionBinding<S, T> binding,
Function<OptionImpl<S, T>, Control<T>> control,
EnumSet<OptionFlag> flags,
OptionImpact impact,
boolean enabled) {
this.storage = storage;
this.name = name;
this.tooltip = new LiteralText(tooltip);
this.tooltip = tooltip;
this.binding = binding;
this.impact = impact;
this.flags = flags;
Expand All @@ -53,7 +52,7 @@ private OptionImpl(OptionStorage<S> storage,
}

@Override
public String getName() {
public Text getName() {
return this.name;
}

Expand Down Expand Up @@ -120,8 +119,8 @@ public static <S, T> OptionImpl.Builder<S, T> createBuilder(Class<T> type, Optio

public static class Builder<S, T> {
private final OptionStorage<S> storage;
private String name;
private String tooltip;
private Text name;
private Text tooltip;
private OptionBinding<S, T> binding;
private Function<OptionImpl<S, T>, Control<T>> control;
private OptionImpact impact;
Expand All @@ -132,15 +131,15 @@ private Builder(OptionStorage<S> storage) {
this.storage = storage;
}

public Builder<S, T> setName(String name) {
public Builder<S, T> setName(Text name) {
Validate.notNull(name, "Argument must not be null");

this.name = name;

return this;
}

public Builder<S, T> setTooltip(String tooltip) {
public Builder<S, T> setTooltip(Text tooltip) {
Validate.notNull(tooltip, "Argument must not be null");

this.tooltip = tooltip;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package me.jellysquid.mods.sodium.client.gui.options;

import com.google.common.collect.ImmutableList;
import net.minecraft.text.Text;

public class OptionPage {
private final String name;
private final Text name;
private final ImmutableList<OptionGroup> groups;
private final ImmutableList<Option<?>> options;

public OptionPage(String name, ImmutableList<OptionGroup> groups) {
public OptionPage(Text name, ImmutableList<OptionGroup> groups) {
this.name = name;
this.groups = groups;

Expand All @@ -28,7 +29,7 @@ public ImmutableList<Option<?>> getOptions() {
return this.options;
}

public String getName() {
public Text getName() {
return this.name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.jellysquid.mods.sodium.client.gui.options;

import net.minecraft.text.Text;

public interface TextProvider {
String getLocalizedName();
Text getLocalizedName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class ControlElement<T> extends AbstractWidget {
Expand All @@ -24,7 +25,7 @@ public boolean isHovered() {

@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
String name = this.option.getName();
String name = this.option.getName().getString();
String label;

if (this.hovered && this.font.getWidth(name) > (this.dim.width() - this.option.getControl().getMaxWidth())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package me.jellysquid.mods.sodium.client.gui.options.control;

import net.minecraft.text.TranslatableText;

public interface ControlValueFormatter {
static ControlValueFormatter guiScale() {
return (v) -> (v == 0) ? "Auto" : v + "x";
return (v) -> (v == 0) ? new TranslatableText("options.guiScale.auto").getString() : v + "x";
}

static ControlValueFormatter fpsLimit() {
return (v) -> (v == 260) ? "Unlimited" : v + " FPS";
return (v) -> (v == 260) ? new TranslatableText("options.framerateLimit.max").getString() : v + " FPS";
}

static ControlValueFormatter brightness() {
return (v) -> {
if (v == 0) {
return "Moody";
return new TranslatableText("options.gamma.min").getString();
} else if (v == 100) {
return "Bright";
return new TranslatableText("options.gamma.max").getString();
} else {
return v + "%";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import me.jellysquid.mods.sodium.client.gui.options.TextProvider;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

public class CyclingControl<T extends Enum<T>> implements Control<T> {
private final Option<T> option;
private final T[] allowedValues;
private final String[] names;
private final Text[] names;

public CyclingControl(Option<T> option, Class<T> enumType) {
this(option, enumType, enumType.getEnumConstants());
}

public CyclingControl(Option<T> option, Class<T> enumType, String[] names) {
public CyclingControl(Option<T> option, Class<T> enumType, Text[] names) {
T[] universe = enumType.getEnumConstants();

Validate.isTrue(universe.length == names.length, "Mismatch between universe length and names array length");
Expand All @@ -31,16 +33,16 @@ public CyclingControl(Option<T> option, Class<T> enumType, T[] allowedValues) {

this.option = option;
this.allowedValues = allowedValues;
this.names = new String[universe.length];
this.names = new Text[universe.length];

for (int i = 0; i < this.names.length; i++) {
String name;
Text name;
T value = universe[i];

if (value instanceof TextProvider) {
name = ((TextProvider) value).getLocalizedName();
} else {
name = value.name();
name = new LiteralText(value.name());
}

this.names[i] = name;
Expand All @@ -64,10 +66,10 @@ public int getMaxWidth() {

private static class CyclingControlElement<T extends Enum<T>> extends ControlElement<T> {
private final T[] allowedValues;
private final String[] names;
private final Text[] names;
private int currentIndex;

public CyclingControlElement(Option<T> option, Dim2i dim, T[] allowedValues, String[] names) {
public CyclingControlElement(Option<T> option, Dim2i dim, T[] allowedValues, Text[] names) {
super(option, dim);

this.allowedValues = allowedValues;
Expand All @@ -87,7 +89,7 @@ public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta)
super.render(matrixStack, mouseX, mouseY, delta);

Enum<T> value = this.option.getValue();
String name = this.names[value.ordinal()];
Text name = this.names[value.ordinal()];

int strWidth = this.getStringWidth(name);
this.drawString(matrixStack, name, this.dim.getLimitX() - strWidth - 6, this.dim.getCenterY() - 4, 0xFFFFFFFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;

import java.util.function.Consumer;

Expand All @@ -25,6 +27,10 @@ protected void drawString(MatrixStack matrixStack, String str, int x, int y, int
this.font.draw(matrixStack, str, x, y, color);
}

protected void drawString(MatrixStack matrixStack, Text text, int x, int y, int color) {
this.font.draw(matrixStack, text, x, y, color);
}

protected void drawRect(double x1, double y1, double x2, double y2, int color) {
float a = (float) (color >> 24 & 255) / 255.0F;
float r = (float) (color >> 16 & 255) / 255.0F;
Expand Down Expand Up @@ -69,6 +75,10 @@ protected int getStringWidth(String text) {
return this.font.getWidth(text);
}

protected int getStringWidth(StringVisitable text) {
return this.font.getWidth(text);
}

public Selectable.SelectionType getType() {
// FIXME
return SelectionType.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

public class FlatButtonWidget extends AbstractWidget implements Drawable {
private final Dim2i dim;
private final String label;
private final Text label;
private final Runnable action;

private boolean selected;
private boolean enabled = true;
private boolean visible = true;

public FlatButtonWidget(Dim2i dim, String label, Runnable action) {
public FlatButtonWidget(Dim2i dim, Text label, Runnable action) {
this.dim = dim;
this.label = label;
this.action = action;
Expand Down
Empty file.
Loading

0 comments on commit 5306c9c

Please sign in to comment.