| 1 | package net.minecraft.client.gui.screens.options;
|
| 2 |
|
| 3 | import java.util.function.Supplier;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.Options;
|
| 7 | import net.minecraft.client.gui.components.Button;
|
| 8 | import net.minecraft.client.gui.components.StringWidget;
|
| 9 | import net.minecraft.client.gui.components.Tooltip;
|
| 10 | import net.minecraft.client.gui.layouts.GridLayout;
|
| 11 | import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
| 12 | import net.minecraft.client.gui.layouts.LayoutElement;
|
| 13 | import net.minecraft.client.gui.layouts.LayoutSettings;
|
| 14 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 15 | import net.minecraft.client.gui.screens.CreditsAndAttributionScreen;
|
| 16 | import net.minecraft.client.gui.screens.Screen;
|
| 17 | import net.minecraft.client.gui.screens.options.controls.ControlsScreen;
|
| 18 | import net.minecraft.client.gui.screens.packs.PackSelectionScreen;
|
| 19 | import net.minecraft.client.gui.screens.telemetry.TelemetryInfoScreen;
|
| 20 | import net.minecraft.network.chat.CommonComponents;
|
| 21 | import net.minecraft.network.chat.Component;
|
| 22 | import net.minecraft.server.packs.repository.PackRepository;
|
| 23 |
|
| 24 | @Environment(EnvType.CLIENT)
|
| 25 | public class OptionsScreen extends Screen {
|
| 26 | private static final Component TITLE = Component.translatable("options.title");
|
| 27 | private static final Component SKIN_CUSTOMIZATION = Component.translatable("options.skinCustomisation");
|
| 28 | private static final Component SOUNDS = Component.translatable("options.sounds");
|
| 29 | private static final Component VIDEO = Component.translatable("options.video");
|
| 30 | public static final Component CONTROLS = Component.translatable("options.controls");
|
| 31 | private static final Component LANGUAGE = Component.translatable("options.language");
|
| 32 | private static final Component CHAT = Component.translatable("options.chat");
|
| 33 | private static final Component RESOURCEPACK = Component.translatable("options.resourcepack");
|
| 34 | private static final Component ACCESSIBILITY = Component.translatable("options.accessibility");
|
| 35 | private static final Component TELEMETRY = Component.translatable("options.telemetry");
|
| 36 | private static final Tooltip TELEMETRY_DISABLED_TOOLTIP = Tooltip.create(Component.translatable("options.telemetry.disabled"));
|
| 37 | private static final Component CREDITS_AND_ATTRIBUTION = Component.translatable("options.credits_and_attribution");
|
| 38 | private static final int COLUMNS = 2;
|
| 39 | private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 61, 33);
|
| 40 | private final Screen lastScreen;
|
| 41 | private final Options options;
|
| 42 |
|
| 43 | public OptionsScreen(final Screen lastScreen, final Options options) {
|
| 44 | super(TITLE);
|
| 45 | this.lastScreen = lastScreen;
|
| 46 | this.options = options;
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | protected void init() {
|
| 51 | LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(8));
|
| 52 | header.addChild(new StringWidget(TITLE, this.font), LayoutSettings::alignHorizontallyCenter);
|
| 53 | LinearLayout subHeader = header.addChild(LinearLayout.horizontal()).spacing(8);
|
| 54 | subHeader.addChild(this.options.fov().createButton(this.minecraft.options));
|
| 55 | subHeader.addChild(this.createOnlineButton());
|
| 56 | GridLayout gridLayout = new GridLayout();
|
| 57 | gridLayout.defaultCellSetting().paddingHorizontal(4).paddingBottom(4).alignHorizontallyCenter();
|
| 58 | GridLayout.RowHelper helper = gridLayout.createRowHelper(2);
|
| 59 | helper.addChild(this.openScreenButton(SKIN_CUSTOMIZATION, () -> new SkinCustomizationScreen(this, this.options)));
|
| 60 | helper.addChild(this.openScreenButton(SOUNDS, () -> new SoundOptionsScreen(this, this.options)));
|
| 61 | helper.addChild(this.openScreenButton(VIDEO, () -> new VideoSettingsScreen(this, this.minecraft, this.options)));
|
| 62 | helper.addChild(this.openScreenButton(CONTROLS, () -> new ControlsScreen(this, this.options)));
|
| 63 | helper.addChild(this.openScreenButton(LANGUAGE, () -> new LanguageSelectScreen(this, this.options, this.minecraft.getLanguageManager())));
|
| 64 | helper.addChild(this.openScreenButton(CHAT, () -> new ChatOptionsScreen(this, this.options)));
|
| 65 | helper.addChild(
|
| 66 | this.openScreenButton(
|
| 67 | RESOURCEPACK,
|
| 68 | () -> new PackSelectionScreen(
|
| 69 | this.minecraft.getResourcePackRepository(), this::applyPacks, this.minecraft.getResourcePackDirectory(), Component.translatable("resourcePack.title")
|
| 70 | )
|
| 71 | )
|
| 72 | );
|
| 73 | helper.addChild(this.openScreenButton(ACCESSIBILITY, () -> new AccessibilityOptionsScreen(this, this.options)));
|
| 74 | Button telemetryButton = helper.addChild(this.openScreenButton(TELEMETRY, () -> new TelemetryInfoScreen(this, this.options)));
|
| 75 | if (!this.minecraft.allowsTelemetry()) {
|
| 76 | telemetryButton.active = false;
|
| 77 | telemetryButton.setTooltip(TELEMETRY_DISABLED_TOOLTIP);
|
| 78 | }
|
| 79 |
|
| 80 | helper.addChild(this.openScreenButton(CREDITS_AND_ATTRIBUTION, () -> new CreditsAndAttributionScreen(this)));
|
| 81 | this.layout.addToContents(gridLayout);
|
| 82 | this.layout.addToFooter(Button.builder(CommonComponents.GUI_DONE, var1x -> this.onClose()).width(200).build());
|
| 83 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 84 | this.repositionElements();
|
| 85 | }
|
| 86 |
|
| 87 | @Override
|
| 88 | protected void repositionElements() {
|
| 89 | this.layout.arrangeElements();
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public void onClose() {
|
| 94 | this.minecraft.gui.setScreen(this.lastScreen);
|
| 95 | }
|
| 96 |
|
| 97 | public Screen getLastScreen() {
|
| 98 | return this.lastScreen;
|
| 99 | }
|
| 100 |
|
| 101 | private void applyPacks(final PackRepository packRepository) {
|
| 102 | this.options.updateResourcePacks(packRepository);
|
| 103 | this.minecraft.gui.setScreen(this);
|
| 104 | }
|
| 105 |
|
| 106 | private LayoutElement createOnlineButton() {
|
| 107 | return Button.builder(Component.translatable("options.online"), var1 -> this.minecraft.gui.setScreen(new OnlineOptionsScreen(this, this.options)))
|
| 108 | .bounds(this.width / 2 + 5, this.height / 6 - 12 + 24, 150, 20)
|
| 109 | .build();
|
| 110 | }
|
| 111 |
|
| 112 | @Override
|
| 113 | public void removed() {
|
| 114 | this.options.save();
|
| 115 | }
|
| 116 |
|
| 117 | private Button openScreenButton(final Component message, final Supplier<Screen> screenToScreen) {
|
| 118 | return Button.builder(message, var2 -> this.minecraft.gui.setScreen(screenToScreen.get())).build();
|
| 119 | }
|
| 120 | }
|
| 121 |
|