OptionsSubScreen .java

net.minecraft.client.gui.screens.options.OptionsSubScreen (class): members: resetOption, addContents, addTitle, addFooter, addOptions, list, options, init.

net.minecraft.client.gui.screens.optionsclass86 linesclientextends Screen2.4 KB

API Surface (8)

void init()
void addTitle()
void addContents()
void addFooter()
void repositionElements()
void removed()
void onClose()
void resetOption(final OptionInstance<?> option)

Fields & Constants (4)

lastScreen
options
list
layout

Full Source

OptionsSubScreen.java86 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.options;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.NarratorStatus;
6
import net.minecraft.client.OptionInstance;
7
import net.minecraft.client.Options;
8
import net.minecraft.client.gui.components.Button;
9
import net.minecraft.client.gui.components.CycleButton;
10
import net.minecraft.client.gui.components.OptionsList;
11
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
12
import net.minecraft.client.gui.screens.Screen;
13
import net.minecraft.network.chat.CommonComponents;
14
import net.minecraft.network.chat.Component;
15
import org.jspecify.annotations.Nullable;
16
17
@Environment(EnvType.CLIENT)
18
public abstract class OptionsSubScreen extends Screen {
19
	protected final Screen lastScreen;
20
	protected final Options options;
21
	protected @Nullable OptionsList list;
22
	public final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
23
24
	public OptionsSubScreen(final Screen lastScreen, final Options options, final Component title) {
25
		super(title);
26
		this.lastScreen = lastScreen;
27
		this.options = options;
28
	}
29
30
	@Override
31
	protected void init() {
32
		this.addTitle();
33
		this.addContents();
34
		this.addFooter();
35
		this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
36
		this.repositionElements();
37
	}
38
39
	protected void addTitle() {
40
		this.layout.addTitleHeader(this.title, this.font);
41
	}
42
43
	protected void addContents() {
44
		this.list = this.layout.addToContents(new OptionsList(this.minecraft, this.width, this));
45
		this.addOptions();
46
		if (this.list.findOption(this.options.narrator()) instanceof CycleButton<?> cycleButton) {
47
			this.narratorButton = (CycleButton<NarratorStatus>)cycleButton;
48
			this.narratorButton.active = this.minecraft.getNarrator().isActive();
49
		}
50
	}
51
52
	protected abstract void addOptions();
53
54
	protected void addFooter() {
55
		this.layout.addToFooter(Button.builder(CommonComponents.GUI_DONE, button -> this.onClose()).width(200).build());
56
	}
57
58
	@Override
59
	protected void repositionElements() {
60
		this.layout.arrangeElements();
61
		if (this.list != null) {
62
			this.list.updateSize(this.width, this.layout);
63
		}
64
	}
65
66
	@Override
67
	public void removed() {
68
		this.minecraft.options.save();
69
	}
70
71
	@Override
72
	public void onClose() {
73
		if (this.list != null) {
74
			this.list.applyUnsavedChanges();
75
		}
76
77
		this.minecraft.gui.setScreen(this.lastScreen);
78
	}
79
80
	public void resetOption(final OptionInstance<?> option) {
81
		if (this.list != null) {
82
			this.list.resetOption(option);
83
		}
84
	}
85
}
86

Decompiled Minecraft 26.3 source of OptionsSubScreen (net/minecraft/client/gui/screens/options/OptionsSubScreen.java) with Mojang official mappings, stored verbatim on the site.