Interface
Caffeine comes with two standard Interface objects. Categories and Hotbars.
Categories
A Category is a page in the Settings panel that your users may interact with to change settings for your module.
Caffeine.Interface.Category:New(name[, parent]) : CategoryObject
name is the user-facing name of your category, as well as the name of the config file for the category itself and all of it’s child categories.
parent is only necessary for sub-categories.
Example
local your_category = Caffeine.Interface.Category:New("Category")
You can access the Config object of each Category with Category.config
Config Example
your_config = your_category.config
your_config:Read("prefix_variable", default_value)
Checkboxes
CategoryObject:Checkbox(details) : CheckBoxObject
details contains the following fields:
category: This is the “prefix” for the config value of your setting. (category_var)var: This is the variable for the config value of your settings. (category_var)name: This is the user-facing name of your checkbox.tooltip: This is the user-facing tooltip of your option.default: This is the default value of your option.disabled: This is whether your option is disabled or not.
Example
your_category:Checkbox({
category = "prefix",
var = "variable",
name = "Your Checkbox",
tooltip = "Your tooltip here. This supports newline characters.",
default = false,
disabled = false
})
Sliders
CategoryObject:Slider(details) : SliderObject
details contains the following fields:
category: This is the “prefix” for the config value of your setting. (category_var)var: This is the variable for the config value of your settings. (category_var)name: This is the user-facing name of your checkbox.tooltip: This is the user-facing tooltip of your option.default: This is the default value of your option.min: This is the minimum value of your slider.max: This is the maximum value of your slider.step: One “tick” of your slider goes up this many.disabled: This is whether your option is disabled or not. Optional.
Example
your_category:Slider({
category = "prefix",
var = "variable",
name = "Your Slider",
tooltip = "Your tooltip here.",
default = 50,
min = 0,
max = 100,
step = 5,
})
Dropdowns
CategoryObject:Dropdown(details) : DropdownObject
details contains the following fields:
category: This is the “prefix” for the config value of your setting. (category_var)var: This is the variable for the config value of your settings. (category_var)name: This is the user-facing name of your checkbox.tooltip: This is the user-facing tooltip of your option.default: This is the default value of your option.options: This is a table containing the options of your dropdown. Each item in the table should have a Label and a Value.disabled: This is whether your option is disabled or not. Optional.
Example
your_category:Dropdown({
category = "prefix",
var = "variable",
name = "Your Dropdown",
tooltip = "Your tooltip here.",
default = "option_one",
options = {
{ "Option One", "option_one" },
{ "Option Two", "option_two" },
}
})
Registering the Category
A parent category should be registered once you have finished adding components. You do not need to register child categories.
your_category:Register()
This allows your UI to function in-game.
Using your configs
When you create a parent category, Caffeine automatically creates a new Configuration file for that category. This will be located in the root unlocker directory.
Accessing your config variables is simple. Let’s use the previous checkbox code as an example. For reference, the category was ‘prefix’ and the var was ‘variable’.
your_category.config:Read("prefix_variable", default_value)
default_value must be set in each Read function.
Hotbars
A Hotbar is a draggable button bar that users may interact with to toggle various options on and off, or have quick access to settings.
Caffeine.Interface.Hotbar:New(details) : HotbarObject
details contains the following fields:
name: This is the label above the hotbar.options: This is the parent CategoryObject for your module.buttonCount: How many buttons your Hotbar will have.
Example
local your_hotbar = Caffeine.Interface.Hotbar:New({
name = "Main",
options = your_category,
buttonCount = 3,
})
Buttons
HotbarObject:AddButton(details)
details contains the following fields:
name: This is the name of your button.tooltip: This is the tooltip for your button.texture: This is the texture for your button.toggle: This determines whether your button is a toggle or not.onClick: This is the onClick function of your button.
Example
your_hotbar:AddButton({
name = "Module Toggle",
texture = "Interface\\ICONS\\Ability_DualWieldSpecialization",
tooltip = "This is your button's tooltip.",
toggle = true,
onClick = function()
local your_module = Caffeine:FindModule("Module Name")
if your_module then
your_module.enabled = not your_module.enabled
if your_module.enabled then
Caffeine:Print("Enabled Module Name")
else
Caffeine:Print("Disabled Module Name")
end
end
end,
})