Create ingame settings

LabyMod offers an API with which you can easily create ingame settings. After an addon gets loaded, the method LabyModAddon#fillSettings( List subSettings ) will be called which you can use to add the addon's ingame settings. For that purpose we deliver many element types:

BooleanElement

Screenshot of BooleanElement

1
2
3
4
5
6
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

Screenshot of ColorPickerCheckBoxBulkElement

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 );

Screenshot of DropDownElement

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

Screenshot of KeyElement

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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

Screenshot of NumberElement

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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

Screenshot of StringElement

1
2
3
4
5
6
7
8
9
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

Screenshot of SliderElement

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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 );