yellowfive@57
|
1 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
2 Text Button Widget
|
yellowfive@57
|
3 Based on the AceGUI button, but a custom look that just shows text.
|
yellowfive@57
|
4 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
5 local Type, Version = "AmrUiTextButton", 1
|
yellowfive@57
|
6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
|
yellowfive@57
|
7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
|
yellowfive@57
|
8
|
yellowfive@57
|
9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
10
|
yellowfive@57
|
11 -- Lua APIs
|
yellowfive@57
|
12 local pairs = pairs
|
yellowfive@57
|
13
|
yellowfive@57
|
14 -- WoW APIs
|
yellowfive@57
|
15 local _G = _G
|
yellowfive@133
|
16 local CreateFrame, UIParent = CreateFrame, UIParent
|
yellowfive@57
|
17
|
yellowfive@57
|
18
|
yellowfive@57
|
19 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
20 Scripts
|
yellowfive@57
|
21 -------------------------------------------------------------------------------]]
|
yellowfive@161
|
22 -- to facilitate some use cases, we have click fired on PostClick for this widget
|
yellowfive@161
|
23 --[[local function buttonOnClick(frame, ...)
|
yellowfive@57
|
24 AceGUI:ClearFocus()
|
yellowfive@112
|
25 --PlaySound("igMainMenuOption")
|
yellowfive@57
|
26 frame.obj:Fire("OnClick", ...)
|
yellowfive@161
|
27 end]]
|
yellowfive@161
|
28
|
yellowfive@161
|
29 local function buttonPreClick(frame, ...)
|
yellowfive@161
|
30 frame.obj:Fire("PreClick", ...)
|
yellowfive@161
|
31 end
|
yellowfive@161
|
32
|
yellowfive@161
|
33 local function buttonPostClick(frame, ...)
|
yellowfive@161
|
34 frame.obj:Fire("OnClick", ...)
|
yellowfive@57
|
35 end
|
yellowfive@57
|
36
|
yellowfive@57
|
37 local function buttonOnEnter(frame)
|
yellowfive@57
|
38 frame.obj.bg:Hide()
|
yellowfive@57
|
39 frame.obj.hover:Show()
|
yellowfive@57
|
40 frame.obj:Fire("OnEnter")
|
yellowfive@57
|
41 end
|
yellowfive@57
|
42
|
yellowfive@57
|
43 local function buttonOnLeave(frame)
|
yellowfive@57
|
44 frame.obj.bg:Show()
|
yellowfive@57
|
45 frame.obj.hover:Hide()
|
yellowfive@57
|
46 frame.obj:Fire("OnLeave")
|
yellowfive@57
|
47 end
|
yellowfive@57
|
48
|
yellowfive@57
|
49 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
50 Methods
|
yellowfive@57
|
51 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
52 local methods = {
|
yellowfive@57
|
53 ["OnAcquire"] = function(self)
|
yellowfive@57
|
54 -- restore default values
|
yellowfive@57
|
55 self:SetHeight(24)
|
yellowfive@57
|
56 self:SetWidth(200)
|
yellowfive@57
|
57 self:SetBackgroundColor(Amr.Colors.Black, 0)
|
yellowfive@57
|
58 self:SetHoverBackgroundColor(Amr.Colors.Black, 0)
|
yellowfive@57
|
59 self:SetDisabled(false)
|
yellowfive@57
|
60
|
yellowfive@57
|
61 self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
|
yellowfive@57
|
62 self:SetHoverFont(Amr.CreateFont("Regular", 16, Amr.Colors.TextHover))
|
yellowfive@57
|
63 self:SetText("")
|
yellowfive@57
|
64 self:SetWordWrap(true)
|
yellowfive@57
|
65 self:SetJustifyH("CENTER")
|
yellowfive@57
|
66 self:SetJustifyV("MIDDLE")
|
yellowfive@57
|
67 self:SetTextPadding()
|
yellowfive@57
|
68
|
yellowfive@57
|
69 self:SetSubtextFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
|
yellowfive@57
|
70 self:SetSubtext()
|
yellowfive@57
|
71 self:SetSubtextWordWrap(true)
|
yellowfive@57
|
72 self:SetSubtextJustifyH("CENTER")
|
yellowfive@57
|
73 self:SetSubtextJustifyV("MIDDLE")
|
yellowfive@57
|
74 self:SetSubtextPadding()
|
yellowfive@57
|
75
|
yellowfive@57
|
76 self.frame:ClearAllPoints()
|
yellowfive@57
|
77 self.bg:Show()
|
yellowfive@57
|
78 self.hover:Hide()
|
yellowfive@57
|
79 end,
|
yellowfive@57
|
80
|
yellowfive@57
|
81 ["OnWidthSet"] = function(self, width)
|
yellowfive@57
|
82 self.frame:GetFontString():SetWidth(width)
|
yellowfive@57
|
83 end,
|
yellowfive@57
|
84
|
yellowfive@57
|
85 ["OnHeightSet"] = function(self, height)
|
yellowfive@57
|
86 self.frame:GetFontString():SetHeight(height)
|
yellowfive@57
|
87 end,
|
yellowfive@57
|
88
|
yellowfive@57
|
89 ["SetBackgroundColor"] = function(self, color, alpha)
|
yellowfive@81
|
90 self.bg:SetColorTexture(color.R, color.G, color.B, alpha)
|
yellowfive@57
|
91 end,
|
yellowfive@57
|
92
|
yellowfive@57
|
93 ["SetBackgroundImage"] = function(self, image)
|
yellowfive@57
|
94 self.bg:SetTexture(image)
|
yellowfive@57
|
95 self.bg:SetDesaturated(false)
|
yellowfive@57
|
96 end,
|
yellowfive@57
|
97
|
yellowfive@57
|
98 ["SetHoverBackgroundColor"] = function(self, color, alpha)
|
yellowfive@81
|
99 self.hover:SetColorTexture(color.R, color.G, color.B, alpha)
|
yellowfive@57
|
100 end,
|
yellowfive@57
|
101
|
yellowfive@57
|
102 ["SetHoverBackgroundImage"] = function(self, image)
|
yellowfive@57
|
103 self.hover:SetTexture(image)
|
yellowfive@57
|
104 end,
|
yellowfive@57
|
105
|
yellowfive@57
|
106 ["SetText"] = function(self, text)
|
yellowfive@57
|
107 self.frame:SetText(text)
|
yellowfive@57
|
108 end,
|
yellowfive@57
|
109
|
yellowfive@57
|
110 ["SetWordWrap"] = function(self, enable)
|
yellowfive@57
|
111 self.frame:GetFontString():SetWordWrap(enable)
|
yellowfive@57
|
112 end,
|
yellowfive@57
|
113
|
yellowfive@57
|
114 ["SetJustifyH"] = function(self, val)
|
yellowfive@57
|
115 self.frame:GetFontString():SetJustifyH(val)
|
yellowfive@57
|
116 end,
|
yellowfive@57
|
117
|
yellowfive@57
|
118 ["SetJustifyV"] = function(self, val)
|
yellowfive@57
|
119 self.frame:GetFontString():SetJustifyV(val)
|
yellowfive@57
|
120 end,
|
yellowfive@57
|
121
|
yellowfive@57
|
122 ["SetTextPadding"] = function(self, top, right, bottom, left)
|
yellowfive@57
|
123 local f = self.frame:GetFontString()
|
yellowfive@57
|
124 f:ClearAllPoints()
|
yellowfive@57
|
125
|
yellowfive@57
|
126 if not top and not right and not bottom and not left then
|
yellowfive@57
|
127 f:SetPoint("CENTER")
|
yellowfive@57
|
128 end
|
yellowfive@57
|
129
|
yellowfive@57
|
130 if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end
|
yellowfive@57
|
131 if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end
|
yellowfive@57
|
132 if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end
|
yellowfive@57
|
133 if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end
|
yellowfive@57
|
134 end,
|
yellowfive@57
|
135
|
yellowfive@57
|
136 ["SetFont"] = function(self, font)
|
yellowfive@57
|
137 self.frame:SetNormalFontObject(font)
|
yellowfive@57
|
138 end,
|
yellowfive@57
|
139
|
yellowfive@57
|
140 ["SetHoverFont"] = function(self, font)
|
yellowfive@57
|
141 self.frame:SetHighlightFontObject(font)
|
yellowfive@57
|
142 end,
|
yellowfive@57
|
143
|
yellowfive@57
|
144 ["SetSubtext"] = function(self, text)
|
yellowfive@57
|
145 self.subtxt:SetText(text)
|
yellowfive@57
|
146 if text then
|
yellowfive@57
|
147 self.subtxt:Show()
|
yellowfive@57
|
148 else
|
yellowfive@57
|
149 self.subtxt:Hide()
|
yellowfive@57
|
150 end
|
yellowfive@57
|
151 end,
|
yellowfive@57
|
152
|
yellowfive@57
|
153 ["SetSubtextWordWrap"] = function(self, enable)
|
yellowfive@57
|
154 self.subtxt:SetWordWrap(enable)
|
yellowfive@57
|
155 end,
|
yellowfive@57
|
156
|
yellowfive@57
|
157 ["SetSubtextJustifyH"] = function(self, val)
|
yellowfive@57
|
158 self.subtxt:SetJustifyH(val)
|
yellowfive@57
|
159 end,
|
yellowfive@57
|
160
|
yellowfive@57
|
161 ["SetSubtextJustifyV"] = function(self, val)
|
yellowfive@57
|
162 self.subtxt:SetJustifyV(val)
|
yellowfive@57
|
163 end,
|
yellowfive@57
|
164
|
yellowfive@57
|
165 ["SetSubtextPadding"] = function(self, top, right, bottom, left)
|
yellowfive@57
|
166 local f = self.subtxt
|
yellowfive@57
|
167 f:ClearAllPoints()
|
yellowfive@57
|
168 if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end
|
yellowfive@57
|
169 if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end
|
yellowfive@57
|
170 if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end
|
yellowfive@57
|
171 if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end
|
yellowfive@57
|
172 end,
|
yellowfive@57
|
173
|
yellowfive@57
|
174 ["SetSubtextFont"] = function(self, font)
|
yellowfive@57
|
175 self.subtxt:SetFontObject(font)
|
yellowfive@57
|
176 end,
|
yellowfive@57
|
177
|
yellowfive@57
|
178 ["SetDisabled"] = function(self, disabled)
|
yellowfive@57
|
179 self.disabled = disabled
|
yellowfive@57
|
180 if disabled then
|
yellowfive@57
|
181 self.frame:Disable()
|
yellowfive@57
|
182 else
|
yellowfive@57
|
183 self.frame:Enable()
|
yellowfive@57
|
184 end
|
yellowfive@57
|
185 end,
|
yellowfive@57
|
186
|
yellowfive@57
|
187 ["SetVisible"] = function(self, visible)
|
yellowfive@57
|
188 if visible then
|
yellowfive@57
|
189 self.frame:Show()
|
yellowfive@57
|
190 else
|
yellowfive@57
|
191 self.frame:Hide()
|
yellowfive@57
|
192 end
|
yellowfive@161
|
193 end,
|
yellowfive@161
|
194
|
yellowfive@161
|
195 --
|
yellowfive@161
|
196 -- If text is specified, turns this into a button that calls a macro
|
yellowfive@161
|
197 --
|
yellowfive@161
|
198 ["SetMacroText"] = function(self, text)
|
yellowfive@161
|
199 if text then
|
yellowfive@161
|
200 self.frame:SetAttribute("type", "macro")
|
yellowfive@161
|
201 self.frame:SetAttribute("macrotext", text)
|
yellowfive@161
|
202 else
|
yellowfive@161
|
203 self.frame:SetAttribute("type", nil)
|
yellowfive@161
|
204 self.frame:SetAttribute("macrotext", nil)
|
yellowfive@161
|
205 end
|
yellowfive@57
|
206 end
|
yellowfive@57
|
207 }
|
yellowfive@57
|
208
|
yellowfive@57
|
209 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
210 Constructor
|
yellowfive@57
|
211 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
212 local function Constructor()
|
yellowfive@57
|
213 local name = "AmrUiTextButton" .. AceGUI:GetNextWidgetNum(Type)
|
yellowfive@161
|
214 local frame = CreateFrame("Button", name, UIParent, "SecureActionButtonTemplate")
|
yellowfive@57
|
215 frame:Hide()
|
yellowfive@57
|
216
|
yellowfive@57
|
217 local txt = frame:CreateFontString()
|
yellowfive@57
|
218 frame:SetFontString(txt)
|
yellowfive@57
|
219
|
yellowfive@57
|
220 local subtxt = frame:CreateFontString()
|
yellowfive@57
|
221 subtxt:Hide()
|
yellowfive@57
|
222
|
yellowfive@57
|
223 frame:EnableMouse(true)
|
yellowfive@57
|
224 frame:SetScript("OnEnter", buttonOnEnter)
|
yellowfive@57
|
225 frame:SetScript("OnLeave", buttonOnLeave)
|
yellowfive@161
|
226 --frame:SetScript("OnClick", buttonOnClick)
|
yellowfive@161
|
227 frame:SetScript("PreClick", buttonPreClick)
|
yellowfive@161
|
228 frame:SetScript("PostClick", buttonPostClick)
|
yellowfive@57
|
229
|
yellowfive@57
|
230 local bg = frame:CreateTexture()
|
yellowfive@57
|
231 bg:SetAllPoints()
|
yellowfive@57
|
232
|
yellowfive@57
|
233 local hover = frame:CreateTexture()
|
yellowfive@57
|
234 hover:SetAllPoints()
|
yellowfive@57
|
235
|
yellowfive@57
|
236 local widget = {
|
yellowfive@57
|
237 bg = bg,
|
yellowfive@57
|
238 subtxt = subtxt,
|
yellowfive@57
|
239 hover = hover,
|
yellowfive@57
|
240 frame = frame,
|
yellowfive@57
|
241 type = Type
|
yellowfive@57
|
242 }
|
yellowfive@57
|
243 for method, func in pairs(methods) do
|
yellowfive@57
|
244 widget[method] = func
|
yellowfive@57
|
245 end
|
yellowfive@57
|
246
|
yellowfive@57
|
247 return AceGUI:RegisterAsWidget(widget)
|
yellowfive@57
|
248 end
|
yellowfive@57
|
249
|
yellowfive@57
|
250 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|