Skip to content

Commit

Permalink
Add tooltips and named slider options to config screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Oct 4, 2023
1 parent 300f2c9 commit d13b27f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/main/java/dynamic_fps/impl/GraphicsState.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum GraphicsState {
public static final Codec<GraphicsState> CODEC = new PrimitiveCodec<GraphicsState>() {
@Override
public <T> T write(DynamicOps<T> ops, GraphicsState value) {
return ops.createString(value.toString().toLowerCase(Locale.ROOT));
return ops.createString(value.toString());
}

@Override
Expand All @@ -43,4 +43,9 @@ public <T> DataResult<GraphicsState> read(DynamicOps<T> ops, T input) {
}
}
};

@Override
public String toString() {
return super.toString().toLowerCase(Locale.ROOT);
}
}
56 changes: 48 additions & 8 deletions src/main/java/dynamic_fps/impl/compat/ClothConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

import static dynamic_fps.impl.util.Localization.localized;

import java.util.Optional;

import dynamic_fps.impl.DynamicFPSMod;
import dynamic_fps.impl.GraphicsState;
import dynamic_fps.impl.PowerState;
Expand All @@ -30,17 +34,14 @@ public static Screen genConfigScreen(Screen parent) {

builder.getOrCreateCategory(
localized("config", "category." + state.toString().toLowerCase()))
.addEntry(
entryBuilder
.startTextDescription(
localized("config", "frame_rate_target_description")).build())
.addEntry(entryBuilder
.startIntSlider(
localized("config", "frame_rate_target"),
config.frameRateTarget(),
-1, 60)
.setDefaultValue(standard.frameRateTarget())
.setSaveConsumer(config::setFrameRateTarget)
fromConfigFpsTarget(config.frameRateTarget()),
0, 61)
.setDefaultValue(fromConfigFpsTarget(standard.frameRateTarget()))
.setSaveConsumer(value -> config.setFrameRateTarget(toConfigFpsTarget(value)))
.setTextGetter(ClothConfig::fpsTargetMessage)
.build())
.addEntry(entryBuilder
.startIntSlider(
Expand All @@ -49,6 +50,7 @@ public static Screen genConfigScreen(Screen parent) {
0, 100)
.setDefaultValue((int) (standard.volumeMultiplier() * 100))
.setSaveConsumer(value -> config.setVolumeMultiplier(value / 100f))
.setTextGetter(ClothConfig::volumeMultiplierMessage)
.build())
.addEntry(entryBuilder
.startEnumSelector(
Expand All @@ -57,23 +59,61 @@ public static Screen genConfigScreen(Screen parent) {
config.graphicsState())
.setDefaultValue(standard.graphicsState())
.setSaveConsumer(config::setGraphicsState)
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
.build())
.addEntry(entryBuilder
.startBooleanToggle(
localized("config", "show_toasts"),
config.showToasts())
.setDefaultValue(standard.showToasts())
.setSaveConsumer(config::setShowToasts)
.setTooltip(localized("config", "show_toasts_tooltip"))
.build())
.addEntry(entryBuilder
.startBooleanToggle(
localized("config", "run_garbage_collector"),
config.runGarbageCollector())
.setDefaultValue(standard.runGarbageCollector())
.setSaveConsumer(config::setRunGarbageCollector)
.setTooltip(localized("config", "run_garbage_collector_tooltip"))
.build());
}

return builder.build();
}

// Convert magic -1 number to 61 (and reverse)
// So the "unlocked" FPS value is on the right
private static int toConfigFpsTarget(int value) {
return value == 61 ? -1 : value;
}

private static int fromConfigFpsTarget(int value) {
return value == -1 ? 61 : value;
}

private static Component fpsTargetMessage(int value) {
if (toConfigFpsTarget(value) != -1) {
return Component.translatable("options.framerate", value);
} else {
return Component.translatable("options.framerateLimit.max");
}
}

private static Component volumeMultiplierMessage(int value) {
return Component.literal(Integer.toString(value) + "%");
}

private static Component graphicsStateMessage(Enum<GraphicsState> graphicsState) {
return localized("config", "graphics_state_" + graphicsState.toString());
}

private static Optional<Component[]> graphicsStateTooltip(GraphicsState graphicsState) {
if (!graphicsState.equals(GraphicsState.MINIMAL)) {
return Optional.empty();
}

return Optional.of(new Component[]{ localized("config", "graphics_state_minimal_tooltip").withStyle(ChatFormatting.RED) });
}
}
3 changes: 2 additions & 1 deletion src/main/java/dynamic_fps/impl/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import dynamic_fps.impl.DynamicFPSMod;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

