YesNoSetting - ParzivalExe/guiapi GitHub Wiki

From Overview

As you can see from the word Setting being in this Component as well, YesNoSetting is based on the Settings-Component. In fact, it actually has the same logic but now only supports two SettingOptions, the YesSettingOption and the NoSettingOption and is therefore used for Settings where only two states are possible (These states must not necessarily be "Yes" and "No" as you can change look and title for these two SettingOptions as well).

Implementation

So, the YesNoSetting-Component is much more traditional to implement, which is the whole concept of this Component. It is probably the use case you will want to use the Settings-Component most for so there is a separat Component for it making your live much easier.

ComponentMeta yesMeta = new ComponentMeta("YES", new ItemStack(351, 1, (short) 0, (byte) 10));
ComponentMeta noMeta = new ComponentMeta("no", new ItemStack(351, 1, (short) 0, (byte) 8));

YesNoSetting yesNoSetting = new YesNoSetting(yesMeta, noMeta);
//manipulate yesNoSetting here

gui.addComponent(yesNoSetting);

This is the general implementation of this Component. As you can see, you no longer have to implement an entire ArrayList and only of the SettingOption-Stuff but can simply implement it like any other Component, just that this one needs two ComponentMetas instead of one.

Important to mention here is, that you generally don't set the description for this Component through the description-field inside both ComponentMetas, but through the Component itself which then applies this description to both states of the Setting (Yes and No). This is done because the description for a Yes or No Setting usually stays the same. So for setting the description you write: yesNoSetting.setDescription(descriptionArrayList);

By the way, this YesNoSetting-Component we just created is also created if you call the YesNoSetting-Constructor without any arguments because most of the time you will probably create YesNoSettings based on this blueprint.

Events

ComponentClickedEvent = fired, when YesNoSetting (or any other Component) is clicked

YesNoSettingChosenEvent = fired, when the YesNoSetting is clicked and therefore has changed it's Setting

XML-Attributes

yesTitle="{yesTitle}" = Sets the Title of the Yes-Setting (example: yesTitle="YES")

noTitle="{noTitle}" = Sets the Title of the No-Setting (example: noTitle="no")

yesLook="{yesLook}" = Sets the Look of the Yes-Setting (example: yesLook="351:10" or yesLook="DYE:10")

noLook="{noLook}" = Sets the Look of the No-Setting (example: noLook="351:8" or noLook="DYE:8")

description="[{line1}, {line2}...]" = sets the description of both SettingOptions (example: description="[This is a Description, with a \,]")

place="{PLACE}" = sets the place this Component should be placed at in the Gui (example: place="4")

Resources

Component-Code: io.github.parzivalExe.guiApi.components.YesNoSetting


Great, now you know how to implement a YesNoSetting with a few lines. Next Component on the List is the AdditionalOptionsComponent