New Api version, new LibAddonMenu version, enabled new categories by default in the settings
This commit is contained in:
parent
dadd1bf70c
commit
2f38fb14e3
@ -1,10 +1,11 @@
|
|||||||
## Title: AchievementInfo
|
## Title: AchievementInfo
|
||||||
## Description: Displays progress updates for achievements in the chat. You can display update-details like 'Slay 25/100 Monsters' if interested. |cFF0000Important:|r The messages appear only when an achievement is updated. This is no permanent tracking tool.
|
## Description: Displays progress updates for achievements in the chat. You can display update-details like 'Slay 25/100 Monsters' if interested. |cFF0000Important:|r The messages appear only when an achievement is updated. This is no permanent tracking tool.
|
||||||
## Version: 2.16
|
## AddOnVersion 220
|
||||||
|
## Version: 2.20
|
||||||
## Author: |c87B7CCAsto|r, @Astarax
|
## Author: |c87B7CCAsto|r, @Astarax
|
||||||
## Contact: mail@coded-with-heart.com
|
## Contact: mail@coded-with-heart.com
|
||||||
|
|
||||||
## APIVersion: 100022
|
## APIVersion: 100025
|
||||||
## SavedVariables: ACHIEVEMENT_INFO_DB
|
## SavedVariables: ACHIEVEMENT_INFO_DB
|
||||||
|
|
||||||
## OptionalDependsOn: LibAddonMenu-2.0, LibStub
|
## OptionalDependsOn: LibAddonMenu-2.0, LibStub
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
AchievementInfo = {}
|
AchievementInfo = {}
|
||||||
AchievementInfo.name = "AchievementInfo"
|
AchievementInfo.name = "AchievementInfo"
|
||||||
AchievementInfo.author = "Asto, @Astarax"
|
AchievementInfo.author = "Asto, @Astarax"
|
||||||
AchievementInfo.version = 2.16
|
AchievementInfo.version = 2.20
|
||||||
AchievementInfo.savedVars = nil
|
AchievementInfo.savedVars = nil
|
||||||
AchievementInfo.LangStore = {}
|
AchievementInfo.LangStore = {}
|
||||||
|
|
||||||
|
@ -24,6 +24,18 @@ function AchievementInfo.loadSavedVars()
|
|||||||
cat8 = true,
|
cat8 = true,
|
||||||
cat9 = true,
|
cat9 = true,
|
||||||
cat10 = true,
|
cat10 = true,
|
||||||
|
cat11 = true,
|
||||||
|
cat12 = true,
|
||||||
|
cat13 = true,
|
||||||
|
cat14 = true,
|
||||||
|
cat15 = true,
|
||||||
|
cat16 = true,
|
||||||
|
cat17 = true,
|
||||||
|
cat18 = true,
|
||||||
|
cat19 = true,
|
||||||
|
cat20 = true,
|
||||||
|
cat21 = true,
|
||||||
|
cat22 = true,
|
||||||
devDebug = false
|
devDebug = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
## APIVersion: 100011
|
## APIVersion: 100022 100023
|
||||||
## Title: LibAddonMenu-2.0
|
## Title: LibAddonMenu-2.0
|
||||||
## Version: 2.0 r18
|
## Version: 2.0 r26
|
||||||
|
## AddOnVersion: 26
|
||||||
## Author: Seerah, sirinsidiator, et al.
|
## Author: Seerah, sirinsidiator, et al.
|
||||||
## Contributors: votan, merlight, Garkin
|
## Contributors: votan, merlight, Garkin, Randactyl, KuroiLight, silvereyes333, Baertram, kyoma
|
||||||
## Description: A library to aid in the creation of option panels.
|
## Description: A library to aid in the creation of option panels.
|
||||||
|
##
|
||||||
|
## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates.
|
||||||
|
## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries.
|
||||||
|
## All rights reserved
|
||||||
|
##
|
||||||
|
## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms
|
||||||
|
|
||||||
LibStub\LibStub.lua
|
LibStub\LibStub.lua
|
||||||
|
|
||||||
@ -23,3 +29,4 @@ LibAddonMenu-2.0\controls\header.lua
|
|||||||
LibAddonMenu-2.0\controls\slider.lua
|
LibAddonMenu-2.0\controls\slider.lua
|
||||||
LibAddonMenu-2.0\controls\texture.lua
|
LibAddonMenu-2.0\controls\texture.lua
|
||||||
LibAddonMenu-2.0\controls\iconpicker.lua
|
LibAddonMenu-2.0\controls\iconpicker.lua
|
||||||
|
LibAddonMenu-2.0\controls\divider.lua
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
The Artistic License 2.0
|
The Artistic License 2.0
|
||||||
|
|
||||||
Copyright (c) 2015 Ryan Lakanen (Seerah)
|
Copyright (c) 2016 Ryan Lakanen (Seerah)
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,89 +1,91 @@
|
|||||||
--[[buttonData = {
|
--[[buttonData = {
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "My Button",
|
name = "My Button", -- string id or function returning a string
|
||||||
tooltip = "Button's tooltip text.",
|
func = function() end,
|
||||||
func = function() end,
|
tooltip = "Button's tooltip text.", -- string id or function returning a string (optional)
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
||||||
icon = "icon\\path.dds", --(optional)
|
icon = "icon\\path.dds", --(optional)
|
||||||
warning = "Will need to reload the UI.", --(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)
|
||||||
reference = "MyAddonButton" --(optional) unique global reference to control
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
} ]]
|
reference = "MyAddonButton", -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
local widgetVersion = 11
|
||||||
local widgetVersion = 7
|
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("button", widgetVersion) then return end
|
if not LAM:RegisterWidget("button", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable = control.data.disabled
|
||||||
if type(control.data.disabled) == "function" then
|
if type(disable) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = disable()
|
||||||
else
|
end
|
||||||
disable = control.data.disabled
|
control.button:SetEnabled(not disable)
|
||||||
end
|
|
||||||
|
|
||||||
control.button:SetEnabled(not disable)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--controlName is optional
|
--controlName is optional
|
||||||
local MIN_HEIGHT = 28 -- default_button height
|
local MIN_HEIGHT = 28 -- default_button height
|
||||||
local HALF_WIDTH_LINE_SPACING = 2
|
local HALF_WIDTH_LINE_SPACING = 2
|
||||||
function LAMCreateControl.button(parent, buttonData, controlName)
|
function LAMCreateControl.button(parent, buttonData, controlName)
|
||||||
local control = LAM.util.CreateBaseControl(parent, buttonData, controlName)
|
local control = LAM.util.CreateBaseControl(parent, buttonData, controlName)
|
||||||
control:SetMouseEnabled(true)
|
control:SetMouseEnabled(true)
|
||||||
|
|
||||||
local width = control:GetWidth()
|
local width = control:GetWidth()
|
||||||
if control.isHalfWidth then
|
if control.isHalfWidth then
|
||||||
control:SetDimensions(width / 2, MIN_HEIGHT * 2 + HALF_WIDTH_LINE_SPACING)
|
control:SetDimensions(width / 2, MIN_HEIGHT * 2 + HALF_WIDTH_LINE_SPACING)
|
||||||
else
|
else
|
||||||
control:SetDimensions(width, MIN_HEIGHT)
|
control:SetDimensions(width, MIN_HEIGHT)
|
||||||
end
|
end
|
||||||
|
|
||||||
if buttonData.icon then
|
if buttonData.icon then
|
||||||
control.button = wm:CreateControl(nil, control, CT_BUTTON)
|
control.button = wm:CreateControl(nil, control, CT_BUTTON)
|
||||||
control.button:SetDimensions(26, 26)
|
control.button:SetDimensions(26, 26)
|
||||||
control.button:SetNormalTexture(buttonData.icon)
|
control.button:SetNormalTexture(buttonData.icon)
|
||||||
control.button:SetPressedOffset(2, 2)
|
control.button:SetPressedOffset(2, 2)
|
||||||
else
|
else
|
||||||
--control.button = wm:CreateControlFromVirtual(controlName.."Button", control, "ZO_DefaultButton")
|
--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")
|
||||||
control.button:SetWidth(width / 3)
|
control.button:SetWidth(width / 3)
|
||||||
control.button:SetText(buttonData.name)
|
control.button:SetText(LAM.util.GetStringFromValue(buttonData.name))
|
||||||
end
|
if buttonData.isDangerous then control.button:SetNormalFontColor(ZO_ERROR_COLOR:UnpackRGBA()) end
|
||||||
local button = control.button
|
end
|
||||||
button:SetAnchor(control.isHalfWidth and CENTER or RIGHT)
|
local button = control.button
|
||||||
button:SetClickSound("Click")
|
button:SetAnchor(control.isHalfWidth and CENTER or RIGHT)
|
||||||
button.data = {tooltipText = LAM.util.GetTooltipText(buttonData.tooltip)}
|
button:SetClickSound("Click")
|
||||||
button:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
button.data = {tooltipText = LAM.util.GetStringFromValue(buttonData.tooltip)}
|
||||||
button:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
|
button:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
||||||
button:SetHandler("OnClicked", function(self, ...)
|
button:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
|
||||||
buttonData.func(self, ...)
|
button:SetHandler("OnClicked", function(...)
|
||||||
if control.panel.data.registerForRefresh then
|
local args = {...}
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
local function callback()
|
||||||
end
|
buttonData.func(unpack(args))
|
||||||
end)
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
|
end
|
||||||
|
|
||||||
if buttonData.warning then
|
if(buttonData.isDangerous) then
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
local title = LAM.util.GetStringFromValue(buttonData.name)
|
||||||
control.warning:SetAnchor(RIGHT, button, LEFT, -5, 0)
|
local body = LAM.util.GetStringFromValue(buttonData.warning)
|
||||||
control.warning.data = {tooltipText = buttonData.warning}
|
LAM.util.ShowConfirmationDialog(title, body, callback)
|
||||||
end
|
else
|
||||||
|
callback()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
if buttonData.disabled then
|
if buttonData.warning ~= nil then
|
||||||
control.UpdateDisabled = UpdateDisabled
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
control:UpdateDisabled()
|
control.warning:SetAnchor(RIGHT, button, LEFT, -5, 0)
|
||||||
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
--this is here because buttons don't have an UpdateValue method
|
if buttonData.disabled ~= nil then
|
||||||
if control.panel.data.registerForRefresh then --if our parent window wants to refresh controls, then add this to the list
|
control.UpdateDisabled = UpdateDisabled
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
control:UpdateDisabled()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
end
|
|
||||||
|
return control
|
||||||
|
end
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
--[[checkboxData = {
|
--[[checkboxData = {
|
||||||
type = "checkbox",
|
type = "checkbox",
|
||||||
name = "My Checkbox",
|
name = "My Checkbox", -- or string id or function returning a string
|
||||||
tooltip = "Checkbox's tooltip text.",
|
getFunc = function() return db.var end,
|
||||||
getFunc = function() return db.var end,
|
setFunc = function(value) db.var = value doStuff() 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)
|
width = "full", -- or "half" (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional)
|
||||||
default = defaults.var, --(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)
|
||||||
reference = "MyAddonCheckbox" --(optional) unique global reference to control
|
default = defaults.var, -- a boolean or function that returns a boolean (optional)
|
||||||
} ]]
|
reference = "MyAddonCheckbox", -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 9
|
local widgetVersion = 14
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("checkbox", widgetVersion) then return end
|
if not LAM:RegisterWidget("checkbox", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
--label
|
--label
|
||||||
local enabledColor = ZO_DEFAULT_ENABLED_COLOR
|
local enabledColor = ZO_DEFAULT_ENABLED_COLOR
|
||||||
local enabledHLcolor = ZO_HIGHLIGHT_TEXT
|
local enabledHLcolor = ZO_HIGHLIGHT_TEXT
|
||||||
@ -30,115 +30,113 @@ local checkboxHLcolor = ZO_HIGHLIGHT_TEXT
|
|||||||
|
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = control.data.disabled()
|
||||||
else
|
else
|
||||||
disable = control.data.disabled
|
disable = control.data.disabled
|
||||||
end
|
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.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.checkbox:SetColor((disable and ZO_DEFAULT_DISABLED_COLOR or ZO_NORMAL_TEXT):UnpackRGBA())
|
||||||
--control:SetMouseEnabled(not disable)
|
--control:SetMouseEnabled(not disable)
|
||||||
--control:SetMouseEnabled(true)
|
--control:SetMouseEnabled(true)
|
||||||
|
|
||||||
control.isDisabled = disable
|
control.isDisabled = disable
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ToggleCheckbox(control)
|
local function ToggleCheckbox(control)
|
||||||
if control.value then
|
if control.value then
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
control.checkbox:SetText(control.checkedText)
|
control.checkbox:SetText(control.checkedText)
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
control.checkbox:SetText(control.uncheckedText)
|
control.checkbox:SetText(control.uncheckedText)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, value)
|
local function UpdateValue(control, forceDefault, value)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
value = control.data.default
|
value = LAM.util.GetDefaultValue(control.data.default)
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
elseif value ~= nil then --our value could be false
|
elseif value ~= nil then --our value could be false
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
else
|
||||||
end
|
value = control.data.getFunc()
|
||||||
else
|
end
|
||||||
value = control.data.getFunc()
|
control.value = value
|
||||||
end
|
|
||||||
control.value = value
|
|
||||||
|
|
||||||
ToggleCheckbox(control)
|
ToggleCheckbox(control)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function OnMouseEnter(control)
|
local function OnMouseEnter(control)
|
||||||
ZO_Options_OnMouseEnter(control)
|
ZO_Options_OnMouseEnter(control)
|
||||||
|
|
||||||
if control.isDisabled then return end
|
if control.isDisabled then return end
|
||||||
|
|
||||||
local label = control.label
|
local label = control.label
|
||||||
if control.value then
|
if control.value then
|
||||||
label:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA())
|
label:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA())
|
||||||
else
|
else
|
||||||
label:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
label:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
control.checkbox:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA())
|
control.checkbox:SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function OnMouseExit(control)
|
local function OnMouseExit(control)
|
||||||
ZO_Options_OnMouseExit(control)
|
ZO_Options_OnMouseExit(control)
|
||||||
|
|
||||||
if control.isDisabled then return end
|
if control.isDisabled then return end
|
||||||
|
|
||||||
local label = control.label
|
local label = control.label
|
||||||
if control.value then
|
if control.value then
|
||||||
label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
control.checkbox:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
|
control.checkbox:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
|
||||||
end
|
end
|
||||||
|
|
||||||
--controlName is optional
|
--controlName is optional
|
||||||
function LAMCreateControl.checkbox(parent, checkboxData, controlName)
|
function LAMCreateControl.checkbox(parent, checkboxData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, checkboxData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, checkboxData, controlName)
|
||||||
control:SetHandler("OnMouseEnter", OnMouseEnter)
|
control:SetHandler("OnMouseEnter", OnMouseEnter)
|
||||||
control:SetHandler("OnMouseExit", OnMouseExit)
|
control:SetHandler("OnMouseExit", OnMouseExit)
|
||||||
control:SetHandler("OnMouseUp", function(control)
|
control:SetHandler("OnMouseUp", function(control)
|
||||||
if control.isDisabled then return end
|
if control.isDisabled then return end
|
||||||
PlaySound(SOUNDS.DEFAULT_CLICK)
|
PlaySound(SOUNDS.DEFAULT_CLICK)
|
||||||
control.value = not control.value
|
control.value = not control.value
|
||||||
control:UpdateValue(false, control.value)
|
control:UpdateValue(false, control.value)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
control.checkbox = wm:CreateControl(nil, control.container, CT_LABEL)
|
control.checkbox = wm:CreateControl(nil, control.container, CT_LABEL)
|
||||||
local checkbox = control.checkbox
|
local checkbox = control.checkbox
|
||||||
checkbox:SetAnchor(LEFT, control.container, LEFT, 0, 0)
|
checkbox:SetAnchor(LEFT, control.container, LEFT, 0, 0)
|
||||||
checkbox:SetFont("ZoFontGameBold")
|
checkbox:SetFont("ZoFontGameBold")
|
||||||
checkbox:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
|
checkbox:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
|
||||||
control.checkedText = GetString(SI_CHECK_BUTTON_ON):upper()
|
control.checkedText = GetString(SI_CHECK_BUTTON_ON):upper()
|
||||||
control.uncheckedText = GetString(SI_CHECK_BUTTON_OFF):upper()
|
control.uncheckedText = GetString(SI_CHECK_BUTTON_OFF):upper()
|
||||||
|
|
||||||
if checkboxData.warning then
|
if checkboxData.warning ~= nil or checkboxData.requiresReload then
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
control.warning:SetAnchor(RIGHT, checkbox, LEFT, -5, 0)
|
control.warning:SetAnchor(RIGHT, checkbox, LEFT, -5, 0)
|
||||||
control.warning.data = {tooltipText = checkboxData.warning}
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
end
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
control.data.tooltipText = LAM.util.GetTooltipText(checkboxData.tooltip)
|
control.data.tooltipText = LAM.util.GetStringFromValue(checkboxData.tooltip)
|
||||||
|
|
||||||
if checkboxData.disabled then
|
control.UpdateValue = UpdateValue
|
||||||
control.UpdateDisabled = UpdateDisabled
|
control:UpdateValue()
|
||||||
control:UpdateDisabled()
|
if checkboxData.disabled ~= nil then
|
||||||
end
|
control.UpdateDisabled = UpdateDisabled
|
||||||
control.UpdateValue = UpdateValue
|
control:UpdateDisabled()
|
||||||
control:UpdateValue()
|
end
|
||||||
|
|
||||||
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,110 +1,106 @@
|
|||||||
--[[colorpickerData = {
|
--[[colorpickerData = {
|
||||||
type = "colorpicker",
|
type = "colorpicker",
|
||||||
name = "My Color Picker",
|
name = "My Color Picker", -- or string id or function returning a string
|
||||||
tooltip = "Color Picker's tooltip text.",
|
getFunc = function() return db.r, db.g, db.b, db.a end, --(alpha is optional)
|
||||||
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)
|
||||||
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)
|
width = "full", --or "half" (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "May cause permanent awesomeness.", -- or string id or function returning a string (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])
|
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)
|
||||||
reference = "MyAddonColorpicker" --(optional) unique global reference to control
|
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
|
||||||
} ]]
|
reference = "MyAddonColorpicker" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 7
|
local widgetVersion = 13
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("colorpicker", widgetVersion) then return end
|
if not LAM:RegisterWidget("colorpicker", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = control.data.disabled()
|
||||||
else
|
else
|
||||||
disable = control.data.disabled
|
disable = control.data.disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
if disable then
|
if disable then
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
|
|
||||||
control.isDisabled = disable
|
control.isDisabled = disable
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, valueR, valueG, valueB, valueA)
|
local function UpdateValue(control, forceDefault, valueR, valueG, valueB, valueA)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
local color = control.data.default
|
local color = LAM.util.GetDefaultValue(control.data.default)
|
||||||
valueR, valueG, valueB, valueA = color.r, color.g, color.b, color.a
|
valueR, valueG, valueB, valueA = color.r, color.g, color.b, color.a
|
||||||
control.data.setFunc(valueR, valueG, valueB, valueA)
|
control.data.setFunc(valueR, valueG, valueB, valueA)
|
||||||
elseif valueR and valueG and valueB then
|
elseif valueR and valueG and valueB then
|
||||||
control.data.setFunc(valueR, valueG, valueB, valueA or 1)
|
control.data.setFunc(valueR, valueG, valueB, valueA or 1)
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
else
|
||||||
end
|
valueR, valueG, valueB, valueA = control.data.getFunc()
|
||||||
else
|
end
|
||||||
valueR, valueG, valueB, valueA = control.data.getFunc()
|
|
||||||
end
|
|
||||||
|
|
||||||
control.thumb:SetColor(valueR, valueG, valueB, valueA or 1)
|
control.thumb:SetColor(valueR, valueG, valueB, valueA or 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function LAMCreateControl.colorpicker(parent, colorpickerData, controlName)
|
function LAMCreateControl.colorpicker(parent, colorpickerData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, colorpickerData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, colorpickerData, controlName)
|
||||||
|
|
||||||
control.color = control.container
|
control.color = control.container
|
||||||
local color = control.color
|
local color = control.color
|
||||||
|
|
||||||
control.thumb = wm:CreateControl(nil, color, CT_TEXTURE)
|
control.thumb = wm:CreateControl(nil, color, CT_TEXTURE)
|
||||||
local thumb = control.thumb
|
local thumb = control.thumb
|
||||||
thumb:SetDimensions(36, 18)
|
thumb:SetDimensions(36, 18)
|
||||||
thumb:SetAnchor(LEFT, color, LEFT, 4, 0)
|
thumb:SetAnchor(LEFT, color, LEFT, 4, 0)
|
||||||
|
|
||||||
color.border = wm:CreateControl(nil, color, CT_TEXTURE)
|
color.border = wm:CreateControl(nil, color, CT_TEXTURE)
|
||||||
local border = color.border
|
local border = color.border
|
||||||
border:SetTexture("EsoUI\\Art\\ChatWindow\\chatOptions_bgColSwatch_frame.dds")
|
border:SetTexture("EsoUI\\Art\\ChatWindow\\chatOptions_bgColSwatch_frame.dds")
|
||||||
border:SetTextureCoords(0, .625, 0, .8125)
|
border:SetTextureCoords(0, .625, 0, .8125)
|
||||||
border:SetDimensions(40, 22)
|
border:SetDimensions(40, 22)
|
||||||
border:SetAnchor(CENTER, thumb, CENTER, 0, 0)
|
border:SetAnchor(CENTER, thumb, CENTER, 0, 0)
|
||||||
|
|
||||||
local function ColorPickerCallback(r, g, b, a)
|
local function ColorPickerCallback(r, g, b, a)
|
||||||
control:UpdateValue(false, r, g, b, a)
|
control:UpdateValue(false, r, g, b, a)
|
||||||
end
|
end
|
||||||
|
|
||||||
control:SetHandler("OnMouseUp", function(self, btn, upInside)
|
control:SetHandler("OnMouseUp", function(self, btn, upInside)
|
||||||
if self.isDisabled then return end
|
if self.isDisabled then return end
|
||||||
|
|
||||||
if upInside then
|
if upInside then
|
||||||
local r, g, b, a = colorpickerData.getFunc()
|
local r, g, b, a = colorpickerData.getFunc()
|
||||||
COLOR_PICKER:Show(ColorPickerCallback, r, g, b, a, colorpickerData.name)
|
COLOR_PICKER:Show(ColorPickerCallback, r, g, b, a, LAM.util.GetStringFromValue(colorpickerData.name))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if colorpickerData.warning then
|
if colorpickerData.warning ~= nil or colorpickerData.requiresReload then
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
control.warning:SetAnchor(RIGHT, control.color, LEFT, -5, 0)
|
control.warning:SetAnchor(RIGHT, control.color, LEFT, -5, 0)
|
||||||
control.warning.data = {tooltipText = colorpickerData.warning}
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
end
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
control.data.tooltipText = LAM.util.GetTooltipText(colorpickerData.tooltip)
|
control.data.tooltipText = LAM.util.GetStringFromValue(colorpickerData.tooltip)
|
||||||
|
|
||||||
if colorpickerData.disabled then
|
control.UpdateValue = UpdateValue
|
||||||
control.UpdateDisabled = UpdateDisabled
|
control:UpdateValue()
|
||||||
control:UpdateDisabled()
|
if colorpickerData.disabled ~= nil then
|
||||||
end
|
control.UpdateDisabled = UpdateDisabled
|
||||||
control.UpdateValue = UpdateValue
|
control:UpdateDisabled()
|
||||||
control:UpdateValue()
|
end
|
||||||
|
|
||||||
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,40 +1,35 @@
|
|||||||
--[[customData = {
|
--[[customData = {
|
||||||
type = "custom",
|
type = "custom",
|
||||||
reference = "MyAddonCustomControl", --(optional) unique name for your control to use as reference
|
reference = "MyAddonCustomControl", --(optional) unique name for your control to use as reference
|
||||||
refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh
|
refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
} ]]
|
} ]]
|
||||||
|
|
||||||
local widgetVersion = 6
|
local widgetVersion = 7
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("custom", widgetVersion) then return end
|
if not LAM:RegisterWidget("custom", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local function UpdateValue(control)
|
local function UpdateValue(control)
|
||||||
if control.data.refreshFunc then
|
if control.data.refreshFunc then
|
||||||
control.data.refreshFunc(control)
|
control.data.refreshFunc(control)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local MIN_HEIGHT = 26
|
local MIN_HEIGHT = 26
|
||||||
function LAMCreateControl.custom(parent, customData, controlName)
|
function LAMCreateControl.custom(parent, customData, controlName)
|
||||||
local control = LAM.util.CreateBaseControl(parent, customData, controlName)
|
local control = LAM.util.CreateBaseControl(parent, customData, controlName)
|
||||||
local width = control:GetWidth()
|
local width = control:GetWidth()
|
||||||
control:SetResizeToFitDescendents(true)
|
control:SetResizeToFitDescendents(true)
|
||||||
|
|
||||||
if control.isHalfWidth then --note these restrictions
|
if control.isHalfWidth then --note these restrictions
|
||||||
control:SetDimensionConstraints(width / 2, MIN_HEIGHT, width / 2, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width / 2, MIN_HEIGHT, width / 2, MIN_HEIGHT * 4)
|
||||||
else
|
else
|
||||||
control:SetDimensionConstraints(width, MIN_HEIGHT, width, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width, MIN_HEIGHT, width, MIN_HEIGHT * 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
control.UpdateValue = UpdateValue
|
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,64 +1,60 @@
|
|||||||
--[[descriptionData = {
|
--[[descriptionData = {
|
||||||
type = "description",
|
type = "description",
|
||||||
title = "My Title", --(optional)
|
text = "My description text to display.", -- or string id or function returning a string
|
||||||
text = "My description text to display.",
|
title = "My Title", -- or string id or function returning a string (optional)
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
reference = "MyAddonDescription" --(optional) unique global reference to control
|
reference = "MyAddonDescription" -- unique global reference to control (optional)
|
||||||
} ]]
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 6
|
local widgetVersion = 8
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("description", widgetVersion) then return end
|
if not LAM:RegisterWidget("description", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local function UpdateValue(control)
|
local function UpdateValue(control)
|
||||||
if control.title then
|
if control.title then
|
||||||
control.title:SetText(control.data.title)
|
control.title:SetText(LAM.util.GetStringFromValue(control.data.title))
|
||||||
end
|
end
|
||||||
control.desc:SetText(control.data.text)
|
control.desc:SetText(LAM.util.GetStringFromValue(control.data.text))
|
||||||
end
|
end
|
||||||
|
|
||||||
local MIN_HEIGHT = 26
|
|
||||||
function LAMCreateControl.description(parent, descriptionData, controlName)
|
function LAMCreateControl.description(parent, descriptionData, controlName)
|
||||||
local control = LAM.util.CreateBaseControl(parent, descriptionData, controlName)
|
local control = LAM.util.CreateBaseControl(parent, descriptionData, controlName)
|
||||||
local isHalfWidth = control.isHalfWidth
|
local isHalfWidth = control.isHalfWidth
|
||||||
local width = control:GetWidth()
|
local width = control:GetWidth()
|
||||||
control:SetResizeToFitDescendents(true)
|
control:SetResizeToFitDescendents(true)
|
||||||
|
|
||||||
if isHalfWidth then
|
if isHalfWidth then
|
||||||
control:SetDimensionConstraints(width / 2, MIN_HEIGHT, width / 2, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width / 2, 0, width / 2, 0)
|
||||||
else
|
else
|
||||||
control:SetDimensionConstraints(width, MIN_HEIGHT, width, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width, 0, width, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
control.desc = wm:CreateControl(nil, control, CT_LABEL)
|
control.desc = wm:CreateControl(nil, control, CT_LABEL)
|
||||||
local desc = control.desc
|
local desc = control.desc
|
||||||
desc:SetVerticalAlignment(TEXT_ALIGN_TOP)
|
desc:SetVerticalAlignment(TEXT_ALIGN_TOP)
|
||||||
desc:SetFont("ZoFontGame")
|
desc:SetFont("ZoFontGame")
|
||||||
desc:SetText(descriptionData.text)
|
desc:SetText(LAM.util.GetStringFromValue(descriptionData.text))
|
||||||
desc:SetWidth(isHalfWidth and width / 2 or width)
|
desc:SetWidth(isHalfWidth and width / 2 or width)
|
||||||
|
|
||||||
if descriptionData.title then
|
if descriptionData.title then
|
||||||
control.title = wm:CreateControl(nil, control, CT_LABEL)
|
control.title = wm:CreateControl(nil, control, CT_LABEL)
|
||||||
local title = control.title
|
local title = control.title
|
||||||
title:SetWidth(isHalfWidth and width / 2 or width)
|
title:SetWidth(isHalfWidth and width / 2 or width)
|
||||||
title:SetAnchor(TOPLEFT, control, TOPLEFT)
|
title:SetAnchor(TOPLEFT, control, TOPLEFT)
|
||||||
title:SetFont("ZoFontWinH4")
|
title:SetFont("ZoFontWinH4")
|
||||||
title:SetText(descriptionData.title)
|
title:SetText(LAM.util.GetStringFromValue(descriptionData.title))
|
||||||
desc:SetAnchor(TOPLEFT, title, BOTTOMLEFT)
|
desc:SetAnchor(TOPLEFT, title, BOTTOMLEFT)
|
||||||
else
|
else
|
||||||
desc:SetAnchor(TOPLEFT)
|
desc:SetAnchor(TOPLEFT)
|
||||||
end
|
end
|
||||||
|
|
||||||
control.UpdateValue = UpdateValue
|
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
|
|
||||||
end
|
end
|
||||||
|
45
Libs/LibAddonMenu-2.0/controls/divider.lua
Normal file
45
Libs/LibAddonMenu-2.0/controls/divider.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
--[[dividerData = {
|
||||||
|
type = "divider",
|
||||||
|
width = "full", --or "half" (optional)
|
||||||
|
height = 10, (optional)
|
||||||
|
alpha = 0.25, (optional)
|
||||||
|
reference = "MyAddonDivider" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
|
local widgetVersion = 2
|
||||||
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
|
if not LAM:RegisterWidget("divider", widgetVersion) then return end
|
||||||
|
|
||||||
|
local wm = WINDOW_MANAGER
|
||||||
|
|
||||||
|
local MIN_HEIGHT = 10
|
||||||
|
local MAX_HEIGHT = 50
|
||||||
|
local MIN_ALPHA = 0
|
||||||
|
local MAX_ALPHA = 1
|
||||||
|
local DEFAULT_ALPHA = 0.25
|
||||||
|
|
||||||
|
local function GetValueInRange(value, min, max, default)
|
||||||
|
if not value or type(value) ~= "number" then
|
||||||
|
return default
|
||||||
|
end
|
||||||
|
return math.min(math.max(min, value), max)
|
||||||
|
end
|
||||||
|
|
||||||
|
function LAMCreateControl.divider(parent, dividerData, controlName)
|
||||||
|
local control = LAM.util.CreateBaseControl(parent, dividerData, controlName)
|
||||||
|
local isHalfWidth = control.isHalfWidth
|
||||||
|
local width = control:GetWidth()
|
||||||
|
local height = GetValueInRange(dividerData.height, MIN_HEIGHT, MAX_HEIGHT, MIN_HEIGHT)
|
||||||
|
local alpha = GetValueInRange(dividerData.alpha, MIN_ALPHA, MAX_ALPHA, DEFAULT_ALPHA)
|
||||||
|
|
||||||
|
control:SetDimensions(isHalfWidth and width / 2 or width, height)
|
||||||
|
|
||||||
|
control.divider = wm:CreateControlFromVirtual(nil, control, "ZO_Options_Divider")
|
||||||
|
local divider = control.divider
|
||||||
|
divider:SetWidth(isHalfWidth and width / 2 or width)
|
||||||
|
divider:SetAnchor(TOPLEFT)
|
||||||
|
divider:SetAlpha(alpha)
|
||||||
|
|
||||||
|
return control
|
||||||
|
end
|
@ -1,131 +1,387 @@
|
|||||||
--[[dropdownData = {
|
--[[dropdownData = {
|
||||||
type = "dropdown",
|
type = "dropdown",
|
||||||
name = "My Dropdown",
|
name = "My Dropdown", -- or string id or function returning a string
|
||||||
tooltip = "Dropdown's tooltip text.",
|
choices = {"table", "of", "choices"},
|
||||||
choices = {"table", "of", "choices"},
|
choicesValues = {"foo", 2, "three"}, -- if specified, these values will get passed to setFunc instead (optional)
|
||||||
sort = "name-up", --or "name-down", "numeric-up", "numeric-down" (optional) - if not provided, list will not be sorted
|
getFunc = function() return db.var end,
|
||||||
getFunc = function() return db.var end,
|
setFunc = function(var) db.var = var doStuff() end,
|
||||||
setFunc = function(var) db.var = var doStuff() end,
|
tooltip = "Dropdown's tooltip text.", -- or string id or function returning a string (optional)
|
||||||
width = "full", --or "half" (optional)
|
choicesTooltips = {"tooltip 1", "tooltip 2", "tooltip 3"}, -- or array of string ids or array of functions returning a string (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (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
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
width = "full", --or "half" (optional)
|
||||||
default = defaults.var, --(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)
|
||||||
reference = "MyAddonDropdown" --(optional) unique global reference to control
|
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)
|
||||||
|
reference = "MyAddonDropdown" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 9
|
local widgetVersion = 18
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("dropdown", widgetVersion) then return end
|
if not LAM:RegisterWidget("dropdown", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
local SORT_BY_VALUE = { ["value"] = {} }
|
||||||
local tinsert = table.insert
|
local SORT_BY_VALUE_NUMERIC = { ["value"] = { isNumeric = true } }
|
||||||
|
local SORT_TYPES = {
|
||||||
|
name = ZO_SORT_BY_NAME,
|
||||||
|
numeric = ZO_SORT_BY_NAME_NUMERIC,
|
||||||
|
value = SORT_BY_VALUE,
|
||||||
|
numericvalue = SORT_BY_VALUE_NUMERIC,
|
||||||
|
}
|
||||||
|
local SORT_ORDERS = {
|
||||||
|
up = ZO_SORT_ORDER_UP,
|
||||||
|
down = ZO_SORT_ORDER_DOWN,
|
||||||
|
}
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = control.data.disabled()
|
||||||
else
|
else
|
||||||
disable = control.data.disabled
|
disable = control.data.disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
control.dropdown:SetEnabled(not disable)
|
control.dropdown:SetEnabled(not disable)
|
||||||
if disable then
|
if disable then
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, value)
|
local function UpdateValue(control, forceDefault, value)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
value = control.data.default
|
value = LAM.util.GetDefaultValue(control.data.default)
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
control.dropdown:SetSelectedItem(value)
|
control.dropdown:SetSelectedItem(control.choices[value])
|
||||||
elseif value then
|
elseif value then
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
else
|
||||||
end
|
value = control.data.getFunc()
|
||||||
else
|
control.dropdown:SetSelectedItem(control.choices[value])
|
||||||
value = control.data.getFunc()
|
end
|
||||||
control.dropdown:SetSelectedItem(value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function DropdownCallback(control, choiceText, choice)
|
local function DropdownCallback(control, choiceText, choice)
|
||||||
choice.control:UpdateValue(false, choiceText)
|
choice.control:UpdateValue(false, choice.value or choiceText)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateChoices(control, choices)
|
local function SetupTooltips(comboBox, choicesTooltips)
|
||||||
control.dropdown:ClearItems() --remove previous choices --(need to call :SetSelectedItem()?)
|
local function ShowTooltip(control)
|
||||||
|
InitializeTooltip(InformationTooltip, control, TOPLEFT, 0, 0, BOTTOMRIGHT)
|
||||||
|
SetTooltipText(InformationTooltip, LAM.util.GetStringFromValue(control.tooltip))
|
||||||
|
InformationTooltipTopLevel:BringWindowToTop()
|
||||||
|
end
|
||||||
|
local function HideTooltip(control)
|
||||||
|
ClearTooltip(InformationTooltip)
|
||||||
|
end
|
||||||
|
|
||||||
--build new list of choices
|
-- allow for tooltips on the drop down entries
|
||||||
local choices = choices or control.data.choices
|
local originalShow = comboBox.ShowDropdownInternal
|
||||||
for i = 1, #choices do
|
comboBox.ShowDropdownInternal = function(comboBox)
|
||||||
local entry = control.dropdown:CreateItemEntry(choices[i], DropdownCallback)
|
originalShow(comboBox)
|
||||||
entry.control = control
|
local entries = ZO_Menu.items
|
||||||
control.dropdown:AddItem(entry, not control.data.sort and ZO_COMBOBOX_SUPRESS_UPDATE) --if sort type/order isn't specified, then don't sort
|
for i = 1, #entries do
|
||||||
end
|
local entry = entries[i]
|
||||||
|
local control = entries[i].item
|
||||||
|
control.tooltip = choicesTooltips[i]
|
||||||
|
entry.onMouseEnter = control:GetHandler("OnMouseEnter")
|
||||||
|
entry.onMouseExit = control:GetHandler("OnMouseExit")
|
||||||
|
ZO_PreHookHandler(control, "OnMouseEnter", ShowTooltip)
|
||||||
|
ZO_PreHookHandler(control, "OnMouseExit", HideTooltip)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local originalHide = comboBox.HideDropdownInternal
|
||||||
|
comboBox.HideDropdownInternal = function(self)
|
||||||
|
local entries = ZO_Menu.items
|
||||||
|
for i = 1, #entries do
|
||||||
|
local entry = entries[i]
|
||||||
|
local control = entries[i].item
|
||||||
|
control:SetHandler("OnMouseEnter", entry.onMouseEnter)
|
||||||
|
control:SetHandler("OnMouseExit", entry.onMouseExit)
|
||||||
|
control.tooltip = nil
|
||||||
|
end
|
||||||
|
originalHide(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function UpdateChoices(control, choices, choicesValues, choicesTooltips)
|
||||||
|
control.dropdown:ClearItems() --remove previous choices --(need to call :SetSelectedItem()?)
|
||||||
|
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
|
||||||
|
|
||||||
|
if choicesValues then
|
||||||
|
assert(#choices == #choicesValues, "choices and choicesValues need to have the same size")
|
||||||
|
end
|
||||||
|
|
||||||
|
if choicesTooltips then
|
||||||
|
assert(#choices == #choicesTooltips, "choices and choicesTooltips need to have the same size")
|
||||||
|
if not control.scrollHelper then -- only do this for non-scrollable
|
||||||
|
SetupTooltips(control.dropdown, choicesTooltips)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, #choices do
|
||||||
|
local entry = control.dropdown:CreateItemEntry(choices[i], DropdownCallback)
|
||||||
|
entry.control = control
|
||||||
|
if choicesValues then
|
||||||
|
entry.value = choicesValues[i]
|
||||||
|
end
|
||||||
|
if choicesTooltips and control.scrollHelper then
|
||||||
|
entry.tooltip = choicesTooltips[i]
|
||||||
|
end
|
||||||
|
control.choices[entry.value or entry.name] = 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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function GrabSortingInfo(sortInfo)
|
local function GrabSortingInfo(sortInfo)
|
||||||
local t, i = {}, 1
|
local t, i = {}, 1
|
||||||
for info in string.gmatch(sortInfo, "([^%-]+)") do
|
for info in string.gmatch(sortInfo, "([^%-]+)") do
|
||||||
t[i] = info
|
t[i] = info
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local DEFAULT_VISIBLE_ROWS = 10
|
||||||
|
local SCROLLABLE_ENTRY_TEMPLATE_HEIGHT = 25 -- same as in zo_combobox.lua
|
||||||
|
local CONTENT_PADDING = 24
|
||||||
|
local SCROLLBAR_PADDING = 16
|
||||||
|
local PADDING = GetMenuPadding() / 2 -- half the amount looks closer to the regular dropdown
|
||||||
|
local ROUNDING_MARGIN = 0.01 -- needed to avoid rare issue with too many anchors processed
|
||||||
|
local ScrollableDropdownHelper = ZO_Object:Subclass()
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:New(...)
|
||||||
|
local object = ZO_Object.New(self)
|
||||||
|
object:Initialize(...)
|
||||||
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:Initialize(parent, control, visibleRows)
|
||||||
|
local combobox = control.combobox
|
||||||
|
local dropdown = control.dropdown
|
||||||
|
self.parent = parent
|
||||||
|
self.control = control
|
||||||
|
self.combobox = combobox
|
||||||
|
self.dropdown = dropdown
|
||||||
|
self.visibleRows = visibleRows
|
||||||
|
|
||||||
|
-- clear anchors so we can adjust the width dynamically
|
||||||
|
dropdown.m_dropdown:ClearAnchors()
|
||||||
|
dropdown.m_dropdown:SetAnchor(TOPLEFT, combobox, BOTTOMLEFT)
|
||||||
|
|
||||||
|
-- handle dropdown or settingsmenu opening/closing
|
||||||
|
local function onShow() self:OnShow() end
|
||||||
|
local function onHide() self:OnHide() end
|
||||||
|
local function doHide() self:DoHide() end
|
||||||
|
|
||||||
|
ZO_PreHook(dropdown, "ShowDropdownOnMouseUp", onShow)
|
||||||
|
ZO_PreHook(dropdown, "HideDropdownInternal", onHide)
|
||||||
|
combobox:SetHandler("OnEffectivelyHidden", onHide)
|
||||||
|
parent:SetHandler("OnEffectivelyHidden", doHide)
|
||||||
|
|
||||||
|
-- dont fade entries near the edges
|
||||||
|
local scrollList = dropdown.m_scroll
|
||||||
|
scrollList.selectionTemplate = nil
|
||||||
|
scrollList.highlightTemplate = nil
|
||||||
|
ZO_ScrollList_EnableSelection(scrollList, "ZO_SelectionHighlight")
|
||||||
|
ZO_ScrollList_EnableHighlight(scrollList, "ZO_SelectionHighlight")
|
||||||
|
ZO_Scroll_SetUseFadeGradient(scrollList, false)
|
||||||
|
|
||||||
|
-- adjust scroll content anchor to mimic menu padding
|
||||||
|
local scroll = dropdown.m_dropdown:GetNamedChild("Scroll")
|
||||||
|
local anchor1 = {scroll:GetAnchor(0)}
|
||||||
|
local anchor2 = {scroll:GetAnchor(1)}
|
||||||
|
scroll:ClearAnchors()
|
||||||
|
scroll:SetAnchor(anchor1[2], anchor1[3], anchor1[4], anchor1[5] + PADDING, anchor1[6] + PADDING)
|
||||||
|
scroll:SetAnchor(anchor2[2], anchor2[3], anchor2[4], anchor2[5] - PADDING, anchor2[6] - PADDING)
|
||||||
|
ZO_ScrollList_Commit(scrollList)
|
||||||
|
|
||||||
|
-- hook mouse enter/exit
|
||||||
|
local function onMouseEnter(control) self:OnMouseEnter(control) end
|
||||||
|
local function onMouseExit(control) self:OnMouseExit(control) end
|
||||||
|
|
||||||
|
-- adjust row setup to mimic the highlight padding
|
||||||
|
local dataType1 = ZO_ScrollList_GetDataTypeTable(dropdown.m_scroll, 1)
|
||||||
|
local dataType2 = ZO_ScrollList_GetDataTypeTable(dropdown.m_scroll, 2)
|
||||||
|
local oSetup = dataType1.setupCallback -- both types have the same setup function
|
||||||
|
local function SetupEntry(control, data, list)
|
||||||
|
oSetup(control, data, list)
|
||||||
|
control.m_label:SetAnchor(LEFT, nil, nil, 2)
|
||||||
|
-- no need to store old ones since we have full ownership of our dropdown controls
|
||||||
|
if not control.hookedMouseHandlers then --only do it once per control
|
||||||
|
control.hookedMouseHandlers = true
|
||||||
|
ZO_PreHookHandler(control, "OnMouseEnter", onMouseEnter)
|
||||||
|
ZO_PreHookHandler(control, "OnMouseExit", onMouseExit)
|
||||||
|
-- we could also just replace the handlers
|
||||||
|
--control:SetHandler("OnMouseEnter", onMouseEnter)
|
||||||
|
--control:SetHandler("OnMouseExit", onMouseExit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
dataType1.setupCallback = SetupEntry
|
||||||
|
dataType2.setupCallback = SetupEntry
|
||||||
|
|
||||||
|
-- adjust dimensions based on entries
|
||||||
|
local scrollContent = scroll:GetNamedChild("Contents")
|
||||||
|
ZO_PreHook(dropdown, "AddMenuItems", function()
|
||||||
|
local width = PADDING * 2 + zo_max(self:GetMaxWidth(), combobox:GetWidth())
|
||||||
|
local numItems = #dropdown.m_sortedItems
|
||||||
|
local anchorOffset = 0
|
||||||
|
if(numItems > self.visibleRows) then
|
||||||
|
width = width + CONTENT_PADDING + SCROLLBAR_PADDING
|
||||||
|
anchorOffset = -SCROLLBAR_PADDING
|
||||||
|
numItems = self.visibleRows
|
||||||
|
end
|
||||||
|
scrollContent:SetAnchor(BOTTOMRIGHT, nil, nil, anchorOffset)
|
||||||
|
local height = PADDING * 2 + numItems * (SCROLLABLE_ENTRY_TEMPLATE_HEIGHT + dropdown.m_spacing) - dropdown.m_spacing + ROUNDING_MARGIN
|
||||||
|
dropdown.m_dropdown:SetWidth(width)
|
||||||
|
dropdown.m_dropdown:SetHeight(height)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:OnShow()
|
||||||
|
local dropdown = self.dropdown
|
||||||
|
if dropdown.m_lastParent ~= ZO_Menus then
|
||||||
|
dropdown.m_lastParent = dropdown.m_dropdown:GetParent()
|
||||||
|
dropdown.m_dropdown:SetParent(ZO_Menus)
|
||||||
|
ZO_Menus:BringWindowToTop()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:OnHide()
|
||||||
|
local dropdown = self.dropdown
|
||||||
|
if dropdown.m_lastParent then
|
||||||
|
dropdown.m_dropdown:SetParent(dropdown.m_lastParent)
|
||||||
|
dropdown.m_lastParent = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:DoHide()
|
||||||
|
local dropdown = self.dropdown
|
||||||
|
if dropdown:IsDropdownVisible() then
|
||||||
|
dropdown:HideDropdown()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:GetMaxWidth()
|
||||||
|
local dropdown = self.dropdown
|
||||||
|
local dataType = ZO_ScrollList_GetDataTypeTable(dropdown.m_scroll, 1)
|
||||||
|
|
||||||
|
local dummy = dataType.pool:AcquireObject()
|
||||||
|
dataType.setupCallback(dummy, {
|
||||||
|
m_owner = dropdown,
|
||||||
|
name = "Dummy"
|
||||||
|
}, dropdown)
|
||||||
|
|
||||||
|
local maxWidth = 0
|
||||||
|
local label = dummy.m_label
|
||||||
|
local entries = dropdown.m_sortedItems
|
||||||
|
local numItems = #entries
|
||||||
|
for index = 1, numItems do
|
||||||
|
label:SetText(entries[index].name)
|
||||||
|
local width = label:GetTextWidth()
|
||||||
|
if (width > maxWidth) then
|
||||||
|
maxWidth = width
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
dataType.pool:ReleaseObject(dummy.key)
|
||||||
|
return maxWidth
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScrollableDropdownHelper:OnMouseEnter(control)
|
||||||
|
-- call original code if we replace instead of hook the handler
|
||||||
|
--ZO_ScrollableComboBox_Entry_OnMouseEnter(control)
|
||||||
|
-- show tooltip
|
||||||
|
if control.m_data.tooltip then
|
||||||
|
InitializeTooltip(InformationTooltip, control, TOPLEFT, 0, 0, BOTTOMRIGHT)
|
||||||
|
SetTooltipText(InformationTooltip, LAM.util.GetStringFromValue(control.m_data.tooltip))
|
||||||
|
InformationTooltipTopLevel:BringWindowToTop()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function ScrollableDropdownHelper:OnMouseExit(control)
|
||||||
|
-- call original code if we replace instead of hook the handler
|
||||||
|
--ZO_ScrollableComboBox_Entry_OnMouseExit(control)
|
||||||
|
-- hide tooltip
|
||||||
|
if control.m_data.tooltip then
|
||||||
|
ClearTooltip(InformationTooltip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function LAMCreateControl.dropdown(parent, dropdownData, controlName)
|
function LAMCreateControl.dropdown(parent, dropdownData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, dropdownData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, dropdownData, controlName)
|
||||||
|
control.choices = {}
|
||||||
|
|
||||||
local countControl = parent
|
local countControl = parent
|
||||||
local name = parent:GetName()
|
local name = parent:GetName()
|
||||||
if not name or #name == 0 then
|
if not name or #name == 0 then
|
||||||
countControl = LAMCreateControl
|
countControl = LAMCreateControl
|
||||||
name = "LAM"
|
name = "LAM"
|
||||||
end
|
end
|
||||||
local comboboxCount = (countControl.comboboxCount or 0) + 1
|
local comboboxCount = (countControl.comboboxCount or 0) + 1
|
||||||
countControl.comboboxCount = comboboxCount
|
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, dropdownData.scrollable and "ZO_ScrollableComboBox" or "ZO_ComboBox")
|
||||||
|
|
||||||
local combobox = control.combobox
|
local combobox = control.combobox
|
||||||
combobox:SetAnchor(TOPLEFT)
|
combobox:SetAnchor(TOPLEFT)
|
||||||
combobox:SetDimensions(control.container:GetDimensions())
|
combobox:SetDimensions(control.container:GetDimensions())
|
||||||
combobox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
combobox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
||||||
combobox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end)
|
combobox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end)
|
||||||
control.dropdown = ZO_ComboBox_ObjectFromContainer(combobox)
|
control.dropdown = ZO_ComboBox_ObjectFromContainer(combobox)
|
||||||
local dropdown = control.dropdown
|
local dropdown = control.dropdown
|
||||||
if dropdownData.sort then
|
dropdown:SetSortsItems(false) -- need to sort ourselves in order to be able to sort by value
|
||||||
local sortInfo = GrabSortingInfo(dropdownData.sort)
|
|
||||||
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
|
|
||||||
|
|
||||||
if dropdownData.warning then
|
if dropdownData.scrollable then
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
local visibleRows = type(dropdownData.scrollable) == "number" and dropdownData.scrollable or DEFAULT_VISIBLE_ROWS
|
||||||
control.warning:SetAnchor(RIGHT, combobox, LEFT, -5, 0)
|
control.scrollHelper = ScrollableDropdownHelper:New(parent, control, visibleRows)
|
||||||
control.warning.data = {tooltipText = dropdownData.warning}
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if dropdownData.disabled then
|
ZO_PreHook(dropdown, "UpdateItems", function(self)
|
||||||
control.UpdateDisabled = UpdateDisabled
|
assert(not self.m_sortsItems, "built-in dropdown sorting was reactivated, sorting is handled by LAM")
|
||||||
control:UpdateDisabled()
|
if control.m_sortOrder ~= nil and control.m_sortType then
|
||||||
end
|
local sortKey = next(control.m_sortType)
|
||||||
control.UpdateChoices = UpdateChoices
|
local sortFunc = function(item1, item2) return ZO_TableOrderingFunction(item1, item2, sortKey, control.m_sortType, control.m_sortOrder) end
|
||||||
control:UpdateChoices(dropdownData.choices)
|
table.sort(self.m_sortedItems, sortFunc)
|
||||||
control.UpdateValue = UpdateValue
|
end
|
||||||
control:UpdateValue()
|
end)
|
||||||
|
|
||||||
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
|
if dropdownData.sort then
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
local sortInfo = GrabSortingInfo(dropdownData.sort)
|
||||||
end
|
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
|
||||||
|
end
|
||||||
|
|
||||||
return control
|
if dropdownData.warning ~= nil or dropdownData.requiresReload then
|
||||||
end
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
|
control.warning:SetAnchor(RIGHT, combobox, LEFT, -5, 0)
|
||||||
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
|
control.UpdateChoices = UpdateChoices
|
||||||
|
control:UpdateChoices(dropdownData.choices, dropdownData.choicesValues)
|
||||||
|
control.UpdateValue = UpdateValue
|
||||||
|
control:UpdateValue()
|
||||||
|
if dropdownData.disabled ~= nil then
|
||||||
|
control.UpdateDisabled = UpdateDisabled
|
||||||
|
control:UpdateDisabled()
|
||||||
|
end
|
||||||
|
|
||||||
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
|
|
||||||
|
return control
|
||||||
|
end
|
||||||
|
@ -1,136 +1,156 @@
|
|||||||
--[[editboxData = {
|
--[[editboxData = {
|
||||||
type = "editbox",
|
type = "editbox",
|
||||||
name = "My Editbox",
|
name = "My Editbox", -- or string id or function returning a string
|
||||||
tooltip = "Editbox's tooltip text.",
|
getFunc = function() return db.text end,
|
||||||
getFunc = function() return db.text end,
|
setFunc = function(text) db.text = text doStuff() 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
|
isMultiline = true, --boolean (optional)
|
||||||
width = "full", --or "half" (optional)
|
isExtraWide = true, --boolean (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
width = "full", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
||||||
default = defaults.text, --(optional)
|
warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional)
|
||||||
reference = "MyAddonEditbox" --(optional) unique global reference to control
|
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)
|
||||||
|
reference = "MyAddonEditbox" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 8
|
local widgetVersion = 14
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("editbox", widgetVersion) then return end
|
if not LAM:RegisterWidget("editbox", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = control.data.disabled()
|
||||||
else
|
else
|
||||||
disable = control.data.disabled
|
disable = control.data.disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
if disable then
|
if disable then
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
control.editbox:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
control.editbox:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
control.editbox:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.editbox:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
--control.editbox:SetEditEnabled(not disable)
|
--control.editbox:SetEditEnabled(not disable)
|
||||||
control.editbox:SetMouseEnabled(not disable)
|
control.editbox:SetMouseEnabled(not disable)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, value)
|
local function UpdateValue(control, forceDefault, value)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
value = control.data.default
|
value = LAM.util.GetDefaultValue(control.data.default)
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
control.editbox:SetText(value)
|
control.editbox:SetText(value)
|
||||||
elseif value then
|
elseif value then
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
else
|
||||||
end
|
value = control.data.getFunc()
|
||||||
else
|
control.editbox:SetText(value)
|
||||||
value = control.data.getFunc()
|
end
|
||||||
control.editbox:SetText(value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local MIN_HEIGHT = 26
|
local MIN_HEIGHT = 24
|
||||||
local HALF_WIDTH_LINE_SPACING = 2
|
local HALF_WIDTH_LINE_SPACING = 2
|
||||||
function LAMCreateControl.editbox(parent, editboxData, controlName)
|
function LAMCreateControl.editbox(parent, editboxData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, editboxData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, editboxData, controlName)
|
||||||
|
|
||||||
local container = control.container
|
local container = control.container
|
||||||
control.bg = wm:CreateControlFromVirtual(nil, container, "ZO_EditBackdrop")
|
control.bg = wm:CreateControlFromVirtual(nil, container, "ZO_EditBackdrop")
|
||||||
local bg = control.bg
|
local bg = control.bg
|
||||||
bg:SetAnchorFill()
|
bg:SetAnchorFill()
|
||||||
|
|
||||||
if editboxData.isMultiline then
|
if editboxData.isMultiline then
|
||||||
control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditMultiLineForBackdrop")
|
control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditMultiLineForBackdrop")
|
||||||
control.editbox:SetHandler("OnMouseWheel", function(self, delta)
|
control.editbox:SetHandler("OnMouseWheel", function(self, delta)
|
||||||
if self:HasFocus() then --only set focus to new spots if the editbox is currently in use
|
if self:HasFocus() then --only set focus to new spots if the editbox is currently in use
|
||||||
local cursorPos = self:GetCursorPosition()
|
local cursorPos = self:GetCursorPosition()
|
||||||
local text = self:GetText()
|
local text = self:GetText()
|
||||||
local textLen = text:len()
|
local textLen = text:len()
|
||||||
local newPos
|
local newPos
|
||||||
if delta > 0 then --scrolling up
|
if delta > 0 then --scrolling up
|
||||||
local reverseText = text:reverse()
|
local reverseText = text:reverse()
|
||||||
local revCursorPos = textLen - cursorPos
|
local revCursorPos = textLen - cursorPos
|
||||||
local revPos = reverseText:find("\n", revCursorPos+1)
|
local revPos = reverseText:find("\n", revCursorPos+1)
|
||||||
newPos = revPos and textLen - revPos
|
newPos = revPos and textLen - revPos
|
||||||
else --scrolling down
|
else --scrolling down
|
||||||
newPos = text:find("\n", cursorPos+1)
|
newPos = text:find("\n", cursorPos+1)
|
||||||
end
|
end
|
||||||
if newPos then --if we found a new line, then scroll, otherwise don't
|
if newPos then --if we found a new line, then scroll, otherwise don't
|
||||||
self:SetCursorPosition(newPos)
|
self:SetCursorPosition(newPos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditForBackdrop")
|
control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditForBackdrop")
|
||||||
end
|
end
|
||||||
local editbox = control.editbox
|
local editbox = control.editbox
|
||||||
editbox:SetText(editboxData.getFunc())
|
editbox:SetText(editboxData.getFunc())
|
||||||
editbox:SetMaxInputChars(3000)
|
editbox:SetMaxInputChars(3000)
|
||||||
editbox:SetHandler("OnFocusLost", function(self) control:UpdateValue(false, self:GetText()) end)
|
editbox:SetHandler("OnFocusLost", function(self) control:UpdateValue(false, self:GetText()) end)
|
||||||
editbox:SetHandler("OnEscape", function(self) self:LoseFocus() control:UpdateValue(false, self:GetText()) end)
|
editbox:SetHandler("OnEscape", function(self) self:LoseFocus() control:UpdateValue(false, self:GetText()) end)
|
||||||
editbox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
editbox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
||||||
editbox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end)
|
editbox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end)
|
||||||
|
|
||||||
if not editboxData.isMultiline then
|
local MIN_WIDTH = (parent.GetWidth and (parent:GetWidth() / 10)) or (parent.panel.GetWidth and (parent.panel:GetWidth() / 10)) or 0
|
||||||
container:SetHeight(24)
|
|
||||||
else
|
|
||||||
local width = container:GetWidth()
|
|
||||||
local height = control.isHalfWidth and 74 or 100
|
|
||||||
container:SetHeight(height)
|
|
||||||
editbox:SetDimensionConstraints(width, height, width, 500)
|
|
||||||
|
|
||||||
if control.lineControl then
|
control.label:ClearAnchors()
|
||||||
control.lineControl:SetHeight(MIN_HEIGHT + height + HALF_WIDTH_LINE_SPACING)
|
container:ClearAnchors()
|
||||||
else
|
|
||||||
control:SetHeight(height)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if editboxData.warning then
|
control.label:SetAnchor(TOPLEFT, control, TOPLEFT, 0, 0)
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, 0, 0)
|
||||||
control.warning:SetAnchor(TOPRIGHT, control.bg, TOPLEFT, -5, 0)
|
|
||||||
control.warning.data = {tooltipText = editboxData.warning}
|
|
||||||
end
|
|
||||||
|
|
||||||
if editboxData.disabled then
|
if control.isHalfWidth then
|
||||||
control.UpdateDisabled = UpdateDisabled
|
container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, 0, 0)
|
||||||
control:UpdateDisabled()
|
end
|
||||||
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
|
if editboxData.isExtraWide then
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
container:SetAnchor(BOTTOMLEFT, control, BOTTOMLEFT, 0, 0)
|
||||||
end
|
else
|
||||||
|
container:SetWidth(MIN_WIDTH * 3.2)
|
||||||
|
end
|
||||||
|
|
||||||
return control
|
if editboxData.isMultiline then
|
||||||
end
|
container:SetHeight(MIN_HEIGHT * 3)
|
||||||
|
else
|
||||||
|
container:SetHeight(MIN_HEIGHT)
|
||||||
|
end
|
||||||
|
|
||||||
|
if control.isHalfWidth ~= true and editboxData.isExtraWide ~= true then
|
||||||
|
control:SetHeight(container:GetHeight())
|
||||||
|
else
|
||||||
|
control:SetHeight(container:GetHeight() + control.label:GetHeight())
|
||||||
|
end
|
||||||
|
|
||||||
|
editbox:ClearAnchors()
|
||||||
|
editbox:SetAnchor(TOPLEFT, container, TOPLEFT, 2, 2)
|
||||||
|
editbox:SetAnchor(BOTTOMRIGHT, container, BOTTOMRIGHT, -2, -2)
|
||||||
|
|
||||||
|
if editboxData.warning ~= nil or editboxData.requiresReload then
|
||||||
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
|
if editboxData.isExtraWide then
|
||||||
|
control.warning:SetAnchor(BOTTOMRIGHT, control.bg, TOPRIGHT, 2, 0)
|
||||||
|
else
|
||||||
|
control.warning:SetAnchor(TOPRIGHT, control.bg, TOPLEFT, -5, 0)
|
||||||
|
end
|
||||||
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
|
control.UpdateValue = UpdateValue
|
||||||
|
control:UpdateValue()
|
||||||
|
if editboxData.disabled ~= nil then
|
||||||
|
control.UpdateDisabled = UpdateDisabled
|
||||||
|
control:UpdateDisabled()
|
||||||
|
end
|
||||||
|
|
||||||
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
|
|
||||||
|
return control
|
||||||
|
end
|
||||||
|
@ -1,45 +1,42 @@
|
|||||||
--[[headerData = {
|
--[[headerData = {
|
||||||
type = "header",
|
type = "header",
|
||||||
name = "My Header",
|
name = "My Header", -- or string id or function returning a string
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
reference = "MyAddonHeader" --(optional) unique global reference to control
|
reference = "MyAddonHeader" -- unique global reference to control (optional)
|
||||||
} ]]
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 6
|
local widgetVersion = 8
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("header", widgetVersion) then return end
|
if not LAM:RegisterWidget("header", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local function UpdateValue(control)
|
local function UpdateValue(control)
|
||||||
control.header:SetText(control.data.name)
|
control.header:SetText(LAM.util.GetStringFromValue(control.data.name))
|
||||||
end
|
end
|
||||||
|
|
||||||
local MIN_HEIGHT = 30
|
local MIN_HEIGHT = 30
|
||||||
function LAMCreateControl.header(parent, headerData, controlName)
|
function LAMCreateControl.header(parent, headerData, controlName)
|
||||||
local control = LAM.util.CreateBaseControl(parent, headerData, controlName)
|
local control = LAM.util.CreateBaseControl(parent, headerData, controlName)
|
||||||
local isHalfWidth = control.isHalfWidth
|
local isHalfWidth = control.isHalfWidth
|
||||||
local width = control:GetWidth()
|
local width = control:GetWidth()
|
||||||
control:SetDimensions(isHalfWidth and width / 2 or width, MIN_HEIGHT)
|
control:SetDimensions(isHalfWidth and width / 2 or width, MIN_HEIGHT)
|
||||||
|
|
||||||
control.divider = wm:CreateControlFromVirtual(nil, control, "ZO_Options_Divider")
|
control.divider = wm:CreateControlFromVirtual(nil, control, "ZO_Options_Divider")
|
||||||
local divider = control.divider
|
local divider = control.divider
|
||||||
divider:SetWidth(isHalfWidth and width / 2 or width)
|
divider:SetWidth(isHalfWidth and width / 2 or width)
|
||||||
divider:SetAnchor(TOPLEFT)
|
divider:SetAnchor(TOPLEFT)
|
||||||
|
|
||||||
control.header = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel")
|
control.header = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel")
|
||||||
local header = control.header
|
local header = control.header
|
||||||
header:SetAnchor(TOPLEFT, divider, BOTTOMLEFT)
|
header:SetAnchor(TOPLEFT, divider, BOTTOMLEFT)
|
||||||
header:SetAnchor(BOTTOMRIGHT)
|
header:SetAnchor(BOTTOMRIGHT)
|
||||||
header:SetText(headerData.name)
|
header:SetText(LAM.util.GetStringFromValue(headerData.name))
|
||||||
|
|
||||||
control.UpdateValue = UpdateValue
|
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,441 +1,436 @@
|
|||||||
--[[iconpickerData = {
|
--[[iconpickerData = {
|
||||||
type = "iconpicker",
|
type = "iconpicker",
|
||||||
name = "My Icon Picker",
|
name = "My Icon Picker", -- or string id or function returning a string
|
||||||
tooltip = "Color Picker's tooltip text.",
|
choices = {"texture path 1", "texture path 2", "texture path 3"},
|
||||||
choices = {"texture path 1", "texture path 2", "texture path 3"},
|
getFunc = function() return db.var end,
|
||||||
choicesTooltips = {"icon tooltip 1", "icon tooltip 2", "icon tooltip 3"}, --(optional)
|
setFunc = function(var) db.var = var doStuff() end,
|
||||||
getFunc = function() return db.var end,
|
tooltip = "Color Picker's tooltip text.", -- or string id or function returning a string (optional)
|
||||||
setFunc = function(var) db.var = var doStuff() end,
|
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, --(optional) number of icons in one row
|
maxColumns = 5, -- number of icons in one row (optional)
|
||||||
visibleRows = 4.5, --(optional) number of visible rows
|
visibleRows = 4.5, -- number of visible rows (optional)
|
||||||
iconSize = 28, --(optional) size of the icons
|
iconSize = 28, -- size of the icons (optional)
|
||||||
defaultColor = ZO_ColorDef:New("FFFFFF"), --(optional) default color of the icons
|
defaultColor = ZO_ColorDef:New("FFFFFF"), -- default color of the icons (optional)
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
beforeShow = function(control, iconPicker) return preventShow end, --(optional)
|
beforeShow = function(control, iconPicker) return preventShow end, --(optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional)
|
||||||
default = defaults.var, --(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)
|
||||||
reference = "MyAddonIconPicker" --(optional) unique global reference to control
|
default = defaults.var, -- default value or function that returns the default value (optional)
|
||||||
} ]]
|
reference = "MyAddonIconPicker" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
local widgetVersion = 2
|
local widgetVersion = 8
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("iconpicker", widgetVersion) then return end
|
if not LAM:RegisterWidget("iconpicker", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local IconPickerMenu = ZO_Object:Subclass()
|
local IconPickerMenu = ZO_Object:Subclass()
|
||||||
local iconPicker
|
local iconPicker
|
||||||
LAM.util.GetIconPickerMenu = function()
|
LAM.util.GetIconPickerMenu = function()
|
||||||
if not iconPicker then
|
if not iconPicker then
|
||||||
iconPicker = IconPickerMenu:New("LAMIconPicker")
|
iconPicker = IconPickerMenu:New("LAMIconPicker")
|
||||||
local sceneFragment = LAM:GetAddonSettingsFragment()
|
local sceneFragment = LAM:GetAddonSettingsFragment()
|
||||||
ZO_PreHook(sceneFragment, "OnHidden", function()
|
ZO_PreHook(sceneFragment, "OnHidden", function()
|
||||||
if not iconPicker.control:IsHidden() then
|
if not iconPicker.control:IsHidden() then
|
||||||
iconPicker:Clear()
|
iconPicker:Clear()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
return iconPicker
|
return iconPicker
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:New(...)
|
function IconPickerMenu:New(...)
|
||||||
local object = ZO_Object.New(self)
|
local object = ZO_Object.New(self)
|
||||||
object:Initialize(...)
|
object:Initialize(...)
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:Initialize(name)
|
function IconPickerMenu:Initialize(name)
|
||||||
local control = wm:CreateTopLevelWindow(name)
|
local control = wm:CreateTopLevelWindow(name)
|
||||||
control:SetDrawTier(DT_HIGH)
|
control:SetDrawTier(DT_HIGH)
|
||||||
control:SetHidden(true)
|
control:SetHidden(true)
|
||||||
self.control = control
|
self.control = control
|
||||||
|
|
||||||
local scrollContainer = wm:CreateControlFromVirtual(name .. "ScrollContainer", control, "ZO_ScrollContainer")
|
local scrollContainer = wm:CreateControlFromVirtual(name .. "ScrollContainer", control, "ZO_ScrollContainer")
|
||||||
-- control:SetDimensions(control.container:GetWidth(), height) -- adjust to icon size / col count
|
-- control:SetDimensions(control.container:GetWidth(), height) -- adjust to icon size / col count
|
||||||
scrollContainer:SetAnchorFill()
|
scrollContainer:SetAnchorFill()
|
||||||
ZO_Scroll_SetUseFadeGradient(scrollContainer, false)
|
ZO_Scroll_SetUseFadeGradient(scrollContainer, false)
|
||||||
ZO_Scroll_SetHideScrollbarOnDisable(scrollContainer, false)
|
ZO_Scroll_SetHideScrollbarOnDisable(scrollContainer, false)
|
||||||
ZO_VerticalScrollbarBase_OnMouseExit(scrollContainer:GetNamedChild("ScrollBar")) -- scrollbar initialization seems to be broken so we force it to update the correct alpha value
|
ZO_VerticalScrollbarBase_OnMouseExit(scrollContainer:GetNamedChild("ScrollBar")) -- scrollbar initialization seems to be broken so we force it to update the correct alpha value
|
||||||
local scroll = GetControl(scrollContainer, "ScrollChild")
|
local scroll = GetControl(scrollContainer, "ScrollChild")
|
||||||
self.scroll = scroll
|
self.scroll = scroll
|
||||||
self.scrollContainer = scrollContainer
|
self.scrollContainer = scrollContainer
|
||||||
|
|
||||||
local bg = wm:CreateControl(nil, scrollContainer, CT_BACKDROP)
|
local bg = wm:CreateControl(nil, scrollContainer, CT_BACKDROP)
|
||||||
bg:SetAnchor(TOPLEFT, scrollContainer, TOPLEFT, 0, -3)
|
bg:SetAnchor(TOPLEFT, scrollContainer, TOPLEFT, 0, -3)
|
||||||
bg:SetAnchor(BOTTOMRIGHT, scrollContainer, BOTTOMRIGHT, 2, 5)
|
bg:SetAnchor(BOTTOMRIGHT, scrollContainer, BOTTOMRIGHT, 2, 5)
|
||||||
bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16)
|
bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16)
|
||||||
bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds")
|
bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds")
|
||||||
bg:SetInsets(16, 16, -16, -16)
|
bg:SetInsets(16, 16, -16, -16)
|
||||||
|
|
||||||
local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE)
|
local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE)
|
||||||
mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds")
|
mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds")
|
||||||
mungeOverlay:SetDrawLevel(1)
|
mungeOverlay:SetDrawLevel(1)
|
||||||
mungeOverlay:SetAddressMode(TEX_MODE_WRAP)
|
mungeOverlay:SetAddressMode(TEX_MODE_WRAP)
|
||||||
mungeOverlay:SetAnchorFill()
|
mungeOverlay:SetAnchorFill()
|
||||||
|
|
||||||
local mouseOver = wm:CreateControl(nil, scrollContainer, CT_TEXTURE)
|
local mouseOver = wm:CreateControl(nil, scrollContainer, CT_TEXTURE)
|
||||||
mouseOver:SetDrawLevel(2)
|
mouseOver:SetDrawLevel(2)
|
||||||
mouseOver:SetTexture("EsoUI/Art/Buttons/minmax_mouseover.dds")
|
mouseOver:SetTexture("EsoUI/Art/Buttons/minmax_mouseover.dds")
|
||||||
mouseOver:SetHidden(true)
|
mouseOver:SetHidden(true)
|
||||||
|
|
||||||
local function IconFactory(pool)
|
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)
|
||||||
icon:SetMouseEnabled(true)
|
icon:SetMouseEnabled(true)
|
||||||
icon:SetDrawLevel(3)
|
icon:SetDrawLevel(3)
|
||||||
icon:SetHandler("OnMouseEnter", function()
|
icon:SetHandler("OnMouseEnter", function()
|
||||||
mouseOver:SetAnchor(TOPLEFT, icon, TOPLEFT, 0, 0)
|
mouseOver:SetAnchor(TOPLEFT, icon, TOPLEFT, 0, 0)
|
||||||
mouseOver:SetAnchor(BOTTOMRIGHT, icon, BOTTOMRIGHT, 0, 0)
|
mouseOver:SetAnchor(BOTTOMRIGHT, icon, BOTTOMRIGHT, 0, 0)
|
||||||
mouseOver:SetHidden(false)
|
mouseOver:SetHidden(false)
|
||||||
if self.customOnMouseEnter then
|
if self.customOnMouseEnter then
|
||||||
self.customOnMouseEnter(icon)
|
self.customOnMouseEnter(icon)
|
||||||
else
|
else
|
||||||
self:OnMouseEnter(icon)
|
self:OnMouseEnter(icon)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
icon:SetHandler("OnMouseExit", function()
|
icon:SetHandler("OnMouseExit", function()
|
||||||
mouseOver:ClearAnchors()
|
mouseOver:ClearAnchors()
|
||||||
mouseOver:SetHidden(true)
|
mouseOver:SetHidden(true)
|
||||||
if self.customOnMouseExit then
|
if self.customOnMouseExit then
|
||||||
self.customOnMouseExit(icon)
|
self.customOnMouseExit(icon)
|
||||||
else
|
else
|
||||||
self:OnMouseExit(icon)
|
self:OnMouseExit(icon)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
icon:SetHandler("OnMouseUp", function(control, ...)
|
icon:SetHandler("OnMouseUp", function(control, ...)
|
||||||
PlaySound("Click")
|
PlaySound("Click")
|
||||||
icon.OnSelect(icon, icon.texture)
|
icon.OnSelect(icon, icon.texture)
|
||||||
self:Clear()
|
self:Clear()
|
||||||
end)
|
end)
|
||||||
return icon
|
return icon
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ResetFunction(icon)
|
local function ResetFunction(icon)
|
||||||
icon:ClearAnchors()
|
icon:ClearAnchors()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.iconPool = ZO_ObjectPool:New(IconFactory, ResetFunction)
|
self.iconPool = ZO_ObjectPool:New(IconFactory, ResetFunction)
|
||||||
self:SetMaxColumns(1)
|
self:SetMaxColumns(1)
|
||||||
self.icons = {}
|
self.icons = {}
|
||||||
self.color = ZO_DEFAULT_ENABLED_COLOR
|
self.color = ZO_DEFAULT_ENABLED_COLOR
|
||||||
|
|
||||||
EVENT_MANAGER:RegisterForEvent(name .. "_OnGlobalMouseUp", EVENT_GLOBAL_MOUSE_UP, function()
|
EVENT_MANAGER:RegisterForEvent(name .. "_OnGlobalMouseUp", EVENT_GLOBAL_MOUSE_UP, function()
|
||||||
if self.refCount ~= nil then
|
if self.refCount ~= nil then
|
||||||
local moc = wm:GetMouseOverControl()
|
local moc = wm:GetMouseOverControl()
|
||||||
if(moc:GetOwningWindow() ~= control) then
|
if(moc:GetOwningWindow() ~= control) then
|
||||||
self.refCount = self.refCount - 1
|
self.refCount = self.refCount - 1
|
||||||
if self.refCount <= 0 then
|
if self.refCount <= 0 then
|
||||||
self:Clear()
|
self:Clear()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:OnMouseEnter(icon)
|
function IconPickerMenu:OnMouseEnter(icon)
|
||||||
InitializeTooltip(InformationTooltip, icon, TOPLEFT, 0, 0, BOTTOMRIGHT)
|
InitializeTooltip(InformationTooltip, icon, TOPLEFT, 0, 0, BOTTOMRIGHT)
|
||||||
SetTooltipText(InformationTooltip, LAM.util.GetTooltipText(icon.tooltip))
|
SetTooltipText(InformationTooltip, LAM.util.GetStringFromValue(icon.tooltip))
|
||||||
InformationTooltipTopLevel:BringWindowToTop()
|
InformationTooltipTopLevel:BringWindowToTop()
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:OnMouseExit(icon)
|
function IconPickerMenu:OnMouseExit(icon)
|
||||||
ClearTooltip(InformationTooltip)
|
ClearTooltip(InformationTooltip)
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:SetMaxColumns(value)
|
function IconPickerMenu:SetMaxColumns(value)
|
||||||
self.maxCols = value ~= nil and value or 5
|
self.maxCols = value ~= nil and value or 5
|
||||||
end
|
end
|
||||||
|
|
||||||
local DEFAULT_SIZE = 28
|
local DEFAULT_SIZE = 28
|
||||||
function IconPickerMenu:SetIconSize(value)
|
function IconPickerMenu:SetIconSize(value)
|
||||||
local iconSize = DEFAULT_SIZE
|
local iconSize = DEFAULT_SIZE
|
||||||
if value ~= nil then iconSize = math.max(iconSize, value) end
|
if value ~= nil then iconSize = math.max(iconSize, value) end
|
||||||
self.iconSize = iconSize
|
self.iconSize = iconSize
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:SetVisibleRows(value)
|
function IconPickerMenu:SetVisibleRows(value)
|
||||||
self.visibleRows = value ~= nil and value or 4.5
|
self.visibleRows = value ~= nil and value or 4.5
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:SetMouseHandlers(onEnter, onExit)
|
function IconPickerMenu:SetMouseHandlers(onEnter, onExit)
|
||||||
self.customOnMouseEnter = onEnter
|
self.customOnMouseEnter = onEnter
|
||||||
self.customOnMouseExit = onExit
|
self.customOnMouseExit = onExit
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:UpdateDimensions()
|
function IconPickerMenu:UpdateDimensions()
|
||||||
local iconSize = self.iconSize
|
local iconSize = self.iconSize
|
||||||
local width = iconSize * self.maxCols + 20
|
local width = iconSize * self.maxCols + 20
|
||||||
local height = iconSize * self.visibleRows
|
local height = iconSize * self.visibleRows
|
||||||
self.control:SetDimensions(width, height)
|
self.control:SetDimensions(width, height)
|
||||||
|
|
||||||
local icons = self.icons
|
local icons = self.icons
|
||||||
for i = 1, #icons do
|
for i = 1, #icons do
|
||||||
local icon = icons[i]
|
local icon = icons[i]
|
||||||
icon:SetDimensions(iconSize, iconSize)
|
icon:SetDimensions(iconSize, iconSize)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:UpdateAnchors()
|
function IconPickerMenu:UpdateAnchors()
|
||||||
local iconSize = self.iconSize
|
local iconSize = self.iconSize
|
||||||
local col, maxCols = 1, self.maxCols
|
local col, maxCols = 1, self.maxCols
|
||||||
local previousCol, previousRow
|
local previousCol, previousRow
|
||||||
local scroll = self.scroll
|
local scroll = self.scroll
|
||||||
local icons = self.icons
|
local icons = self.icons
|
||||||
|
|
||||||
for i = 1, #icons do
|
for i = 1, #icons do
|
||||||
local icon = icons[i]
|
local icon = icons[i]
|
||||||
icon:ClearAnchors()
|
icon:ClearAnchors()
|
||||||
if i == 1 then
|
if i == 1 then
|
||||||
icon:SetAnchor(TOPLEFT, scroll, TOPLEFT, 0, 0)
|
icon:SetAnchor(TOPLEFT, scroll, TOPLEFT, 0, 0)
|
||||||
previousRow = icon
|
previousRow = icon
|
||||||
elseif col == 1 then
|
elseif col == 1 then
|
||||||
icon:SetAnchor(TOPLEFT, previousRow, BOTTOMLEFT, 0, 0)
|
icon:SetAnchor(TOPLEFT, previousRow, BOTTOMLEFT, 0, 0)
|
||||||
previousRow = icon
|
previousRow = icon
|
||||||
else
|
else
|
||||||
icon:SetAnchor(TOPLEFT, previousCol, TOPRIGHT, 0, 0)
|
icon:SetAnchor(TOPLEFT, previousCol, TOPRIGHT, 0, 0)
|
||||||
end
|
end
|
||||||
previousCol = icon
|
previousCol = icon
|
||||||
col = col >= maxCols and 1 or col + 1
|
col = col >= maxCols and 1 or col + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:Clear()
|
function IconPickerMenu:Clear()
|
||||||
self.icons = {}
|
self.icons = {}
|
||||||
self.iconPool:ReleaseAllObjects()
|
self.iconPool:ReleaseAllObjects()
|
||||||
self.control:SetHidden(true)
|
self.control:SetHidden(true)
|
||||||
self.color = ZO_DEFAULT_ENABLED_COLOR
|
self.color = ZO_DEFAULT_ENABLED_COLOR
|
||||||
self.refCount = nil
|
self.refCount = nil
|
||||||
self.parent = nil
|
self.parent = nil
|
||||||
self.customOnMouseEnter = nil
|
self.customOnMouseEnter = nil
|
||||||
self.customOnMouseExit = nil
|
self.customOnMouseExit = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:AddIcon(texturePath, callback, tooltip)
|
function IconPickerMenu:AddIcon(texturePath, callback, tooltip)
|
||||||
local icon, key = self.iconPool:AcquireObject()
|
local icon, key = self.iconPool:AcquireObject()
|
||||||
icon:SetTexture(texturePath)
|
icon:SetTexture(texturePath)
|
||||||
icon:SetColor(self.color:UnpackRGBA())
|
icon:SetColor(self.color:UnpackRGBA())
|
||||||
icon.texture = texturePath
|
icon.texture = texturePath
|
||||||
icon.tooltip = tooltip
|
icon.tooltip = tooltip
|
||||||
icon.OnSelect = callback
|
icon.OnSelect = callback
|
||||||
self.icons[#self.icons + 1] = icon
|
self.icons[#self.icons + 1] = icon
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:Show(parent)
|
function IconPickerMenu:Show(parent)
|
||||||
if #self.icons == 0 then return false end
|
if #self.icons == 0 then return false end
|
||||||
if not self.control:IsHidden() then self:Clear() return false end
|
if not self.control:IsHidden() then self:Clear() return false end
|
||||||
self:UpdateDimensions()
|
self:UpdateDimensions()
|
||||||
self:UpdateAnchors()
|
self:UpdateAnchors()
|
||||||
|
|
||||||
local control = self.control
|
local control = self.control
|
||||||
control:ClearAnchors()
|
control:ClearAnchors()
|
||||||
control:SetAnchor(TOPLEFT, parent, BOTTOMLEFT, 0, 8)
|
control:SetAnchor(TOPLEFT, parent, BOTTOMLEFT, 0, 8)
|
||||||
control:SetHidden(false)
|
control:SetHidden(false)
|
||||||
control:BringWindowToTop()
|
control:BringWindowToTop()
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.refCount = 2
|
self.refCount = 2
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function IconPickerMenu:SetColor(color)
|
function IconPickerMenu:SetColor(color)
|
||||||
local icons = self.icons
|
local icons = self.icons
|
||||||
self.color = color
|
self.color = color
|
||||||
for i = 1, #icons do
|
for i = 1, #icons do
|
||||||
local icon = icons[i]
|
local icon = icons[i]
|
||||||
icon:SetColor(color:UnpackRGBA())
|
icon:SetColor(color:UnpackRGBA())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|
||||||
local function UpdateChoices(control, choices, choicesTooltips)
|
local function UpdateChoices(control, choices, choicesTooltips)
|
||||||
local data = control.data
|
local data = control.data
|
||||||
if not choices then
|
if not choices then
|
||||||
choices, choicesTooltips = data.choices, data.choicesTooltips
|
choices, choicesTooltips = data.choices, data.choicesTooltips or {}
|
||||||
end
|
end
|
||||||
local addedChoices = {}
|
local addedChoices = {}
|
||||||
|
|
||||||
local iconPicker = LAM.util.GetIconPickerMenu()
|
local iconPicker = LAM.util.GetIconPickerMenu()
|
||||||
iconPicker:Clear()
|
iconPicker:Clear()
|
||||||
for i = 1, #choices do
|
for i = 1, #choices do
|
||||||
local texture = choices[i]
|
local texture = choices[i]
|
||||||
if not addedChoices[texture] then -- remove duplicates
|
if not addedChoices[texture] then -- remove duplicates
|
||||||
iconPicker:AddIcon(choices[i], function(self, texture)
|
iconPicker:AddIcon(choices[i], function(self, texture)
|
||||||
control.icon:SetTexture(texture)
|
control.icon:SetTexture(texture)
|
||||||
data.setFunc(texture)
|
data.setFunc(texture)
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
end, LAM.util.GetStringFromValue(choicesTooltips[i]))
|
||||||
end
|
addedChoices[texture] = true
|
||||||
end, choicesTooltips[i])
|
end
|
||||||
addedChoices[texture] = true
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function IsDisabled(control)
|
local function IsDisabled(control)
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
return control.data.disabled()
|
return control.data.disabled()
|
||||||
else
|
else
|
||||||
return control.data.disabled
|
return control.data.disabled
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function SetColor(control, color)
|
local function SetColor(control, color)
|
||||||
local icon = control.icon
|
local icon = control.icon
|
||||||
if IsDisabled(control) then
|
if IsDisabled(control) then
|
||||||
icon:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
icon:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
icon.color = color or control.data.defaultColor or ZO_DEFAULT_ENABLED_COLOR
|
icon.color = color or control.data.defaultColor or ZO_DEFAULT_ENABLED_COLOR
|
||||||
icon:SetColor(icon.color:UnpackRGBA())
|
icon:SetColor(icon.color:UnpackRGBA())
|
||||||
end
|
end
|
||||||
|
|
||||||
local iconPicker = LAM.util.GetIconPickerMenu()
|
local iconPicker = LAM.util.GetIconPickerMenu()
|
||||||
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
||||||
iconPicker:SetColor(icon.color)
|
iconPicker:SetColor(icon.color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable = IsDisabled(control)
|
local disable = IsDisabled(control)
|
||||||
|
|
||||||
control.dropdown:SetMouseEnabled(not disable)
|
control.dropdown:SetMouseEnabled(not disable)
|
||||||
control.dropdownButton:SetEnabled(not disable)
|
control.dropdownButton:SetEnabled(not disable)
|
||||||
|
|
||||||
local iconPicker = LAM.util.GetIconPickerMenu()
|
local iconPicker = LAM.util.GetIconPickerMenu()
|
||||||
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
||||||
iconPicker:Clear()
|
iconPicker:Clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
SetColor(control)
|
SetColor(control, control.icon.color)
|
||||||
if disable then
|
if disable then
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, value)
|
local function UpdateValue(control, forceDefault, value)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
value = control.data.default
|
value = LAM.util.GetDefaultValue(control.data.default)
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
control.icon:SetTexture(value)
|
control.icon:SetTexture(value)
|
||||||
elseif value then
|
elseif value then
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
if control.panel.data.registerForRefresh then
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
else
|
||||||
end
|
value = control.data.getFunc()
|
||||||
else
|
control.icon:SetTexture(value)
|
||||||
value = control.data.getFunc()
|
end
|
||||||
control.icon:SetTexture(value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local MIN_HEIGHT = 26
|
local MIN_HEIGHT = 26
|
||||||
local HALF_WIDTH_LINE_SPACING = 2
|
local HALF_WIDTH_LINE_SPACING = 2
|
||||||
local function SetIconSize(control, size)
|
local function SetIconSize(control, size)
|
||||||
local icon = control.icon
|
local icon = control.icon
|
||||||
icon.size = size
|
icon.size = size
|
||||||
icon:SetDimensions(size, size)
|
icon:SetDimensions(size, size)
|
||||||
|
|
||||||
local height = size + 4
|
local height = size + 4
|
||||||
control.dropdown:SetDimensions(size + 20, height)
|
control.dropdown:SetDimensions(size + 20, height)
|
||||||
height = math.max(height, MIN_HEIGHT)
|
height = math.max(height, MIN_HEIGHT)
|
||||||
control.container:SetHeight(height)
|
control.container:SetHeight(height)
|
||||||
if control.lineControl then
|
if control.lineControl then
|
||||||
control.lineControl:SetHeight(MIN_HEIGHT + size + HALF_WIDTH_LINE_SPACING)
|
control.lineControl:SetHeight(MIN_HEIGHT + size + HALF_WIDTH_LINE_SPACING)
|
||||||
else
|
else
|
||||||
control:SetHeight(height)
|
control:SetHeight(height)
|
||||||
end
|
end
|
||||||
|
|
||||||
local iconPicker = LAM.util.GetIconPickerMenu()
|
local iconPicker = LAM.util.GetIconPickerMenu()
|
||||||
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
if iconPicker.parent == control.container and not iconPicker.control:IsHidden() then
|
||||||
iconPicker:SetIconSize(size)
|
iconPicker:SetIconSize(size)
|
||||||
iconPicker:UpdateDimensions()
|
iconPicker:UpdateDimensions()
|
||||||
iconPicker:UpdateAnchors()
|
iconPicker:UpdateAnchors()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function LAMCreateControl.iconpicker(parent, iconpickerData, controlName)
|
function LAMCreateControl.iconpicker(parent, iconpickerData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, iconpickerData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, iconpickerData, controlName)
|
||||||
|
|
||||||
local function ShowIconPicker()
|
local function ShowIconPicker()
|
||||||
local iconPicker = LAM.util.GetIconPickerMenu()
|
local iconPicker = LAM.util.GetIconPickerMenu()
|
||||||
if iconPicker.parent == control.container then
|
if iconPicker.parent == control.container then
|
||||||
iconPicker:Clear()
|
iconPicker:Clear()
|
||||||
else
|
else
|
||||||
iconPicker:SetMaxColumns(iconpickerData.maxColumns)
|
iconPicker:SetMaxColumns(iconpickerData.maxColumns)
|
||||||
iconPicker:SetVisibleRows(iconpickerData.visibleRows)
|
iconPicker:SetVisibleRows(iconpickerData.visibleRows)
|
||||||
iconPicker:SetIconSize(control.icon.size)
|
iconPicker:SetIconSize(control.icon.size)
|
||||||
UpdateChoices(control)
|
UpdateChoices(control)
|
||||||
iconPicker:SetColor(control.icon.color)
|
iconPicker:SetColor(control.icon.color)
|
||||||
if iconpickerData.beforeShow then
|
if iconpickerData.beforeShow then
|
||||||
if iconpickerData.beforeShow(control, iconPicker) then
|
if iconpickerData.beforeShow(control, iconPicker) then
|
||||||
iconPicker:Clear()
|
iconPicker:Clear()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
iconPicker:Show(control.container)
|
iconPicker:Show(control.container)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local iconSize = iconpickerData.iconSize ~= nil and iconpickerData.iconSize or DEFAULT_SIZE
|
local iconSize = iconpickerData.iconSize ~= nil and iconpickerData.iconSize or DEFAULT_SIZE
|
||||||
control.dropdown = wm:CreateControl(nil, control.container, CT_CONTROL)
|
control.dropdown = wm:CreateControl(nil, control.container, CT_CONTROL)
|
||||||
local dropdown = control.dropdown
|
local dropdown = control.dropdown
|
||||||
dropdown:SetAnchor(LEFT, control.container, LEFT, 0, 0)
|
dropdown:SetAnchor(LEFT, control.container, LEFT, 0, 0)
|
||||||
dropdown:SetMouseEnabled(true)
|
dropdown:SetMouseEnabled(true)
|
||||||
dropdown:SetHandler("OnMouseUp", ShowIconPicker)
|
dropdown:SetHandler("OnMouseUp", ShowIconPicker)
|
||||||
dropdown:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
dropdown:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
||||||
dropdown:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(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)
|
||||||
local icon = control.icon
|
local icon = control.icon
|
||||||
icon:SetAnchor(LEFT, dropdown, LEFT, 3, 0)
|
icon:SetAnchor(LEFT, dropdown, LEFT, 3, 0)
|
||||||
icon:SetDrawLevel(2)
|
icon:SetDrawLevel(2)
|
||||||
|
|
||||||
local dropdownButton = wm:CreateControlFromVirtual(nil, dropdown, "ZO_DropdownButton")
|
local dropdownButton = wm:CreateControlFromVirtual(nil, dropdown, "ZO_DropdownButton")
|
||||||
dropdownButton:SetDimensions(16, 16)
|
dropdownButton:SetDimensions(16, 16)
|
||||||
dropdownButton:SetHandler("OnClicked", ShowIconPicker)
|
dropdownButton:SetHandler("OnClicked", ShowIconPicker)
|
||||||
dropdownButton:SetAnchor(RIGHT, dropdown, RIGHT, -3, 0)
|
dropdownButton:SetAnchor(RIGHT, dropdown, RIGHT, -3, 0)
|
||||||
control.dropdownButton = dropdownButton
|
control.dropdownButton = dropdownButton
|
||||||
|
|
||||||
control.bg = wm:CreateControl(nil, dropdown, CT_BACKDROP)
|
control.bg = wm:CreateControl(nil, dropdown, CT_BACKDROP)
|
||||||
local bg = control.bg
|
local bg = control.bg
|
||||||
bg:SetAnchor(TOPLEFT, dropdown, TOPLEFT, 0, -3)
|
bg:SetAnchor(TOPLEFT, dropdown, TOPLEFT, 0, -3)
|
||||||
bg:SetAnchor(BOTTOMRIGHT, dropdown, BOTTOMRIGHT, 2, 5)
|
bg:SetAnchor(BOTTOMRIGHT, dropdown, BOTTOMRIGHT, 2, 5)
|
||||||
bg:SetEdgeTexture("EsoUI/Art/Tooltips/UI-Border.dds", 128, 16)
|
bg:SetEdgeTexture("EsoUI/Art/Tooltips/UI-Border.dds", 128, 16)
|
||||||
bg:SetCenterTexture("EsoUI/Art/Tooltips/UI-TooltipCenter.dds")
|
bg:SetCenterTexture("EsoUI/Art/Tooltips/UI-TooltipCenter.dds")
|
||||||
bg:SetInsets(16, 16, -16, -16)
|
bg:SetInsets(16, 16, -16, -16)
|
||||||
local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE)
|
local mungeOverlay = wm:CreateControl(nil, bg, CT_TEXTURE)
|
||||||
mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds")
|
mungeOverlay:SetTexture("EsoUI/Art/Tooltips/munge_overlay.dds")
|
||||||
mungeOverlay:SetDrawLevel(1)
|
mungeOverlay:SetDrawLevel(1)
|
||||||
mungeOverlay:SetAddressMode(TEX_MODE_WRAP)
|
mungeOverlay:SetAddressMode(TEX_MODE_WRAP)
|
||||||
mungeOverlay:SetAnchorFill()
|
mungeOverlay:SetAnchorFill()
|
||||||
|
|
||||||
if iconpickerData.warning then
|
if iconpickerData.warning ~= nil or iconpickerData.requiresReload then
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
control.warning:SetAnchor(RIGHT, control.container, LEFT, -5, 0)
|
control.warning:SetAnchor(RIGHT, control.container, LEFT, -5, 0)
|
||||||
control.warning.data = {tooltipText = iconpickerData.warning}
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
end
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
if iconpickerData.disabled then
|
|
||||||
control.UpdateDisabled = UpdateDisabled
|
|
||||||
control:UpdateDisabled()
|
|
||||||
end
|
|
||||||
|
|
||||||
control.UpdateChoices = UpdateChoices
|
|
||||||
control.UpdateValue = UpdateValue
|
|
||||||
control:UpdateValue()
|
|
||||||
control.SetColor = SetColor
|
|
||||||
control:SetColor()
|
|
||||||
control.SetIconSize = SetIconSize
|
|
||||||
control:SetIconSize(iconSize)
|
|
||||||
|
|
||||||
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
|
control.UpdateChoices = UpdateChoices
|
||||||
|
control.UpdateValue = UpdateValue
|
||||||
|
control:UpdateValue()
|
||||||
|
control.SetColor = SetColor
|
||||||
|
control:SetColor()
|
||||||
|
control.SetIconSize = SetIconSize
|
||||||
|
control:SetIconSize(iconSize)
|
||||||
|
|
||||||
|
if iconpickerData.disabled ~= nil then
|
||||||
|
control.UpdateDisabled = UpdateDisabled
|
||||||
|
control:UpdateDisabled()
|
||||||
|
end
|
||||||
|
|
||||||
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
|
|
||||||
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
--[[panelData = {
|
--[[panelData = {
|
||||||
type = "panel",
|
type = "panel",
|
||||||
name = "Window Title",
|
name = "Window Title", -- or string id or function returning a string
|
||||||
displayName = "My Longer Window Title", --(optional) (can be useful for long addon names or if you want to colorize it)
|
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", --(optional)
|
author = "Seerah", -- or string id or function returning a string (optional)
|
||||||
version = "2.0", --(optional)
|
version = "2.0", -- or string id or function returning a string (optional)
|
||||||
keywords = "settings", --(optional) additional keywords for search filter (it looks for matches in name..keywords..author)
|
website = "http://www.esoui.com/downloads/info7-LibAddonMenu.html", -- URL of website where the addon can be updated (optional)
|
||||||
slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel (don't forget to include the slash!)
|
keywords = "settings", -- additional keywords for search filter (it looks for matches in name..keywords..author) (optional)
|
||||||
registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
|
slashCommand = "/myaddon", -- will register a keybind to open to this panel (don't forget to include the slash!) (optional)
|
||||||
registerForDefaults = true, --boolean (optional) (will set all options controls back to default values)
|
registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
|
||||||
resetFunc = function() print("defaults reset") end, --(optional) custom function to run after settings are reset to defaults
|
registerForDefaults = true, --boolean (optional) (will set all options controls back to default values)
|
||||||
} ]]
|
resetFunc = function() print("defaults reset") end, --(optional) custom function to run after settings are reset to defaults
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
|
||||||
local widgetVersion = 9
|
local widgetVersion = 13
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("panel", widgetVersion) then return end
|
if not LAM:RegisterWidget("panel", widgetVersion) then return end
|
||||||
|
|
||||||
@ -20,113 +21,106 @@ local wm = WINDOW_MANAGER
|
|||||||
local cm = CALLBACK_MANAGER
|
local cm = CALLBACK_MANAGER
|
||||||
|
|
||||||
local function RefreshPanel(control)
|
local function RefreshPanel(control)
|
||||||
local panel = control.panel or control --callback can be fired by a single control or by the panel showing
|
local panel = LAM.util.GetTopPanel(control) --callback can be fired by a single control, by the panel showing or by a nested submenu
|
||||||
local panelControls = panel.controlsToRefresh
|
local panelControls = panel.controlsToRefresh
|
||||||
|
|
||||||
for i = 1, #panelControls do
|
for i = 1, #panelControls do
|
||||||
local updateControl = panelControls[i]
|
local updateControl = panelControls[i]
|
||||||
if updateControl ~= control then
|
if updateControl ~= control and updateControl.UpdateValue then
|
||||||
if updateControl.UpdateValue then
|
updateControl:UpdateValue()
|
||||||
updateControl:UpdateValue()
|
end
|
||||||
end
|
if updateControl.UpdateDisabled then
|
||||||
if updateControl.UpdateDisabled then
|
updateControl:UpdateDisabled()
|
||||||
updateControl:UpdateDisabled()
|
end
|
||||||
end
|
if updateControl.UpdateWarning then
|
||||||
end
|
updateControl:UpdateWarning()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ForceDefaults(panel)
|
local function ForceDefaults(panel)
|
||||||
local panelControls = panel.controlsToRefresh
|
local panelControls = panel.controlsToRefresh
|
||||||
|
|
||||||
for i = 1, #panelControls do
|
for i = 1, #panelControls do
|
||||||
local updateControl = panelControls[i]
|
local updateControl = panelControls[i]
|
||||||
if updateControl.UpdateValue and updateControl.data.default ~= nil then
|
if updateControl.UpdateValue and updateControl.data.default ~= nil then
|
||||||
updateControl:UpdateValue(true)
|
updateControl:UpdateValue(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if panel.data.resetFunc then
|
if panel.data.resetFunc then
|
||||||
panel.data.resetFunc()
|
panel.data.resetFunc()
|
||||||
end
|
end
|
||||||
|
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", panel)
|
cm:FireCallbacks("LAM-RefreshPanel", panel)
|
||||||
end
|
end
|
||||||
ESO_Dialogs["LAM_DEFAULTS"] = {
|
|
||||||
title = {
|
|
||||||
text = SI_INTERFACE_OPTIONS_RESET_TO_DEFAULT_TOOLTIP,
|
|
||||||
},
|
|
||||||
mainText = {
|
|
||||||
text = SI_OPTIONS_RESET_PROMPT,
|
|
||||||
align = TEXT_ALIGN_CENTER,
|
|
||||||
},
|
|
||||||
buttons = {
|
|
||||||
[1] = {
|
|
||||||
text = SI_OPTIONS_RESET,
|
|
||||||
callback = function(dialog) ForceDefaults(dialog.data[1]) end,
|
|
||||||
},
|
|
||||||
[2] = {
|
|
||||||
text = SI_DIALOG_CANCEL,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local callbackRegistered = false
|
local callbackRegistered = false
|
||||||
LAMCreateControl.scrollCount = LAMCreateControl.scrollCount or 1
|
LAMCreateControl.scrollCount = LAMCreateControl.scrollCount or 1
|
||||||
|
local SEPARATOR = " - "
|
||||||
|
local LINK_COLOR = ZO_ColorDef:New("5959D5")
|
||||||
|
local LINK_MOUSE_OVER_COLOR = ZO_ColorDef:New("B8B8D3")
|
||||||
|
|
||||||
function LAMCreateControl.panel(parent, panelData, controlName)
|
function LAMCreateControl.panel(parent, panelData, controlName)
|
||||||
local control = wm:CreateControl(controlName, parent, CT_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")
|
||||||
local label = control.label
|
local label = control.label
|
||||||
label:SetAnchor(TOPLEFT, control, TOPLEFT, 0, 4)
|
label:SetAnchor(TOPLEFT, control, TOPLEFT, 0, 4)
|
||||||
label:SetText(panelData.displayName or panelData.name)
|
label:SetText(LAM.util.GetStringFromValue(panelData.displayName or panelData.name))
|
||||||
|
|
||||||
if panelData.author or panelData.version then
|
if panelData.author or panelData.version then
|
||||||
control.info = wm:CreateControl(nil, control, CT_LABEL)
|
control.info = wm:CreateControl(nil, control, CT_LABEL)
|
||||||
local info = control.info
|
local info = control.info
|
||||||
info:SetFont("$(CHAT_FONT)|14|soft-shadow-thin")
|
info:SetFont(LAM.util.L["PANEL_INFO_FONT"])
|
||||||
info:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, -2)
|
info:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, -2)
|
||||||
if panelData.author and panelData.version then
|
|
||||||
info:SetText(string.format("Version: %s - %s: %s", panelData.version, GetString(SI_ADDON_MANAGER_AUTHOR), panelData.author))
|
|
||||||
elseif panelData.author then
|
|
||||||
info:SetText(string.format("%s: %s", GetString(SI_ADDON_MANAGER_AUTHOR), panelData.author))
|
|
||||||
else
|
|
||||||
info:SetText("Version: "..panelData.version)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
control.container = wm:CreateControlFromVirtual("LAMAddonPanelContainer"..LAMCreateControl.scrollCount, control, "ZO_ScrollContainer")
|
local output = {}
|
||||||
LAMCreateControl.scrollCount = LAMCreateControl.scrollCount + 1
|
if panelData.author then
|
||||||
local container = control.container
|
output[#output + 1] = zo_strformat(LAM.util.L["AUTHOR"], LAM.util.GetStringFromValue(panelData.author))
|
||||||
container:SetAnchor(TOPLEFT, control.info or label, BOTTOMLEFT, 0, 20)
|
end
|
||||||
container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, -3, -3)
|
if panelData.version then
|
||||||
control.scroll = GetControl(control.container, "ScrollChild")
|
output[#output + 1] = zo_strformat(LAM.util.L["VERSION"], LAM.util.GetStringFromValue(panelData.version))
|
||||||
control.scroll:SetResizeToFitPadding(0, 20)
|
end
|
||||||
|
info:SetText(table.concat(output, SEPARATOR))
|
||||||
|
end
|
||||||
|
|
||||||
if panelData.registerForDefaults then
|
if panelData.website then
|
||||||
control.defaultButton = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultTextButton")
|
control.website = wm:CreateControl(nil, control, CT_BUTTON)
|
||||||
local defaultButton = control.defaultButton
|
local website = control.website
|
||||||
defaultButton:SetFont("ZoFontDialogKeybindDescription")
|
website:SetClickSound("Click")
|
||||||
defaultButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
|
website:SetFont(LAM.util.L["PANEL_INFO_FONT"])
|
||||||
--defaultButton:SetText("Reset To Defaults")
|
website:SetNormalFontColor(LINK_COLOR:UnpackRGBA())
|
||||||
defaultButton:SetText(GetString(SI_OPTIONS_DEFAULTS))
|
website:SetMouseOverFontColor(LINK_MOUSE_OVER_COLOR:UnpackRGBA())
|
||||||
defaultButton:SetDimensions(200, 30)
|
if(control.info) then
|
||||||
defaultButton:SetAnchor(TOPLEFT, control, BOTTOMLEFT, 0, 2)
|
website:SetAnchor(TOPLEFT, control.info, TOPRIGHT, 0, 0)
|
||||||
defaultButton:SetHandler("OnClicked", function()
|
website:SetText(string.format("|cffffff%s|r%s", SEPARATOR, LAM.util.L["WEBSITE"]))
|
||||||
ZO_Dialogs_ShowDialog("LAM_DEFAULTS", {control})
|
else
|
||||||
end)
|
website:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, -2)
|
||||||
end
|
website:SetText(LAM.util.L["WEBSITE"])
|
||||||
|
end
|
||||||
|
website:SetDimensions(website:GetLabelControl():GetTextDimensions())
|
||||||
|
website:SetHandler("OnClicked", function()
|
||||||
|
RequestOpenUnsafeURL(panelData.website)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
if panelData.registerForRefresh and not callbackRegistered then --don't want to register our callback more than once
|
control.container = wm:CreateControlFromVirtual("LAMAddonPanelContainer"..LAMCreateControl.scrollCount, control, "ZO_ScrollContainer")
|
||||||
cm:RegisterCallback("LAM-RefreshPanel", RefreshPanel)
|
LAMCreateControl.scrollCount = LAMCreateControl.scrollCount + 1
|
||||||
callbackRegistered = true
|
local container = control.container
|
||||||
end
|
container:SetAnchor(TOPLEFT, control.info or label, BOTTOMLEFT, 0, 20)
|
||||||
|
container:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT, -3, -3)
|
||||||
|
control.scroll = GetControl(control.container, "ScrollChild")
|
||||||
|
control.scroll:SetResizeToFitPadding(0, 20)
|
||||||
|
|
||||||
control.data = panelData
|
if panelData.registerForRefresh and not callbackRegistered then --don't want to register our callback more than once
|
||||||
control.controlsToRefresh = {}
|
cm:RegisterCallback("LAM-RefreshPanel", RefreshPanel)
|
||||||
|
callbackRegistered = true
|
||||||
|
end
|
||||||
|
|
||||||
return control
|
control.ForceDefaults = ForceDefaults
|
||||||
|
control.data = panelData
|
||||||
|
control.controlsToRefresh = {}
|
||||||
|
|
||||||
|
return control
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- vi: noexpandtab
|
|
||||||
|
@ -1,157 +1,212 @@
|
|||||||
--[[sliderData = {
|
--[[sliderData = {
|
||||||
type = "slider",
|
type = "slider",
|
||||||
name = "My Slider",
|
name = "My Slider", -- or string id or function returning a string
|
||||||
tooltip = "Slider's tooltip text.",
|
getFunc = function() return db.var end,
|
||||||
min = 0,
|
setFunc = function(value) db.var = value doStuff() end,
|
||||||
max = 20,
|
min = 0,
|
||||||
step = 1, --(optional)
|
max = 20,
|
||||||
getFunc = function() return db.var end,
|
step = 1, --(optional)
|
||||||
setFunc = function(value) db.var = value doStuff() end,
|
clampInput = true, -- boolean, if set to false the input won't clamp to min and max and allow any number instead (optional)
|
||||||
width = "full", --or "half" (optional)
|
decimals = 0, -- when specified the input value is rounded to the specified number of decimals (optional)
|
||||||
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
|
autoSelect = false, -- boolean, automatically select everything in the text input field when it gains focus (optional)
|
||||||
warning = "Will need to reload the UI.", --(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)
|
||||||
default = defaults.var, --(optional)
|
tooltip = "Slider's tooltip text.", -- or string id or function returning a string (optional)
|
||||||
reference = "MyAddonSlider" --(optional) unique global reference to control
|
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)
|
||||||
|
reference = "MyAddonSlider" -- unique global reference to control (optional)
|
||||||
|
} ]]
|
||||||
|
|
||||||
|
local widgetVersion = 12
|
||||||
local widgetVersion = 7
|
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("slider", widgetVersion) then return end
|
if not LAM:RegisterWidget("slider", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local cm = CALLBACK_MANAGER
|
|
||||||
local round = zo_round
|
|
||||||
local strformat = string.format
|
local strformat = string.format
|
||||||
local tinsert = table.insert
|
|
||||||
|
local function RoundDecimalToPlace(d, place)
|
||||||
|
return tonumber(strformat("%." .. tostring(place) .. "f", d))
|
||||||
|
end
|
||||||
|
|
||||||
local function UpdateDisabled(control)
|
local function UpdateDisabled(control)
|
||||||
local disable
|
local disable
|
||||||
if type(control.data.disabled) == "function" then
|
if type(control.data.disabled) == "function" then
|
||||||
disable = control.data.disabled()
|
disable = control.data.disabled()
|
||||||
else
|
else
|
||||||
disable = control.data.disabled
|
disable = control.data.disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
control.slider:SetEnabled(not disable)
|
control.slider:SetEnabled(not disable)
|
||||||
control.slidervalue:SetEditEnabled(not disable)
|
control.slidervalue:SetEditEnabled(not disable)
|
||||||
if disable then
|
if disable then
|
||||||
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
control.minText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.minText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
control.maxText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
control.maxText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA())
|
||||||
control.slidervalue:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
control.slidervalue:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA())
|
||||||
else
|
else
|
||||||
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
control.minText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.minText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
control.maxText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.maxText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
control.slidervalue:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
control.slidervalue:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateValue(control, forceDefault, value)
|
local function UpdateValue(control, forceDefault, value)
|
||||||
if forceDefault then --if we are forcing defaults
|
if forceDefault then --if we are forcing defaults
|
||||||
value = control.data.default
|
value = LAM.util.GetDefaultValue(control.data.default)
|
||||||
control.data.setFunc(value)
|
control.data.setFunc(value)
|
||||||
elseif value and value >= control.data.min and value <= control.data.max then
|
elseif value then
|
||||||
control.data.setFunc(value)
|
if control.data.decimals then
|
||||||
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
value = RoundDecimalToPlace(value, control.data.decimals)
|
||||||
if control.panel.data.registerForRefresh then
|
end
|
||||||
cm:FireCallbacks("LAM-RefreshPanel", control)
|
if control.data.clampInput ~= false then
|
||||||
end
|
value = math.max(math.min(value, control.data.max), control.data.min)
|
||||||
else
|
end
|
||||||
value = control.data.getFunc()
|
control.data.setFunc(value)
|
||||||
end
|
--after setting this value, let's refresh the others to see if any should be disabled or have their settings changed
|
||||||
|
LAM.util.RequestRefreshIfNeeded(control)
|
||||||
|
else
|
||||||
|
value = control.data.getFunc()
|
||||||
|
end
|
||||||
|
|
||||||
control.slider:SetValue(value)
|
control.slider:SetValue(value)
|
||||||
control.slidervalue:SetText(value)
|
control.slidervalue:SetText(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function LAMCreateControl.slider(parent, sliderData, controlName)
|
function LAMCreateControl.slider(parent, sliderData, controlName)
|
||||||
local control = LAM.util.CreateLabelAndContainerControl(parent, sliderData, controlName)
|
local control = LAM.util.CreateLabelAndContainerControl(parent, sliderData, controlName)
|
||||||
|
local isInputOnRight = sliderData.inputLocation == "right"
|
||||||
|
|
||||||
--skipping creating the backdrop... Is this the actual slider texture?
|
--skipping creating the backdrop... Is this the actual slider texture?
|
||||||
control.slider = wm:CreateControl(nil, control.container, CT_SLIDER)
|
control.slider = wm:CreateControl(nil, control.container, CT_SLIDER)
|
||||||
local slider = control.slider
|
local slider = control.slider
|
||||||
slider:SetAnchor(TOPLEFT)
|
slider:SetAnchor(TOPLEFT)
|
||||||
slider:SetAnchor(TOPRIGHT)
|
slider:SetHeight(14)
|
||||||
slider:SetHeight(14)
|
if(isInputOnRight) then
|
||||||
slider:SetMouseEnabled(true)
|
slider:SetAnchor(TOPRIGHT, nil, nil, -60)
|
||||||
slider:SetOrientation(ORIENTATION_HORIZONTAL)
|
else
|
||||||
--put nil for highlighted texture file path, and what look to be texture coords
|
slider:SetAnchor(TOPRIGHT)
|
||||||
slider:SetThumbTexture("EsoUI\\Art\\Miscellaneous\\scrollbox_elevator.dds", "EsoUI\\Art\\Miscellaneous\\scrollbox_elevator_disabled.dds", nil, 8, 16)
|
end
|
||||||
local minValue = sliderData.min
|
slider:SetMouseEnabled(true)
|
||||||
local maxValue = sliderData.max
|
slider:SetOrientation(ORIENTATION_HORIZONTAL)
|
||||||
slider:SetMinMax(minValue, maxValue)
|
--put nil for highlighted texture file path, and what look to be texture coords
|
||||||
slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end)
|
slider:SetThumbTexture("EsoUI\\Art\\Miscellaneous\\scrollbox_elevator.dds", "EsoUI\\Art\\Miscellaneous\\scrollbox_elevator_disabled.dds", nil, 8, 16)
|
||||||
slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseExit(control) end)
|
local minValue = sliderData.min
|
||||||
|
local maxValue = sliderData.max
|
||||||
|
slider:SetMinMax(minValue, maxValue)
|
||||||
|
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)
|
||||||
local bg = slider.bg
|
local bg = slider.bg
|
||||||
bg:SetCenterColor(0, 0, 0)
|
bg:SetCenterColor(0, 0, 0)
|
||||||
bg:SetAnchor(TOPLEFT, slider, TOPLEFT, 0, 4)
|
bg:SetAnchor(TOPLEFT, slider, TOPLEFT, 0, 4)
|
||||||
bg:SetAnchor(BOTTOMRIGHT, slider, BOTTOMRIGHT, 0, -4)
|
bg:SetAnchor(BOTTOMRIGHT, slider, BOTTOMRIGHT, 0, -4)
|
||||||
bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-SliderBackdrop.dds", 32, 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)
|
||||||
local minText = control.minText
|
local minText = control.minText
|
||||||
minText:SetFont("ZoFontGameSmall")
|
minText:SetFont("ZoFontGameSmall")
|
||||||
minText:SetAnchor(TOPLEFT, slider, BOTTOMLEFT)
|
minText:SetAnchor(TOPLEFT, slider, BOTTOMLEFT)
|
||||||
minText:SetText(sliderData.min)
|
minText:SetText(sliderData.min)
|
||||||
|
|
||||||
control.maxText = wm:CreateControl(nil, slider, CT_LABEL)
|
control.maxText = wm:CreateControl(nil, slider, CT_LABEL)
|
||||||
local maxText = control.maxText
|
local maxText = control.maxText
|
||||||
maxText:SetFont("ZoFontGameSmall")
|
maxText:SetFont("ZoFontGameSmall")
|
||||||
maxText:SetAnchor(TOPRIGHT, slider, BOTTOMRIGHT)
|
maxText:SetAnchor(TOPRIGHT, slider, BOTTOMRIGHT)
|
||||||
maxText:SetText(sliderData.max)
|
maxText:SetText(sliderData.max)
|
||||||
|
|
||||||
control.slidervalueBG = wm:CreateControlFromVirtual(nil, slider, "ZO_EditBackdrop")
|
control.slidervalueBG = wm:CreateControlFromVirtual(nil, slider, "ZO_EditBackdrop")
|
||||||
control.slidervalueBG:SetDimensions(50, 16)
|
if(isInputOnRight) then
|
||||||
control.slidervalueBG:SetAnchor(TOP, slider, BOTTOM, 0, 0)
|
control.slidervalueBG:SetDimensions(60, 26)
|
||||||
control.slidervalue = wm:CreateControlFromVirtual(nil, control.slidervalueBG, "ZO_DefaultEditForBackdrop")
|
control.slidervalueBG:SetAnchor(LEFT, slider, RIGHT, 5, 0)
|
||||||
local slidervalue = control.slidervalue
|
else
|
||||||
slidervalue:ClearAnchors()
|
control.slidervalueBG:SetDimensions(50, 16)
|
||||||
slidervalue:SetAnchor(TOPLEFT, control.slidervalueBG, TOPLEFT, 3, 1)
|
control.slidervalueBG:SetAnchor(TOP, slider, BOTTOM, 0, 0)
|
||||||
slidervalue:SetAnchor(BOTTOMRIGHT, control.slidervalueBG, BOTTOMRIGHT, -3, -1)
|
end
|
||||||
slidervalue:SetTextType(TEXT_TYPE_NUMERIC)
|
control.slidervalue = wm:CreateControlFromVirtual(nil, control.slidervalueBG, "ZO_DefaultEditForBackdrop")
|
||||||
slidervalue:SetFont("ZoFontGameSmall")
|
local slidervalue = control.slidervalue
|
||||||
slidervalue:SetHandler("OnEscape", function(self)
|
slidervalue:ClearAnchors()
|
||||||
self:LoseFocus()
|
slidervalue:SetAnchor(TOPLEFT, control.slidervalueBG, TOPLEFT, 3, 1)
|
||||||
control:UpdateValue()
|
slidervalue:SetAnchor(BOTTOMRIGHT, control.slidervalueBG, BOTTOMRIGHT, -3, -1)
|
||||||
end)
|
slidervalue:SetTextType(TEXT_TYPE_NUMERIC)
|
||||||
slidervalue:SetHandler("OnEnter", function(self)
|
if(isInputOnRight) then
|
||||||
self:LoseFocus()
|
slidervalue:SetFont("ZoFontGameLarge")
|
||||||
control:UpdateValue(false, tonumber(self:GetText()))
|
else
|
||||||
end)
|
slidervalue:SetFont("ZoFontGameSmall")
|
||||||
|
end
|
||||||
|
|
||||||
local range = maxValue - minValue
|
local isHandlingChange = false
|
||||||
slider:SetValueStep(sliderData.step or 1)
|
local function HandleValueChanged(value)
|
||||||
slider:SetHandler("OnValueChanged", function(self, value, eventReason)
|
if isHandlingChange then return end
|
||||||
if eventReason == EVENT_REASON_SOFTWARE then return end
|
if sliderData.decimals then
|
||||||
self:SetValue(value) --do we actually need this line?
|
value = RoundDecimalToPlace(value, sliderData.decimals)
|
||||||
slidervalue:SetText(value)
|
end
|
||||||
end)
|
isHandlingChange = true
|
||||||
slider:SetHandler("OnSliderReleased", function(self, value)
|
slider:SetValue(value)
|
||||||
--sliderData.setFunc(value)
|
slidervalue:SetText(value)
|
||||||
control:UpdateValue(false, value) --does this work here instead?
|
isHandlingChange = false
|
||||||
end)
|
end
|
||||||
|
|
||||||
if sliderData.warning then
|
slidervalue:SetHandler("OnEscape", function(self)
|
||||||
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
HandleValueChanged(sliderData.getFunc())
|
||||||
control.warning:SetAnchor(RIGHT, slider, LEFT, -5, 0)
|
self:LoseFocus()
|
||||||
control.warning.data = {tooltipText = sliderData.warning}
|
end)
|
||||||
end
|
slidervalue:SetHandler("OnEnter", function(self)
|
||||||
|
self:LoseFocus()
|
||||||
|
end)
|
||||||
|
slidervalue:SetHandler("OnFocusLost", function(self)
|
||||||
|
local value = tonumber(self:GetText())
|
||||||
|
control:UpdateValue(false, value)
|
||||||
|
end)
|
||||||
|
slidervalue:SetHandler("OnTextChanged", function(self)
|
||||||
|
local input = self:GetText()
|
||||||
|
if(#input > 1 and not input:sub(-1):match("[0-9]")) then return end
|
||||||
|
local value = tonumber(input)
|
||||||
|
if(value) then
|
||||||
|
HandleValueChanged(value)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
if(sliderData.autoSelect) then
|
||||||
|
ZO_PreHookHandler(slidervalue, "OnFocusGained", function(self)
|
||||||
|
self:SelectAll()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
if sliderData.disabled then
|
local range = maxValue - minValue
|
||||||
control.UpdateDisabled = UpdateDisabled
|
slider:SetValueStep(sliderData.step or 1)
|
||||||
control:UpdateDisabled()
|
slider:SetHandler("OnValueChanged", function(self, value, eventReason)
|
||||||
end
|
if eventReason == EVENT_REASON_SOFTWARE then return end
|
||||||
control.UpdateValue = UpdateValue
|
HandleValueChanged(value)
|
||||||
control:UpdateValue()
|
end)
|
||||||
|
slider:SetHandler("OnSliderReleased", function(self, value)
|
||||||
|
control:UpdateValue(false, value)
|
||||||
|
end)
|
||||||
|
slider:SetHandler("OnMouseWheel", function(self, value)
|
||||||
|
if(not self:GetEnabled()) then return end
|
||||||
|
local new_value = (tonumber(slidervalue:GetText()) or sliderData.min or 0) + ((sliderData.step or 1) * value)
|
||||||
|
control:UpdateValue(false, new_value)
|
||||||
|
end)
|
||||||
|
|
||||||
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
|
if sliderData.warning ~= nil or sliderData.requiresReload then
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
|
||||||
end
|
control.warning:SetAnchor(RIGHT, slider, LEFT, -5, 0)
|
||||||
|
control.UpdateWarning = LAM.util.UpdateWarning
|
||||||
|
control:UpdateWarning()
|
||||||
|
end
|
||||||
|
|
||||||
return control
|
control.UpdateValue = UpdateValue
|
||||||
end
|
control:UpdateValue()
|
||||||
|
|
||||||
|
if sliderData.disabled ~= nil then
|
||||||
|
control.UpdateDisabled = UpdateDisabled
|
||||||
|
control:UpdateDisabled()
|
||||||
|
end
|
||||||
|
|
||||||
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
|
LAM.util.RegisterForReloadIfNeeded(control)
|
||||||
|
|
||||||
|
return control
|
||||||
|
end
|
||||||
|
@ -1,112 +1,108 @@
|
|||||||
--[[submenuData = {
|
--[[submenuData = {
|
||||||
type = "submenu",
|
type = "submenu",
|
||||||
name = "Submenu Title",
|
name = "Submenu Title", -- or string id or function returning a string
|
||||||
tooltip = "My submenu tooltip", --(optional)
|
tooltip = "My submenu tooltip", -- -- or string id or function returning a string (optional)
|
||||||
controls = {sliderData, buttonData} --(optional) used by LAM
|
controls = {sliderData, buttonData} --(optional) used by LAM
|
||||||
reference = "MyAddonSubmenu" --(optional) unique global reference to control
|
reference = "MyAddonSubmenu" --(optional) unique global reference to control
|
||||||
} ]]
|
} ]]
|
||||||
|
|
||||||
local widgetVersion = 9
|
local widgetVersion = 11
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("submenu", widgetVersion) then return end
|
if not LAM:RegisterWidget("submenu", widgetVersion) then return end
|
||||||
|
|
||||||
local wm = WINDOW_MANAGER
|
local wm = WINDOW_MANAGER
|
||||||
local am = ANIMATION_MANAGER
|
local am = ANIMATION_MANAGER
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
|
|
||||||
local function UpdateValue(control)
|
local function UpdateValue(control)
|
||||||
control.label:SetText(control.data.name)
|
control.label:SetText(LAM.util.GetStringFromValue(control.data.name))
|
||||||
if control.data.tooltip then
|
if control.data.tooltip then
|
||||||
control.label.data.tooltipText = LAM.util.GetTooltipText(control.data.tooltip)
|
control.label.data.tooltipText = LAM.util.GetStringFromValue(control.data.tooltip)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function AnimateSubmenu(clicked)
|
local function AnimateSubmenu(clicked)
|
||||||
local control = clicked:GetParent()
|
local control = clicked:GetParent()
|
||||||
control.open = not control.open
|
control.open = not control.open
|
||||||
|
|
||||||
if control.open then
|
if control.open then
|
||||||
control.animation:PlayFromStart()
|
control.animation:PlayFromStart()
|
||||||
else
|
else
|
||||||
control.animation:PlayFromEnd()
|
control.animation:PlayFromEnd()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function LAMCreateControl.submenu(parent, submenuData, controlName)
|
function LAMCreateControl.submenu(parent, submenuData, controlName)
|
||||||
local width = parent:GetWidth() - 45
|
local width = parent:GetWidth() - 45
|
||||||
local control = wm:CreateControl(controlName or submenuData.reference, parent.scroll or parent, CT_CONTROL)
|
local control = wm:CreateControl(controlName or submenuData.reference, parent.scroll or parent, CT_CONTROL)
|
||||||
control.panel = parent
|
control.panel = parent
|
||||||
control.data = submenuData
|
control.data = submenuData
|
||||||
|
|
||||||
control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel")
|
control.label = wm:CreateControlFromVirtual(nil, control, "ZO_Options_SectionTitleLabel")
|
||||||
local label = control.label
|
local label = control.label
|
||||||
label:SetAnchor(TOPLEFT, control, TOPLEFT, 5, 5)
|
label:SetAnchor(TOPLEFT, control, TOPLEFT, 5, 5)
|
||||||
label:SetDimensions(width, 30)
|
label:SetDimensions(width, 30)
|
||||||
label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
|
label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
|
||||||
label:SetText(submenuData.name)
|
label:SetText(LAM.util.GetStringFromValue(submenuData.name))
|
||||||
label:SetMouseEnabled(true)
|
label:SetMouseEnabled(true)
|
||||||
if submenuData.tooltip then
|
if submenuData.tooltip then
|
||||||
label.data = {tooltipText = LAM.util.GetTooltipText(submenuData.tooltip)}
|
label.data = {tooltipText = LAM.util.GetStringFromValue(submenuData.tooltip)}
|
||||||
label:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
label:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
||||||
label:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
|
label:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
|
||||||
end
|
end
|
||||||
|
|
||||||
control.scroll = wm:CreateControl(nil, control, CT_SCROLL)
|
control.scroll = wm:CreateControl(nil, control, CT_SCROLL)
|
||||||
local scroll = control.scroll
|
local scroll = control.scroll
|
||||||
scroll:SetParent(control)
|
scroll:SetParent(control)
|
||||||
scroll:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, 10)
|
scroll:SetAnchor(TOPLEFT, label, BOTTOMLEFT, 0, 10)
|
||||||
scroll:SetDimensionConstraints(width + 5, 0, width + 5, 2500)
|
scroll:SetDimensionConstraints(width + 5, 0, width + 5, 0)
|
||||||
|
|
||||||
control.bg = wm:CreateControl(nil, label, CT_BACKDROP)
|
control.bg = wm:CreateControl(nil, label, CT_BACKDROP)
|
||||||
local bg = control.bg
|
local bg = control.bg
|
||||||
bg:SetAnchor(TOPLEFT, label, TOPLEFT, -5, -5)
|
bg:SetAnchor(TOPLEFT, label, TOPLEFT, -5, -5)
|
||||||
bg:SetAnchor(BOTTOMRIGHT, scroll, BOTTOMRIGHT, -7, 0)
|
bg:SetAnchor(BOTTOMRIGHT, scroll, BOTTOMRIGHT, -7, 0)
|
||||||
bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16)
|
bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-Border.dds", 128, 16)
|
||||||
bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds")
|
bg:SetCenterTexture("EsoUI\\Art\\Tooltips\\UI-TooltipCenter.dds")
|
||||||
bg:SetInsets(16, 16, -16, -16)
|
bg:SetInsets(16, 16, -16, -16)
|
||||||
|
|
||||||
control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE)
|
control.arrow = wm:CreateControl(nil, bg, CT_TEXTURE)
|
||||||
local arrow = control.arrow
|
local arrow = control.arrow
|
||||||
arrow:SetDimensions(28, 28)
|
arrow:SetDimensions(28, 28)
|
||||||
arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") --list_sortup for the other way
|
arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds") --list_sortup for the other way
|
||||||
arrow:SetAnchor(TOPRIGHT, bg, TOPRIGHT, -5, 5)
|
arrow:SetAnchor(TOPRIGHT, bg, TOPRIGHT, -5, 5)
|
||||||
|
|
||||||
--figure out the cool animation later...
|
--figure out the cool animation later...
|
||||||
control.animation = am:CreateTimeline()
|
control.animation = am:CreateTimeline()
|
||||||
local animation = control.animation
|
local animation = control.animation
|
||||||
animation:SetPlaybackType(ANIMATION_SIZE, 0) --2nd arg = loop count
|
animation:SetPlaybackType(ANIMATION_SIZE, 0) --2nd arg = loop count
|
||||||
|
|
||||||
control:SetResizeToFitDescendents(true)
|
control:SetResizeToFitDescendents(true)
|
||||||
control.open = false
|
control.open = false
|
||||||
label:SetHandler("OnMouseUp", AnimateSubmenu)
|
label:SetHandler("OnMouseUp", AnimateSubmenu)
|
||||||
animation:SetHandler("OnStop", function(self, completedPlaying)
|
animation:SetHandler("OnStop", function(self, completedPlaying)
|
||||||
scroll:SetResizeToFitDescendents(control.open)
|
scroll:SetResizeToFitDescendents(control.open)
|
||||||
if control.open then
|
if control.open then
|
||||||
control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortup.dds")
|
control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortup.dds")
|
||||||
scroll:SetResizeToFitPadding(5, 20)
|
scroll:SetResizeToFitPadding(5, 20)
|
||||||
else
|
else
|
||||||
control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds")
|
control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds")
|
||||||
scroll:SetResizeToFitPadding(5, 0)
|
scroll:SetResizeToFitPadding(5, 0)
|
||||||
scroll:SetHeight(0)
|
scroll:SetHeight(0)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--small strip at the bottom of the submenu that you can click to close it
|
--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)
|
||||||
local btmToggle = control.btmToggle
|
local btmToggle = control.btmToggle
|
||||||
btmToggle:SetMouseEnabled(true)
|
btmToggle:SetMouseEnabled(true)
|
||||||
btmToggle:SetAnchor(BOTTOMLEFT, control.scroll, BOTTOMLEFT)
|
btmToggle:SetAnchor(BOTTOMLEFT, control.scroll, BOTTOMLEFT)
|
||||||
btmToggle:SetAnchor(BOTTOMRIGHT, control.scroll, BOTTOMRIGHT)
|
btmToggle:SetAnchor(BOTTOMRIGHT, control.scroll, BOTTOMRIGHT)
|
||||||
btmToggle:SetHeight(15)
|
btmToggle:SetHeight(15)
|
||||||
btmToggle:SetAlpha(0)
|
btmToggle:SetAlpha(0)
|
||||||
btmToggle:SetHandler("OnMouseUp", AnimateSubmenu)
|
btmToggle:SetHandler("OnMouseUp", AnimateSubmenu)
|
||||||
|
|
||||||
control.UpdateValue = UpdateValue
|
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
|
LAM.util.RegisterForRefreshIfNeeded(control)
|
||||||
tinsert(control.panel.controlsToRefresh, control)
|
|
||||||
end
|
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
--[[textureData = {
|
--[[textureData = {
|
||||||
type = "texture",
|
type = "texture",
|
||||||
image = "file/path.dds",
|
image = "file/path.dds",
|
||||||
imageWidth = 64, --max of 250 for half width, 510 for full
|
imageWidth = 64, --max of 250 for half width, 510 for full
|
||||||
imageHeight = 32, --max of 100
|
imageHeight = 32, --max of 100
|
||||||
tooltip = "Image's tooltip text.", --(optional)
|
tooltip = "Image's tooltip text.", -- or string id or function returning a string (optional)
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
reference = "MyAddonTexture" --(optional) unique global reference to control
|
reference = "MyAddonTexture" --(optional) unique global reference to control
|
||||||
} ]]
|
} ]]
|
||||||
|
|
||||||
--add texture coords support?
|
--add texture coords support?
|
||||||
|
|
||||||
local widgetVersion = 7
|
local widgetVersion = 9
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
if not LAM:RegisterWidget("texture", widgetVersion) then return end
|
if not LAM:RegisterWidget("texture", widgetVersion) then return end
|
||||||
|
|
||||||
@ -18,28 +18,28 @@ local wm = WINDOW_MANAGER
|
|||||||
|
|
||||||
local MIN_HEIGHT = 26
|
local MIN_HEIGHT = 26
|
||||||
function LAMCreateControl.texture(parent, textureData, controlName)
|
function LAMCreateControl.texture(parent, textureData, controlName)
|
||||||
local control = LAM.util.CreateBaseControl(parent, textureData, controlName)
|
local control = LAM.util.CreateBaseControl(parent, textureData, controlName)
|
||||||
local width = control:GetWidth()
|
local width = control:GetWidth()
|
||||||
control:SetResizeToFitDescendents(true)
|
control:SetResizeToFitDescendents(true)
|
||||||
|
|
||||||
if control.isHalfWidth then --note these restrictions
|
if control.isHalfWidth then --note these restrictions
|
||||||
control:SetDimensionConstraints(width / 2, MIN_HEIGHT, width / 2, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width / 2, MIN_HEIGHT, width / 2, MIN_HEIGHT * 4)
|
||||||
else
|
else
|
||||||
control:SetDimensionConstraints(width, MIN_HEIGHT, width, MIN_HEIGHT * 4)
|
control:SetDimensionConstraints(width, MIN_HEIGHT, width, MIN_HEIGHT * 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
control.texture = wm:CreateControl(nil, control, CT_TEXTURE)
|
control.texture = wm:CreateControl(nil, control, CT_TEXTURE)
|
||||||
local texture = control.texture
|
local texture = control.texture
|
||||||
texture:SetAnchor(CENTER)
|
texture:SetAnchor(CENTER)
|
||||||
texture:SetDimensions(textureData.imageWidth, textureData.imageHeight)
|
texture:SetDimensions(textureData.imageWidth, textureData.imageHeight)
|
||||||
texture:SetTexture(textureData.image)
|
texture:SetTexture(textureData.image)
|
||||||
|
|
||||||
if textureData.tooltip then
|
if textureData.tooltip then
|
||||||
texture:SetMouseEnabled(true)
|
texture:SetMouseEnabled(true)
|
||||||
texture.data = {tooltipText = LAM.util.GetTooltipText(textureData.tooltip)}
|
texture.data = {tooltipText = LAM.util.GetStringFromValue(textureData.tooltip)}
|
||||||
texture:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
texture:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
|
||||||
texture:SetHandler("OnMouseEnter", ZO_Options_OnMouseExit)
|
texture:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
|
||||||
end
|
end
|
||||||
|
|
||||||
return control
|
return control
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
-- LibStub developed for World of Warcraft by above members of the WowAce community.
|
-- LibStub developed for World of Warcraft by above members of the WowAce community.
|
||||||
-- Ported to Elder Scrolls Online by Seerah
|
-- Ported to Elder Scrolls Online by Seerah
|
||||||
|
|
||||||
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 3
|
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 4
|
||||||
local LibStub = _G[LIBSTUB_MAJOR]
|
local LibStub = _G[LIBSTUB_MAJOR]
|
||||||
|
|
||||||
local strformat = string.format
|
local strformat = string.format
|
||||||
@ -34,3 +34,5 @@ if not LibStub or LibStub.minor < LIBSTUB_MINOR then
|
|||||||
function LibStub:IterateLibraries() return pairs(self.libs) end
|
function LibStub:IterateLibraries() return pairs(self.libs) end
|
||||||
setmetatable(LibStub, { __call = LibStub.GetLibrary })
|
setmetatable(LibStub, { __call = LibStub.GetLibrary })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
LibStub.SILENT = true
|
@ -1,119 +1,119 @@
|
|||||||
local panelData = {
|
local panelData = {
|
||||||
type = "panel",
|
type = "panel",
|
||||||
name = "Window Title",
|
name = "Window Title",
|
||||||
displayName = "Longer Window Title",
|
displayName = "Longer Window Title",
|
||||||
author = "Seerah",
|
author = "Seerah",
|
||||||
version = "1.3",
|
version = "1.3",
|
||||||
slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel
|
slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel
|
||||||
registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
|
registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
|
||||||
registerForDefaults = true, --boolean (optional) (will set all options controls back to default values)
|
registerForDefaults = true, --boolean (optional) (will set all options controls back to default values)
|
||||||
}
|
}
|
||||||
|
|
||||||
local optionsTable = {
|
local optionsTable = {
|
||||||
[1] = {
|
[1] = {
|
||||||
type = "header",
|
type = "header",
|
||||||
name = "My Header",
|
name = "My Header",
|
||||||
width = "full", --or "half" (optional)
|
width = "full", --or "half" (optional)
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
type = "description",
|
type = "description",
|
||||||
--title = "My Title", --(optional)
|
--title = "My Title", --(optional)
|
||||||
title = nil, --(optional)
|
title = nil, --(optional)
|
||||||
text = "My description text to display. blah blah blah blah blah blah blah - even more sample text!!",
|
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" (optional)
|
||||||
},
|
},
|
||||||
[3] = {
|
[3] = {
|
||||||
type = "dropdown",
|
type = "dropdown",
|
||||||
name = "My Dropdown",
|
name = "My Dropdown",
|
||||||
tooltip = "Dropdown's tooltip text.",
|
tooltip = "Dropdown's tooltip text.",
|
||||||
choices = {"table", "of", "choices"},
|
choices = {"table", "of", "choices"},
|
||||||
getFunc = function() return "of" end,
|
getFunc = function() return "of" end,
|
||||||
setFunc = function(var) print(var) end,
|
setFunc = function(var) print(var) end,
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
},
|
},
|
||||||
[4] = {
|
[4] = {
|
||||||
type = "dropdown",
|
type = "dropdown",
|
||||||
name = "My Dropdown",
|
name = "My Dropdown",
|
||||||
tooltip = "Dropdown's tooltip text.",
|
tooltip = "Dropdown's tooltip text.",
|
||||||
choices = {"table", "of", "choices"},
|
choices = {"table", "of", "choices"},
|
||||||
getFunc = function() return "of" end,
|
getFunc = function() return "of" end,
|
||||||
setFunc = function(var) print(var) end,
|
setFunc = function(var) print(var) end,
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
},
|
},
|
||||||
[5] = {
|
[5] = {
|
||||||
type = "slider",
|
type = "slider",
|
||||||
name = "My Slider",
|
name = "My Slider",
|
||||||
tooltip = "Slider's tooltip text.",
|
tooltip = "Slider's tooltip text.",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 20,
|
max = 20,
|
||||||
step = 1, --(optional)
|
step = 1, --(optional)
|
||||||
getFunc = function() return 3 end,
|
getFunc = function() return 3 end,
|
||||||
setFunc = function(value) d(value) end,
|
setFunc = function(value) d(value) end,
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
default = 5, --(optional)
|
default = 5, --(optional)
|
||||||
},
|
},
|
||||||
[6] = {
|
[6] = {
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "My Button",
|
name = "My Button",
|
||||||
tooltip = "Button's tooltip text.",
|
tooltip = "Button's tooltip text.",
|
||||||
func = function() d("button pressed!") end,
|
func = function() d("button pressed!") end,
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
},
|
},
|
||||||
[7] = {
|
[7] = {
|
||||||
type = "submenu",
|
type = "submenu",
|
||||||
name = "Submenu Title",
|
name = "Submenu Title",
|
||||||
tooltip = "My submenu tooltip", --(optional)
|
tooltip = "My submenu tooltip", --(optional)
|
||||||
controls = {
|
controls = {
|
||||||
[1] = {
|
[1] = {
|
||||||
type = "checkbox",
|
type = "checkbox",
|
||||||
name = "My Checkbox",
|
name = "My Checkbox",
|
||||||
tooltip = "Checkbox's tooltip text.",
|
tooltip = "Checkbox's tooltip text.",
|
||||||
getFunc = function() return true end,
|
getFunc = function() return true end,
|
||||||
setFunc = function(value) d(value) end,
|
setFunc = function(value) d(value) end,
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
type = "colorpicker",
|
type = "colorpicker",
|
||||||
name = "My Color Picker",
|
name = "My Color Picker",
|
||||||
tooltip = "Color Picker's tooltip text.",
|
tooltip = "Color Picker's tooltip text.",
|
||||||
getFunc = function() return 1, 0, 0, 1 end, --(alpha is optional)
|
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)
|
setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional)
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "warning text",
|
warning = "warning text",
|
||||||
},
|
},
|
||||||
[3] = {
|
[3] = {
|
||||||
type = "editbox",
|
type = "editbox",
|
||||||
name = "My Editbox",
|
name = "My Editbox",
|
||||||
tooltip = "Editbox's tooltip text.",
|
tooltip = "Editbox's tooltip text.",
|
||||||
getFunc = function() return "this is some text" end,
|
getFunc = function() return "this is some text" end,
|
||||||
setFunc = function(text) print(text) end,
|
setFunc = function(text) print(text) end,
|
||||||
isMultiline = false, --boolean
|
isMultiline = false, --boolean
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
warning = "Will need to reload the UI.", --(optional)
|
warning = "Will need to reload the UI.", --(optional)
|
||||||
default = "", --(optional)
|
default = "", --(optional)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[8] = {
|
[8] = {
|
||||||
type = "custom",
|
type = "custom",
|
||||||
reference = "MyAddonCustomControl", --unique name for your control to use as reference
|
reference = "MyAddonCustomControl", --unique name for your control to use as reference
|
||||||
refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh
|
refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
},
|
},
|
||||||
[9] = {
|
[9] = {
|
||||||
type = "texture",
|
type = "texture",
|
||||||
image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds",
|
image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds",
|
||||||
imageWidth = 64, --max of 250 for half width, 510 for full
|
imageWidth = 64, --max of 250 for half width, 510 for full
|
||||||
imageHeight = 64, --max of 100
|
imageHeight = 64, --max of 100
|
||||||
tooltip = "Image's tooltip text.", --(optional)
|
tooltip = "Image's tooltip text.", --(optional)
|
||||||
width = "half", --or "half" (optional)
|
width = "half", --or "half" (optional)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local LAM = LibStub("LibAddonMenu-2.0")
|
local LAM = LibStub("LibAddonMenu-2.0")
|
||||||
LAM:RegisterAddonPanel("MyAddon", panelData)
|
LAM:RegisterAddonPanel("MyAddon", panelData)
|
||||||
LAM:RegisterOptionControls("MyAddon", optionsTable)
|
LAM:RegisterOptionControls("MyAddon", optionsTable)
|
||||||
|
Loading…
Reference in New Issue
Block a user