LibConsoleDialogs (1.0.0)

For console addon developers only.
Dependencies
LibHarvensAddonSettings
Description
This library helps with two challenges creating UI for consoles:
Creating own dialogs (aka scenes).
Adding functionality to built-in dialogs without knowing which other addon already using the limited keybinds.
On PC you can create additional elements like buttons, context menus and so on to avoid conflict with other addons. But console does not have a mouse pointer.
You also can not create new keybindings letting the user assign one out of hundred keys to it. There is no keyboard.
The console UI is very much based on the key-strip and parametric scroll lists.
This library helps creating simple settings-like dialogs/scenes quicker. Reusing the controls of LibHarvensAddonSettings and thereby reducing the number of controls created. This is saving memory, which is limited to 100MB for consoles.
Technically the dialogs are settings not shown in the addon list.
For a description of how to create the dialog controls look at LibHarvensAddonSettings.
API:
local dialog = LibConsoleDialogs:Create(title)
Creates and returns a new dialog instance.
Use dialog:AddSetting(option) or dialog:AddSettings(options). See LibHarvensAddonSettings for details.
Use dialog:Select() or dialog:Show() to activate the dialog.
LibConsoleDialogs:RegisterKeybind(sceneOrName, buttonInfo)
Registers a keybind to the given scene. The actual used key is assign on demand.
sceneOrName can be a scene object or a string with the name of an existing scene.
buttonInfo =
{
name = number, string or function,
alignment = KEYBIND_STRIP_ALIGN_CENTER/LEFT/RIGHT,
tooltip = number, string or function,
callback = function(buttonInfo) end,
visible = boolean or function,
order = number — Order on screen depends on the alignment.
}
LibConsoleDialogs:Close()
Closes the keybind overflow dialog, if open. Use this, if you want to auto go back. If not, the user has to click the back button.
You can call this function even if your keybind was activated directly.
Example:
local settings = LibConsoleDialogs:Create(“Dialog A”) — The title. Does not need to be unique.
–]
local checked = false
–Define checkbox table
local checkbox = {
type = LibHarvensAddonSettings.ST_CHECKBOX, –setting type
label = “Example Checkbox”, –label text
tooltip = “This is an example checkbox”, –tooltip text (optional)
default = false, –default value, only used when options.allowDefaults == true (optional)
setFunction = function(state) –this function is called when the setting is changed
checked = state
end,
getFunction = function()
–this function is called to set initial state of the checkbox
return checked
end,
disable = function()
return areSettingsDisabled
end –when options.allowRefresh == true, this function will be called when any other setting is changed (optional)
}
–Add the checkbox to your “container”
settings:AddSetting(checkbox)
–And that’s is everything, below are other controls examples
–]
local sliderVal = 5
local slider = {
type = LibHarvensAddonSettings.ST_SLIDER,
label = “Example Slider”,
tooltip = “This is an example slider”,
setFunction = function(value)
sliderVal = value
end,
getFunction = function()
return sliderVal
end,
default = 5,
min = 1,
max = 10,
step = 1,
unit = “s”, –optional unit
format = “%d”, –value format
disable = function()
return areSettingsDisabled
end
}
settings:AddSetting(slider)
–]
local button = {
type = LibHarvensAddonSettings.ST_BUTTON,
label = “Example Button”,
tooltip = “This is an example button”,
buttonText = “Click me!”,
clickHandler = function(control, button)
d(“Click”)
end,
disable = function()
return areSettingsDisabled
end
}
settings:AddSetting(button)
–]
local editValue = “Hello”
local edit = {
type = LibHarvensAddonSettings.ST_EDIT,
label = “Example Edit”,
tooltip = “This is an example edit”,
default = “Hello”,
setFunction = function(value)
editValue = value
end,
getFunction = function()
return editValue
end,
disable = function()
return areSettingsDisabled
end
}
settings:AddSetting(edit)
local TEST_DIALOG_A = settings
local settings = LibConsoleDialogs:Create(“Dialog B”)
–]
local selectedText = “Item 4”
local dropdown = {
type = LibHarvensAddonSettings.ST_DROPDOWN,
label = “Example Dropdown”,
tooltip = “This is an example dropdown”,
setFunction = function(combobox, name, item)
d(“Selected item: ” .. name .. “, data: ” .. tostring(item.data))
selectedText = name
end,
getFunction = function()
return selectedText
end,
default = “Item 4”,
items = {
{
name = “Item 1”,
data = 1
},
{
name = “Item 2”,
data = “Some string”
},
{
name = “Item 3”,
data = true
},
{
name = “Item 4”,
data = {
value = 10
}
}
},
disable = function()
return areSettingsDisabled
end
}
settings:AddSetting(dropdown)
–]
local label = {
type = LibHarvensAddonSettings.ST_LABEL,
label = “Example LabelnMultiline! |cff0000and colors|r”
}
settings:AddSetting(label)
–]
local section = {
type = LibHarvensAddonSettings.ST_SECTION,
label = “Example Section”
}
settings:AddSetting(section)
–]
local colorR = 0.3
local colorG = 0.6
local colorB = 0.2
local colorA = 1.0
local color = {
type = LibHarvensAddonSettings.ST_COLOR,
label = “Example Color”,
tooltip = “This is an example color”,
setFunction = function(…) –newR, newG, newB, newA
colorR, colorG, colorB, colorA = …
end,
default = {0.3, 0.6, 0.2, 1.0},
getFunction = function()
return colorR, colorG, colorB, colorA
end,
disable = function()
return areSettingsDisabled
end
}
settings:AddSetting(color)
local disableAll = {
type = LibHarvensAddonSettings.ST_CHECKBOX,
label = “Disable All”,
tooltip = “This will disable all other settings”,
default = false,
setFunction = function(state)
areSettingsDisabled = state
end,
getFunction = function()
return areSettingsDisabled
end
}
settings:AddSetting(disableAll)
local TEST_DIALOG_B = settings
— Adding the dialog to the journal.
LibConsoleDialogs:RegisterKeybind(
GAMEPAD_QUEST_JOURNAL_ROOT_SCENE,
{
name = “Option 1”,
tooltip = “Brief description of option 1”, — optional
alignment = KEYBIND_STRIP_ALIGN_CENTER,
callback = function(buttonInfo)
— Do your stuff here, eg.
TEST_DIALOG_A:Show()
— You can use SCENE_MANAGER:ShowScene(yourScene) for more complex UI
end,
visible = true,
order = 100
}
)
LibConsoleDialogs:RegisterKeybind(
GAMEPAD_QUEST_JOURNAL_ROOT_SCENE,
{
name = “Option 2”,
callback = function(buttonInfo)
TEST_DIALOG_B:Show()
end,
visible = true,
order = 101
}
)
As you can see, most of the code is for the dialog logic. And not all the code you need to do before, without this library.
May this is all you need already. May it is a kickstart for your own console UI.