forked from phuein/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.lua
More file actions
91 lines (80 loc) · 3.57 KB
/
Copy pathbutton.lua
File metadata and controls
91 lines (80 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--[[buttonData = {
type = "button",
name = "My Button", -- string id or function returning a string
func = function() end,
tooltip = "Button's tooltip text.", -- string id or function returning a string (optional)
width = "full", --or "half" (optional)
disabled = function() return db.someBooleanSetting end, --or boolean (optional)
icon = "icon\\path.dds", --(optional)
isDangerous = false, -- boolean, if set to true, the button text will be red and a confirmation dialog with the button label and warning text will show on click before the callback is executed (optional)
warning = "Will need to reload the UI.", --(optional)
reference = "MyAddonButton", -- unique global reference to control (optional)
} ]]
local widgetVersion = 11
local LAM = LibStub("LibAddonMenu-2.0")
if not LAM:RegisterWidget("button", widgetVersion) then return end
local wm = WINDOW_MANAGER
local function UpdateDisabled(control)
local disable = control.data.disabled
if type(disable) == "function" then
disable = disable()
end
control.button:SetEnabled(not disable)
end
--controlName is optional
local MIN_HEIGHT = 28 -- default_button height
local HALF_WIDTH_LINE_SPACING = 2
function LAMCreateControl.button(parent, buttonData, controlName)
local control = LAM.util.CreateBaseControl(parent, buttonData, controlName)
control:SetMouseEnabled(true)
local width = control:GetWidth()
if control.isHalfWidth then
control:SetDimensions(width / 2, MIN_HEIGHT * 2 + HALF_WIDTH_LINE_SPACING)
else
control:SetDimensions(width, MIN_HEIGHT)
end
if buttonData.icon then
control.button = wm:CreateControl(nil, control, CT_BUTTON)
control.button:SetDimensions(26, 26)
control.button:SetNormalTexture(buttonData.icon)
control.button:SetPressedOffset(2, 2)
else
--control.button = wm:CreateControlFromVirtual(controlName.."Button", control, "ZO_DefaultButton")
control.button = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultButton")
control.button:SetWidth(width / 3)
control.button:SetText(LAM.util.GetStringFromValue(buttonData.name))
if buttonData.isDangerous then control.button:SetNormalFontColor(ZO_ERROR_COLOR:UnpackRGBA()) end
end
local button = control.button
button:SetAnchor(control.isHalfWidth and CENTER or RIGHT)
button:SetClickSound("Click")
button.data = {tooltipText = LAM.util.GetStringFromValue(buttonData.tooltip)}
button:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
button:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
button:SetHandler("OnClicked", function(...)
local args = {...}
local function callback()
buttonData.func(unpack(args))
LAM.util.RequestRefreshIfNeeded(control)
end
if(buttonData.isDangerous) then
local title = LAM.util.GetStringFromValue(buttonData.name)
local body = LAM.util.GetStringFromValue(buttonData.warning)
LAM.util.ShowConfirmationDialog(title, body, callback)
else
callback()
end
end)
if buttonData.warning ~= nil then
control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon")
control.warning:SetAnchor(RIGHT, button, LEFT, -5, 0)
control.UpdateWarning = LAM.util.UpdateWarning
control:UpdateWarning()
end
if buttonData.disabled ~= nil then
control.UpdateDisabled = UpdateDisabled
control:UpdateDisabled()
end
LAM.util.RegisterForRefreshIfNeeded(control)
return control
end