OptionsScreen.java

net.minecraft.client.gui.screens.options.OptionsScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.options.OptionsScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.options
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/options/OptionsScreen.java
  • 起始行号:L29
  • 继承:Screen
  • 实现:HasGamemasterPermissionReaction, HasDifficultyReaction
  • 职责:

    TODO

字段/常量

  • TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L30
    • 说明:

      TODO

  • SKIN_CUSTOMIZATION

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L31
    • 说明:

      TODO

  • SOUNDS

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L32
    • 说明:

      TODO

  • VIDEO

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L33
    • 说明:

      TODO

  • CONTROLS

    • 类型: Component
    • 修饰符: public static final
    • 源码定位: L34
    • 说明:

      TODO

  • LANGUAGE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L35
    • 说明:

      TODO

  • CHAT

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L36
    • 说明:

      TODO

  • RESOURCEPACK

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L37
    • 说明:

      TODO

  • ACCESSIBILITY

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L38
    • 说明:

      TODO

  • TELEMETRY

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L39
    • 说明:

      TODO

  • TELEMETRY_DISABLED_TOOLTIP

    • 类型: Tooltip
    • 修饰符: private static final
    • 源码定位: L40
    • 说明:

      TODO

  • CREDITS_AND_ATTRIBUTION

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L41
    • 说明:

      TODO

  • COLUMNS

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L42
    • 说明:

      TODO

  • layout

    • 类型: HeaderAndFooterLayout
    • 修饰符: private final
    • 源码定位: L43
    • 说明:

      TODO

  • lastScreen

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L44
    • 说明:

      TODO

  • options

    • 类型: Options
    • 修饰符: private final
    • 源码定位: L45
    • 说明:

      TODO

  • inWorld

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L46
    • 说明:

      TODO

  • difficultyButtons

    • 类型: DifficultyButtons
    • 修饰符: private
    • 源码定位: L47
    • 说明:

      TODO

内部类/嵌套类型

构造器

public OptionsScreen(Screen lastScreen, Options options, boolean inWorld) @ L49

  • 构造器名:OptionsScreen
  • 源码定位:L49
  • 修饰符:public

参数:

  • lastScreen: Screen
  • options: Options
  • inWorld: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void init() @ L56

  • 方法名:init
  • 源码定位:L56
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void repositionElements() @ L102

  • 方法名:repositionElements
  • 源码定位:L102
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public void onClose() @ L107

  • 方法名:onClose
  • 源码定位:L107
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public Screen getLastScreen() @ L112

  • 方法名:getLastScreen
  • 源码定位:L112
  • 返回类型:Screen
  • 修饰符:public

参数:

说明:

TODO

private void applyPacks(PackRepository packRepository) @ L116

  • 方法名:applyPacks
  • 源码定位:L116
  • 返回类型:void
  • 修饰符:private

参数:

  • packRepository: PackRepository

说明:

TODO

private LayoutElement createOnlineButton() @ L121

  • 方法名:createOnlineButton
  • 源码定位:L121
  • 返回类型:LayoutElement
  • 修饰符:private

参数:

说明:

TODO

private LayoutElement createWorldOptionsButtonOrDifficultyButton(Level level) @ L127

  • 方法名:createWorldOptionsButtonOrDifficultyButton
  • 源码定位:L127
  • 返回类型:LayoutElement
  • 修饰符:private

参数:

  • level: Level

说明:

TODO

private boolean canShowWorldOptions() @ L139

  • 方法名:canShowWorldOptions
  • 源码定位:L139
  • 返回类型:boolean
  • 修饰符:private

参数:

说明:

TODO

public void removed() @ L145

  • 方法名:removed
  • 源码定位:L145
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private Button openScreenButton(Component message, Supplier<Screen> screenToScreen) @ L150

  • 方法名:openScreenButton
  • 源码定位:L150
  • 返回类型:Button
  • 修饰符:private

参数:

  • message: Component
  • screenToScreen: Supplier

说明:

TODO

public void onGamemasterPermissionChanged(boolean hasGamemasterPermission) @ L154

  • 方法名:onGamemasterPermissionChanged
  • 源码定位:L154
  • 返回类型:void
  • 修饰符:public

参数:

  • hasGamemasterPermission: boolean

说明:

TODO

