Settings - ParzivalExe/guiapi GitHub Wiki
From Overview
The Settings
-Component is a bit more complicated. It has different SettingOption
s. Every SettingOption
has it's own ComponentMeta
. If the Settings
-Component is now clicked, it will cycle through this SettingOption
-List. Every click therefore the Look
, Title
and Description
of this Component will change.
It also fires an Event every time the SettingOption
changes giving your plugin an option to respond to this accordingly.
Another way to use this Component is by getting the current SettingOption
when the Gui
is closed and make the necessary changes.
Settings
is the first Component in this Tutorial, that isn't set up like every other Component, by a ComponentMeta
. Instead it has multiple ComponentMeta
s packed inside the Object SettingOption
. Here is the general creating of a Settings
-Component
//creating SettingOptions
SettingOption beginner = new SettingOption("beginner", new ItemStack(Material.APPLE));
SettingOption advanced = new SettingOption("advanced", new ItemStack(Material.GOLDEN_APPLE));
SettingOption professional = new SettingOption("PROFESSIONAL", new ItemStack(Material.GOLDEN_APPLE, 1, (short) 0, (byte) 1));
//creating SettingOptions-ArrayList
ArrayList<SettingOption> settingOptions = new ArrayList<SettingOption>();
settingOptions.add(beginner);
settingOptions.add(advanced);
settingOptions.add(professional);
Settings settings = new Settings(settingOptions);
//manipulate settings here
gui.addComponent(settings);
As you can see, a SettingOption
simply includes a normal ComponentMeta
as is even more obvious because you can also choose a constructor that simply takes a ComponentMeta
as it's only argument. You can also define a description for every single SettingOption
, I just left that out of this tutorial, as descriptions take a lot more code and with them, the code seems much more complicated than it actually is.
The good part, after you implemented the Settings-Component in this a bit more involved process, there is not much more to do about it. It simply works and has no special fields to take care of.
ComponentClickedEvent
= fired, when Settings (or any other Component) is clicked
SettingsClickedEvent
= fired, when Settings is clicked, also giving the old and new SettingOption of the Settings-Component
place="{PLACE}"
= sets the place this Component should be placed at in the Gui (example: place="4"
)
Inside the Tag <Settings>{Content}</Settings>
we must specify all the SettingOption
s, that are needed for this specific Settings
-Component. Don't forget, that you also have to either use the full ClassName
of SettingOption
or create an Include
-Tag in the Library
-Tag to include this Class as a Tag in your Gui-XML. Example:
<io.github.parzivalExe.guiApi.components.Settings>
<io.github.parzivalExe.guiApi.components.SettingOption title="beginner" look="260"/>
<io.github.parzivalExe.guiApi.components.SettingOption title="Advanced" look="2x322"/>
<io.github.parzivalExe.guiApi.components.SettingOption title="PROFESSIONAL" look="3x322:1"/>
</io.github.parzivalExe.guiApi.components.Settings>
Of course, in XML too you would implement a description
for every SettingOption
-Tag just like you would for a normal component in XML but in order to keep this more compact, I didn't do that in this example.
Component-Code: io.github.parzivalExe.guiApi.components.Settings
SettingOption-Code: io.github.parzivalExe.guiApi.components.SettingOption
Great, now you know how to implement a Settings-Component with a few lines. Next Component on the List is the YesNoSetting