Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 36 | Seerah-7 | --[[colorpickerData = { |
2 | Seerah-7 | type = "colorpicker", |
|
3 | Seerah-7 | name = "My Color Picker", |
|
4 | Seerah-7 | tooltip = "Color Picker's tooltip text.", |
|
5 | Seerah-7 | getFunc = function() return db.r, db.g, db.b, db.a end, --(alpha is optional) |
|
6 | Seerah-7 | setFunc = function(r,g,b,a) db.r=r, db.g=g, db.b=b, db.a=a end, --(alpha is optional) |
|
7 | Seerah-7 | width = "full", --or "half" (optional) |
|
8 | Seerah-7 | disabled = function() return db.someBooleanSetting end, --or boolean (optional) |
|
9 | Seerah-7 | warning = "Will need to reload the UI.", --(optional) |
|
10 | 53 | Seerah-7 | 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]) |
11 | 36 | Seerah-7 | reference = "MyAddonColorpicker" --(optional) unique global reference to control |
12 | Seerah-7 | } ]] |
|
13 | Seerah-7 | ||
14 | Seerah-7 | ||
15 | 53 | Seerah-7 | local widgetVersion = 5 |
16 | 36 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
17 | Seerah-7 | if not LAM:RegisterWidget("colorpicker", widgetVersion) then return end |
|
18 | Seerah-7 | ||
19 | Seerah-7 | local wm = WINDOW_MANAGER |
|
20 | Seerah-7 | local cm = CALLBACK_MANAGER |
|
21 | Seerah-7 | local tinsert = table.insert |
|
22 | Seerah-7 | ||
23 | Seerah-7 | ||
24 | Seerah-7 | local function UpdateDisabled(control) |
|
25 | Seerah-7 | local disable |
|
26 | Seerah-7 | if type(control.data.disabled) == "function" then |
|
27 | Seerah-7 | disable = control.data.disabled() |
|
28 | Seerah-7 | else |
|
29 | Seerah-7 | disable = control.data.disabled |
|
30 | Seerah-7 | end |
|
31 | Seerah-7 | ||
32 | Seerah-7 | if disable then |
|
33 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) |
|
34 | Seerah-7 | else |
|
35 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
36 | Seerah-7 | end |
|
37 | Seerah-7 | ||
38 | Seerah-7 | control.isDisabled = disable |
|
39 | Seerah-7 | end |
|
40 | Seerah-7 | ||
41 | Seerah-7 | local function UpdateValue(control, forceDefault, valueR, valueG, valueB, valueA) |
|
42 | Seerah-7 | if forceDefault then --if we are forcing defaults |
|
43 | Seerah-7 | local color = control.data.default |
|
44 | Seerah-7 | valueR, valueG, valueB, valueA = color.r, color.g, color.b, color.a |
|
45 | Seerah-7 | control.data.setFunc(valueR, valueG, valueB, valueA) |
|
46 | Seerah-7 | elseif valueR and valueG and valueB then |
|
47 | Seerah-7 | control.data.setFunc(valueR, valueG, valueB, valueA or 1) |
|
48 | Seerah-7 | --after setting this value, let's refresh the others to see if any should be disabled or have their settings changed |
|
49 | Seerah-7 | if control.panel.data.registerForRefresh then |
|
50 | Seerah-7 | cm:FireCallbacks("LAM-RefreshPanel", control) |
|
51 | Seerah-7 | end |
|
52 | Seerah-7 | else |
|
53 | Seerah-7 | valueR, valueG, valueB, valueA = control.data.getFunc() |
|
54 | Seerah-7 | end |
|
55 | Seerah-7 | ||
56 | Seerah-7 | control.thumb:SetColor(valueR, valueG, valueB, valueA or 1) |
|
57 | Seerah-7 | end |
|
58 | Seerah-7 | ||
59 | Seerah-7 | ||
60 | Seerah-7 | function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) |
|
61 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName or colorpickerData.reference) |
|
62 | 45 | Seerah-7 | control:SetParent(parent.scroll or parent) |
63 | 36 | Seerah-7 | control:SetMouseEnabled(true) |
64 | 53 | Seerah-7 | --control.tooltipText = colorpickerData.tooltip |
65 | 36 | Seerah-7 | control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) |
66 | Seerah-7 | control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) |
|
67 | Seerah-7 | ||
68 | Seerah-7 | control.label = wm:CreateControl(nil, control, CT_LABEL) |
|
69 | Seerah-7 | local label = control.label |
|
70 | Seerah-7 | label:SetDimensions(300, 26) |
|
71 | Seerah-7 | label:SetAnchor(TOPLEFT) |
|
72 | Seerah-7 | label:SetFont("ZoFontWinH4") |
|
73 | Seerah-7 | label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) |
|
74 | Seerah-7 | label:SetText(colorpickerData.name) |
|
75 | Seerah-7 | ||
76 | Seerah-7 | control.color = wm:CreateControl(nil, control, CT_CONTROL) |
|
77 | Seerah-7 | local color = control.color |
|
78 | Seerah-7 | ||
79 | Seerah-7 | local isHalfWidth = colorpickerData.width == "half" |
|
80 | Seerah-7 | if isHalfWidth then |
|
81 | Seerah-7 | control:SetDimensions(250, 55) |
|
82 | Seerah-7 | label:SetDimensions(250, 26) |
|
83 | Seerah-7 | color:SetDimensions(100, 24) |
|
84 | Seerah-7 | color:SetAnchor(TOPRIGHT, label, BOTTOMRIGHT) |
|
85 | Seerah-7 | else |
|
86 | Seerah-7 | control:SetDimensions(510, 30) |
|
87 | Seerah-7 | label:SetDimensions(300, 26) |
|
88 | Seerah-7 | color:SetDimensions(200, 24) |
|
89 | Seerah-7 | color:SetAnchor(TOPRIGHT) |
|
90 | Seerah-7 | end |
|
91 | Seerah-7 | ||
92 | Seerah-7 | control.thumb = wm:CreateControl(nil, color, CT_TEXTURE) |
|
93 | Seerah-7 | local thumb = control.thumb |
|
94 | Seerah-7 | thumb:SetDimensions(36, 18) |
|
95 | Seerah-7 | thumb:SetAnchor(LEFT, color, LEFT, 4, 0) |
|
96 | Seerah-7 | ||
97 | Seerah-7 | color.border = wm:CreateControl(nil, color, CT_TEXTURE) |
|
98 | Seerah-7 | local border = color.border |
|
99 | Seerah-7 | border:SetTexture("EsoUI\\Art\\ChatWindow\\chatOptions_bgColSwatch_frame.dds") |
|
100 | Seerah-7 | border:SetTextureCoords(0, .625, 0, .8125) |
|
101 | Seerah-7 | border:SetDimensions(40, 22) |
|
102 | Seerah-7 | border:SetAnchor(CENTER, thumb, CENTER, 0, 0) |
|
103 | Seerah-7 | ||
104 | Seerah-7 | local function ColorPickerCallback(r, g, b, a) |
|
105 | Seerah-7 | control:UpdateValue(false, r, g, b, a) |
|
106 | Seerah-7 | end |
|
107 | Seerah-7 | ||
108 | Seerah-7 | control:SetHandler("OnMouseUp", function(self, btn, upInside) |
|
109 | Seerah-7 | if self.isDisabled then return end |
|
110 | Seerah-7 | ||
111 | Seerah-7 | if upInside then |
|
112 | Seerah-7 | local r, g, b, a = colorpickerData.getFunc() |
|
113 | Seerah-7 | COLOR_PICKER:Show(ColorPickerCallback, r, g, b, a, colorpickerData.name) |
|
114 | Seerah-7 | end |
|
115 | Seerah-7 | end) |
|
116 | Seerah-7 | ||
117 | Seerah-7 | if colorpickerData.warning then |
|
118 | Seerah-7 | control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") |
|
119 | Seerah-7 | control.warning:SetAnchor(RIGHT, control.color, LEFT, -5, 0) |
|
120 | 53 | Seerah-7 | --control.warning.tooltipText = colorpickerData.warning |
121 | Seerah-7 | control.warning.data = {tooltipText = colorpickerData.warning} |
|
122 | 36 | Seerah-7 | end |
123 | Seerah-7 | ||
124 | Seerah-7 | control.panel = parent.panel or parent --if this is in a submenu, panel is its parent |
|
125 | Seerah-7 | control.data = colorpickerData |
|
126 | 53 | Seerah-7 | control.data.tooltipText = colorpickerData.tooltip |
127 | 36 | Seerah-7 | |
128 | Seerah-7 | if colorpickerData.disabled then |
|
129 | Seerah-7 | control.UpdateDisabled = UpdateDisabled |
|
130 | Seerah-7 | control:UpdateDisabled() |
|
131 | Seerah-7 | end |
|
132 | Seerah-7 | control.UpdateValue = UpdateValue |
|
133 | Seerah-7 | control:UpdateValue() |
|
134 | Seerah-7 | ||
135 | Seerah-7 | 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 |
|
136 | Seerah-7 | tinsert(control.panel.controlsToRefresh, control) |
|
137 | Seerah-7 | end |
|
138 | Seerah-7 | ||
139 | Seerah-7 | return control |
|
140 | Seerah-7 | end |