public void added() @ L159

  • 方法名:added
  • 源码定位:L159
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void onDifficultyChanged() @ L166

  • 方法名:onDifficultyChanged
  • 源码定位:L166
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class OptionsScreen extends Screen implements HasGamemasterPermissionReaction, HasDifficultyReaction {
    private static final Component TITLE = Component.translatable("options.title");
    private static final Component SKIN_CUSTOMIZATION = Component.translatable("options.skinCustomisation");
    private static final Component SOUNDS = Component.translatable("options.sounds");
    private static final Component VIDEO = Component.translatable("options.video");
    public static final Component CONTROLS = Component.translatable("options.controls");
    private static final Component LANGUAGE = Component.translatable("options.language");
    private static final Component CHAT = Component.translatable("options.chat");
    private static final Component RESOURCEPACK = Component.translatable("options.resourcepack");
    private static final Component ACCESSIBILITY = Component.translatable("options.accessibility");
    private static final Component TELEMETRY = Component.translatable("options.telemetry");
    private static final Tooltip TELEMETRY_DISABLED_TOOLTIP = Tooltip.create(Component.translatable("options.telemetry.disabled"));
    private static final Component CREDITS_AND_ATTRIBUTION = Component.translatable("options.credits_and_attribution");
    private static final int COLUMNS = 2;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 61, 33);
    private final Screen lastScreen;
    private final Options options;
    private final boolean inWorld;
    private @Nullable DifficultyButtons difficultyButtons;
 
    public OptionsScreen(Screen lastScreen, Options options, boolean inWorld) {
        super(TITLE);
        this.lastScreen = lastScreen;
        this.options = options;
        this.inWorld = inWorld;
    }
 
    @Override
    protected void init() {
        LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(8));
        header.addChild(new StringWidget(TITLE, this.font), LayoutSettings::alignHorizontallyCenter);
        LinearLayout subHeader = header.addChild(LinearLayout.horizontal()).spacing(8);
        subHeader.addChild(this.options.fov().createButton(this.minecraft.options));
        if (this.inWorld) {
            subHeader.addChild(this.createWorldOptionsButtonOrDifficultyButton(Objects.requireNonNull(this.minecraft.level)));
        } else {
            subHeader.addChild(this.createOnlineButton());
        }
 
        GridLayout gridLayout = new GridLayout();
        gridLayout.defaultCellSetting().paddingHorizontal(4).paddingBottom(4).alignHorizontallyCenter();
        GridLayout.RowHelper helper = gridLayout.createRowHelper(2);
        helper.addChild(this.openScreenButton(SKIN_CUSTOMIZATION, () -> new SkinCustomizationScreen(this, this.options)));
        helper.addChild(this.openScreenButton(SOUNDS, () -> new SoundOptionsScreen(this, this.options)));
        helper.addChild(this.openScreenButton(VIDEO, () -> new VideoSettingsScreen(this, this.minecraft, this.options)));
        helper.addChild(this.openScreenButton(CONTROLS, () -> new ControlsScreen(this, this.options)));
        helper.addChild(this.openScreenButton(LANGUAGE, () -> new LanguageSelectScreen(this, this.options, this.minecraft.getLanguageManager())));
        helper.addChild(this.openScreenButton(CHAT, () -> new ChatOptionsScreen(this, this.options)));
        helper.addChild(
            this.openScreenButton(
                RESOURCEPACK,
                () -> new PackSelectionScreen(
                    this.minecraft.getResourcePackRepository(),
                    this::applyPacks,
                    this.minecraft.getResourcePackDirectory(),
                    Component.translatable("resourcePack.title")
                )
            )
        );
        helper.addChild(this.openScreenButton(ACCESSIBILITY, () -> new AccessibilityOptionsScreen(this, this.options)));
        Button telemetryButton = helper.addChild(this.openScreenButton(TELEMETRY, () -> new TelemetryInfoScreen(this, this.options)));
        if (!this.minecraft.allowsTelemetry()) {
            telemetryButton.active = false;
            telemetryButton.setTooltip(TELEMETRY_DISABLED_TOOLTIP);
        }
 
        helper.addChild(this.openScreenButton(CREDITS_AND_ATTRIBUTION, () -> new CreditsAndAttributionScreen(this)));
        this.layout.addToContents(gridLayout);
        this.layout.addToFooter(Button.builder(CommonComponents.GUI_DONE, button -> this.onClose()).width(200).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    public Screen getLastScreen() {
        return this.lastScreen;
    }
 
    private void applyPacks(PackRepository packRepository) {
        this.options.updateResourcePacks(packRepository);
        this.minecraft.setScreen(this);
    }
 
    private LayoutElement createOnlineButton() {
        return Button.builder(Component.translatable("options.online"), button -> this.minecraft.setScreen(new OnlineOptionsScreen(this, this.options)))
            .bounds(this.width / 2 + 5, this.height / 6 - 12 + 24, 150, 20)
            .build();
    }
 
    private LayoutElement createWorldOptionsButtonOrDifficultyButton(Level level) {
        if (!this.canShowWorldOptions()) {
            this.difficultyButtons = DifficultyButtons.create(this.minecraft, level, this);
            return this.difficultyButtons.layout();
        } else {
            return Button.builder(
                    Component.translatable("options.worldOptions.button"), button -> this.minecraft.setScreen(new WorldOptionsScreen(this, level))
                )
                .build();
        }
    }
 
    private boolean canShowWorldOptions() {
        return this.minecraft.player == null
            ? false
            : this.minecraft.player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER) || this.minecraft.player.chatAbilities().hasAnyRestrictions();
    }
 
    @Override
    public void removed() {
        this.options.save();
    }
 
    private Button openScreenButton(Component message, Supplier<Screen> screenToScreen) {
        return Button.builder(message, button -> this.minecraft.setScreen(screenToScreen.get())).build();
    }
 
    @Override
    public void onGamemasterPermissionChanged(boolean hasGamemasterPermission) {
        this.minecraft.setScreen(new OptionsScreen(this.lastScreen, this.minecraft.options, true));
    }
 
    @Override
    public void added() {
        if (this.difficultyButtons != null) {
            this.difficultyButtons.refresh(this.minecraft);
        }
    }
 
    @Override
    public void onDifficultyChanged() {
        if (this.difficultyButtons != null) {
            this.difficultyButtons.refresh(this.minecraft);
        }
    }
}

引用的其他类