| 1 | package net.minecraft.client.gui.screens.options;
|
| 2 |
|
| 3 | import java.util.Arrays;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.OptionInstance;
|
| 7 | import net.minecraft.client.Options;
|
| 8 | import net.minecraft.client.gui.components.AbstractWidget;
|
| 9 | import net.minecraft.client.gui.components.Button;
|
| 10 | import net.minecraft.client.gui.components.Tooltip;
|
| 11 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 12 | import net.minecraft.client.gui.screens.ConfirmLinkScreen;
|
| 13 | import net.minecraft.client.gui.screens.Screen;
|
| 14 | import net.minecraft.client.gui.screens.options.controls.ControlsScreen;
|
| 15 | import net.minecraft.network.chat.CommonComponents;
|
| 16 | import net.minecraft.network.chat.Component;
|
| 17 | import net.minecraft.util.CommonLinks;
|
| 18 | import net.minecraft.world.flag.FeatureFlags;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class AccessibilityOptionsScreen extends OptionsSubScreen {
|
| 22 | public static final Component TITLE = Component.translatable("options.accessibility.title");
|
| 23 |
|
| 24 | private static OptionInstance<?>[] options(final Options options) {
|
| 25 | return new OptionInstance[]{
|
| 26 | options.narrator(),
|
| 27 | options.showSubtitles(),
|
| 28 | options.highContrast(),
|
| 29 | options.menuBackgroundBlurriness(),
|
| 30 | options.textBackgroundOpacity(),
|
| 31 | options.backgroundForChatOnly(),
|
| 32 | options.chatOpacity(),
|
| 33 | options.chatLineSpacing(),
|
| 34 | options.chatDelay(),
|
| 35 | options.notificationDisplayTime(),
|
| 36 | options.bobView(),
|
| 37 | options.screenEffectScale(),
|
| 38 | options.fovEffectScale(),
|
| 39 | options.darknessEffectScale(),
|
| 40 | options.damageTiltStrength(),
|
| 41 | options.glintSpeed(),
|
| 42 | options.glintStrength(),
|
| 43 | options.hideLightningFlash(),
|
| 44 | options.darkMojangStudiosBackground(),
|
| 45 | options.panoramaSpeed(),
|
| 46 | options.hideSplashTexts(),
|
| 47 | options.narratorHotkey(),
|
| 48 | options.rotateWithMinecart(),
|
| 49 | options.highContrastBlockOutline()
|
| 50 | };
|
| 51 | }
|
| 52 |
|
| 53 | public AccessibilityOptionsScreen(final Screen lastScreen, final Options options) {
|
| 54 | super(lastScreen, options, TITLE);
|
| 55 | }
|
| 56 |
|
| 57 | @Override
|
| 58 | protected void init() {
|
| 59 | super.init();
|
| 60 | AbstractWidget highContrast = this.list.findOption(this.options.highContrast());
|
| 61 | if (highContrast != null && !this.minecraft.getResourcePackRepository().getAvailableIds().contains("high_contrast")) {
|
| 62 | highContrast.active = false;
|
| 63 | highContrast.setTooltip(Tooltip.create(Component.translatable("options.accessibility.high_contrast.error.tooltip")));
|
| 64 | }
|
| 65 |
|
| 66 | AbstractWidget rotateWithMinecart = this.list.findOption(this.options.rotateWithMinecart());
|
| 67 | if (rotateWithMinecart != null) {
|
| 68 | rotateWithMinecart.active = this.isMinecartOptionEnabled();
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | protected void addOptions() {
|
| 74 | OptionInstance<?>[] optionsInstances = options(this.options);
|
| 75 | Button controlsLink = Button.builder(OptionsScreen.CONTROLS, var1x -> this.minecraft.gui.setScreen(new ControlsScreen(this, this.options))).build();
|
| 76 | OptionInstance<?> firstOptionInstance = optionsInstances[0];
|
| 77 | this.list.addSmall(firstOptionInstance.createButton(this.options), this.options.narrator(), controlsLink);
|
| 78 | this.list.addSmall(Arrays.stream(optionsInstances).filter(instance -> instance != firstOptionInstance).toArray(OptionInstance[]::new));
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | protected void addFooter() {
|
| 83 | LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
|
| 84 | footer.addChild(
|
| 85 | Button.builder(Component.translatable("options.accessibility.link"), ConfirmLinkScreen.confirmLink(this, CommonLinks.ACCESSIBILITY_HELP)).build()
|
| 86 | );
|
| 87 | footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> this.minecraft.gui.setScreen(this.lastScreen)).build());
|
| 88 | }
|
| 89 |
|
| 90 | private boolean isMinecartOptionEnabled() {
|
| 91 | return this.minecraft.level != null && this.minecraft.level.enabledFeatures().contains(FeatureFlags.MINECART_IMPROVEMENTS);
|
| 92 | }
|
| 93 | }
|
| 94 |
|