diff --git a/LibAddonMenu-2.0/LibAddonMenu-2.0.lua b/LibAddonMenu-2.0/LibAddonMenu-2.0.lua index 8e76b8d..55a7c03 100644 --- a/LibAddonMenu-2.0/LibAddonMenu-2.0.lua +++ b/LibAddonMenu-2.0/LibAddonMenu-2.0.lua @@ -5,6 +5,29 @@ local MAJOR, MINOR = "LibAddonMenu-2.0", _LAM2_VERSION_NUMBER or -1 +---@alias Stringy SafeStringKey|string|fun():(string|nil) a string id, string, or function returning a string + +---@class LAM2_ControlData +---@field type "button"|"checkbox"|"colorpicker"|"custom"|"description"|"divider"|"dropdown"|"editbox"|"header"|"iconpicker"|"panel"|"slider"|"submenu"|"texture" +---@field name nil|Stringy + +---@class LAM2_ControlWithHelpUrlData: LAM2_ControlData +---@field helpUrl nil|Stringy ex. "https://www.esoui.com/portal.php?id=218&a=faq" + +---@class LAM2_BaseControlData: LAM2_ControlData +---@field width nil|"full"|"half" default "full" +---@field reference nil|string a unique global reference to the created control ex. "MyAddonButton" + +---@class LAM2_LabelAndContainerControlData: LAM2_BaseControlData, LAM2_ControlWithHelpUrlData +---@field tooltip nil|Stringy ex. "Button's tooltip text." +---@field tooltipText nil|string + +---@class LAM2_Control: Control + +---@class LAM2_ControlWithHelpUrl: LAM2_Control +---@field data LAM2_ControlWithHelpUrlData +---@field faqControl LAM2_FAQControl + local lam if(not LibStub) then lam = {} @@ -42,6 +65,7 @@ else logger = setmetatable({}, { __index = function() return noop end }) end +---@diagnostic disable-next-line: undefined-global if LAMSettingsPanelCreated and not LAMCompatibilityWarning then PrintLater("An old version of LibAddonMenu with compatibility issues was detected. For more information on how to proceed search for LibAddonMenu on esoui.com") LAMCompatibilityWarning = true @@ -64,6 +88,7 @@ local LAM_DEFAULTS_DIALOG = "LAM_DEFAULTS" local LAM_RELOAD_DIALOG = "LAM_RELOAD_DIALOG" local addonsForList = {} +---@type table local addonToOptionsMap = {} local optionsState = {} lam.widgets = lam.widgets or {} @@ -100,12 +125,14 @@ local function GetColorForState(disabled) return disabled and ZO_DEFAULT_DISABLED_COLOR or ZO_DEFAULT_ENABLED_COLOR end +--- @param control LAM2_ControlWithHelpUrl local function CreateFAQTexture(control) local controlData = control.data if not control or not controlData then logger:Warn("CreateFAQTexture - missing or invalid control") return end local helpUrl = controlData and GetStringFromValue(controlData.helpUrl) if not helpUrl or helpUrl == "" then return end + ---@class LAM2_FAQControl: TextureControl local faqControl = wm:CreateControl(nil, control, CT_TEXTURE) control.faqControl = faqControl @@ -144,7 +171,9 @@ local function CreateFAQTexture(control) return faqControl end +---@param controlData LAM2_BaseControlData local function CreateBaseControl(parent, controlData, controlName) + ---@class LAM2_BaseControl: LAM2_Control local control = wm:CreateControl(controlName or controlData.reference, parent.scroll or parent, CT_CONTROL) control.panel = parent.panel or parent -- if this is in a submenu, panel is the submenu's parent control.data = controlData @@ -156,7 +185,10 @@ local function CreateBaseControl(parent, controlData, controlName) return control end +---@param controlData LAM2_LabelAndContainerControlData local function CreateLabelAndContainerControl(parent, controlData, controlName) + ---@class LAM2_LabelAndContainerControl: LAM2_BaseControl + ---@field data LAM2_LabelAndContainerControlData local control = CreateBaseControl(parent, controlData, controlName) local width = control:GetWidth() @@ -172,7 +204,7 @@ local function CreateLabelAndContainerControl(parent, controlData, controlName) control.labelContainer = container end - local label = wm:CreateControl(nil, labelContainer or control, CT_LABEL) + local label = wm:CreateControl(nil, labelContainer or control, CT_LABEL) --[[@as LabelControl]] label:SetFont("ZoFontWinH4") label:SetHeight(MIN_HEIGHT) label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) @@ -207,6 +239,15 @@ local function CreateLabelAndContainerControl(parent, controlData, controlName) return control end +---@class TooltipData +---@field tooltipText string + +---@class ControlWithData: Control +---@field data TooltipData + +---@param control ControlWithData +---@param data LAM2_LabelAndContainerControlData +---@param tooltipData TooltipData local function SetUpTooltip(control, data, tooltipData) if not data.tooltip then return end control:SetMouseEnabled(true) @@ -726,15 +767,15 @@ local function PopulateAddonList(addonList, filter) end ---METHOD: REGISTER WIDGET-- ---each widget has its version checked before loading, ---so we only have the most recent one in memory ---Usage: --- widgetType = "string"; the type of widget being registered --- widgetVersion = integer; the widget's version number + LAMCreateControl = LAMCreateControl or {} local lamcc = LAMCreateControl +--METHOD: REGISTER WIDGET-- +--each widget has its version checked before loading, +--so we only have the most recent one in memory +---@param widgetType string the type of widget being registered +---@param widgetVersion integer the widget's version number function lam:RegisterWidget(widgetType, widgetVersion) if widgets[widgetType] and widgets[widgetType] >= widgetVersion then return false @@ -784,11 +825,10 @@ local function CloseCurrentPanel() end end +local locSettings = GetString(SI_GAME_MENU_SETTINGS) --METHOD: OPEN TO ADDON PANEL-- --opens to a specific addon's option panel ---Usage: --- panel = userdata; the panel returned by the :RegisterOptionsPanel method -local locSettings = GetString(SI_GAME_MENU_SETTINGS) +---@param panel LAM2_Panel the panel returned by the :RegisterOptionsPanel method function lam:OpenToPanel(panel) -- find and select the panel's row in addon list @@ -808,7 +848,7 @@ function lam:OpenToPanel(panel) ZO_ScrollList_SelectData(addonList, selectedData) ZO_ScrollList_RefreshVisible(addonList, selectedData) - local srchEdit = LAMAddonSettingsWindow:GetNamedChild("SearchFilterEdit") + local srchEdit = LAMAddonSettingsWindow:GetNamedChild("SearchFilterEdit") --[[@as EditControl]] srchEdit:Clear() -- note that ZO_ScrollList doesn't require `selectedData` to be actually @@ -817,7 +857,7 @@ function lam:OpenToPanel(panel) local function openAddonSettingsMenu() local gameMenu = ZO_GameMenu_InGame.gameMenu - local settingsMenu = gameMenu.headerControls[locSettings] + local settingsMenu = gameMenu.headerControls[locSettings] --[[@as ZO_TreeNode]] if settingsMenu then -- an instance of ZO_TreeNode local children = settingsMenu:GetChildren() @@ -842,10 +882,13 @@ function lam:OpenToPanel(panel) end local TwinOptionsContainer_Index = 0 +---@param leftWidget Control +---@param rightWidget Control local function TwinOptionsContainer(parent, leftWidget, rightWidget) TwinOptionsContainer_Index = TwinOptionsContainer_Index + 1 local cParent = parent.scroll or parent local panel = parent.panel or cParent + ---@class Container: Control local container = wm:CreateControl("$(parent)TwinContainer" .. tostring(TwinOptionsContainer_Index), cParent, CT_CONTROL) container:SetResizeToFitDescendents(true) @@ -869,6 +912,7 @@ end --INTERNAL FUNCTION --creates controls when options panel is first shown --controls anchoring of these controls in the panel +---@param panel LAM2_Panel local function CreateOptionsControls(panel) local addonID = panel:GetName() if(optionsState[addonID] == OPTIONS_CREATED) then @@ -1024,9 +1068,9 @@ end --METHOD: REGISTER ADDON PANEL --registers your addon with LibAddonMenu and creates a panel ---Usage: --- addonID = "string"; unique ID which will be the global name of your panel --- panelData = table; data object for your panel - see controls\panel.lua +---@param addonID string unique ID which will be the global name of your panel +---@param panelData LAM2_PanelData data object for your panel - see controls\panel.lua +---@return LAM2_Panel function lam:RegisterAddonPanel(addonID, panelData) CheckSafetyAndInitialize(addonID) local container = lam:GetAddonPanelContainer() @@ -1067,11 +1111,10 @@ end --registers the options you want shown for your addon --these are stored in a table where each key-value pair is the order --of the options in the panel and the data for that control, respectively ---see exampleoptions.lua for an example ---see controls\.lua for each widget type ---Usage: --- addonID = "string"; the same string passed to :RegisterAddonPanel --- optionsTable = table; the table containing all of the options controls and their data +---@see exampleoptions.lua for an example +---@see controls/.lua for each widget type +---@param addonID string the same string passed to :RegisterAddonPanel +---@param optionsTable LAM2_ControlData[] a list of data to create options controls from function lam:RegisterOptionControls(addonID, optionsTable) --optionsTable = {sliderData, buttonData, etc} addonToOptionsMap[addonID] = optionsTable end @@ -1096,7 +1139,7 @@ local function CreateAddonSettingsMenuEntry() sm:AddFragment(lam:GetAddonSettingsFragment()) KEYBOARD_OPTIONS:ChangePanels(lam.panelId) - local title = LAMAddonSettingsWindow:GetNamedChild("Title") + local title = LAMAddonSettingsWindow:GetNamedChild("Title") --[[@as LabelControl]] title:SetText(panelData.name) if not addonListSorted and #addonsForList > 0 then @@ -1122,7 +1165,7 @@ end --INTERNAL FUNCTION --creates the left-hand menu in LAM's window local function CreateAddonList(name, parent) - local addonList = wm:CreateControlFromVirtual(name, parent, "ZO_ScrollList") + local addonList = wm:CreateControlFromVirtual(name, parent, "ZO_ScrollList") --[[@as ZO_ScrollList]] local function addonListRow_OnMouseDown(control, button) if button == 1 then @@ -1166,7 +1209,7 @@ local function CreateAddonList(name, parent) local addonListRow_CreateRaw = addonDataType.pool.m_Factory local function addonListRow_Create(pool) - local control = addonListRow_CreateRaw(pool) + local control = addonListRow_CreateRaw(pool) --[[@as LabelControl]] control:SetHandler("OnMouseDown", addonListRow_OnMouseDown) --control:SetHandler("OnMouseEnter", addonListRow_OnMouseEnter) --control:SetHandler("OnMouseExit", addonListRow_OnMouseExit) @@ -1188,19 +1231,19 @@ end local function CreateSearchFilterBox(name, parent) local boxControl = wm:CreateControl(name, parent, CT_CONTROL) - local srchButton = wm:CreateControl("$(parent)Button", boxControl, CT_BUTTON) + local srchButton = wm:CreateControl("$(parent)Button", boxControl, CT_BUTTON) --[[@as ButtonControl]] srchButton:SetDimensions(32, 32) srchButton:SetAnchor(LEFT, nil, LEFT, 2, 0) srchButton:SetNormalTexture("EsoUI/Art/LFG/LFG_tabIcon_groupTools_up.dds") srchButton:SetPressedTexture("EsoUI/Art/LFG/LFG_tabIcon_groupTools_down.dds") srchButton:SetMouseOverTexture("EsoUI/Art/LFG/LFG_tabIcon_groupTools_over.dds") - local srchEdit = wm:CreateControlFromVirtual("$(parent)Edit", boxControl, "ZO_DefaultEdit") + local srchEdit = wm:CreateControlFromVirtual("$(parent)Edit", boxControl, "ZO_DefaultEdit") --[[@as EditControl]] srchEdit:SetAnchor(LEFT, srchButton, RIGHT, 4, 1) srchEdit:SetAnchor(RIGHT, nil, RIGHT, -4, 1) srchEdit:SetColor(ZO_NORMAL_TEXT:UnpackRGBA()) - local srchBg = wm:CreateControl("$(parent)Bg", boxControl, CT_BACKDROP) + local srchBg = wm:CreateControl("$(parent)Bg", boxControl, CT_BACKDROP) --[[@as BackdropControl]] srchBg:SetAnchorFill() srchBg:SetAlpha(0) srchBg:SetCenterColor(0, 0, 0, 0.5) @@ -1291,6 +1334,8 @@ end --creates LAM's Addon Settings top-level window local function CreateAddonSettingsWindow() local tlw = wm:CreateTopLevelWindow("LAMAddonSettingsWindow") + ---@type Window + LAMAddonSettingsWindow = LAMAddonSettingsWindow tlw:SetHidden(true) tlw:SetDimensions(1010, 914) -- same height as ZO_OptionsWindow @@ -1298,14 +1343,14 @@ local function CreateAddonSettingsWindow() -- create black background for the window (mimic ZO_RightFootPrintBackground) - local bgLeft = wm:CreateControl("$(parent)BackgroundLeft", tlw, CT_TEXTURE) + local bgLeft = wm:CreateControl("$(parent)BackgroundLeft", tlw, CT_TEXTURE) --[[@as TextureControl]] bgLeft:SetTexture("EsoUI/Art/Miscellaneous/centerscreen_left.dds") bgLeft:SetDimensions(1024, 1024) bgLeft:SetAnchor(TOPLEFT, nil, TOPLEFT) bgLeft:SetDrawLayer(DL_BACKGROUND) bgLeft:SetExcludeFromResizeToFitExtents(true) - local bgRight = wm:CreateControl("$(parent)BackgroundRight", tlw, CT_TEXTURE) + local bgRight = wm:CreateControl("$(parent)BackgroundRight", tlw, CT_TEXTURE) --[[@as TextureControl]] bgRight:SetTexture("EsoUI/Art/Miscellaneous/centerscreen_right.dds") bgRight:SetDimensions(64, 1024) bgRight:SetAnchor(TOPLEFT, bgLeft, TOPRIGHT) @@ -1314,14 +1359,14 @@ local function CreateAddonSettingsWindow() -- create gray background for addon list (mimic ZO_TreeUnderlay) - local underlayLeft = wm:CreateControl("$(parent)UnderlayLeft", tlw, CT_TEXTURE) + local underlayLeft = wm:CreateControl("$(parent)UnderlayLeft", tlw, CT_TEXTURE) --[[@as TextureControl]] underlayLeft:SetTexture("EsoUI/Art/Miscellaneous/centerscreen_indexArea_left.dds") underlayLeft:SetDimensions(256, 1024) underlayLeft:SetAnchor(TOPLEFT, bgLeft, TOPLEFT) underlayLeft:SetDrawLayer(DL_BACKGROUND) underlayLeft:SetExcludeFromResizeToFitExtents(true) - local underlayRight = wm:CreateControl("$(parent)UnderlayRight", tlw, CT_TEXTURE) + local underlayRight = wm:CreateControl("$(parent)UnderlayRight", tlw, CT_TEXTURE) --[[@as TextureControl]] underlayRight:SetTexture("EsoUI/Art/Miscellaneous/centerscreen_indexArea_right.dds") underlayRight:SetDimensions(128, 1024) underlayRight:SetAnchor(TOPLEFT, underlayLeft, TOPRIGHT) @@ -1330,7 +1375,7 @@ local function CreateAddonSettingsWindow() -- create title bar (mimic ZO_OptionsWindow) - local title = wm:CreateControl("$(parent)Title", tlw, CT_LABEL) + local title = wm:CreateControl("$(parent)Title", tlw, CT_LABEL) --[[@as LabelControl]] title:SetAnchor(TOPLEFT, nil, TOPLEFT, 65, 70) title:SetFont("ZoFontWinH1") title:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE) diff --git a/LibAddonMenu-2.0/controls/button.lua b/LibAddonMenu-2.0/controls/button.lua index 23be855..abc6efb 100644 --- a/LibAddonMenu-2.0/controls/button.lua +++ b/LibAddonMenu-2.0/controls/button.lua @@ -1,17 +1,12 @@ ---[[buttonData = { - type = "button", - name = "My Button", -- string id or function returning a string - func = function() end, - tooltip = "Button's tooltip text.", -- string id or function returning a string (optional) - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - icon = "icon\\path.dds", -- (optional) - isDangerous = false, -- boolean, if set to true, the button text will be red and a confirmation dialog with the button label and warning text will show on click before the callback is executed (optional) - warning = "Will need to reload the UI.", -- (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonButton", -- unique global reference to control (optional) - resetFunc = function(buttonControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_ButtonData: LAM2_BaseControlData +---@field type "button" +---@field func fun() will be called when the button is pressed +---@field tooltip nil|Stringy ex. "Button's tooltip text." +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field icon nil|string ex. "icon\\path.dds" +---@field isDangerous nil|boolean if set to true, the button text will be red and a confirmation dialog with the button label and warning text will show on click before the callback is executed +---@field warning nil|Stringy ex. "Will need to reload the UI." +---@field resetFunc nil|fun(buttonControl: LAM2_Button) custom function to run after the control is reset to defaults ex. function(buttonControl) d("defaults reset") end local widgetVersion = 12 local LAM = LibAddonMenu2 @@ -30,7 +25,10 @@ end --controlName is optional local MIN_HEIGHT = 28 -- default_button height local HALF_WIDTH_LINE_SPACING = 2 + +---@param buttonData LAM2_ButtonData function LAMCreateControl.button(parent, buttonData, controlName) + ---@class LAM2_Button: LAM2_BaseControl local control = LAM.util.CreateBaseControl(parent, buttonData, controlName) control:SetMouseEnabled(true) @@ -42,17 +40,18 @@ function LAMCreateControl.button(parent, buttonData, controlName) end if buttonData.icon then - control.button = wm:CreateControl(nil, control, CT_BUTTON) + control.button = wm:CreateControl(nil, control, CT_BUTTON) --[[@as LAM2_ButtonControl]] control.button:SetDimensions(26, 26) control.button:SetNormalTexture(buttonData.icon) control.button:SetPressedOffset(2, 2) else --control.button = wm:CreateControlFromVirtual(controlName.."Button", control, "ZO_DefaultButton") - control.button = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultButton") + control.button = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultButton") --[[@as LAM2_ButtonControl]] control.button:SetWidth(width / 3) control.button:SetText(LAM.util.GetStringFromValue(buttonData.name)) if buttonData.isDangerous then control.button:SetNormalFontColor(ZO_ERROR_COLOR:UnpackRGBA()) end end + ---@class LAM2_ButtonControl: ButtonControl local button = control.button button:SetAnchor(control.isHalfWidth and CENTER or RIGHT) button:SetClickSound("Click") diff --git a/LibAddonMenu-2.0/controls/checkbox.lua b/LibAddonMenu-2.0/controls/checkbox.lua index 3272270..59261ca 100644 --- a/LibAddonMenu-2.0/controls/checkbox.lua +++ b/LibAddonMenu-2.0/controls/checkbox.lua @@ -1,18 +1,12 @@ ---[[checkboxData = { - type = "checkbox", - name = "My Checkbox", -- or string id or function returning a string - getFunc = function() return db.var end, - setFunc = function(value) db.var = value doStuff() end, - tooltip = "Checkbox's tooltip text.", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = defaults.var, -- a boolean or function that returns a boolean (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonCheckbox", -- unique global reference to control (optional) - resetFunc = function(checkboxControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_CheckboxData: LAM2_LabelAndContainerControlData +---@field type "checkbox" +---@field getFunc fun(): boolean ex. function() return db.var end +---@field setFunc fun(boolean) ex. function(value) db.var = value doStuff() end +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting +---@field warning nil|Stringy ex. "May cause permanent awesomeness" +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed. +---@field default nil|boolean|fun(): boolean ex. defaults.var +---@field resetFunc nil|fun(checkboxControl: LAM2_Checkbox) custom function to run after the control is reset to defaults ex. function(checkboxControl) d("defaults reset") end local widgetVersion = 15 @@ -101,8 +95,10 @@ local function OnMouseExit(control) control.checkbox:SetColor(ZO_NORMAL_TEXT:UnpackRGBA()) end ---controlName is optional +---@param checkboxData LAM2_CheckboxData +---@param controlName string|nil function LAMCreateControl.checkbox(parent, checkboxData, controlName) + ---@class LAM2_Checkbox: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, checkboxData, controlName) control:SetHandler("OnMouseEnter", OnMouseEnter) control:SetHandler("OnMouseExit", OnMouseExit) @@ -113,7 +109,7 @@ function LAMCreateControl.checkbox(parent, checkboxData, controlName) control:UpdateValue(false, control.value) end) - control.checkbox = wm:CreateControl(nil, control.container, CT_LABEL) + control.checkbox = wm:CreateControl(nil, control.container, CT_LABEL) --[[@as LabelControl]] local checkbox = control.checkbox checkbox:SetAnchor(LEFT, control.container, LEFT, 0, 0) checkbox:SetFont("ZoFontGameBold") diff --git a/LibAddonMenu-2.0/controls/colorpicker.lua b/LibAddonMenu-2.0/controls/colorpicker.lua index 0f0ff88..413e061 100644 --- a/LibAddonMenu-2.0/controls/colorpicker.lua +++ b/LibAddonMenu-2.0/controls/colorpicker.lua @@ -1,19 +1,14 @@ ---[[colorpickerData = { - type = "colorpicker", - name = "My Color Picker", -- or string id or function returning a string - getFunc = function() return db.r, db.g, db.b, db.a end, -- (alpha is optional) - setFunc = function(r,g,b,a) db.r=r, db.g=g, db.b=b, db.a=a end, -- (alpha is optional) - tooltip = "Color Picker's tooltip text.", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = {r = defaults.r, g = defaults.g, b = defaults.b, a = defaults.a}, -- (optional) table of default color values (or default = defaultColor, where defaultColor is a table with keys of r, g, b[, a]) or a function that returns the color - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonColorpicker", -- unique global reference to control (optional) - resetFunc = function(colorpickerControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] - +---@alias ColorTable {["r"]: number, ["g"]: number, ["b"]: number, ["a"]: number|nil} + +---@class LAM2_ColorPickerData: LAM2_LabelAndContainerControlData +---@field type "colorpicker" +---@field getFunc fun(): number, number, number, number|nil returns r, g, b, a +---@field setFunc fun(r: number, g: number, b: number, a:number|nil) +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field warning nil|Stringy ex. "May cause permanent awesomeness." +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after a UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed +---@field default nil|ColorTable|fun(): ColorTable table of default color values ex. {r = defaults.r, g = defaults.g, b = defaults.b, a = defaults.a} +---@field resetFunc nil|fun(colorPickerControl: LAM2_ColorPicker) custom function to run after the control is reset to defaults ex. function(colorpickerControl) d("defaults reset") end local widgetVersion = 15 local LAM = LibAddonMenu2 @@ -54,18 +49,22 @@ local function UpdateValue(control, forceDefault, valueR, valueG, valueB, valueA control.thumb:SetColor(valueR, valueG, valueB, valueA or 1) end +---@param colorpickerData LAM2_ColorPickerData function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) + ---@class LAM2_ColorPicker: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, colorpickerData, controlName) + ---@class LAM2_BorderedContainer: Control + ---@field border TextureControl control.color = control.container local color = control.color - control.thumb = wm:CreateControl(nil, color, CT_TEXTURE) + control.thumb = wm:CreateControl(nil, color, CT_TEXTURE) --[[@as TextureControl]] local thumb = control.thumb thumb:SetDimensions(36, 18) thumb:SetAnchor(LEFT, color, LEFT, 4, 0) - color.border = wm:CreateControl(nil, color, CT_TEXTURE) + color.border = wm:CreateControl(nil, color, CT_TEXTURE) --[[@as TextureControl]] local border = color.border border:SetTexture("EsoUI\\Art\\ChatWindow\\chatOptions_bgColSwatch_frame.dds") border:SetTextureCoords(0, .625, 0, .8125) diff --git a/LibAddonMenu-2.0/controls/custom.lua b/LibAddonMenu-2.0/controls/custom.lua index 4fc6d97..6025fae 100644 --- a/LibAddonMenu-2.0/controls/custom.lua +++ b/LibAddonMenu-2.0/controls/custom.lua @@ -1,13 +1,11 @@ ---[[customData = { - type = "custom", - reference = "MyAddonCustomControl", -- unique name for your control to use as reference (optional) - createFunc = function(customControl) end, -- function to call when this custom control was created (optional) - refreshFunc = function(customControl) end, -- function to call when panel/controls refresh (optional) - width = "full", -- or "half" (optional) - minHeight = function() return db.minHeightNumber end, --or number for the minimum height of this control. Default: 26 (optional) - maxHeight = function() return db.maxHeightNumber end, --or number for the maximum height of this control. Default: 4 * minHeight (optional) - resetFunc = function(customControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_CustomData: LAM2_BaseControlData +---@field type "custom" +---@field createFunc nil|fun(customControl: LAM2_Custom) called when this custom control is created +---@field refreshFunc nil|fun(customControl: LAM2_Custom) called when the created custom control is refreshed +---@field minHeight nil|integer|fun(): integer default 26. the minimum height of the control. +---@field maxHeight nil|integer|fun(): integer default 4*minHeight. the maximum height of the control. +---@field resetFunc nil|fun(customControl: LAM2_Custom) custom function to run after the control is reset to defaults ex. function(customControl) d("defaults reset") end + local widgetVersion = 9 local LAM = LibAddonMenu2 @@ -21,7 +19,10 @@ end local MIN_HEIGHT = 26 +---@param customData LAM2_CustomData function LAMCreateControl.custom(parent, customData, controlName) + ---@class LAM2_Custom: LAM2_BaseControl + ---@field data LAM2_CustomData local control = LAM.util.CreateBaseControl(parent, customData, controlName) local width = control:GetWidth() control:SetResizeToFitDescendents(true) diff --git a/LibAddonMenu-2.0/controls/description.lua b/LibAddonMenu-2.0/controls/description.lua index a4a807a..e411aae 100644 --- a/LibAddonMenu-2.0/controls/description.lua +++ b/LibAddonMenu-2.0/controls/description.lua @@ -1,16 +1,11 @@ ---[[descriptionData = { - type = "description", - text = "My description text to display.", -- or string id or function returning a string - title = "My Title", -- or string id or function returning a string (optional) - tooltip = "My Tooltip", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - enableLinks = nil, -- or true for default tooltips, or function OnLinkClicked handler (optional) - -- see: https://wiki.esoui.com/UI_XML#OnLinkClicked - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonDescription", -- unique global reference to control (optional) - resetFunc = function(descriptionControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_DescriptionData: LAM2_BaseControlData, LAM2_ControlWithHelpUrlData +---@field type "description" +---@field text Stringy ex. "My description text to display." +---@field title nil|Stringy ex. "My Title" +---@field tooltip Stringy ex. "Description's tooltip text." +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field enableLinks nil|true|fun(self, linkData, linkText, button, ctrl, alt, shift, command) true for default tooltips, or function OnLinkClicked handler (see: https://wiki.esoui.com/UI_XML#OnLinkClicked) +---@field resetFunc nil|fun(descriptionControl: LAM2_Description) custom function to run after the control is reset to defaults ex. function(descriptionControl) d("defaults reset") end local widgetVersion = 14 @@ -46,6 +41,7 @@ local function UpdateValue(control) end function LAMCreateControl.description(parent, descriptionData, controlName) + ---@class LAM2_Description: LAM2_BaseControl local control = LAM.util.CreateBaseControl(parent, descriptionData, controlName) local isHalfWidth = control.isHalfWidth local width = control:GetWidth() @@ -59,7 +55,8 @@ function LAMCreateControl.description(parent, descriptionData, controlName) control:SetResizeToFitConstrains(ANCHOR_CONSTRAINS_Y) end - control.desc = wm:CreateControl(nil, control, CT_LABEL) + control.desc = wm:CreateControl(nil, control, CT_LABEL) --[[@as LabelControl]] + ---@class ControlDesc: LabelControl, ControlWithData local desc = control.desc desc:SetVerticalAlignment(TEXT_ALIGN_TOP) desc:SetFont("ZoFontGame") @@ -68,7 +65,7 @@ function LAMCreateControl.description(parent, descriptionData, controlName) LAM.util.SetUpTooltip(desc, descriptionData) if descriptionData.title then - control.title = wm:CreateControl(nil, control, CT_LABEL) + control.title = wm:CreateControl(nil, control, CT_LABEL) --[[@as LabelControl]] local title = control.title title:SetWidth(isHalfWidth and width / 2 or width) title:SetAnchor(TOPLEFT, control, TOPLEFT) diff --git a/LibAddonMenu-2.0/controls/divider.lua b/LibAddonMenu-2.0/controls/divider.lua index 2d64cd4..8faaac8 100644 --- a/LibAddonMenu-2.0/controls/divider.lua +++ b/LibAddonMenu-2.0/controls/divider.lua @@ -1,10 +1,7 @@ ---[[dividerData = { - type = "divider", - width = "full", -- or "half" (optional) - height = 10, -- (optional) - alpha = 0.25, -- (optional) - reference = "MyAddonDivider" -- unique global reference to control (optional) -} ]] +---@class LAM2_DividerData: LAM2_BaseControlData +---@field type "divider" +---@field height nil|integer ex. 10 +---@field alpha nil|number 0-1. ex. 0.25 local widgetVersion = 2 @@ -26,7 +23,9 @@ local function GetValueInRange(value, min, max, default) return math.min(math.max(min, value), max) end +---@param dividerData LAM2_DividerData function LAMCreateControl.divider(parent, dividerData, controlName) + ---@class LAM2_Divider: LAM2_BaseControl local control = LAM.util.CreateBaseControl(parent, dividerData, controlName) local isHalfWidth = control.isHalfWidth local width = control:GetWidth() diff --git a/LibAddonMenu-2.0/controls/dropdown.lua b/LibAddonMenu-2.0/controls/dropdown.lua index 607d1b6..d7cf7c2 100644 --- a/LibAddonMenu-2.0/controls/dropdown.lua +++ b/LibAddonMenu-2.0/controls/dropdown.lua @@ -1,30 +1,45 @@ ---[[dropdownData = { - type = "dropdown", - name = "My Dropdown", -- or string id or function returning a string - choices = {"table", "of", "choices"}, - choicesValues = {"foo", 2, "three"}, -- if specified, these values will get passed to setFunc instead (optional) - getFunc = function() return db.var end, -- if multiSelect is true the getFunc must return a table - setFunc = function(var) db.var = var doStuff() end, -- if multiSelect is true the setFunc's var must be a table - tooltip = "Dropdown's tooltip text.", -- or string id or function returning a string (optional) - choicesTooltips = {"tooltip 1", "tooltip 2", "tooltip 3"}, -- or array of string ids or array of functions returning a string (optional) - sort = "name-up", -- or "name-down", "numeric-up", "numeric-down", "value-up", "value-down", "numericvalue-up", "numericvalue-down" (optional) - if not provided, list will not be sorted - width = "full", -- or "half" (optional) - scrollable = true, -- boolean or number, if set the dropdown will feature a scroll bar if there are a large amount of choices and limit the visible lines to the specified number or 10 if true is used (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = defaults.var, -- default value or function that returns the default value (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonDropdown", -- unique global reference to control (optional) - resetFunc = function(dropdownControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) - multiSelect = false, -- boolean or function returning a boolean. If set to true you can select multiple entries at the list (optional) - multiSelectTextFormatter = SI_COMBO_BOX_DEFAULT_MULTISELECTION_TEXT_FORMATTER, -- or string id or function returning a string. If specified, this will be used with zo_strformat(multiSelectTextFormatter, numSelectedItems) to set the "selected item text". Only incombination with multiSelect = true (optional) - multiSelectNoSelectionText = SI_COMBO_BOX_DEFAULT_NO_SELECTION_TEXT, -- or string id or function returning a string. Only incombination with multiSelect = true (optional) - multiSelectMaxSelections = 5, --Number or function returning a number of the maximum of selectable entries. If not specified there is no max selection. Only incombination with multiSelect = true (optional) -} ]] - - -local widgetVersion = 27 +---@alias LAM2_SortType "name-up"|"name-down"|"numeric-up"|"numeric-down"|"value-up"|"value-down"|"numericvalue-up"|"numericvalue-down" + +--- TODO: use generic classes instead once they're available? +---@alias LAM2_DropdownChoice any + +---@class LAM2_DropdownData: LAM2_LabelAndContainerControlData +---@field type "dropdown" +---@field choices string[] ex. {"table", "of", "choices"} +---@field getFunc fun(): LAM2_DropdownChoice|LAM2_DropdownChoice[] ex. function() return db.var end +---@field setFunc fun(var: LAM2_DropdownChoice|LAM2_DropdownChoice[]) ex. function(var) db.var = var doStuff() end +---@field choicesValues nil|LAM2_DropdownChoice[] if specified, these values will get passed to setFunc instead ex. {"foo", 2, "three"} +---@field choicesTooltips nil|string[] ex. {"tooltip 1", "tooltip 2", "tooltip 3"} +---@field sort nil|LAM2_SortType if not provided, list will not be sorted +---@field scrollable nil|boolean|integer if set the dropdown will feature a scroll bar if there are a large amount of choices and limit the visible lines to the specified number or 10 if true is used +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field warning nil|Stringy ex. "May cause permanent awesomeness" +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after a UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed +---@field default nil|LAM2_DropdownChoice|LAM2_DropdownChoice[]|fun(): (LAM2_DropdownChoice|LAM2_DropdownChoice[]) default value or function that returns the default value +---@field helpUrl nil|Stringy ex. "https://www.esoui.com/portal.php?id=218&a=faq" +---@field resetFunc nil|fun(dropdownControl: LAM2_Dropdown) custom function to run after the control is reset to defaults ex. function(dropdownControl) d("defaults reset") end +---@field multiSelect nil|boolean|fun(): boolean if set to true, you can have multiple entries selected at the same time +---@field multiSelectTextFormatter nil|Stringy If specified, this will be used with zo_strformat(multiSelectTextFormatter, numSelectedItems) to set the "selected item text". Only in combination with multiSelect = true. ex SI_COMBO_BOX_DEFAULT_MULTISELECTION_TEXT_FORMATTER +---@field multiSelectNoSelectionText nil|Stringy Only incombination with multiSelect = true. ex. SI_COMBO_BOX_DEFAULT_NO_SELECTION_TEXT +---@field multiSelectMaxSelections nil|integer|fun(): integer The maximum number of entries that can be selected at once. If not specified there is no limit. Only incombination with multiSelect = true. ex. 5 + +---@class LAM2_SingleSelectDropdownData: LAM2_DropdownData +---@field multiSelect nil +---@field getFunc fun(): LAM2_DropdownChoice +---@field setFunc fun(var: LAM2_DropdownChoice) +---@field default nil|LAM2_DropdownChoice|fun(): LAM2_DropdownChoice +---@field multiSelectTextFormatter nil +---@field multiSelectNoSelectionText nil +---@field multiSelectMaxSelections nil + +---@class LAM2_MultiSelectDropdownData: LAM2_DropdownData +---@field multiSelect true +---@field getFunc fun(): LAM2_DropdownChoice[] +---@field setFunc fun(var: LAM2_DropdownChoice[]) +---@field default nil|LAM2_DropdownChoice[]|fun(): LAM2_DropdownChoice[] + + +local widgetVersion = 28 local LAM = LibAddonMenu2 if not LAM:RegisterWidget("dropdown", widgetVersion) then return end @@ -160,6 +175,8 @@ local function DoShowTooltip(control, tooltip) if tooltipText ~= nil and tooltipText ~= "" then InitializeTooltip(InformationTooltip, control, TOPLEFT, 0, 0, BOTTOMRIGHT) SetTooltipText(InformationTooltip, tooltipText) + ---@type TopLevelWindow + InformationTooltipTopLevel = InformationTooltipTopLevel InformationTooltipTopLevel:BringWindowToTop() end end @@ -190,9 +207,9 @@ local function UpdateChoices(control, choices, choicesValues, choicesTooltips) ZO_ClearTable(control.choices) --build new list of choices - local choices = choices or control.data.choices - local choicesValues = choicesValues or control.data.choicesValues - local choicesTooltips = choicesTooltips or control.data.choicesTooltips + choices = choices or control.data.choices + choicesValues = choicesValues or control.data.choicesValues + choicesTooltips = choicesTooltips or control.data.choicesTooltips if choicesValues then assert(#choices == #choicesValues, "choices and choicesValues need to have the same size") @@ -216,10 +233,13 @@ local function UpdateChoices(control, choices, choicesValues, choicesTooltips) if entryValue == nil then entryValue = entry.name end control.choices[entryValue] = entry.name - control.dropdown:AddItem(entry, not control.data.sort and ZO_COMBOBOX_SUPRESS_UPDATE) --if sort type/order isn't specified, then don't sort + -- why the "and 2" at the end? + control.dropdown:AddItem(entry, not control.data.sort and ZO_COMBOBOX_SUPPRESS_UPDATE) --if sort type/order isn't specified, then don't sort end end +---@param sortInfo LAM2_SortType +---@return ["name"|"numeric"|"value"|"numericvalue", "up"|"down"] local function GrabSortingInfo(sortInfo) local t, i = {}, 1 for info in string.gmatch(sortInfo, "([^%-]+)") do @@ -269,10 +289,11 @@ local function SetDropdownHeight(control, dropdown, dropdownData) return visibleRows, min, max end +---@param dropdown ZO_ComboBox local function CalculateContentWidth(dropdown) local dataType = ZO_ScrollList_GetDataTypeTable(dropdown.m_scroll, 1) - local dummy = dataType.pool:AcquireObject() + local dummy = dataType.pool:AcquireObject() --[[@as ZO_ComboBoxDropdown_Keyboard_Entry]] local item = { m_owner = dropdown, name = "Dummy" @@ -298,10 +319,13 @@ local function CalculateContentWidth(dropdown) return maxWidth end +---@param control LAM2_Dropdown +---@param dropdown ZO_ComboBox +---@param dropdownData LAM2_DropdownData local function AdjustDimensions(control, dropdown, dropdownData) local numItems = #dropdown.m_sortedItems local dropdownObject = dropdown.m_dropdown - local scroll = dropdownObject:GetNamedChild("Scroll") + local scroll = dropdownObject:GetNamedChild("Scroll") --[[@as ZO_ScrollList]] local scrollContent = scroll:GetNamedChild("Contents") local anchorOffset = 0 @@ -358,8 +382,9 @@ local function OnMultiSelectComboBoxMouseUp(control, combobox, button, upInside, end end - +---@param dropdownData LAM2_DropdownData function LAMCreateControl.dropdown(parent, dropdownData, controlName) + ---@class LAM2_Dropdown: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, dropdownData, controlName) control.choices = {} @@ -371,7 +396,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) end local comboboxCount = (countControl.comboboxCount or 0) + 1 countControl.comboboxCount = comboboxCount - control.combobox = wm:CreateControlFromVirtual(zo_strjoin(nil, name, "Combobox", comboboxCount), control.container, "ZO_ComboBox") + control.combobox = wm:CreateControlFromVirtual(zo_strjoin(nil, name, "Combobox", comboboxCount), control.container, "ZO_ComboBox") --[[@as ZO_ComboBox_Control]] local combobox = control.combobox combobox:SetAnchor(TOPLEFT) @@ -423,7 +448,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) local sortInfo = GrabSortingInfo(dropdownData.sort) control.m_sortType, control.m_sortOrder = SORT_TYPES[sortInfo[1]], SORT_ORDERS[sortInfo[2]] elseif dropdownData.choicesValues then - control.m_sortType, control.m_sortOrder = ZO_SORT_ORDER_UP, SORT_BY_VALUE + control.m_sortType, control.m_sortOrder = SORT_BY_VALUE, ZO_SORT_ORDER_UP end if dropdownData.warning ~= nil or dropdownData.requiresReload then diff --git a/LibAddonMenu-2.0/controls/editbox.lua b/LibAddonMenu-2.0/controls/editbox.lua index 8c6fcd3..e557600 100644 --- a/LibAddonMenu-2.0/controls/editbox.lua +++ b/LibAddonMenu-2.0/controls/editbox.lua @@ -1,22 +1,16 @@ ---[[editboxData = { - type = "editbox", - name = "My Editbox", -- or string id or function returning a string - getFunc = function() return db.text end, - setFunc = function(text) db.text = text doStuff() end, - tooltip = "Editbox's tooltip text.", -- or string id or function returning a string (optional) - isMultiline = true, -- boolean (optional) - isExtraWide = true, -- boolean (optional) - maxChars = 3000, -- number (optional) - textType = TEXT_TYPE_NUMERIC, -- number (optional) or function returning a number. Valid TextType numbers: TEXT_TYPE_ALL, TEXT_TYPE_ALPHABETIC, TEXT_TYPE_ALPHABETIC_NO_FULLWIDTH_LATIN, TEXT_TYPE_NUMERIC, TEXT_TYPE_NUMERIC_UNSIGNED_INT, TEXT_TYPE_PASSWORD - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = defaults.text, -- default value or function that returns the default value (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonEditbox", -- unique global reference to control (optional) - resetFunc = function(editboxControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_EditboxData: LAM2_LabelAndContainerControlData +---@field type "editbox" +---@field getFunc fun(): string ex. function() return db.txt end +---@field setFunc fun(string) ex. function(text) db.text = text doStuff() end +---@field isMultiline nil|boolean +---@field isExtraWide nil|boolean +---@field maxChars nil|integer ex. 3000 +---@field textType nil|TextType|fun(): TextType ex. TEXT_TYPE_NUMERIC +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field warning nil|Stringy ex. "May cause permanent awesomeness" +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after a UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed. +---@field default nil|Stringy ex. defaults.text +---@field resetFunc nil|fun(editboxControl: LAM2_Editbox) custom function to run after the control is reset to defaults ex. function(editboxControl) d("defaults reset") end local widgetVersion = 16 @@ -69,7 +63,10 @@ end local MIN_HEIGHT = 24 local HALF_WIDTH_LINE_SPACING = 2 + +---@param editboxData LAM2_EditboxData function LAMCreateControl.editbox(parent, editboxData, controlName) + ---@class LAM2_Editbox: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, editboxData, controlName) local container = control.container @@ -78,7 +75,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) bg:SetAnchorFill() if editboxData.isMultiline then - control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditMultiLineForBackdrop") + control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditMultiLineForBackdrop") --[[@as EditControl]] control.editbox:SetHandler("OnMouseWheel", function(self, delta) if self:HasFocus() then --only set focus to new spots if the editbox is currently in use local cursorPos = self:GetCursorPosition() @@ -99,7 +96,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) end end) else - control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditForBackdrop") + control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditForBackdrop") --[[@as EditControl]] end diff --git a/LibAddonMenu-2.0/controls/header.lua b/LibAddonMenu-2.0/controls/header.lua index 2bb4075..f8abd83 100644 --- a/LibAddonMenu-2.0/controls/header.lua +++ b/LibAddonMenu-2.0/controls/header.lua @@ -1,12 +1,6 @@ ---[[headerData = { - type = "header", - name = "My Header", -- or string id or function returning a string - tooltip = "My Tooltip", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonHeader", -- unique global reference to control (optional) - resetFunc = function(headerControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_HeaderData: LAM2_LabelAndContainerControlData +---@field type "header" +---@field resetFunc nil|fun(headerControl: LAM2_Header) custom function to run after the control is reset to defaults ex. function(headerControl) d("defaults reset") end local widgetVersion = 11 @@ -20,7 +14,10 @@ local function UpdateValue(control) end local MIN_HEIGHT = 30 + +---@param headerData LAM2_HeaderData function LAMCreateControl.header(parent, headerData, controlName) + ---@class LAM2_Header: LAM2_BaseControl local control = LAM.util.CreateBaseControl(parent, headerData, controlName) local isHalfWidth = control.isHalfWidth local width = control:GetWidth() @@ -31,7 +28,7 @@ function LAMCreateControl.header(parent, headerData, controlName) divider:SetWidth(isHalfWidth and width / 2 or width) divider:SetAnchor(TOPLEFT) - control.header = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") + control.header = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") --[[@as LabelControl]] local header = control.header header:SetAnchor(TOPLEFT, divider, BOTTOMLEFT) header:SetAnchor(BOTTOMRIGHT) diff --git a/LibAddonMenu-2.0/controls/iconpicker.lua b/LibAddonMenu-2.0/controls/iconpicker.lua index 16f2db6..6597a38 100644 --- a/LibAddonMenu-2.0/controls/iconpicker.lua +++ b/LibAddonMenu-2.0/controls/iconpicker.lua @@ -1,25 +1,20 @@ ---[[iconpickerData = { - type = "iconpicker", - name = "My Icon Picker", -- or string id or function returning a string - choices = {"texture path 1", "texture path 2", "texture path 3"}, - getFunc = function() return db.var end, - setFunc = function(var) db.var = var doStuff() end, - tooltip = "Color Picker's tooltip text.", -- or string id or function returning a string (optional) - choicesTooltips = {"icon tooltip 1", "icon tooltip 2", "icon tooltip 3"}, -- or array of string ids or array of functions returning a string (optional) - maxColumns = 5, -- number of icons in one row (optional) - visibleRows = 4.5, -- number of visible rows (optional) - iconSize = 28, -- size of the icons (optional) - defaultColor = ZO_ColorDef:New("FFFFFF"), -- default color of the icons (optional) - width = "full", --or "half" (optional) - beforeShow = function(control, iconPicker) return preventShow end, -- (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = defaults.var, -- default value or function that returns the default value (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonIconPicker", -- unique global reference to control (optional) - resetFunc = function(iconpickerControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_IconPickerData: LAM2_LabelAndContainerControlData +---@field type "iconpicker" +---@field choices string[] ex. {"texture path 1", "texture path 2", "texture path 3"} +---@field getFunc fun(): string ex. function() return db.var end +---@field setFunc fun(string) ex. function(var) db.var = var doStuff() end +---@field choicesTooltips nil|Stringy[] ex. {"icon tooltip 1", "icon tooltip 2", "icon tooltip 3"} +---@field maxColumns nil|integer number of icons in one row ex. 5 +---@field visibleRows nil|number number of visible rows ex. 4.5 +---@field iconSize nil|integer size of the icons ex. 28 +---@field defaultColor nil|ZO_ColorDef default color of the icons ex. ZO_ColorDef:New("FFFFFF") +---@field beforeShow nil|fun(control: LAM2_IconPicker, iconPicker: IconPickerMenu): boolean ex. function(control, iconPicker) return preventShow end +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting +---@field warning nil|Stringy ex. "May cause permanent awesomeness" +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed. +---@field default nil|Stringy ex. defaults.var +---@field resetFunc nil|fun(iconpickerControl: LAM2_IconPicker) custom function to run after the control is reset to defaults ex. function(iconpickerControl) d("defaults reset") end + local widgetVersion = 11 local LAM = LibAddonMenu2 @@ -27,6 +22,15 @@ if not LAM:RegisterWidget("iconpicker", widgetVersion) then return end local wm = WINDOW_MANAGER +---@class IconPickerIcon: TextureControl +---@field color ZO_ColorDef +---@field size integer +---@field texture string +---@field tooltip string +---@field OnSelect fun(icon: IconPickerIcon, texture: string) + +---@class IconPickerMenu: ZO_Object +---@field control TopLevelWindow local IconPickerMenu = ZO_Object:Subclass() local iconPicker LAM.util.GetIconPickerMenu = function() @@ -43,7 +47,7 @@ LAM.util.GetIconPickerMenu = function() end function IconPickerMenu:New(...) - local object = ZO_Object.New(self) + local object = ZO_Object.New(self) --[[@as IconPickerMenu]] object:Initialize(...) return object end @@ -64,26 +68,26 @@ function IconPickerMenu:Initialize(name) self.scroll = scroll self.scrollContainer = scrollContainer - local bg = wm:CreateControl(nil, scrollContainer, CT_BACKDROP) + local bg = wm:CreateControl(nil, scrollContainer, CT_BACKDROP) --[[@as BackdropControl]] bg:SetAnchor(TOPLEFT, scrollContainer, TOPLEFT, 0, -3) bg:SetAnchor(BOTTOMRIGHT, scrollContainer, BOTTOMRIGHT, 2, 5) bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16) bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds") bg:SetInsets(16, 16, -16, -16) - local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE) + local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE) --[[@as TextureControl]] mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds") mungeOverlay:SetDrawLevel(1) mungeOverlay:SetAddressMode(TEX_MODE_WRAP) mungeOverlay:SetAnchorFill() - local mouseOver = wm:CreateControl(nil, scrollContainer, CT_TEXTURE) + local mouseOver = wm:CreateControl(nil, scrollContainer, CT_TEXTURE) --[[@as TextureControl]] mouseOver:SetDrawLevel(2) mouseOver:SetTexture("EsoUI/Art/Buttons/minmax_mouseover.dds") mouseOver:SetHidden(true) local function IconFactory(pool) - local icon = wm:CreateControl(name .. "Entry" .. pool:GetNextControlId(), scroll, CT_TEXTURE) + local icon = wm:CreateControl(name .. "Entry" .. pool:GetNextControlId(), scroll, CT_TEXTURE) --[[@as IconPickerIcon]] icon:SetMouseEnabled(true) icon:SetDrawLevel(3) icon:SetDrawLayer(DL_CONTROLS) @@ -119,7 +123,7 @@ function IconPickerMenu:Initialize(name) icon:SetHidden(true) end - self.iconPool = ZO_ObjectPool:New(IconFactory, ResetFunction) + self.iconPool = ZO_ObjectPool:New(IconFactory, ResetFunction) --[[@as ZO_ControlPool]] self:SetMaxColumns(1) self.icons = {} self.color = ZO_DEFAULT_ENABLED_COLOR @@ -219,7 +223,7 @@ function IconPickerMenu:Clear() end function IconPickerMenu:AddIcon(texturePath, callback, tooltip) - local icon, key = self.iconPool:AcquireObject() + local icon, key = self.iconPool:AcquireObject() --[[@as IconPickerIcon]] icon:SetHidden(false) icon:SetTexture(texturePath) icon:SetColor(self.color:UnpackRGBA()) @@ -361,7 +365,9 @@ local function SetIconSize(control, size) end end +---@param iconpickerData LAM2_IconPickerData function LAMCreateControl.iconpicker(parent, iconpickerData, controlName) + ---@class LAM2_IconPicker: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, iconpickerData, controlName) local function ShowIconPicker() @@ -393,7 +399,7 @@ function LAMCreateControl.iconpicker(parent, iconpickerData, controlName) dropdown:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) dropdown:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) - control.icon = wm:CreateControl(nil, dropdown, CT_TEXTURE) + control.icon = wm:CreateControl(nil, dropdown, CT_TEXTURE) --[[@as IconPickerIcon]] local icon = control.icon icon:SetAnchor(LEFT, dropdown, LEFT, 3, 0) icon:SetDrawLevel(2) @@ -404,14 +410,14 @@ function LAMCreateControl.iconpicker(parent, iconpickerData, controlName) dropdownButton:SetAnchor(RIGHT, dropdown, RIGHT, -3, 0) control.dropdownButton = dropdownButton - control.bg = wm:CreateControl(nil, dropdown, CT_BACKDROP) + control.bg = wm:CreateControl(nil, dropdown, CT_BACKDROP) --[[@as BackdropControl]] local bg = control.bg bg:SetAnchor(TOPLEFT, dropdown, TOPLEFT, 0, -3) bg:SetAnchor(BOTTOMRIGHT, dropdown, BOTTOMRIGHT, 2, 5) bg:SetEdgeTexture("EsoUI/Art/Tooltips/UI-Border.dds", 128, 16) bg:SetCenterTexture("EsoUI/Art/Tooltips/UI-TooltipCenter.dds") bg:SetInsets(16, 16, -16, -16) - local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE) + local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE) --[[@as TextureControl]] mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds") mungeOverlay:SetDrawLevel(1) mungeOverlay:SetAddressMode(TEX_MODE_WRAP) diff --git a/LibAddonMenu-2.0/controls/panel.lua b/LibAddonMenu-2.0/controls/panel.lua index d5c8bec..457dd7d 100644 --- a/LibAddonMenu-2.0/controls/panel.lua +++ b/LibAddonMenu-2.0/controls/panel.lua @@ -1,19 +1,17 @@ ---[[panelData = { - type = "panel", - name = "Window Title", -- or string id or function returning a string - displayName = "My Longer Window Title", -- or string id or function returning a string (optional) (can be useful for long addon names or if you want to colorize it) - author = "Seerah", -- or string id or function returning a string (optional) - version = "2.0", -- or string id or function returning a string (optional) - website = "http://www.esoui.com/downloads/info7-LibAddonMenu.html", -- URL of website where the addon can be updated or function (optional) - feedback = "https://www.esoui.com/portal.php?uid=5815", -- URL of website where feedback/feature requests/bugs can be reported for the addon or function (optional) - translation = "https://www.esoui.com/portal.php?uid=5815", -- URL of website where translation texts of the addon can be helped with or function (optional) - donation = "http://www.esoui.com/downloads/info7-LibAddonMenu.html", -- URL of website where a donation for the addon author can be raised or function (optional) - keywords = "settings", -- additional keywords for search filter (it looks for matches in name..keywords..author) (optional) - slashCommand = "/myaddon", -- will register a keybind to open to this panel (don't forget to include the slash!) (optional) - registerForRefresh = true, -- boolean will refresh all options controls when a setting is changed and when the panel is shown (optional) - registerForDefaults = true, -- boolean will set all options controls back to default values (optional), - resetFunc = function(panel) d("defaults reset") end, -- custom function to run after the panel is reset to defaults (optional) -} ]] +---@class LAM2_PanelData: LAM2_ControlData +---@field type "panel" +---@field displayName nil|Stringy can be useful for long addon names or if you want to colorize it ex. "My Longer Window Title" +---@field author nil|Stringy ex. "Seerah" +---@field version nil|Stringy ex. "2.0" +---@field website nil|Stringy URL of website where the addon can be updated ex. "http://www.esoui.com/downloads/info7-LibAddonMenu.html" +---@field feedback nil|Stringy URL of website where feedback/feature requests/bugs can be reported for the addon ex. "https://www.esoui.com/portal.php?uid=5815" +---@field translation nil|Stringy URL of website where translation texts of the addon can be helped with ex. "https://www.esoui.com/portal.php?uid=5815" +---@field donation nil|Stringy URL of website where a donation for the addon author can be raised ex. "http://www.esoui.com/downloads/info7-LibAddonMenu.html" +---@field keywords nil|string additional keywords for search filter (it looks for matches in name..keywords..author) ex. "settings" +---@field slashCommand nil|string will register a keybind to open to this panel (don't forget to include the slash!) ex. "/myaddon" +---@field registerForRefresh nil|boolean if true, will refresh all options controls when a setting is changed and when the panel is shown +---@field registerForDefaults nil|boolean if true, will set all options controls back to default values +---@field resetFunc nil|fun(panel: LAM2_Panel) custom function to run after the panel is reset to defaults ex. function(panel) d("defaults reset") end local widgetVersion = 15 @@ -74,7 +72,7 @@ local LINK_COLOR_DONATE = ZO_ColorDef:New("FFD700") -- golden local LINK_MOUSE_OVER_COLOR_DONATE = ZO_ColorDef:New("FFF6CC") local function CreateButtonControl(control, label, clickAction, relativeTo) - local button = wm:CreateControl(nil, control, CT_BUTTON) + local button = wm:CreateControl(nil, control, CT_BUTTON) --[[@as ButtonControl]] button:SetClickSound("Click") button:SetFont(LAM.util.L["PANEL_INFO_FONT"]) button:SetNormalFontColor(LINK_COLOR:UnpackRGBA()) @@ -101,17 +99,19 @@ local function CreateButtonControl(control, label, clickAction, relativeTo) return button end +---@param panelData LAM2_PanelData function LAMCreateControl.panel(parent, panelData, controlName) + ---@class LAM2_Panel: LAM2_Control local control = wm:CreateControl(controlName, parent, CT_CONTROL) - control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") + control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") --[[@as LabelControl]] local label = control.label label:SetAnchor(TOPLEFT, control, TOPLEFT, 0, 4) label:SetText(LAM.util.GetStringFromValue(panelData.displayName or panelData.name)) local previousInfoControl if panelData.author or panelData.version then - control.info = wm:CreateControl(nil, control, CT_LABEL) + control.info = wm:CreateControl(nil, control, CT_LABEL) --[[@as LabelControl]] local info = control.info info:SetFont(LAM.util.L["PANEL_INFO_FONT"]) info:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, -2) diff --git a/LibAddonMenu-2.0/controls/slider.lua b/LibAddonMenu-2.0/controls/slider.lua index 06af1a7..5010076 100644 --- a/LibAddonMenu-2.0/controls/slider.lua +++ b/LibAddonMenu-2.0/controls/slider.lua @@ -1,27 +1,22 @@ ---[[sliderData = { - type = "slider", - name = "My Slider", -- or string id or function returning a string - getFunc = function() return db.var end, - setFunc = function(value) db.var = value doStuff() end, - min = 0, - max = 20, - step = 1, -- (optional) - clampInput = true, -- boolean, if set to false the input won't clamp to min and max and allow any number instead (optional) - clampFunction = function(value, min, max) return math.max(math.min(value, max), min) end, -- function that is called to clamp the value (optional) - decimals = 0, -- when specified the input value is rounded to the specified number of decimals (optional) - autoSelect = false, -- boolean, automatically select everything in the text input field when it gains focus (optional) - inputLocation = "below", -- or "right", determines where the input field is shown. This should not be used within the addon menu and is for custom sliders (optional) - readOnly = true, -- boolean, you can use the slider, but you can't insert a value manually (optional) - tooltip = "Slider's tooltip text.", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) - requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) - default = defaults.var, -- default value or function that returns the default value (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonSlider", -- unique global reference to control (optional) - resetFunc = function(sliderControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] +---@class LAM2_SliderData: LAM2_LabelAndContainerControlData +---@field type "slider" +---@field getFunc fun(): number ex. function() return db.var end +---@field setFunc fun(value: number) ex. function(value) db.var = value doStuff() end +---@field min number ex. 0 +---@field max number ex. 20 +---@field step nil|number default 1 +---@field clampInput nil|boolean if set to false the input won't clamp to min and max and allow any number instead +---@field clampFunction nil|fun(value: number, min: number, max: number) function that is called to clamp the value ex. function(value, min, max) return math.max(math.min(value, max), min) end +---@field decimals nil|integer when specified the input value is rounded to the specified number of decimals ex. 0 +---@field autoSelect nil|boolean automatically select everything in the text input field when it gains focus +---@field inputLocation nil|"right" if not "right", the input field will be below. This should not be used within the addon menu and is for custom sliders +---@field readOnly nil|boolean if true, you can use the slider, but you can't insert a value manually +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting +---@field warning nil|Stringy ex. "May cause permanent awesomeness" +---@field requiresReload nil|boolean if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed. +---@field default nil|number|fun(): number default value or function that returns the default value +---@field resetFunc nil|fun(sliderControl: LAM2_Slider) custom function to run after the control is reset to defaults ex. function(sliderControl) d("defaults reset") end + local widgetVersion = 16 local LAM = LibAddonMenu2 @@ -86,12 +81,15 @@ local function UpdateValue(control, forceDefault, value) end local index = 1 +---@param sliderData LAM2_SliderData function LAMCreateControl.slider(parent, sliderData, controlName) + ---@class LAM2_Slider: LAM2_LabelAndContainerControl local control = LAM.util.CreateLabelAndContainerControl(parent, sliderData, controlName) local isInputOnRight = sliderData.inputLocation == "right" --skipping creating the backdrop... Is this the actual slider texture? control.slider = wm:CreateControl(nil, control.container, CT_SLIDER) + ---@class SliderControl2: SliderControl local slider = control.slider slider:SetAnchor(TOPLEFT) slider:SetHeight(14) @@ -110,24 +108,24 @@ function LAMCreateControl.slider(parent, sliderData, controlName) slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) slider:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) - slider.bg = wm:CreateControl(nil, slider, CT_BACKDROP) + slider.bg = wm:CreateControl(nil, slider, CT_BACKDROP) --[[@as BackdropControl]] local bg = slider.bg bg:SetCenterColor(0, 0, 0) bg:SetAnchor(TOPLEFT, slider, TOPLEFT, 0, 4) bg:SetAnchor(BOTTOMRIGHT, slider, BOTTOMRIGHT, 0, -4) bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-SliderBackdrop.dds", 32, 4) - control.minText = wm:CreateControl(nil, slider, CT_LABEL) + control.minText = wm:CreateControl(nil, slider, CT_LABEL) --[[@as LabelControl]] local minText = control.minText minText:SetFont("ZoFontGameSmall") minText:SetAnchor(TOPLEFT, slider, BOTTOMLEFT) - minText:SetText(sliderData.min) + minText:SetText(tostring(sliderData.min)) - control.maxText = wm:CreateControl(nil, slider, CT_LABEL) + control.maxText = wm:CreateControl(nil, slider, CT_LABEL) --[[@as LabelControl]] local maxText = control.maxText maxText:SetFont("ZoFontGameSmall") maxText:SetAnchor(TOPRIGHT, slider, BOTTOMRIGHT) - maxText:SetText(sliderData.max) + maxText:SetText(tostring(sliderData.max)) control.slidervalueBG = wm:CreateControlFromVirtual(nil, slider, "ZO_EditBackdrop") if(isInputOnRight) then @@ -137,7 +135,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) control.slidervalueBG:SetDimensions(50, 16) control.slidervalueBG:SetAnchor(TOP, slider, BOTTOM, 0, 0) end - control.slidervalue = wm:CreateControlFromVirtual(nil, control.slidervalueBG, "ZO_DefaultEditForBackdrop") + control.slidervalue = wm:CreateControlFromVirtual(nil, control.slidervalueBG, "ZO_DefaultEditForBackdrop") --[[@as EditControl]] local slidervalue = control.slidervalue slidervalue:ClearAnchors() slidervalue:SetAnchor(TOPLEFT, control.slidervalueBG, TOPLEFT, 3, 1) diff --git a/LibAddonMenu-2.0/controls/submenu.lua b/LibAddonMenu-2.0/controls/submenu.lua index a501379..10d5fda 100644 --- a/LibAddonMenu-2.0/controls/submenu.lua +++ b/LibAddonMenu-2.0/controls/submenu.lua @@ -1,18 +1,18 @@ ---[[submenuData = { - type = "submenu", - name = "Submenu Title", -- or string id or function returning a string - icon = "path/to/my/icon.dds", -- or function returning a string (optional) - iconTextureCoords = {left, right, top, bottom}, -- or function returning a table (optional) - tooltip = "My submenu tooltip", -- or string id or function returning a string (optional) - controls = {sliderData, buttonData} -- used by LAM (optional) - disabled = function() return db.someBooleanSetting end, -- or boolean (optional) - disabledLabel = function() return db.someBooleanSetting end, -- or boolean (optional) - helpUrl = "https://www.esoui.com/portal.php?id=218&a=faq", -- a string URL or a function that returns the string URL (optional) - reference = "MyAddonSubmenu", -- unique global reference to control (optional) - resetFunc = function(submenuControl) d("defaults reset") end, -- custom function to run after the control is reset to defaults (optional) -} ]] - -local widgetVersion = 15 +---@alias IconTextureCoords [number, number, number, number] {left, right, top, bottom} + +---@class LAM2_SubmenuData: LAM2_ControlData, LAM2_ControlWithHelpUrlData +---@field type "submenu" +---@field icon nil|Stringy ex. "path/to/my/icon.dds" +---@field iconTextureCoords nil|IconTextureCoords|fun(): IconTextureCoords +---@field tooltip nil|Stringy ex. "My submenu tooltip" +---@field controls nil|LAM2_ControlData[] data for sub-controls to create +---@field disabled nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field disabledLabel nil|boolean|fun(): boolean ex. function() return db.someBooleanSetting end +---@field reference nil|string a unique global reference to the created control ex. "MyAddonSubmenu" +---@field resetFunc nil|fun(submenuControl: LAM2_Submenu) custom function to run after the control is reset to defaults ex. function(submenuControl) d("defaults reset") end + + +local widgetVersion = 16 local LAM = LibAddonMenu2 if not LAM:RegisterWidget("submenu", widgetVersion) then return end @@ -23,6 +23,7 @@ local ICON_SIZE = 32 local GetDefaultValue = LAM.util.GetDefaultValue local GetColorForState = LAM.util.GetColorForState +---@param control LAM2_Submenu local function UpdateDisabled(control) local disable = GetDefaultValue(control.data.disabled) if disable ~= control.disabled then @@ -47,6 +48,7 @@ local function UpdateDisabled(control) end end +---@param control LAM2_Submenu local function UpdateValue(control) control.label:SetText(LAM.util.GetStringFromValue(control.data.name)) @@ -75,12 +77,17 @@ local function AnimateSubmenu(clicked) end end +---@param submenuData LAM2_SubmenuData function LAMCreateControl.submenu(parent, submenuData, controlName) local width = parent:GetWidth() - 45 + ---@class LAM2_Submenu: LAM2_Control + ---@field disabled boolean + ---@field disabledLabel boolean local control = wm:CreateControl(controlName or submenuData.reference, parent.scroll or parent, CT_CONTROL) control.panel = parent control.data = submenuData + ---@class Label: LabelControl, ControlWithData control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") local label = control.label label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) @@ -89,7 +96,7 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) LAM.util.SetUpTooltip(label, submenuData) if submenuData.icon then - control.icon = wm:CreateControl(nil, control, CT_TEXTURE) + control.icon = wm:CreateControl(nil, control, CT_TEXTURE) --[[@as TextureControl]] local icon = control.icon icon:SetTexture(GetDefaultValue(submenuData.icon)) if(submenuData.iconTextureCoords) then @@ -109,13 +116,13 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) label:SetDimensions(width, 30) end - control.scroll = wm:CreateControl(nil, control, CT_SCROLL) + control.scroll = wm:CreateControl(nil, control, CT_SCROLL) --[[@as ScrollControl]] local scroll = control.scroll scroll:SetParent(control) scroll:SetAnchor(TOPLEFT, control.icon or label, BOTTOMLEFT, 0, 10) scroll:SetDimensionConstraints(width + 5, 0, width + 5, 0) - control.bg = wm:CreateControl(nil, control.icon or label, CT_BACKDROP) + control.bg = wm:CreateControl(nil, control.icon or label, CT_BACKDROP) --[[@as BackdropControl]] local bg = control.bg bg:SetAnchor(TOPLEFT, control.icon or label, TOPLEFT, -5, -5) bg:SetAnchor(BOTTOMRIGHT, scroll, BOTTOMRIGHT, -7, 0) @@ -124,7 +131,7 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) bg:SetInsets(16, 16, -16, -16) bg:SetDrawLayer(DL_BACKGROUND) - control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE) + control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE) --[[@as TextureControl]] local arrow = control.arrow arrow:SetDimensions(28, 28) arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") --list_sortup for the other way @@ -138,7 +145,7 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) --figure out the cool animation later... control.animation = am:CreateTimeline() local animation = control.animation - animation:SetPlaybackType(ANIMATION_SIZE, 0) --2nd arg = loop count + animation:SetPlaybackType(ANIMATION_PLAYBACK_ONE_SHOT, 0) --2nd arg = loop count control:SetResizeToFitDescendents(true) control.open = false @@ -159,7 +166,7 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) end) --small strip at the bottom of the submenu that you can click to close it - control.btmToggle = wm:CreateControl(nil, control, CT_TEXTURE) + control.btmToggle = wm:CreateControl(nil, control, CT_TEXTURE) --[[@as TextureControl]] local btmToggle = control.btmToggle btmToggle:SetMouseEnabled(true) btmToggle:SetAnchor(BOTTOMLEFT, control.scroll, BOTTOMLEFT) diff --git a/LibAddonMenu-2.0/controls/texture.lua b/LibAddonMenu-2.0/controls/texture.lua index 641e8e0..0977e7e 100644 --- a/LibAddonMenu-2.0/controls/texture.lua +++ b/LibAddonMenu-2.0/controls/texture.lua @@ -1,12 +1,9 @@ ---[[textureData = { - type = "texture", - image = "file/path.dds", - imageWidth = 64, -- max of 250 for half width, 510 for full - imageHeight = 32, -- max of 100 - tooltip = "Image's tooltip text.", -- or string id or function returning a string (optional) - width = "full", -- or "half" (optional) - reference = "MyAddonTexture" -- unique global reference to control (optional) -} ]] +---@class LAM2_TextureData: LAM2_BaseControlData +---@field type "texture" +---@field image string ex. "file/path.dds" +---@field imageWidth integer max of 250 for width="half", 510 for "full" ex. 64 +---@field imageHeight integer max of 100 ex. 32 +---@field tooltip Stringy ex. "Texture's tooltip text." -- TODO: add texture coords support? @@ -17,7 +14,9 @@ if not LAM:RegisterWidget("texture", widgetVersion) then return end local wm = WINDOW_MANAGER local MIN_HEIGHT = 26 +---@param textureData LAM2_TextureData function LAMCreateControl.texture(parent, textureData, controlName) + ---@class LAM2_Texture: LAM2_BaseControl local control = LAM.util.CreateBaseControl(parent, textureData, controlName) local width = control:GetWidth() control:SetResizeToFitDescendents(true) @@ -30,7 +29,7 @@ function LAMCreateControl.texture(parent, textureData, controlName) control:SetResizeToFitConstrains(ANCHOR_CONSTRAINS_Y) end - control.texture = wm:CreateControl(nil, control, CT_TEXTURE) + control.texture = wm:CreateControl(nil, control, CT_TEXTURE) --[[@as TextureControl]] local texture = control.texture texture:SetAnchor(CENTER) texture:SetDimensions(textureData.imageWidth, textureData.imageHeight) diff --git a/LibAddonMenu-2.0/exampleoptions.lua b/LibAddonMenu-2.0/exampleoptions.lua index 3b7794a..5964f88 100644 --- a/LibAddonMenu-2.0/exampleoptions.lua +++ b/LibAddonMenu-2.0/exampleoptions.lua @@ -1,3 +1,4 @@ +---@type LAM2_PanelData local panelData = { type = "panel", name = "Window Title", @@ -9,19 +10,23 @@ local panelData = { registerForDefaults = true, --boolean (optional) (will set all options controls back to default values) } +---@type LAM2_ControlData[] local optionsTable = { + ---@type LAM2_HeaderData [1] = { type = "header", name = "My Header", - width = "full", --or "half" (optional) + width = "full", --or "half" (default "full") }, + ---@type LAM2_DescriptionData [2] = { type = "description", --title = "My Title", --(optional) title = nil, --(optional) text = "My description text to display. blah blah blah blah blah blah blah - even more sample text!!", - width = "full", --or "half" (optional) + width = "full", --or "half" (default "full") }, + ---@type LAM2_SingleSelectDropdownData [3] = { type = "dropdown", name = "My Dropdown", @@ -32,6 +37,7 @@ local optionsTable = { width = "half", --or "full" (optional) warning = "Will need to reload the UI.", --(optional) }, + ---@type LAM2_DropdownData [4] = { type = "dropdown", name = "My Dropdown", @@ -42,6 +48,7 @@ local optionsTable = { width = "half", --or "full" (optional) warning = "Will need to reload the UI.", --(optional) }, + ---@type LAM2_SliderData [5] = { type = "slider", name = "My Slider", @@ -51,40 +58,45 @@ local optionsTable = { step = 1, --(optional) getFunc = function() return 3 end, setFunc = function(value) d(value) end, - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") default = 5, --(optional) }, + ---@type LAM2_ButtonData [6] = { type = "button", name = "My Button", tooltip = "Button's tooltip text.", func = function() d("button pressed!") end, - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") warning = "Will need to reload the UI.", --(optional) }, + ---@type LAM2_SubmenuData [7] = { type = "submenu", name = "Submenu Title", tooltip = "My submenu tooltip", --(optional) controls = { + ---@type LAM2_CheckboxData [1] = { type = "checkbox", name = "My Checkbox", tooltip = "Checkbox's tooltip text.", getFunc = function() return true end, setFunc = function(value) d(value) end, - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") warning = "Will need to reload the UI.", --(optional) }, + ---@type LAM2_ColorPickerData [2] = { type = "colorpicker", name = "My Color Picker", tooltip = "Color Picker's tooltip text.", getFunc = function() return 1, 0, 0, 1 end, --(alpha is optional) setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional) - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") warning = "warning text", }, + ---@type LAM2_EditboxData [3] = { type = "editbox", name = "My Editbox", @@ -92,7 +104,7 @@ local optionsTable = { getFunc = function() return "this is some text" end, setFunc = function(text) print(text) end, isMultiline = false, --boolean - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") warning = "Will need to reload the UI.", --(optional) default = "", --(optional) }, @@ -102,15 +114,16 @@ local optionsTable = { type = "custom", reference = "MyAddonCustomControl", --unique name for your control to use as reference refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") }, + ---@type LAM2_TextureData [9] = { type = "texture", image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds", imageWidth = 64, --max of 250 for half width, 510 for full imageHeight = 64, --max of 100 tooltip = "Image's tooltip text.", --(optional) - width = "half", --or "full" (optional) + width = "half", --or "full" (default "full") }, }