Class ConfigurationScreen.ConfigurationListScreen<T>
- All Implemented Interfaces:
net.minecraft.client.gui.components.events.ContainerEventHandler
,net.minecraft.client.gui.components.events.GuiEventListener
,net.minecraft.client.gui.components.Renderable
,net.minecraft.client.gui.components.TabOrderedElement
- Enclosing class:
ConfigurationScreen
This class is automatically used if you use NeoForge's generic configuration UI, see ConfigurationScreen
.
If you have special needs, you can subclass this class to achieve the desired behaviour. For example:
- To change how the label and buttons for the individual elements look, override
createListLabel(int)
. - To use another UI element, override the matching
create*Value()
method and return your new UI element wrapped in aConfigurationScreen.ConfigurationSectionScreen.Element
. - To add additional (synthetic) config values, override
rebuild()
and add them tolist
. (ConfigurationScreen.ConfigurationSectionScreen.createSyntheticValues()
is not used for lists). - To be notified on each changed value instead of getting one
ModConfigEvent
at the end, overrideonChanged(String)
on theConfigurationScreen
, not here. The list will only be updated in theModConfigSpec.ConfigValue
when this screen is closed. - To limit the number of elements in a list, pass a
ModConfigSpec.Range
toModConfigSpec.Builder.defineList(List, Supplier, Supplier, Predicate, Range)
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A widget to be used as a label in a list of configuration values.Nested classes/interfaces inherited from class net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen
ConfigurationScreen.ConfigurationSectionScreen.Context, ConfigurationScreen.ConfigurationSectionScreen.Custom<T>, ConfigurationScreen.ConfigurationSectionScreen.Element, ConfigurationScreen.ConfigurationSectionScreen.Filter
Nested classes/interfaces inherited from class net.minecraft.client.gui.screens.Screen
net.minecraft.client.gui.screens.Screen.NarratableSearchResult
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String
protected final ModConfigSpec.ListValueSpec
protected final ModConfigSpec.ConfigValue
<List<T>> Fields inherited from class net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen
changed, context, doneButton, MAX_SLIDER_SIZE, needsRestart, resetButton, sectionCache, undoButton, undoManager
Fields inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
lastScreen, layout, list, options
Fields inherited from class net.minecraft.client.gui.screens.Screen
CUBE_MAP, font, FOOTER_SEPARATOR, HEADER_SEPARATOR, height, INWORLD_FOOTER_SEPARATOR, INWORLD_HEADER_SEPARATOR, MENU_BACKGROUND, minecraft, narratorButton, PANORAMA, renderables, screenExecutor, title, width
Fields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS
-
Constructor Summary
ConstructorsConstructorDescriptionConfigurationListScreen
(ConfigurationScreen.ConfigurationSectionScreen.Context context, String key, net.minecraft.network.chat.Component title, ModConfigSpec.ListValueSpec spec, ModConfigSpec.ConfigValue<List<T>> valueList) -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
addUndoListener
(boolean simulate, List<T> values) protected void
Creates a button to add a new element to the end of the list and adds it to the UI.protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createBooleanListValue
(int idx, Boolean value) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createDoubleListValue
(int idx, Double value) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createIntegerListValue
(int idx, Integer value) protected net.minecraft.client.gui.components.AbstractWidget
createListLabel
(int idx) Creates a new widget to label a list value and provide manipulation buttons for it.protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createLongListValue
(int idx, Long value) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createOtherValue
(int idx, T entry) Called when a list element is found that has an unknown or unsupported data type.protected void
protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createStringListValue
(int idx, String value) protected boolean
del
(int idx, boolean simulate) Remove the given element.protected boolean
protected void
This is called whenever a value is changed and the change is submitted to the appropriateConfigSpec
.void
onClose()
rebuild()
void
render
(net.minecraft.client.gui.GuiGraphics graphics, int p_281550_, int p_282878_, float p_282465_) protected boolean
swap
(int idx, boolean simulate) Swap the given element with the next one.Methods inherited from class net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen
addFooter, addOptions, createBooleanValue, createDoubleValue, createEnumValue, createIntegerValue, createList, createLongValue, createNumberBox, createOtherSection, createOtherValue, createSection, createSlider, createStringValue, createSyntheticValues, createUndoButton, getComment, getTooltip, getTooltipComponent, getTranslationComponent, getTranslationKey, getValueSpec, isNonDefault, isPartialNumber, setResetButtonstate, setUndoButtonstate
Methods inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
addContents, addTitle, init, removed, repositionElements
Methods inherited from class net.minecraft.client.gui.screens.Screen
added, addRenderableOnly, addRenderableWidget, addWidget, afterKeyboardAction, afterMouseAction, afterMouseMove, changeFocus, children, clearFocus, clearTooltipForNextRenderPass, clearWidgets, fillCrashDetails, findNarratableWidget, getBackgroundMusic, getFont, getMinecraft, getNarrationMessage, getRectangle, getTitle, getTooltipFromItem, getUsageNarration, handleComponentClicked, handleDelayedNarration, hasAltDown, hasControlDown, hasShiftDown, init, insertText, isCopy, isCut, isMouseOver, isPaste, isPauseScreen, isSelectAll, isValidCharacterForName, keyPressed, onFilesDrop, rebuildWidgets, removeWidget, renderBackground, renderBlurredBackground, renderMenuBackground, renderMenuBackground, renderMenuBackgroundTexture, renderPanorama, renderTransparentBackground, renderWithTooltip, resize, setInitialFocus, setInitialFocus, setTooltipForNextRenderPass, setTooltipForNextRenderPass, setTooltipForNextRenderPass, setTooltipForNextRenderPass, shouldCloseOnEsc, shouldNarrateNavigation, showsActiveEffects, tick, triggerImmediateNarration, updateNarratedWidget, updateNarrationState, updateNarratorStatus
Methods inherited from class net.minecraft.client.gui.components.events.AbstractContainerEventHandler
getFocused, isDragging, setDragging, setFocused
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.client.gui.components.events.ContainerEventHandler
charTyped, getChildAt, getCurrentFocusPath, isFocused, keyReleased, mouseClicked, mouseDragged, mouseReleased, mouseScrolled, nextFocusPath, setFocused
Methods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
getBorderForArrowNavigation, mouseMoved
Methods inherited from interface net.minecraft.client.gui.components.TabOrderedElement
getTabOrderGroup
-
Field Details
-
key
-
spec
-
valueList
-
cfgList
-
-
Constructor Details
-
ConfigurationListScreen
public ConfigurationListScreen(ConfigurationScreen.ConfigurationSectionScreen.Context context, String key, net.minecraft.network.chat.Component title, ModConfigSpec.ListValueSpec spec, ModConfigSpec.ConfigValue<List<T>> valueList)
-
-
Method Details
-
rebuild
- Overrides:
rebuild
in classConfigurationScreen.ConfigurationSectionScreen
-
isAnyNondefault
protected boolean isAnyNondefault()- Overrides:
isAnyNondefault
in classConfigurationScreen.ConfigurationSectionScreen
-
createAddElementButton
protected void createAddElementButton()Creates a button to add a new element to the end of the list and adds it to the UI.Override this if you want a different button or want to add more elements.
-
createListLabel
protected net.minecraft.client.gui.components.AbstractWidget createListLabel(int idx) Creates a new widget to label a list value and provide manipulation buttons for it.Override this if you want different labels/buttons.
- Parameters:
idx
- The index into the list.- Returns:
- An
AbstractWidget
to be rendered in the left column of the options screen
-
createOtherValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createOtherValue(int idx, T entry) Called when a list element is found that has an unknown or unsupported data type. Override this to produce whatever UI elements are appropriate for this object.Note that all types of elements that can be read from the config file as part of a list are already supported. You only need this if you manipulate the contents of the list after it has been loaded.
If this returns null, no row will be shown on the screen, but the up/down buttons will still see your element. Which means that the user will see no change when moving another element over the hidden line. Consider returning a
StringWidget
as a placeholder instead.Do not capture
cfgList
here or in another create*Value() method. The undo/reset system will replace the list, so you need to always access the field. You can (and should) capture the index.- Parameters:
idx
- The index into the list.entry
- The entry itself.- Returns:
- null if this element should be skipped or an
ConfigurationScreen.ConfigurationSectionScreen.Element
to be added to the UI.
-
createStringListValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createStringListValue(int idx, String value) -
createDoubleListValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createDoubleListValue(int idx, Double value) -
createLongListValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createLongListValue(int idx, Long value) -
createIntegerListValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createIntegerListValue(int idx, Integer value) -
createBooleanListValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createBooleanListValue(int idx, Boolean value) -
swap
protected boolean swap(int idx, boolean simulate) Swap the given element with the next one. Should be called by the list label widget to manipulate the list. -
del
protected boolean del(int idx, boolean simulate) Remove the given element. Should be called by the list label widget to manipulate the list. -
addUndoListener
-
onClose
public void onClose()- Overrides:
onClose
in classConfigurationScreen.ConfigurationSectionScreen
-
render
public void render(net.minecraft.client.gui.GuiGraphics graphics, int p_281550_, int p_282878_, float p_282465_) - Specified by:
render
in interfacenet.minecraft.client.gui.components.Renderable
- Overrides:
render
in classConfigurationScreen.ConfigurationSectionScreen
-
onChanged
Description copied from class:ConfigurationScreen.ConfigurationSectionScreen
This is called whenever a value is changed and the change is submitted to the appropriateConfigSpec
.- Overrides:
onChanged
in classConfigurationScreen.ConfigurationSectionScreen
- Parameters:
key
- The key of the changed configuration. To get an absolute key, useConfigurationScreen.ConfigurationSectionScreen.Context.makeKeyList(String)
.
-
createResetButton
protected void createResetButton()- Overrides:
createResetButton
in classConfigurationScreen.ConfigurationSectionScreen
-