diff --git a/Librarian.txt b/Librarian.txt index c390f16..3c1d9ee 100644 --- a/Librarian.txt +++ b/Librarian.txt @@ -1,6 +1,6 @@ ## Title: Librarian ## Author: Flamage -## APIVersion: 100010 +## APIVersion: 100011 ## SavedVariables: Librarian_SavedVariables ## OptionalDependsOn: LibAddonMenu-2.0 diff --git a/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua b/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua index 1ab94cf..03fb4c4 100644 --- a/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua +++ b/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua @@ -1,16 +1,34 @@ --- LibAddonMenu-2.0 & its files © Ryan Lakanen (Seerah) -- --- All Rights Reserved -- --- Permission is granted to use Seerah's LibAddonMenu-2.0 -- --- in your project. Any modifications to LibAddonMenu-2.0 -- --- may not be redistributed. -- --------------------------------------------------------------- +-- LibAddonMenu-2.0 & its files © Ryan Lakanen (Seerah) -- +-- Distributed under The Artistic License 2.0 (see LICENSE) -- +------------------------------------------------------------------ --Register LAM with LibStub -local MAJOR, MINOR = "LibAddonMenu-2.0", 16 +local MAJOR, MINOR = "LibAddonMenu-2.0", 17 local lam, oldminor = LibStub:NewLibrary(MAJOR, MINOR) -if not lam then return end --the same or newer version of this lib is already loaded into memory +if not lam then return end --the same or newer version of this lib is already loaded into memory +local messages = {} +local MESSAGE_PREFIX = "[LAM2] " +local function PrintLater(msg) + if(CHAT_SYSTEM.primaryContainer) then + d(MESSAGE_PREFIX .. msg) + else + messages[#messages + 1] = msg + end +end + +local function FlushMessages() + for i = 1, #messages do + d(MESSAGE_PREFIX .. messages[i]) + end + messages = {} +end + +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 +end --UPVALUES-- local wm = WINDOW_MANAGER @@ -48,23 +66,31 @@ end --METHOD: OPEN TO ADDON PANEL-- --opens to a specific addon's option panel --Usage: --- panel = userdata; the panel returned by the :RegisterOptionsPanel method ---local settings = {en = "Settings", de = "Einstellungen", fr = "Réglages"} ---local locSettings = settings[GetCVar("Language.2")] +-- panel = userdata; the panel returned by the :RegisterOptionsPanel method local locSettings = GetString(SI_GAME_MENU_SETTINGS) function lam:OpenToPanel(panel) SCENE_MANAGER:Show("gameMenuInGame") zo_callLater(function() - ZO_GameMenu_InGame.gameMenu.headerControls[locSettings]:SetOpen(true) - SCENE_MANAGER:AddFragment(OPTIONS_WINDOW_FRAGMENT) - --ZO_OptionsWindow_ChangePanels(lam.panelID) - KEYBOARD_OPTIONS:ChangePanels(lam.panelID) - --if not lam.panelSubCategoryControl then - -- lam.panelSubCategoryControl = _G["ZO_GameMenu_InGameNavigationContainerScrollChildZO_GameMenu_SubCategory"..(lam.panelID + 1)] - --end - --ZO_TreeEntry_OnMouseUp(lam.panelSubCategoryControl, true) - panel:SetHidden(false) - end, 200) + local settingsMenu = ZO_GameMenu_InGame.gameMenu.headerControls[locSettings] + settingsMenu:SetOpen(true) + SCENE_MANAGER:AddFragment(OPTIONS_WINDOW_FRAGMENT) + KEYBOARD_OPTIONS:ChangePanels(lam.panelID) + for i, child in pairs(settingsMenu.children) do + if type(child) == "table" and child.data.name == KEYBOARD_OPTIONS.panelNames[lam.panelID] then + ZO_TreeEntry_OnMouseUp(child.control, true) + break + end + end + local scroll = LAMAddonPanelsMenuScrollChild + for i = 1, scroll:GetNumChildren() do + local button = scroll:GetChild(i) + if button.panel == panel then + zo_callHandler(button, "OnClicked") + ZO_Scroll_ScrollControlToTop(LAMAddonPanelsMenu, button) + break + end + end + end, 200) end @@ -74,62 +100,75 @@ end local function CreateOptionsControls(panel) local addonID = panel:GetName() local optionsTable = addonToOptionsMap[addonID] - + if optionsTable then - local lastAddedControl, lacAtHalfRow - for _, widgetData in ipairs(optionsTable) do - local widgetType = widgetData.type + local isHalf, widget + local lastAddedControl, lacAtHalfRow, oIndex, widgetData, widgetType + local submenu, subWidgetData, sIndex, subWidgetType, subWidget + local anchorOffset = 0 + local anchorOffsetSub + local lastAddedControlSub, lacAtHalfRowSub + for oIndex=1,#optionsTable do + widgetData = optionsTable[oIndex] + widgetType = widgetData.type if widgetType == "submenu" then - local submenu = LAMCreateControl[widgetType](panel, widgetData) + submenu = LAMCreateControl[widgetType](panel, widgetData) if lastAddedControl then - submenu:SetAnchor(TOPLEFT, lastAddedControl, BOTTOMLEFT, 0, 15) + submenu:SetAnchor(TOPLEFT, lastAddedControl, BOTTOMLEFT, 0, 15 + anchorOffset) else submenu:SetAnchor(TOPLEFT) end lastAddedControl = submenu lacAtHalfRow = false - - local lastAddedControlSub, lacAtHalfRowSub - for _, subWidgetData in ipairs(widgetData.controls) do - local subWidgetType = subWidgetData.type - local subWidget = LAMCreateControl[subWidgetType](submenu, subWidgetData) - local isHalf = subWidgetData.width == "half" + + anchorOffsetSub = 0 + lacAtHalfRowSub = nil + lastAddedControlSub = nil + for sIndex=1,#widgetData.controls do + subWidgetData = widgetData.controls[sIndex] + subWidgetType = subWidgetData.type + subWidget = LAMCreateControl[subWidgetType](submenu, subWidgetData) + isHalf = subWidgetData.width == "half" if lastAddedControlSub then if lacAtHalfRowSub and isHalf then subWidget:SetAnchor(TOPLEFT, lastAddedControlSub, TOPRIGHT, 5, 0) lacAtHalfRowSub = false + anchorOffsetSub = zo_max(0, subWidget:GetHeight() - lastAddedControlSub:GetHeight()) else - subWidget:SetAnchor(TOPLEFT, lastAddedControlSub, BOTTOMLEFT, 0, 15) - lacAtHalfRowSub = isHalf and true or false + subWidget:SetAnchor(TOPLEFT, lastAddedControlSub, BOTTOMLEFT, 0, 15 + anchorOffsetSub) + lacAtHalfRowSub = isHalf + anchorOffsetSub = 0 lastAddedControlSub = subWidget end else subWidget:SetAnchor(TOPLEFT) - lacAtHalfRowSub = isHalf and true or false + lacAtHalfRowSub = isHalf lastAddedControlSub = subWidget end end else - local widget = LAMCreateControl[widgetType](panel, widgetData) - local isHalf = widgetData.width == "half" + widget = LAMCreateControl[widgetType](panel, widgetData) + isHalf = widgetData.width == "half" if lastAddedControl then if lacAtHalfRow and isHalf then widget:SetAnchor(TOPLEFT, lastAddedControl, TOPRIGHT, 10, 0) + anchorOffset = zo_max(0, widget:GetHeight() - lastAddedControl:GetHeight()) lacAtHalfRow = false else - widget:SetAnchor(TOPLEFT, lastAddedControl, BOTTOMLEFT, 0, 15) - lacAtHalfRow = isHalf and true or false + widget:SetAnchor(TOPLEFT, lastAddedControl, BOTTOMLEFT, 0, 15 + anchorOffset) + lacAtHalfRow = isHalf + anchorOffset = 0 lastAddedControl = widget end else widget:SetAnchor(TOPLEFT) - lacAtHalfRow = isHalf and true or false + lacAtHalfRow = isHalf lastAddedControl = widget end end - end + end end - + optionsCreated[addonID] = true cm:FireCallbacks("LAM-PanelControlsCreated", panel) end @@ -143,14 +182,16 @@ local function ToggleAddonPanels(panel) --called in OnShow of newly shown panel currentlySelected:SetHidden(true) end LAMAddonPanelsMenu.currentlySelected = panel - + if not optionsCreated[panel:GetName()] then --if this is the first time opening this panel, create these options CreateOptionsControls(panel) end - + cm:FireCallbacks("LAM-RefreshPanel", panel) end +local Initialize +local hasInitialized = false --METHOD: REGISTER ADDON PANEL --registers your addon with LibAddonMenu and creates a panel @@ -158,6 +199,7 @@ end -- addonID = "string"; unique ID which will be the global name of your panel -- panelData = table; data object for your panel - see controls\panel.lua function lam:RegisterAddonPanel(addonID, panelData) + if(not hasInitialized) then Initialize(addonID) end local panel = lamcc.panel(nil, panelData, addonID) --addonID==global name of panel panel:SetHidden(true) panel:SetAnchor(TOPLEFT, LAMAddonPanelsMenu, TOPRIGHT, 10, 0) @@ -235,12 +277,11 @@ local function CreateAddonSettingsPanel() es = "Configura Addons", } - ZO_OptionsWindow_AddUserPanel(controlPanelID, controlPanelNames[GetCVar("Language.2")] or controlPanelName["en"]) + ZO_OptionsWindow_AddUserPanel(controlPanelID, controlPanelNames[GetCVar("Language.2")] or controlPanelNames["en"], PANEL_TYPE_SETTINGS) lam.panelID = _G[controlPanelID] - --ZO_PreHook("ZO_OptionsWindow_ChangePanels", HandlePanelSwitching) - ZO_PreHook(ZO_SharedOptions, "ChangePanels", HandlePanelSwitching) + ZO_PreHook(ZO_KeyboardOptions, "ChangePanels", HandlePanelSwitching) LAMSettingsPanelCreated = true end @@ -315,8 +356,29 @@ local function CreateAddonList() return list end - --INITIALIZING -CreateAddonSettingsPanel() -CreateAddonList() +local safeToInitialize = false + +local eventHandle = table.concat({MAJOR, MINOR}, "r") +local function OnLoad(_, addonName) + -- wait for the first loaded event + EVENT_MANAGER:UnregisterForEvent(eventHandle, EVENT_ADD_ON_LOADED) + safeToInitialize = true +end +EVENT_MANAGER:RegisterForEvent(eventHandle, EVENT_ADD_ON_LOADED, OnLoad) +local function OnActivated(_, addonName) + EVENT_MANAGER:UnregisterForEvent(eventHandle, EVENT_PLAYER_ACTIVATED) + FlushMessages() +end +EVENT_MANAGER:RegisterForEvent(eventHandle, EVENT_PLAYER_ACTIVATED, OnActivated) + +function Initialize(addonID) + if(not safeToInitialize) then + local msg = string.format("The panel with id '%s' was registered before addon loading has completed. This might break the AddOn Settings menu.", addonID) + PrintLater(msg) + end + CreateAddonSettingsPanel() + CreateAddonList() + hasInitialized = true +end diff --git a/Libs/LibAddonMenu-2.0/controls/button.lua b/Libs/LibAddonMenu-2.0/controls/button.lua index 187e901..8a6ecda 100644 --- a/Libs/LibAddonMenu-2.0/controls/button.lua +++ b/Libs/LibAddonMenu-2.0/controls/button.lua @@ -11,7 +11,7 @@ } ]] -local widgetVersion = 5 +local widgetVersion = 6 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("button", widgetVersion) then return end @@ -33,13 +33,12 @@ end --controlName is optional function LAMCreateControl.button(parent, buttonData, controlName) - local control = wm:CreateTopLevelWindow(controlName or buttonData.reference) - control:SetParent(parent.scroll or parent) - + local control = wm:CreateControl(controlName or buttonData.reference, parent.scroll or parent, CT_CONTROL) + local isHalfWidth = buttonData.width == "half" control:SetDimensions(isHalfWidth and 250 or 510, isHalfWidth and 55 or 28) control:SetMouseEnabled(true) - + if buttonData.icon then control.button = wm:CreateControl(nil, control, CT_BUTTON) control.button:SetDimensions(26, 26) @@ -64,26 +63,26 @@ function LAMCreateControl.button(parent, buttonData, controlName) cm:FireCallbacks("LAM-RefreshPanel", control) end end) - + if buttonData.warning then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, button, LEFT, -5, 0) --control.warning.tooltipText = buttonData.warning control.warning.data = {tooltipText = buttonData.warning} end - + control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = buttonData - + if buttonData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() - + --this is here because buttons don't have an UpdateValue method if control.panel.data.registerForRefresh then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end end - + return control end \ No newline at end of file diff --git a/Libs/LibAddonMenu-2.0/controls/checkbox.lua b/Libs/LibAddonMenu-2.0/controls/checkbox.lua index a777c7d..ef8bf09 100644 --- a/Libs/LibAddonMenu-2.0/controls/checkbox.lua +++ b/Libs/LibAddonMenu-2.0/controls/checkbox.lua @@ -12,7 +12,7 @@ } ]] -local widgetVersion = 7 +local widgetVersion = 8 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("checkbox", widgetVersion) then return end @@ -36,16 +36,16 @@ local function UpdateDisabled(control) else disable = control.data.disabled end - + control.label:SetColor((disable and ZO_DEFAULT_DISABLED_COLOR or control.value and ZO_DEFAULT_ENABLED_COLOR or ZO_DEFAULT_DISABLED_COLOR):UnpackRGBA()) control.checkbox:SetColor((disable and ZO_DEFAULT_DISABLED_COLOR or ZO_NORMAL_TEXT):UnpackRGBA()) --control:SetMouseEnabled(not disable) --control:SetMouseEnabled(true) - + control.isDisabled = disable end -local function ToggleCheckbox(control) +local function ToggleCheckbox(control) if control.value then control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) control.checkbox:SetText(control.checkedText) @@ -69,13 +69,13 @@ local function UpdateValue(control, forceDefault, value) value = control.data.getFunc() end control.value = value - + ToggleCheckbox(control) end local function OnMouseEnter(control) ZO_Options_OnMouseEnter(control) - + if control.isDisabled then return end local label = control.label @@ -88,8 +88,8 @@ local function OnMouseEnter(control) end local function OnMouseExit(control) - ZO_Options_OnMouseExit(control) - + ZO_Options_OnMouseExit(control) + if control.isDisabled then return end local label = control.label @@ -104,8 +104,7 @@ end --controlName is optional function LAMCreateControl.checkbox(parent, checkboxData, controlName) - local control = wm:CreateTopLevelWindow(controlName or checkboxData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or checkboxData.reference, parent.scroll or parent, CT_CONTROL) control:SetMouseEnabled(true) --control.tooltipText = checkboxData.tooltip control:SetHandler("OnMouseEnter", OnMouseEnter) @@ -116,7 +115,7 @@ function LAMCreateControl.checkbox(parent, checkboxData, controlName) control.value = not control.value control:UpdateValue(false, control.value) end) - + control.label = wm:CreateControl(nil, control, CT_LABEL) local label = control.label label:SetFont("ZoFontWinH4") @@ -143,27 +142,27 @@ function LAMCreateControl.checkbox(parent, checkboxData, controlName) checkbox:SetDimensions(200, 26) checkbox:SetAnchor(RIGHT) label:SetAnchor(LEFT) - label:SetAnchor(RIGHT, checkbox, LEFT, -5, 0) + label:SetAnchor(RIGHT, checkbox, LEFT, -5, 0) end - + if checkboxData.warning then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, checkbox, LEFT, -5, 0) --control.warning.tooltipText = checkboxData.warning control.warning.data = {tooltipText = checkboxData.warning} end - + control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = checkboxData control.data.tooltipText = checkboxData.tooltip - + if checkboxData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() end control.UpdateValue = UpdateValue control:UpdateValue() - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end diff --git a/Libs/LibAddonMenu-2.0/controls/colorpicker.lua b/Libs/LibAddonMenu-2.0/controls/colorpicker.lua index abd9ba4..c5724b0 100644 --- a/Libs/LibAddonMenu-2.0/controls/colorpicker.lua +++ b/Libs/LibAddonMenu-2.0/controls/colorpicker.lua @@ -12,7 +12,7 @@ } ]] -local widgetVersion = 5 +local widgetVersion = 6 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("colorpicker", widgetVersion) then return end @@ -28,13 +28,13 @@ local function UpdateDisabled(control) else disable = control.data.disabled end - + if disable then control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) else control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) end - + control.isDisabled = disable end @@ -58,13 +58,11 @@ end function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) - local control = wm:CreateTopLevelWindow(controlName or colorpickerData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or colorpickerData.reference, parent.scroll or parent, CT_CONTROL) control:SetMouseEnabled(true) - --control.tooltipText = colorpickerData.tooltip control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) - + control.label = wm:CreateControl(nil, control, CT_LABEL) local label = control.label label:SetDimensions(300, 26) @@ -72,10 +70,10 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) label:SetFont("ZoFontWinH4") label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) label:SetText(colorpickerData.name) - + control.color = wm:CreateControl(nil, control, CT_CONTROL) local color = control.color - + local isHalfWidth = colorpickerData.width == "half" if isHalfWidth then control:SetDimensions(250, 55) @@ -88,12 +86,12 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) color:SetDimensions(200, 24) color:SetAnchor(TOPRIGHT) end - + control.thumb = wm:CreateControl(nil, color, CT_TEXTURE) local thumb = control.thumb thumb:SetDimensions(36, 18) thumb:SetAnchor(LEFT, color, LEFT, 4, 0) - + color.border = wm:CreateControl(nil, color, CT_TEXTURE) local border = color.border border:SetTexture("EsoUI\\Art\\ChatWindow\\chatOptions_bgColSwatch_frame.dds") @@ -104,10 +102,10 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) local function ColorPickerCallback(r, g, b, a) control:UpdateValue(false, r, g, b, a) end - + control:SetHandler("OnMouseUp", function(self, btn, upInside) if self.isDisabled then return end - + if upInside then local r, g, b, a = colorpickerData.getFunc() COLOR_PICKER:Show(ColorPickerCallback, r, g, b, a, colorpickerData.name) @@ -120,11 +118,11 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) --control.warning.tooltipText = colorpickerData.warning control.warning.data = {tooltipText = colorpickerData.warning} end - + control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = colorpickerData control.data.tooltipText = colorpickerData.tooltip - + if colorpickerData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() diff --git a/Libs/LibAddonMenu-2.0/controls/custom.lua b/Libs/LibAddonMenu-2.0/controls/custom.lua index 54c9775..6a31c34 100644 --- a/Libs/LibAddonMenu-2.0/controls/custom.lua +++ b/Libs/LibAddonMenu-2.0/controls/custom.lua @@ -5,7 +5,7 @@ width = "full", --or "half" (optional) } ]] -local widgetVersion = 4 +local widgetVersion = 5 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("custom", widgetVersion) then return end @@ -19,10 +19,9 @@ local function UpdateValue(control) end function LAMCreateControl.custom(parent, customData, controlName) - local control = wm:CreateTopLevelWindow(controlName or customData.reference) + local control = wm:CreateControl(controlName or customData.reference, parent.scroll or parent, CT_CONTROL) control:SetResizeToFitDescendents(true) - control:SetParent(parent.scroll or parent) - + local isHalfWidth = customData.width == "half" if isHalfWidth then --note these restrictions control:SetDimensionConstraints(250, 55, 250, 100) @@ -34,12 +33,12 @@ function LAMCreateControl.custom(parent, customData, controlName) control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = customData - + control.UpdateValue = UpdateValue - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end - + return control end \ No newline at end of file diff --git a/Libs/LibAddonMenu-2.0/controls/description.lua b/Libs/LibAddonMenu-2.0/controls/description.lua index 5d7219d..b886b83 100644 --- a/Libs/LibAddonMenu-2.0/controls/description.lua +++ b/Libs/LibAddonMenu-2.0/controls/description.lua @@ -7,7 +7,7 @@ } ]] -local widgetVersion = 4 +local widgetVersion = 5 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("description", widgetVersion) then return end @@ -22,9 +22,8 @@ local function UpdateValue(control) end function LAMCreateControl.description(parent, descriptionData, controlName) - local control = wm:CreateTopLevelWindow(controlName or descriptionData.reference) + local control = wm:CreateControl(controlName or descriptionData.reference, parent.scroll or parent, CT_CONTROL) control:SetResizeToFitDescendents(true) - control:SetParent(parent.scroll or parent) local isHalfWidth = descriptionData.width == "half" if isHalfWidth then control:SetDimensionConstraints(250, 55, 250, 100) @@ -33,7 +32,7 @@ function LAMCreateControl.description(parent, descriptionData, controlName) control:SetDimensionConstraints(510, 40, 510, 100) control:SetDimensions(510, 30) end - + control.desc = wm:CreateControl(nil, control, CT_LABEL) local desc = control.desc desc:SetVerticalAlignment(TEXT_ALIGN_TOP) @@ -55,13 +54,13 @@ function LAMCreateControl.description(parent, descriptionData, controlName) control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = descriptionData - + control.UpdateValue = UpdateValue - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end - + return control end \ No newline at end of file diff --git a/Libs/LibAddonMenu-2.0/controls/dropdown.lua b/Libs/LibAddonMenu-2.0/controls/dropdown.lua index 94cd820..795404c 100644 --- a/Libs/LibAddonMenu-2.0/controls/dropdown.lua +++ b/Libs/LibAddonMenu-2.0/controls/dropdown.lua @@ -14,7 +14,7 @@ } ]] -local widgetVersion = 7 +local widgetVersion = 8 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("dropdown", widgetVersion) then return end @@ -30,7 +30,7 @@ local function UpdateDisabled(control) else disable = control.data.disabled end - + control.dropdown:SetEnabled(not disable) if disable then control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) @@ -39,7 +39,7 @@ local function UpdateDisabled(control) end end -local function UpdateValue(control, forceDefault, value) +local function UpdateValue(control, forceDefault, value) if forceDefault then --if we are forcing defaults value = control.data.default control.data.setFunc(value) @@ -56,13 +56,13 @@ local function UpdateValue(control, forceDefault, value) end end -local function DropdownCallback(choice, choiceText, choice) +local function DropdownCallback(control, choiceText, choice) choice.control:UpdateValue(false, choiceText) end local function UpdateChoices(control, choices) control.dropdown:ClearItems() --remove previous choices --(need to call :SetSelectedItem()?) - + --build new list of choices local choices = choices or control.data.choices for i = 1, #choices do @@ -83,15 +83,12 @@ local function GrabSortingInfo(sortInfo) end -local comboboxCount = 1 function LAMCreateControl.dropdown(parent, dropdownData, controlName) - local control = wm:CreateTopLevelWindow(controlName or dropdownData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or dropdownData.reference, parent.scroll or parent, CT_CONTROL) control:SetMouseEnabled(true) - --control.tooltipText = dropdownData.tooltip control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) - + control.label = wm:CreateControl(nil, control, CT_LABEL) local label = control.label label:SetAnchor(TOPLEFT) @@ -99,8 +96,16 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) label:SetText(dropdownData.name) - control.combobox = wm:CreateControlFromVirtual(parent:GetName().."Combobox"..comboboxCount, control, "ZO_ComboBox") - comboboxCount = comboboxCount + 1 + local countControl = parent + local name = parent:GetName() + if not name or #name == 0 then + countControl = LAMCreateControl + name = "LAM" + end + local comboboxCount = (countControl.comboboxCount or 0) + 1 + countControl.comboboxCount = comboboxCount + control.combobox = wm:CreateControlFromVirtual(zo_strjoin(nil, name, "Combobox", comboboxCount), control, "ZO_ComboBox") + local combobox = control.combobox combobox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) combobox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) @@ -111,7 +116,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) local sortType, sortOrder = sortInfo[1], sortInfo[2] dropdown:SetSortOrder(sortOrder == "up" and ZO_SORT_ORDER_UP or ZO_SORT_ORDER_DOWN, sortType == "name" and ZO_SORT_BY_NAME or ZO_SORT_BY_NAME_NUMERIC) end - + local isHalfWidth = dropdownData.width == "half" if isHalfWidth then control:SetDimensions(250, 55) @@ -124,18 +129,17 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) combobox:SetDimensions(200, 26) combobox:SetAnchor(TOPRIGHT) end - + if dropdownData.warning then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, combobox, LEFT, -5, 0) - --control.warning.tooltipText = dropdownData.warning control.warning.data = {tooltipText = dropdownData.warning} end control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = dropdownData control.data.tooltipText = dropdownData.tooltip - + if dropdownData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() @@ -144,7 +148,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) control:UpdateChoices(dropdownData.choices) control.UpdateValue = UpdateValue control:UpdateValue() - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end diff --git a/Libs/LibAddonMenu-2.0/controls/editbox.lua b/Libs/LibAddonMenu-2.0/controls/editbox.lua index 0d273d3..3ab069f 100644 --- a/Libs/LibAddonMenu-2.0/controls/editbox.lua +++ b/Libs/LibAddonMenu-2.0/controls/editbox.lua @@ -13,7 +13,7 @@ } ]] -local widgetVersion = 6 +local widgetVersion = 7 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("editbox", widgetVersion) then return end @@ -60,24 +60,22 @@ end function LAMCreateControl.editbox(parent, editboxData, controlName) - local control = wm:CreateTopLevelWindow(controlName or editboxData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or editboxData.reference, parent.scroll or parent, CT_CONTROL) control:SetMouseEnabled(true) control:SetResizeToFitDescendents(true) - --control.tooltipText = editboxData.tooltip control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) - + control.label = wm:CreateControl(nil, control, CT_LABEL) local label = control.label label:SetAnchor(TOPLEFT) label:SetFont("ZoFontWinH4") label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) label:SetText(editboxData.name) - + control.bg = wm:CreateControlFromVirtual(nil, control, "ZO_EditBackdrop") local bg = control.bg - + if editboxData.isMultiline then control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditMultiLineForBackdrop") control.editbox:SetHandler("OnMouseWheel", function(self, delta) @@ -109,7 +107,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) editbox:SetHandler("OnEscape", function(self) self:LoseFocus() control:UpdateValue(false, self:GetText()) end) editbox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) editbox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) - + local isHalfWidth = editboxData.width == "half" if isHalfWidth then control:SetDimensions(250, 55) @@ -139,7 +137,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = editboxData control.data.tooltipText = editboxData.tooltip - + if editboxData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() diff --git a/Libs/LibAddonMenu-2.0/controls/header.lua b/Libs/LibAddonMenu-2.0/controls/header.lua index bbf2c60..83c862b 100644 --- a/Libs/LibAddonMenu-2.0/controls/header.lua +++ b/Libs/LibAddonMenu-2.0/controls/header.lua @@ -6,7 +6,7 @@ } ]] -local widgetVersion = 4 +local widgetVersion = 5 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("header", widgetVersion) then return end @@ -18,11 +18,10 @@ local function UpdateValue(control) end function LAMCreateControl.header(parent, headerData, controlName) - local control = wm:CreateTopLevelWindow(controlName or headerData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or headerData.reference, parent.scroll or parent, CT_CONTROL) local isHalfWidth = headerData.width == "half" control:SetDimensions(isHalfWidth and 250 or 510, 30) - + control.divider = wm:CreateControlFromVirtual(nil, control, "ZO_Options_Divider") local divider = control.divider divider:SetWidth(isHalfWidth and 250 or 510) @@ -33,15 +32,15 @@ function LAMCreateControl.header(parent, headerData, controlName) header:SetAnchor(TOPLEFT, divider, BOTTOMLEFT) header:SetAnchor(BOTTOMRIGHT) header:SetText(headerData.name) - + control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = headerData - + control.UpdateValue = UpdateValue - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end - + return control end \ No newline at end of file diff --git a/Libs/LibAddonMenu-2.0/controls/panel.lua b/Libs/LibAddonMenu-2.0/controls/panel.lua index 5f9f41b..8db73ee 100644 --- a/Libs/LibAddonMenu-2.0/controls/panel.lua +++ b/Libs/LibAddonMenu-2.0/controls/panel.lua @@ -21,10 +21,10 @@ local cm = CALLBACK_MANAGER local function RefreshPanel(control) local panel = control.panel or control --callback can be fired by a single control or by the panel showing local panelControls = panel.controlsToRefresh - + for i = 1, #panelControls do local updateControl = panelControls[i] - if updateControl ~= control then + if updateControl ~= control then if updateControl.UpdateValue then updateControl:UpdateValue() end @@ -37,18 +37,18 @@ end local function ForceDefaults(panel) local panelControls = panel.controlsToRefresh - + for i = 1, #panelControls do local updateControl = panelControls[i] if updateControl.UpdateValue and updateControl.data.default ~= nil then updateControl:UpdateValue(true) end end - + if panel.data.resetFunc then panel.data.resetFunc() end - + cm:FireCallbacks("LAM-RefreshPanel", panel) end ESO_Dialogs["LAM_DEFAULTS"] = { @@ -81,12 +81,12 @@ function LAMCreateControl.panel(parent, panelData, controlName) bg:SetAnchorFill() bg:SetEdgeTexture("EsoUI\\Art\\miscellaneous\\borderedinsettransparent_edgefile.dds", 128, 16) bg:SetCenterColor(0, 0, 0, 0) - + control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") local label = control.label label:SetAnchor(TOPLEFT, control, TOPLEFT, 10, 10) label:SetText(panelData.displayName and panelData.displayName or panelData.name) - + if panelData.author or panelData.version then control.info = wm:CreateControl(nil, control, CT_LABEL) local info = control.info @@ -103,7 +103,7 @@ function LAMCreateControl.panel(parent, panelData, controlName) info:SetText("Version: "..panelData.version) end end - + control.container = wm:CreateControlFromVirtual("LAMAddonPanelContainer"..LAMCreateControl.scrollCount, control, "ZO_ScrollContainer") LAMCreateControl.scrollCount = LAMCreateControl.scrollCount + 1 local container = control.container @@ -111,7 +111,7 @@ function LAMCreateControl.panel(parent, panelData, controlName) container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, -3, -3) control.scroll = GetControl(control.container, "ScrollChild") control.scroll:SetResizeToFitPadding(0, 20) - + if panelData.registerForDefaults then control.defaultButton = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultTextButton") local defaultButton = control.defaultButton @@ -133,6 +133,6 @@ function LAMCreateControl.panel(parent, panelData, controlName) control.data = panelData control.controlsToRefresh = {} - + return control end \ No newline at end of file diff --git a/Libs/LibAddonMenu-2.0/controls/slider.lua b/Libs/LibAddonMenu-2.0/controls/slider.lua index f7ab0a3..845fa7d 100644 --- a/Libs/LibAddonMenu-2.0/controls/slider.lua +++ b/Libs/LibAddonMenu-2.0/controls/slider.lua @@ -15,7 +15,7 @@ } ]] -local widgetVersion = 5 +local widgetVersion = 6 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("slider", widgetVersion) then return end @@ -32,7 +32,7 @@ local function UpdateDisabled(control) else disable = control.data.disabled end - + control.slider:SetEnabled(not disable) control.slidervalue:SetEditEnabled(not disable) if disable then @@ -61,15 +61,14 @@ local function UpdateValue(control, forceDefault, value) else value = control.data.getFunc() end - + control.slider:SetValue(value) control.slidervalue:SetText(value) end function LAMCreateControl.slider(parent, sliderData, controlName) - local control = wm:CreateTopLevelWindow(controlName or sliderData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or sliderData.reference, parent.scroll or parent, CT_CONTROL) local isHalfWidth = sliderData.width == "half" if isHalfWidth then control:SetDimensions(250, 55) @@ -80,7 +79,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) --control.tooltipText = sliderData.tooltip control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) - + control.label = wm:CreateControl(nil, control, CT_LABEL) local label = control.label label:SetFont("ZoFontWinH4") @@ -88,7 +87,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) label:SetAnchor(isHalfWidth and TOPLEFT or LEFT) label:SetText(sliderData.name) - + --skipping creating the backdrop... Is this the actual slider texture? control.slider = wm:CreateControl(nil, control, CT_SLIDER) local slider = control.slider @@ -107,14 +106,14 @@ function LAMCreateControl.slider(parent, sliderData, controlName) slider:SetMinMax(minValue, maxValue) slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseExit(control) end) - + slider.bg = wm:CreateControl(nil, slider, CT_BACKDROP) 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) local minText = control.minText minText:SetFont("ZoFontGameSmall") @@ -126,7 +125,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) maxText:SetFont("ZoFontGameSmall") maxText:SetAnchor(TOPRIGHT, slider, BOTTOMRIGHT) maxText:SetText(sliderData.max) - + control.slidervalueBG = wm:CreateControlFromVirtual(nil, slider, "ZO_EditBackdrop") control.slidervalueBG:SetDimensions(50, 16) control.slidervalueBG:SetAnchor(TOP, slider, BOTTOM, 0, 0) @@ -145,7 +144,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) self:LoseFocus() control:UpdateValue(false, tonumber(self:GetText())) end) - + local range = maxValue - minValue slider:SetValueStep(sliderData.step or 1) slider:SetHandler("OnValueChanged", function(self, value, eventReason) @@ -157,18 +156,18 @@ function LAMCreateControl.slider(parent, sliderData, controlName) --sliderData.setFunc(value) control:UpdateValue(false, value) --does this work here instead? end) - + if sliderData.warning then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, slider, LEFT, -5, 0) --control.warning.tooltipText = sliderData.warning control.warning.data = {tooltipText = sliderData.warning} end - + control.panel = parent.panel or parent --if this is in a submenu, panel is the submenu's parent control.data = sliderData control.data.tooltipText = sliderData.tooltip - + if sliderData.disabled then control.UpdateDisabled = UpdateDisabled control:UpdateDisabled() diff --git a/Libs/LibAddonMenu-2.0/controls/submenu.lua b/Libs/LibAddonMenu-2.0/controls/submenu.lua index 761dda5..d3da3eb 100644 --- a/Libs/LibAddonMenu-2.0/controls/submenu.lua +++ b/Libs/LibAddonMenu-2.0/controls/submenu.lua @@ -6,7 +6,7 @@ reference = "MyAddonSubmenu" --(optional) unique global reference to control } ]] -local widgetVersion = 7 +local widgetVersion = 8 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("submenu", widgetVersion) then return end @@ -18,7 +18,6 @@ local tinsert = table.insert local function UpdateValue(control) control.label:SetText(control.data.name) if control.data.tooltip then - --control.label.tooltipText = control.data.tooltip control.label.data = {tooltipText = control.data.tooltip} end end @@ -26,7 +25,7 @@ end local function AnimateSubmenu(clicked) local control = clicked:GetParent() control.open = not control.open - + if control.open then control.animation:PlayFromStart() else @@ -36,11 +35,10 @@ end function LAMCreateControl.submenu(parent, submenuData, controlName) - local control = wm:CreateTopLevelWindow(controlName or submenuData.reference) - control:SetParent(parent.scroll or parent) + local control = wm:CreateControl(controlName or submenuData.reference, parent.scroll or parent, CT_CONTROL) control.panel = parent control:SetDimensions(523, 40) - + control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel") local label = control.label label:SetAnchor(TOPLEFT, control, TOPLEFT, 5, 5) @@ -49,12 +47,11 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) label:SetText(submenuData.name) label:SetMouseEnabled(true) if submenuData.tooltip then - --label.tooltipText = submenuData.tooltip label.data = {tooltipText = submenuData.tooltip} label:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) label:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) end - + control.scroll = wm:CreateControl(nil, control, CT_SCROLL) local scroll = control.scroll scroll:SetParent(control) @@ -68,23 +65,18 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16) bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds") bg:SetInsets(16, 16, -16, -16) - + control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE) local arrow = control.arrow arrow:SetDimensions(28, 28) arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") --list_sortup for the other way arrow:SetAnchor(TOPRIGHT, bg, TOPRIGHT, -5, 5) - + --figure out the cool animation later... control.animation = am:CreateTimeline() local animation = control.animation animation:SetPlaybackType(ANIMATION_SIZE, 0) --2nd arg = loop count - --animation:SetDuration(1) - --animation:SetEasingFunction(ZO_LinearEase) --is this needed? - --animation:SetHeightStartAndEnd(40, 80) --SetStartAndEndHeight - --animation:SetStartAndEndHeight(40, 80) --SetStartAndEndHeight - --animation:SetAnimatedControl(control) - + control:SetResizeToFitDescendents(true) control.open = false label:SetHandler("OnMouseUp", AnimateSubmenu) @@ -99,7 +91,7 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) scroll:SetHeight(0) end end) - + --small strip at the bottom of the submenu that you can click to close it control.btmToggle = wm:CreateControl(nil, control, CT_TEXTURE) local btmToggle = control.btmToggle @@ -109,15 +101,14 @@ function LAMCreateControl.submenu(parent, submenuData, controlName) btmToggle:SetHeight(15) btmToggle:SetAlpha(0) btmToggle:SetHandler("OnMouseUp", AnimateSubmenu) - + control.data = submenuData - + control.UpdateValue = UpdateValue - + if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list tinsert(control.panel.controlsToRefresh, control) end - + return control end - diff --git a/Libs/LibAddonMenu-2.0/controls/texture.lua b/Libs/LibAddonMenu-2.0/controls/texture.lua index 928ab82..26b0353 100644 --- a/Libs/LibAddonMenu-2.0/controls/texture.lua +++ b/Libs/LibAddonMenu-2.0/controls/texture.lua @@ -10,17 +10,16 @@ --add texture coords support? -local widgetVersion = 5 +local widgetVersion = 6 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("texture", widgetVersion) then return end local wm = WINDOW_MANAGER function LAMCreateControl.texture(parent, textureData, controlName) - local control = wm:CreateTopLevelWindow(controlName or textureData.reference) + local control = wm:CreateControl(controlName or textureData.reference, parent.scroll or parent, CT_CONTROL) control:SetResizeToFitDescendents(true) - control:SetParent(parent.scroll or parent) - + local isHalfWidth = textureData.width == "half" if isHalfWidth then control:SetDimensionConstraints(250, 55, 250, 100) @@ -29,13 +28,13 @@ function LAMCreateControl.texture(parent, textureData, controlName) control:SetDimensionConstraints(510, 30, 510, 100) control:SetDimensions(510, 30) end - + control.texture = wm:CreateControl(nil, control, CT_TEXTURE) local texture = control.texture texture:SetAnchor(CENTER) texture:SetDimensions(textureData.imageWidth, textureData.imageHeight) texture:SetTexture(textureData.image) - + if textureData.tooltip then texture:SetMouseEnabled(true) --texture.tooltipText = textureData.tooltip @@ -46,6 +45,6 @@ function LAMCreateControl.texture(parent, textureData, controlName) control.panel = parent.panel or parent --if this is in a submenu, panel is its parent control.data = textureData - + return control end \ No newline at end of file