Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 10 | Seerah-7 | --[[sliderData = { |
2 | Seerah-7 | type = "slider", |
|
3 | Seerah-7 | name = "My Slider", |
|
4 | Seerah-7 | tooltip = "Slider's tooltip text.", |
|
5 | Seerah-7 | min = 0, |
|
6 | Seerah-7 | max = 20, |
|
7 | Seerah-7 | step = 1, --(optional) |
|
8 | Seerah-7 | getFunc = function() return db.var end, |
|
9 | Seerah-7 | setFunc = function(value) db.var = value doStuff() end, |
|
10 | Seerah-7 | width = "full", --or "half" (optional) |
|
11 | Seerah-7 | disabled = function() return db.someBooleanSetting end, --or boolean (optional) |
|
12 | Seerah-7 | warning = "Will need to reload the UI.", --(optional) |
|
13 | Seerah-7 | default = defaults.var, --(optional) |
|
14 | 11 | Seerah-7 | reference = "MyAddonSlider" --(optional) unique global reference to control |
15 | 10 | Seerah-7 | } ]] |
16 | Seerah-7 | ||
17 | Seerah-7 | ||
18 | 16 | Seerah-7 | local widgetVersion = 5 |
19 | 10 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
20 | Seerah-7 | if not LAM:RegisterWidget("slider", widgetVersion) then return end |
|
21 | Seerah-7 | ||
22 | Seerah-7 | local wm = WINDOW_MANAGER |
|
23 | Seerah-7 | local cm = CALLBACK_MANAGER |
|
24 | Seerah-7 | local round = zo_round |
|
25 | Seerah-7 | local strformat = string.format |
|
26 | Seerah-7 | local tinsert = table.insert |
|
27 | Seerah-7 | ||
28 | Seerah-7 | local function UpdateDisabled(control) |
|
29 | Seerah-7 | local disable |
|
30 | Seerah-7 | if type(control.data.disabled) == "function" then |
|
31 | Seerah-7 | disable = control.data.disabled() |
|
32 | Seerah-7 | else |
|
33 | Seerah-7 | disable = control.data.disabled |
|
34 | Seerah-7 | end |
|
35 | Seerah-7 | ||
36 | Seerah-7 | control.slider:SetEnabled(not disable) |
|
37 | Seerah-7 | control.slidervalue:SetEditEnabled(not disable) |
|
38 | Seerah-7 | if disable then |
|
39 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) |
|
40 | Seerah-7 | control.minText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) |
|
41 | Seerah-7 | control.maxText:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) |
|
42 | Seerah-7 | control.slidervalue:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA()) |
|
43 | Seerah-7 | else |
|
44 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
45 | Seerah-7 | control.minText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
46 | Seerah-7 | control.maxText:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
47 | Seerah-7 | control.slidervalue:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
48 | Seerah-7 | end |
|
49 | Seerah-7 | end |
|
50 | Seerah-7 | ||
51 | Seerah-7 | local function UpdateValue(control, forceDefault, value) |
|
52 | Seerah-7 | if forceDefault then --if we are forcing defaults |
|
53 | Seerah-7 | value = control.data.default |
|
54 | Seerah-7 | control.data.setFunc(value) |
|
55 | Seerah-7 | elseif value and value >= control.data.min and value <= control.data.max then |
|
56 | Seerah-7 | control.data.setFunc(value) |
|
57 | Seerah-7 | --after setting this value, let's refresh the others to see if any should be disabled or have their settings changed |
|
58 | Seerah-7 | if control.panel.data.registerForRefresh then |
|
59 | Seerah-7 | cm:FireCallbacks("LAM-RefreshPanel", control) |
|
60 | Seerah-7 | end |
|
61 | Seerah-7 | else |
|
62 | Seerah-7 | value = control.data.getFunc() |
|
63 | Seerah-7 | end |
|
64 | Seerah-7 | ||
65 | Seerah-7 | control.slider:SetValue(value) |
|
66 | Seerah-7 | control.slidervalue:SetText(value) |
|
67 | Seerah-7 | end |
|
68 | Seerah-7 | ||
69 | Seerah-7 | ||
70 | Seerah-7 | function LAMCreateControl.slider(parent, sliderData, controlName) |
|
71 | 11 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName or sliderData.reference) |
72 | 13 | Seerah-7 | control:SetParent(parent.scroll or parent) |
73 | 10 | Seerah-7 | local isHalfWidth = sliderData.width == "half" |
74 | Seerah-7 | if isHalfWidth then |
|
75 | Seerah-7 | control:SetDimensions(250, 55) |
|
76 | Seerah-7 | else |
|
77 | Seerah-7 | control:SetDimensions(510, 40) |
|
78 | Seerah-7 | end |
|
79 | Seerah-7 | control:SetMouseEnabled(true) |
|
80 | 16 | Seerah-7 | --control.tooltipText = sliderData.tooltip |
81 | 10 | Seerah-7 | control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) |
82 | Seerah-7 | control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) |
|
83 | Seerah-7 | ||
84 | Seerah-7 | control.label = wm:CreateControl(nil, control, CT_LABEL) |
|
85 | Seerah-7 | local label = control.label |
|
86 | Seerah-7 | label:SetFont("ZoFontWinH4") |
|
87 | Seerah-7 | label:SetDimensions(isHalfWidth and 250 or 300, 26) |
|
88 | Seerah-7 | label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) |
|
89 | Seerah-7 | label:SetAnchor(isHalfWidth and TOPLEFT or LEFT) |
|
90 | Seerah-7 | label:SetText(sliderData.name) |
|
91 | Seerah-7 | ||
92 | Seerah-7 | --skipping creating the backdrop... Is this the actual slider texture? |
|
93 | Seerah-7 | control.slider = wm:CreateControl(nil, control, CT_SLIDER) |
|
94 | Seerah-7 | local slider = control.slider |
|
95 | Seerah-7 | slider:SetDimensions(190, 14) |
|
96 | Seerah-7 | if isHalfWidth then |
|
97 | Seerah-7 | slider:SetAnchor(TOPRIGHT, label, BOTTOMRIGHT, -5, 2) |
|
98 | Seerah-7 | else |
|
99 | Seerah-7 | slider:SetAnchor(RIGHT, control, RIGHT, -5, -5) |
|
100 | Seerah-7 | end |
|
101 | Seerah-7 | slider:SetMouseEnabled(true) |
|
102 | Seerah-7 | slider:SetOrientation(ORIENTATION_HORIZONTAL) |
|
103 | Seerah-7 | --put nil for highlighted texture file path, and what look to be texture coords |
|
104 | Seerah-7 | slider:SetThumbTexture("EsoUI\\Art\\Miscellaneous\\scrollbox_elevator.dds", "EsoUI\\Art\\Miscellaneous\\scrollbox_elevator_disabled.dds", nil, 8, 16) |
|
105 | Seerah-7 | local minValue = sliderData.min |
|
106 | Seerah-7 | local maxValue = sliderData.max |
|
107 | Seerah-7 | slider:SetMinMax(minValue, maxValue) |
|
108 | Seerah-7 | slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) |
|
109 | Seerah-7 | slider:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseExit(control) end) |
|
110 | Seerah-7 | ||
111 | Seerah-7 | slider.bg = wm:CreateControl(nil, slider, CT_BACKDROP) |
|
112 | Seerah-7 | local bg = slider.bg |
|
113 | Seerah-7 | bg:SetCenterColor(0, 0, 0) |
|
114 | Seerah-7 | bg:SetAnchor(TOPLEFT, slider, TOPLEFT, 0, 4) |
|
115 | Seerah-7 | bg:SetAnchor(BOTTOMRIGHT, slider, BOTTOMRIGHT, 0, -4) |
|
116 | Seerah-7 | bg:SetEdgeTexture("EsoUI\\Art\\Tooltips\\UI-SliderBackdrop.dds", 32, 4) |
|
117 | Seerah-7 | ||
118 | Seerah-7 | control.minText = wm:CreateControl(nil, slider, CT_LABEL) |
|
119 | Seerah-7 | local minText = control.minText |
|
120 | Seerah-7 | minText:SetFont("ZoFontGameSmall") |
|
121 | Seerah-7 | minText:SetAnchor(TOPLEFT, slider, BOTTOMLEFT) |
|
122 | Seerah-7 | minText:SetText(sliderData.min) |
|
123 | Seerah-7 | ||
124 | Seerah-7 | control.maxText = wm:CreateControl(nil, slider, CT_LABEL) |
|
125 | Seerah-7 | local maxText = control.maxText |
|
126 | Seerah-7 | maxText:SetFont("ZoFontGameSmall") |
|
127 | Seerah-7 | maxText:SetAnchor(TOPRIGHT, slider, BOTTOMRIGHT) |
|
128 | Seerah-7 | maxText:SetText(sliderData.max) |
|
129 | Seerah-7 | ||
130 | Seerah-7 | control.slidervalueBG = wm:CreateControlFromVirtual(nil, slider, "ZO_EditBackdrop") |
|
131 | Seerah-7 | control.slidervalueBG:SetDimensions(50, 16) |
|
132 | Seerah-7 | control.slidervalueBG:SetAnchor(TOP, slider, BOTTOM, 0, 0) |
|
133 | Seerah-7 | control.slidervalue = wm:CreateControlFromVirtual(nil, control.slidervalueBG, "ZO_DefaultEditForBackdrop") |
|
134 | Seerah-7 | local slidervalue = control.slidervalue |
|
135 | Seerah-7 | slidervalue:ClearAnchors() |
|
136 | Seerah-7 | slidervalue:SetAnchor(TOPLEFT, slidervaluebg, TOPLEFT, 3, 1) |
|
137 | Seerah-7 | slidervalue:SetAnchor(BOTTOMRIGHT, slidervaluebg, BOTTOMRIGHT, -3, -1) |
|
138 | Seerah-7 | slidervalue:SetTextType(TEXT_TYPE_NUMERIC) |
|
139 | Seerah-7 | slidervalue:SetFont("ZoFontGameSmall") |
|
140 | Seerah-7 | slidervalue:SetHandler("OnEscape", function(self) |
|
141 | Seerah-7 | self:LoseFocus() |
|
142 | Seerah-7 | control:UpdateValue() |
|
143 | Seerah-7 | end) |
|
144 | Seerah-7 | slidervalue:SetHandler("OnEnter", function(self) |
|
145 | Seerah-7 | self:LoseFocus() |
|
146 | Seerah-7 | control:UpdateValue(false, tonumber(self:GetText())) |
|
147 | Seerah-7 | end) |
|
148 | Seerah-7 | ||
149 | Seerah-7 | local range = maxValue - minValue |
|
150 | 11 | Seerah-7 | slider:SetValueStep(sliderData.step or 1) |
151 | 10 | Seerah-7 | slider:SetHandler("OnValueChanged", function(self, value, eventReason) |
152 | Seerah-7 | if eventReason == EVENT_REASON_SOFTWARE then return end |
|
153 | Seerah-7 | self:SetValue(value) --do we actually need this line? |
|
154 | Seerah-7 | slidervalue:SetText(value) |
|
155 | Seerah-7 | end) |
|
156 | Seerah-7 | slider:SetHandler("OnSliderReleased", function(self, value) |
|
157 | Seerah-7 | --sliderData.setFunc(value) |
|
158 | Seerah-7 | control:UpdateValue(false, value) --does this work here instead? |
|
159 | Seerah-7 | end) |
|
160 | Seerah-7 | ||
161 | Seerah-7 | if sliderData.warning then |
|
162 | Seerah-7 | control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") |
|
163 | Seerah-7 | control.warning:SetAnchor(RIGHT, slider, LEFT, -5, 0) |
|
164 | 16 | Seerah-7 | --control.warning.tooltipText = sliderData.warning |
165 | Seerah-7 | control.warning.data = {tooltipText = sliderData.warning} |
|
166 | 10 | Seerah-7 | end |
167 | Seerah-7 | ||
168 | 14 | Seerah-7 | control.panel = parent.panel or parent --if this is in a submenu, panel is the submenu's parent |
169 | 10 | Seerah-7 | control.data = sliderData |
170 | 16 | Seerah-7 | control.data.tooltipText = sliderData.tooltip |
171 | 10 | Seerah-7 | |
172 | Seerah-7 | if sliderData.disabled then |
|
173 | Seerah-7 | control.UpdateDisabled = UpdateDisabled |
|
174 | Seerah-7 | control:UpdateDisabled() |
|
175 | Seerah-7 | end |
|
176 | Seerah-7 | control.UpdateValue = UpdateValue |
|
177 | Seerah-7 | control:UpdateValue() |
|
178 | Seerah-7 | ||
179 | 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 |
|
180 | Seerah-7 | tinsert(control.panel.controlsToRefresh, control) |
|
181 | Seerah-7 | end |
|
182 | Seerah-7 | ||
183 | Seerah-7 | return control |
|
184 | Seerah-7 | end |