Create ingame settings
Warning
This page is for the LabyMod 3 Addon API, which is no longer maintained nor supported. Visit https://wiki.labymod.net/pages/addon/ for the LabyMod 4 Addon API Wiki.
LabyMod offers an API with which you can easily create ingame settings. After an addon gets loaded, the method
LabyModAddon#fillSettings( List
BooleanElement
subSettings.add( new BooleanElement( "Enabled" /* Display name */, new ControlElement.IconData( Material.LEVER ), new Consumer<Boolean>() {
@Override
public void accept( Boolean accepted ) {
System.out.println( "Changed value: " + accepted );
}
} /* Change listener */, true /* current value */ ) );
ColorPickerCheckBoxBulkElement
ColorPickerCheckBoxBulkElement bulkElement = new ColorPickerCheckBoxBulkElement( "Colors" );
bulkElement.setCheckBoxRightBound( true );
// Prefix picker
ColorPicker prefixPicker = new ColorPicker( "Prefix" /* Display name */, ModColor.PINK.getColor() /* selected color */, new ColorPicker.DefaultColorCallback() {
@Override
public Color getDefaultColor() {
return new Color( 255, 255, 255 );
}
} /* Default color callback */, 0 /* x */, 0 /* y */, 0 /* width */, 0 /* height */ );
prefixPicker.setHasDefault( true );
// Adding update listener to prefix picker
prefixPicker.setUpdateListener( new Consumer<Color>() {
@Override
public void accept( Color accepted ) {
System.out.println( "New prefix color: " + accepted );
}
} );
bulkElement.addColorPicker( prefixPicker );
//
// Other color pickers...
//
CheckBox boldCheckBox = new CheckBox( "Bold" /* Display name */, CheckBox.EnumCheckBoxValue.DISABLED /* current value */,
new CheckBox.DefaultCheckBoxValueCallback() {
@Override
public CheckBox.EnumCheckBoxValue getDefaultValue() {
return CheckBox.EnumCheckBoxValue.DISABLED;
}
} /* Default checkbox value callback */, 0 /* x */, 0 /* y */, 0 /* width */, 0 /* height */ );
boldCheckBox.setHasDefault( true );
// Adding update listener to bold checkbox
boldCheckBox.setUpdateListener( new Consumer<CheckBox.EnumCheckBoxValue>() {
@Override
public void accept( CheckBox.EnumCheckBoxValue accepted ) {
System.out.println( "New selected value: " + accepted.name() );
}
} );
bulkElement.addCheckbox( boldCheckBox );
//
// Other checkboxes...
//
subSettings.add( bulkElement );
DropDownElement
final DropDownMenu<EnumModuleAlignment> alignmentDropDownMenu = new DropDownMenu<EnumModuleAlignment>( "Custom Alignment" /* Display name */, 0, 0, 0, 0 )
.fill( EnumModuleAlignment.values() );
DropDownElement<EnumModuleAlignment> alignmentDropDown = new DropDownElement<EnumModuleAlignment>( "Custom Alignment", alignmentDropDownMenu );
// Set selected entry
alignmentDropDownMenu.setSelected( EnumModuleAlignment.DEFAULT );
// Listen on changes
alignmentDropDown.setChangeListener( new Consumer<EnumModuleAlignment>() {
@Override
public void accept( EnumModuleAlignment alignment ) {
System.out.println( "New selected alignment: " + alignment.name() );
}
} );
// Change entry design (optional)
alignmentDropDownMenu.setEntryDrawer( new DropDownMenu.DropDownEntryDrawer() {
@Override
public void draw( Object object, int x, int y, String trimmedEntry ) {
// We translate the value and draw it
String entry = object.toString().toLowerCase();
LabyMod.getInstance().getDrawUtils().drawString( LanguageManager.translate( entry ), x, y );
}
} );
// Add to sublist
subSettings.add( alignmentDropDown );
KeyElement
KeyElement keyElement = new KeyElement( "Open Module Editor" /* Display name */,
new ControlElement.IconData( "labymod/textures/settings/elements/settings/keymoduleeditor.png" ) /* setting's icon */,
Keyboard.KEY_F /* selected key */, new Consumer<Integer>() {
@Override
public void accept( Integer accepted ) {
if ( accepted == -1 ) {
System.out.println( "Set new key to NONE" );
return;
}
System.out.println( "Set new key: " + Keyboard.getKeyName( accepted ) );
}
} /* Change listener */ );
subSettings.add( keyElement );
NumberElement
NumberElement numberElement = new NumberElement( "Update interval" /* Display name */,
new ControlElement.IconData( Material.WATCH ) /* setting's icon */, 30 /* current value */ );
// Adding change listener
numberElement.addCallback( new Consumer<Integer>() {
@Override
public void accept( Integer accepted ) {
System.out.println( "New number: " + accepted );
}
} );
// Adding to settings
subSettings.add( numberElement );
StringElement
StringElement channelStringElement = new StringElement( "Channel URL" /* Display name */, new ControlElement.IconData( Material.PAPER ) /* setting's icon */,
"https://youtube.com/c/LabyMod" /* current value */, new Consumer<String>() {
@Override
public void accept( String accepted ) {
System.out.println( "New value: " + accepted );
}
} /* Change listener */ );
subSettings.add( channelStringElement );
SliderElement
SliderElement scalingSliderElement = new SliderElement( "Gui Scaling" /* Display name */,
new ControlElement.IconData( "labymod/textures/settings/elements/default/gui_scaling.png" ) /* setting's icon */, 100 /* current value */ );
// Setting the slider's min & max values
scalingSliderElement.setRange( 50, 150 );
// Setting slider steps
scalingSliderElement.setSteps( 100 / 20 );
// Adding change listener
scalingSliderElement.addCallback( new Consumer<Integer>() {
@Override
public void accept( Integer accepted ) {
System.out.println( "New slider value: " + accepted );
}
} );
// Adding setting
subSettings.add( scalingSliderElement );