Skip to content

Commit

Permalink
Merge pull request #1 from S-N00B-1/master
Browse files Browse the repository at this point in the history
Replace Strings with Translation Keys
  • Loading branch information
DexrnZacAttack authored Jan 5, 2025
2 parents 23bec81 + e0e8183 commit 136a086
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public LTScreen(Screen parent, TweakParent tweakParent) {

private static Component getTitle(Screen parent, TweakParent tweakParent) {
if (parent instanceof LTScreen ltScreen) {
return ltScreen.title.copy().append(" / " + ((Tweak) tweakParent).getTweakID());
return ltScreen.title.copy().append(" / " + ((Tweak) tweakParent).getTweakName());
}
if (parent instanceof SettingsScreen settingsScreen) {
return getTitle(settingsScreen.getParent(), tweakParent);
Expand Down Expand Up @@ -99,8 +99,8 @@ class SettingEntry extends ContainerObjectSelectionList.Entry<SettingEntry> {
protected final List<AbstractWidget> children = Lists.newArrayList();

public SettingEntry(final Tweak tweak) {
this.title = Component.literal(tweak.getTweakID() + " - " + tweak.getTweakAuthor());
this.label = LTScreen.this.minecraft.font.split(Component.literal(tweak.getTweakDescription()).withStyle(ChatFormatting.GRAY), 175);
this.title = Component.literal(tweak.getTweakName() + " - " + tweak.getTweakAuthor());
this.label = LTScreen.this.minecraft.font.split(Component.empty().append(tweak.getTweakDescription()).withStyle(ChatFormatting.GRAY), 175);

if (!tweak.isGroup()) {
toggleButton = Button.builder(Component.translatable(tweak.isEnabled() ? "lt.main.enabled" : "lt.main.disabled"), button -> {
Expand Down
50 changes: 30 additions & 20 deletions src/main/java/xyz/violaflower/legacy_tweaks/tweaks/Tweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

public abstract class Tweak implements TweakParent {
private String id; // this probably shouldn't have a default
private Component name = Component.literal("Tweaky McTweakFace");
private String author = "Legacy JohnTweaks";
private String description = "Changes... something.";
private String exDescription = "Changes something, I think... Maybe?";
private Component description = Component.literal("Changes... something.");
private Component exDescription = Component.literal("Changes something, I think... Maybe?");
private String version = "1.0.0";
private boolean isEnabled = true;
private boolean isGroup = false;
Expand All @@ -33,9 +34,10 @@ public Tweak(String id) {
this.id = id;
}

public Tweak(String id, String author, String description) {
public Tweak(String id, String author, Component name, Component description) {
this.id = id;
this.author = author;
this.name = name;
this.description = description;
}
public boolean isEnabled() {
Expand Down Expand Up @@ -78,6 +80,14 @@ public void setTweakID(String id) {
this.id = id;
}

public Component getTweakName() {
return name;
}

public void setTweakName(Component name) {
this.name = name;
}

public void setTweakAuthor(String... author) {
this.author = Arrays.stream(author).collect(Collectors.joining(", "));
}
Expand All @@ -86,19 +96,19 @@ public String getTweakAuthor() {
return this.author;
}

public void setTweakDescription(String description) {
public void setTweakDescription(Component description) {
this.description = description;
}

public String getTweakDescription() {
public Component getTweakDescription() {
return this.description;
}

public void setTweakExtendedDescription(String exDescription) {
public void setTweakExtendedDescription(Component exDescription) {
this.exDescription = exDescription;
}

public String getTweakExtendedDescription() {
public Component getTweakExtendedDescription() {
return this.exDescription;
}

Expand Down Expand Up @@ -140,7 +150,7 @@ public Map<String, Tweak> getSubTweaks() {
return subTweaks;
}

public BooleanOption addBooleanOption(String name) {
public BooleanOption addBooleanOption(Component name) {
return add(new BooleanOption(name, ignored -> {}));
}

Expand All @@ -150,7 +160,7 @@ private <T extends Option<?>> T add(T option) {
return option;
}

public DoubleSliderOption addSliderOption(String name, double min, double max) {
public DoubleSliderOption addSliderOption(Component name, double min, double max) {
return add(new DoubleSliderOption(name, ignored -> {}) {
@Override
public Double getMin() {
Expand Down Expand Up @@ -193,11 +203,11 @@ public <T extends Enum<T>> EnumProvider<T> enumProvider(T defaultValue, Supplier
return new EnumProvider<>(defaultValue, values, toString, toComponent);
}

public <T extends Enum<T>> EnumSliderOption<T> addSliderOption(String name, EnumProvider<T> enumProvider) {
public <T extends Enum<T>> EnumSliderOption<T> addSliderOption(Component name, EnumProvider<T> enumProvider) {
return add(new EnumSliderOption<>(name, enumProvider, ignored -> {}) {});
}

public IntSliderOption addSliderOption(String name, int min, int max) {
public IntSliderOption addSliderOption(Component name, int min, int max) {
return add(new IntSliderOption(name, ignored -> {}) {
@Override
public Integer getMin() {
Expand All @@ -217,7 +227,7 @@ public List<Option<?>> getOptions() {

// TODO get this saved to a file and vice versa
public static class BooleanOption extends Option<Boolean> {
public BooleanOption(String name, Consumer<Boolean> onChanged) {
public BooleanOption(Component name, Consumer<Boolean> onChanged) {
super(name, onChanged);
this.value = false;
}
Expand All @@ -234,7 +244,7 @@ public boolean isOn() {

public abstract static class NumberSliderOption<T extends Number> extends SliderOption<T> {
private final Function<Double, T> newT;
public NumberSliderOption(String name, Function<Double, T> newT, Consumer<T> onChanged) {
public NumberSliderOption(Component name, Function<Double, T> newT, Consumer<T> onChanged) {
super(name, newT, onChanged);
this.newT = newT;
}
Expand Down Expand Up @@ -263,7 +273,7 @@ public T unNormalize(double normalise) {

public abstract static class SliderOption<T> extends Option<T> {
private final Function<Double, T> newT;
public SliderOption(String name, Function<Double, T> newT, Consumer<T> onChanged) {
public SliderOption(Component name, Function<Double, T> newT, Consumer<T> onChanged) {
super(name, onChanged);
this.newT = newT;
}
Expand Down Expand Up @@ -294,7 +304,7 @@ public String format(T num) {

public static class EnumSliderOption<T extends Enum<T>> extends SliderOption<T> {
private final EnumProvider<T> provider;
public EnumSliderOption(String name, EnumProvider<T> provider, Consumer<T> onChanged) {
public EnumSliderOption(Component name, EnumProvider<T> provider, Consumer<T> onChanged) {
super(name, f -> provider.values.get()[f.intValue()], onChanged);
this.provider = provider;
this.value = this.provider.defaultValue;
Expand Down Expand Up @@ -327,7 +337,7 @@ public Component fancyFormat(T t) {
}

public static class DoubleSliderOption extends NumberSliderOption<Double> {
public DoubleSliderOption(String name, Consumer<Double> onChanged) {
public DoubleSliderOption(Component name, Consumer<Double> onChanged) {
super(name, f -> f, onChanged);
this.value = 0D;
}
Expand All @@ -349,7 +359,7 @@ public String format(Double double_) {
}

public static class IntSliderOption extends NumberSliderOption<Integer> {
public IntSliderOption(String name, Consumer<Integer> onChanged) {
public IntSliderOption(Component name, Consumer<Integer> onChanged) {
super(name, Double::intValue, onChanged);
this.value = 0;
}
Expand All @@ -371,14 +381,14 @@ public String format(Integer integer) {
}

public abstract static class Option<T> {
private final String name;
private final Component name;
T value;
Consumer<T> onChanged;
public Option(String name, Consumer<T> onChanged) {
public Option(Component name, Consumer<T> onChanged) {
this.name = name;
this.onChanged = onChanged;
}
public String getName() {
public Component getName() {
return this.name;
}
public T get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package xyz.violaflower.legacy_tweaks.tweaks;

import net.minecraft.network.chat.Component;

public class TweakBuilder {

private String id;
private String description;
private Component name;
private Component description;
private boolean defaultEnabled = true;
private String[] authors;
private Runnable onToggled = () -> {};
Expand All @@ -20,7 +23,12 @@ public TweakBuilder tweakID(String string) {
return this;
}

public TweakBuilder description(String description) {
public TweakBuilder name(Component name) {
this.name = name;
return this;
}

public TweakBuilder description(Component description) {
this.description = description;
return this;
}
Expand Down Expand Up @@ -60,6 +68,7 @@ public void onToggled() {
}
};
tweak.setTweakDescription(description);
tweak.setTweakName(name);
tweak.setDefaultEnabled(defaultEnabled);
tweak.setTweakAuthor(authors);
return tweak;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package xyz.violaflower.legacy_tweaks.tweaks.impl;

import net.minecraft.network.chat.Component;
import xyz.violaflower.legacy_tweaks.tweaks.Tweak;

import sun.misc.Unsafe;
import java.lang.reflect.Field;

public class Crash extends Tweak {
public Crash() {
setTweakID("Crash");
setTweakDescription("You should enable this ;)");
setTweakID("crash");
setTweakName(Component.translatable("lt.tweaks.crash"));
setTweakDescription(Component.translatable("lt.tweaks.crash.description"));
setTweakAuthor("Jeremiah");
setEnabled(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import xyz.violaflower.legacy_tweaks.tweaks.Tweak;
import xyz.violaflower.legacy_tweaks.tweaks.TweakBuilder;

Expand All @@ -15,17 +16,18 @@ public class EyeCandy extends Tweak {
public final Tweak legacyWaterColors;

public EyeCandy() {
setTweakID("Eye Candy");
setTweakID("eyeCandy");
setTweakName(Component.translatable("lt.tweaks.eyecandy"));
setGroup();
setTweakAuthor("Jab125");
setTweakDescription("Various cosmetic changes");
setTweakDescription(Component.translatable("lt.tweaks.eyecandy.description"));
addSubTweak(legacyTextShadows = new LegacyTextShadows());
addSubTweak(fineTunedUIScale = new FineTunedUIScale());
addSubTweak(sunsetColors = new SunsetColors());
addSubTweak(models = new Models());
addSubTweak(smallerStars = new TweakBuilder("Smaller Stars").description("Makes the stars smaller, like LCE").authors("Permdog99").setDefaultEnabled(true).build());
addSubTweak(oldButton = new TweakBuilder("Pre 1.15 button").description("Reverts buttons to their pre 1.15 state").authors("Jab125").setDefaultEnabled(true).build());
addSubTweak(legacyWaterColors = new TweakBuilder("Legacy Water Colors").description("앚졸딩도알lk노wn라w소f아v이앋이온텔에잇노왜압에엣호울d베압렏오f뤼잊윙살엗오옷말l독엗잊f앋릳t렙옫요ff텍로운d텝에어f조울세f리엣안위왭엦아웃엡에엣돈t잘에w핱움안s틴깃임봈입레").authors("Jab125", "dexrn").setDefaultEnabled(true).onToggled(() -> {
addSubTweak(smallerStars = new TweakBuilder("smallerStars").name(Component.translatable("lt.tweaks.eyecandy.smallerstars")).description(Component.translatable("lt.tweaks.eyecandy.smallerstars.description")).authors("Permdog99").setDefaultEnabled(true).build());
addSubTweak(oldButton = new TweakBuilder("oldButton").name(Component.translatable("lt.tweaks.eyecandy.oldbutton")).description(Component.translatable("lt.tweaks.eyecandy.oldbutton.description")).authors("Jab125").setDefaultEnabled(true).build());
addSubTweak(legacyWaterColors = new TweakBuilder("legacyWaterColors").name(Component.translatable("lt.tweaks.eyecandy.legacywatercolors")).description(Component.translatable("lt.tweaks.eyecandy.legacywatercolors.description")).authors("Jab125", "dexrn").setDefaultEnabled(true).onToggled(() -> {
//noinspection ConstantValue
if (Minecraft.getInstance().levelRenderer != null) {
Minecraft.getInstance().levelRenderer.allChanged();
Expand All @@ -35,21 +37,23 @@ public EyeCandy() {
public static class LegacyTextShadows extends Tweak {
public final IntSliderOption shadowOffset;
public LegacyTextShadows() {
setTweakID("Legacy Text Shadows");
setTweakID("legacyTextShadows");
setTweakName(Component.translatable("lt.tweaks.eyecandy.legacytextshadows"));
setTweakAuthor("Jab125");
setTweakDescription("Makes shadows consistent with the screen's actual size, not the scaled size.");
shadowOffset = addSliderOption("shadowOffset", 0, 10);
setTweakDescription(Component.translatable("lt.tweaks.eyecandy.legacytextshadows.description"));
shadowOffset = addSliderOption(Component.translatable("lt.tweaks.eyecandy.legacytextshadows.option.shadowoffset"), 0, 10);
shadowOffset.set(1);
}
}
public static class FineTunedUIScale extends Tweak {
public final DoubleSliderOption uiScale;
public FineTunedUIScale() {
setTweakID("Fine Tuned UI Scale");
setTweakID("fineTunedUIScale");
setTweakName(Component.translatable("lt.tweaks.eyecandy.finetuneduiscale"));
setTweakAuthor("Jab125");
setTweakDescription(ChatFormatting.RED + "Don't use this unless you know what you're doing!");
setTweakDescription(Component.translatable("lt.tweaks.eyecandy.finetuneduiscale.description").withStyle(ChatFormatting.RED));
setEnabled(false, false);
uiScale = addSliderOption("uiScale", 0.8D, 5D);
uiScale = addSliderOption(Component.translatable("lt.tweaks.eyecandy.finetuneduiscale.option.uiscale"), 0.8D, 5D);
uiScale.set(1d);
uiScale.setConsumer(d -> {if (isEnabled()) Minecraft.getInstance().resizeDisplay();});
}
Expand All @@ -64,11 +68,12 @@ public static class SunsetColors extends Tweak {
public final IntSliderOption sunsetColors; // TODO change to Enum

public SunsetColors() {
setTweakID("Sunset Colors");
setTweakID("sunsetColors");
setTweakName(Component.translatable("lt.tweaks.eyecandy.sunsetcolors"));
setTweakAuthor("Permdog99");
setTweakDescription("[Currently TU5 does nothing] Sunset & sunrise colors, based on Xbox 360 LCE update version.");
setTweakDescription(Component.translatable("lt.tweaks.eyecandy.sunsetcolors.description"));

sunsetColors = addSliderOption("sunsetColors", 1, 3);
sunsetColors = addSliderOption(Component.translatable("lt.tweaks.eyecandy.sunsetcolors.option.sunsetcolor"), 1, 3);
sunsetColors.set(3);
}
}
Expand All @@ -78,12 +83,13 @@ public static class Models extends Tweak {
public final Tweak legacyFireworkModel;

public Models() {
setTweakID("Models");
setTweakID("models");
setTweakName(Component.translatable("lt.tweaks.eyecandy.models"));
setTweakAuthor("Permdog99");
setTweakDescription("Legacy-styled models for entities and other objects.");
setTweakDescription(Component.translatable("lt.tweaks.eyecandy.models.description"));

addSubTweak(legacyWitchHat = new TweakBuilder("Legacy Witch Hat").description("Legacy-styled witch hat.").authors("Permdog99, Legacy4J 1.7.5-beta").setDefaultEnabled(false).build());
addSubTweak(legacyFireworkModel = new TweakBuilder("Legacy Firework").description("Legacy-styled firework model").authors("Permdog99, Legacy4J 1.7.5-beta").setDefaultEnabled(true).build());
addSubTweak(legacyWitchHat = new TweakBuilder("legacyWitchHat").name(Component.translatable("lt.tweaks.eyecandy.models.legacywitchhat")).description(Component.translatable("lt.tweaks.eyecandy.models.legacywitchhat.description")).authors("Permdog99, Legacy4J 1.7.5-beta").setDefaultEnabled(false).build());
addSubTweak(legacyFireworkModel = new TweakBuilder("legacyFirework").name(Component.translatable("lt.tweaks.eyecandy.models.legacyfireworkmodel")).description(Component.translatable("lt.tweaks.eyecandy.models.legacyfireworkmodel.description")).authors("Permdog99, Legacy4J 1.7.5-beta").setDefaultEnabled(true).build());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package xyz.violaflower.legacy_tweaks.tweaks.impl;

import net.minecraft.network.chat.Component;
import xyz.violaflower.legacy_tweaks.tweaks.Tweak;

public class F3Info extends Tweak {
public final BooleanOption showEnabledTweaks;

public F3Info() {
setTweakID("F3 Info");
setTweakID("f3Info");
setTweakName(Component.translatable("lt.tweaks.f3info"));
setTweakAuthor("DexrnZacAttack", "Jab125");
setTweakDescription("Adds LegacyTweaks related info to the F3 debug screen.");
setTweakDescription(Component.translatable("lt.tweaks.f3info.enabledTweaks"));
// localize hopefully
showEnabledTweaks = addBooleanOption("showEnabledTweaks");
// LOCALISED! - S_N00B
showEnabledTweaks = addBooleanOption(Component.translatable("lt.tweaks.f3info.option.showenabledtweaks"));
}
}
Loading

0 comments on commit 136a086

Please sign in to comment.