public final class Localization {
/** e.g. keyString("title", "config") -> "title.dynamic_fps.config") */
public static String translationKey(String domain, String path) {
return domain + "." + DynamicFPSMod.MOD_ID + "." + path;
}

public static Component localized(String domain, String path, Object... args) {
public static MutableComponent localized(String domain, String path, Object... args) {
return Component.translatable(translationKey(domain, path), args);
}

Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/dynamic_fps/lang/de_at.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
"config.dynamic_fps.category.invisible": "Unsichtbar",

"config.dynamic_fps.frame_rate_target": "Zielbildrate",
"config.dynamic_fps.frame_rate_target_description": "Setze die Zielbildrate auf -1, um die Bildrate nicht zu reduzieren.",
"config.dynamic_fps.volume_multiplier": "Lautstärke",

"config.dynamic_fps.graphics_state": "Grafikoptionen",
"config.dynamic_fps.graphics_state_default": "Standard",
"config.dynamic_fps.graphics_state_reduced": "Reduziert",
"config.dynamic_fps.graphics_state_minimal": "Minimal",
"config.dynamic_fps.graphics_state_minimal_tooltip": "Minimale Grafik bewirkt, dass die Welt neu lädt!",

"config.dynamic_fps.show_toasts": "Toasts Anzeigen",
"config.dynamic_fps.show_toasts_tooltip": "Toast Benachrichtigungen weiterhin anzeigen oder verzögern",

"config.dynamic_fps.run_garbage_collector": "GC auslösen",
"config.dynamic_fps.run_garbage_collector_tooltip": "Ungenutzen Arbeitsspeicher frei machen, wenn dieser Status aktiviert wird",

"key.dynamic_fps.toggle_forced": "Unfokussierten Modus forcieren (Toggle)",
"key.dynamic_fps.toggle_disabled": "Dynamic FPS deaktivieren (Toggle)",
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/dynamic_fps/lang/de_ch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
"config.dynamic_fps.category.invisible": "Unsichtbar",

"config.dynamic_fps.frame_rate_target": "Zielbildrate",
"config.dynamic_fps.frame_rate_target_description": "Setze die Zielbildrate auf -1, um die Bildrate nicht zu reduzieren.",
"config.dynamic_fps.volume_multiplier": "Lautstärke",

"config.dynamic_fps.graphics_state": "Grafikoptionen",
"config.dynamic_fps.graphics_state_default": "Standard",
"config.dynamic_fps.graphics_state_reduced": "Reduziert",
"config.dynamic_fps.graphics_state_minimal": "Minimal",
"config.dynamic_fps.graphics_state_minimal_tooltip": "Minimale Grafik bewirkt, dass die Welt neu lädt!",

"config.dynamic_fps.show_toasts": "Toasts Anzeigen",
"config.dynamic_fps.show_toasts_tooltip": "Toast Benachrichtigungen weiterhin anzeigen oder verzögern",

"config.dynamic_fps.run_garbage_collector": "GC auslösen",
"config.dynamic_fps.run_garbage_collector_tooltip": "Ungenutzen Arbeitsspeicher frei machen, wenn dieser Status aktiviert wird",

"key.dynamic_fps.toggle_forced": "Unfokussierten Modus forcieren (Toggle)",
"key.dynamic_fps.toggle_disabled": "Dynamic FPS deaktivieren (Toggle)",
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/dynamic_fps/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
"config.dynamic_fps.category.invisible": "Unsichtbar",

"config.dynamic_fps.frame_rate_target": "Zielbildrate",
"config.dynamic_fps.frame_rate_target_description": "Setze die Zielbildrate auf -1, um die Bildrate nicht zu reduzieren.",
"config.dynamic_fps.volume_multiplier": "Lautstärke",

"config.dynamic_fps.graphics_state": "Grafikoptionen",
"config.dynamic_fps.graphics_state_default": "Standard",
"config.dynamic_fps.graphics_state_reduced": "Reduziert",
"config.dynamic_fps.graphics_state_minimal": "Minimal",
"config.dynamic_fps.graphics_state_minimal_tooltip": "Minimale Grafik bewirkt, dass die Welt neu lädt!",

"config.dynamic_fps.show_toasts": "Toasts Anzeigen",
"config.dynamic_fps.show_toasts_tooltip": "Toast Benachrichtigungen weiterhin anzeigen oder verzögern",

"config.dynamic_fps.run_garbage_collector": "GC auslösen",
"config.dynamic_fps.run_garbage_collector_tooltip": "Ungenutzen Arbeitsspeicher frei machen, wenn dieser Status aktiviert wird",

"key.dynamic_fps.toggle_forced": "Unfokussierten Modus forcieren (Toggle)",
"key.dynamic_fps.toggle_disabled": "Dynamic FPS deaktivieren (Toggle)",
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/dynamic_fps/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
"config.dynamic_fps.category.invisible": "Invisible",

"config.dynamic_fps.frame_rate_target": "Frame Rate Target",
"config.dynamic_fps.frame_rate_target_description": "Set Frame Rate Target to -1 to disable reducing FPS.",
"config.dynamic_fps.volume_multiplier": "Volume Multiplier",

"config.dynamic_fps.graphics_state": "Graphics Options",
"config.dynamic_fps.graphics_state_default": "Default",
"config.dynamic_fps.graphics_state_reduced": "Reduced",
"config.dynamic_fps.graphics_state_minimal": "Minimal",
"config.dynamic_fps.graphics_state_minimal_tooltip": "Minimal graphics cause the world to reload!",

"config.dynamic_fps.show_toasts": "Show Toasts",
"config.dynamic_fps.show_toasts_tooltip": "Whether to keep displaying or delay toast notifications",

"config.dynamic_fps.run_garbage_collector": "Invoke Garbage Collector",
"config.dynamic_fps.run_garbage_collector_tooltip": "Free up unused memory when switching to this status",

"key.dynamic_fps.toggle_forced": "Force Unfocused Mode (Toggle)",
"key.dynamic_fps.toggle_disabled": "Disable Dynamic FPS (Toggle)",
Expand Down

0 comments on commit d13b27f

Please sign in to comment.