yellowfive@57
|
1 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
2 AMR TabGroup Container
|
yellowfive@57
|
3 Container that uses tabs on top to switch between groups.
|
yellowfive@57
|
4 This is adapted from AceGUIContainer-TabGroup, but has a custom look.
|
yellowfive@57
|
5 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
6 local Type, Version = "AmrUiTabGroup", 1
|
yellowfive@57
|
7 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
|
yellowfive@57
|
8 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
|
yellowfive@57
|
9
|
yellowfive@57
|
10 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
11
|
yellowfive@57
|
12 -- Lua APIs
|
yellowfive@57
|
13 local pairs, ipairs, assert, type, wipe = pairs, ipairs, assert, type, wipe
|
yellowfive@57
|
14
|
yellowfive@57
|
15 -- WoW APIs
|
yellowfive@57
|
16 local PlaySound = PlaySound
|
yellowfive@57
|
17 local CreateFrame, UIParent = CreateFrame, UIParent
|
yellowfive@57
|
18 local _G = _G
|
yellowfive@57
|
19
|
yellowfive@57
|
20
|
yellowfive@57
|
21 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
22 Support functions
|
yellowfive@57
|
23 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
24
|
yellowfive@57
|
25 local function tabSetSelected(frame, selected)
|
yellowfive@57
|
26 frame.selected = selected
|
yellowfive@57
|
27 end
|
yellowfive@57
|
28
|
yellowfive@57
|
29 local function tabSetDisabled(frame, disabled)
|
yellowfive@57
|
30 frame.disabled = disabled
|
yellowfive@57
|
31 end
|
yellowfive@57
|
32
|
yellowfive@57
|
33 local function buildTabsOnUpdate(frame)
|
yellowfive@57
|
34 local self = frame.obj
|
yellowfive@57
|
35 self:BuildTabs()
|
yellowfive@57
|
36 frame:SetScript("OnUpdate", nil)
|
yellowfive@57
|
37 end
|
yellowfive@57
|
38
|
yellowfive@57
|
39
|
yellowfive@57
|
40 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
41 Scripts
|
yellowfive@57
|
42 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
43 local function tabOnClick(frame)
|
yellowfive@57
|
44 if not (frame.selected or frame.disabled) then
|
yellowfive@112
|
45 --PlaySound("igCharacterInfoTab")
|
yellowfive@57
|
46 frame.obj:SelectTab(frame.value)
|
yellowfive@57
|
47 end
|
yellowfive@57
|
48 end
|
yellowfive@57
|
49
|
yellowfive@57
|
50
|
yellowfive@57
|
51 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
52 Methods
|
yellowfive@57
|
53 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
54 local methods = {
|
yellowfive@57
|
55 ["OnAcquire"] = function(self)
|
yellowfive@57
|
56 self.tabSelector:Hide()
|
yellowfive@57
|
57 self.frame:ClearAllPoints()
|
yellowfive@57
|
58 end,
|
yellowfive@57
|
59
|
yellowfive@57
|
60 ["OnRelease"] = function(self)
|
yellowfive@57
|
61 self.status = nil
|
yellowfive@57
|
62 for k in pairs(self.localstatus) do
|
yellowfive@57
|
63 self.localstatus[k] = nil
|
yellowfive@57
|
64 end
|
yellowfive@57
|
65 self.tablist = nil
|
yellowfive@57
|
66 for _, tab in pairs(self.tabs) do
|
yellowfive@57
|
67 tab:Hide()
|
yellowfive@57
|
68 end
|
yellowfive@57
|
69 self.tabSelector:Hide()
|
yellowfive@57
|
70 end,
|
yellowfive@57
|
71
|
yellowfive@57
|
72 ["CreateTab"] = function(self, id, style)
|
yellowfive@57
|
73 local tabname = ("AmrUiTabGroup%dTab%d"):format(self.num, id)
|
yellowfive@57
|
74
|
yellowfive@57
|
75 local tab = CreateFrame("Button", tabname, self.border)
|
yellowfive@57
|
76 tab.obj = self
|
yellowfive@57
|
77 tab.id = id
|
yellowfive@57
|
78
|
yellowfive@57
|
79 if style == "bold" then
|
yellowfive@57
|
80 tab:SetNormalFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHeaderDisabled))
|
yellowfive@57
|
81 tab:SetHighlightFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHover))
|
yellowfive@57
|
82 else
|
yellowfive@57
|
83 tab:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text))
|
yellowfive@57
|
84 tab:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.TextHover))
|
yellowfive@57
|
85 end
|
yellowfive@57
|
86
|
yellowfive@57
|
87 tab:SetScript("OnClick", tabOnClick)
|
yellowfive@57
|
88
|
yellowfive@57
|
89 tab.SetSelected = tabSetSelected
|
yellowfive@57
|
90 tab.SetDisabled = tabSetDisabled
|
yellowfive@57
|
91
|
yellowfive@57
|
92 return tab
|
yellowfive@57
|
93 end,
|
yellowfive@57
|
94
|
yellowfive@57
|
95 ["SetStatusTable"] = function(self, status)
|
yellowfive@57
|
96 assert(type(status) == "table")
|
yellowfive@57
|
97 self.status = status
|
yellowfive@57
|
98 end,
|
yellowfive@57
|
99
|
yellowfive@57
|
100 ["SelectTab"] = function(self, value)
|
yellowfive@57
|
101 local status = self.status or self.localstatus
|
yellowfive@57
|
102
|
yellowfive@57
|
103 self.tabSelector:Hide()
|
yellowfive@57
|
104
|
yellowfive@57
|
105 local found
|
yellowfive@57
|
106 for i, v in ipairs(self.tabs) do
|
yellowfive@57
|
107 if v.value == value then
|
yellowfive@57
|
108 v:SetSelected(true)
|
yellowfive@57
|
109 found = true
|
yellowfive@57
|
110
|
yellowfive@57
|
111 -- show the tab selector under the proper tab
|
yellowfive@57
|
112 if v.style == "underline" then
|
yellowfive@57
|
113 self.tabSelector:SetWidth(v:GetWidth())
|
yellowfive@57
|
114 self.tabSelector:ClearAllPoints()
|
yellowfive@57
|
115 self.tabSelector:SetPoint("TOPLEFT", v, "BOTTOMLEFT", 0, -2)
|
yellowfive@57
|
116 self.tabSelector:Show()
|
yellowfive@57
|
117 v:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text))
|
yellowfive@57
|
118 v:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text))
|
yellowfive@57
|
119 elseif v.style == "bold" then
|
yellowfive@57
|
120 v:SetNormalFontObject(Amr.CreateFont("Bold", 28, Amr.Colors.TextHeaderActive))
|
yellowfive@57
|
121 v:SetHighlightFontObject(Amr.CreateFont("Bold", 28, Amr.Colors.TextHeaderActive))
|
yellowfive@57
|
122 end
|
yellowfive@57
|
123 else
|
yellowfive@57
|
124 v:SetSelected(false)
|
yellowfive@57
|
125 if v.style == "bold" then
|
yellowfive@57
|
126 v:SetNormalFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHeaderDisabled))
|
yellowfive@57
|
127 v:SetHighlightFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHover))
|
yellowfive@57
|
128 else
|
yellowfive@57
|
129 v:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text))
|
yellowfive@57
|
130 v:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.TextHover))
|
yellowfive@57
|
131 end
|
yellowfive@57
|
132 end
|
yellowfive@57
|
133 end
|
yellowfive@57
|
134 status.selected = value
|
yellowfive@57
|
135
|
yellowfive@57
|
136 -- call this to reposition after style change
|
yellowfive@57
|
137 self:BuildTabs()
|
yellowfive@57
|
138
|
yellowfive@57
|
139 if found then
|
yellowfive@57
|
140 self:Fire("OnGroupSelected",value)
|
yellowfive@57
|
141 end
|
yellowfive@57
|
142 end,
|
yellowfive@57
|
143
|
yellowfive@57
|
144 ["SetTabs"] = function(self, tabs)
|
yellowfive@57
|
145 self.tablist = tabs
|
yellowfive@57
|
146 self:BuildTabs()
|
yellowfive@57
|
147 end,
|
yellowfive@57
|
148
|
yellowfive@57
|
149 ["BuildTabs"] = function(self)
|
yellowfive@57
|
150 local status = self.status or self.localstatus
|
yellowfive@57
|
151 local tablist = self.tablist
|
yellowfive@57
|
152 local tabs = self.tabs
|
yellowfive@57
|
153
|
yellowfive@57
|
154 if not tablist then return end
|
yellowfive@57
|
155
|
yellowfive@57
|
156 local first = true
|
yellowfive@57
|
157 for i, v in ipairs(tablist) do
|
yellowfive@57
|
158 local tab = tabs[i]
|
yellowfive@57
|
159 if not tab then
|
yellowfive@57
|
160 tab = self:CreateTab(i)
|
yellowfive@57
|
161 tabs[i] = tab
|
yellowfive@57
|
162 end
|
yellowfive@57
|
163
|
yellowfive@57
|
164 local padding = 20
|
yellowfive@57
|
165 if v.style == "bold" then padding = 0 end
|
yellowfive@57
|
166
|
yellowfive@57
|
167 tab:Show()
|
yellowfive@57
|
168 tab:SetText(v.text)
|
yellowfive@57
|
169 tab:SetWidth(tab:GetTextWidth() + padding)
|
yellowfive@57
|
170 tab:SetHeight(tab:GetTextHeight())
|
yellowfive@57
|
171 tab:SetDisabled(v.disabled)
|
yellowfive@57
|
172 tab.value = v.value
|
yellowfive@57
|
173 tab.style = v.style or "underline"
|
yellowfive@57
|
174
|
yellowfive@57
|
175 tab:ClearAllPoints()
|
yellowfive@57
|
176 if first then
|
yellowfive@57
|
177 local firstOffset = 0
|
yellowfive@57
|
178 if tab.style == "bold" then firstOffset = 4 end
|
yellowfive@57
|
179 tab:SetPoint("BOTTOMLEFT", self.border, "TOPLEFT", firstOffset, 8)
|
yellowfive@57
|
180 first = false
|
yellowfive@57
|
181 else
|
yellowfive@57
|
182 tab:SetPoint("LEFT", tabs[i - 1], "RIGHT", 30, 0)
|
yellowfive@57
|
183 end
|
yellowfive@57
|
184 end
|
yellowfive@57
|
185 end,
|
yellowfive@57
|
186
|
yellowfive@57
|
187 ["OnWidthSet"] = function(self, width)
|
yellowfive@57
|
188 local content = self.content
|
yellowfive@57
|
189 local contentwidth = width - 60
|
yellowfive@57
|
190 if contentwidth < 0 then
|
yellowfive@57
|
191 contentwidth = 0
|
yellowfive@57
|
192 end
|
yellowfive@57
|
193 content:SetWidth(contentwidth)
|
yellowfive@57
|
194 content.width = contentwidth
|
yellowfive@57
|
195 self:BuildTabs(self)
|
yellowfive@57
|
196 self.frame:SetScript("OnUpdate", buildTabsOnUpdate)
|
yellowfive@57
|
197 end,
|
yellowfive@57
|
198
|
yellowfive@57
|
199 ["OnHeightSet"] = function(self, height)
|
yellowfive@57
|
200 local content = self.content
|
yellowfive@57
|
201 local contentheight = height - (self.borderoffset + 23)
|
yellowfive@57
|
202 if contentheight < 0 then
|
yellowfive@57
|
203 contentheight = 0
|
yellowfive@57
|
204 end
|
yellowfive@57
|
205 content:SetHeight(contentheight)
|
yellowfive@57
|
206 content.height = contentheight
|
yellowfive@57
|
207 end,
|
yellowfive@57
|
208
|
yellowfive@57
|
209 ["LayoutFinished"] = function(self, width, height)
|
yellowfive@57
|
210 if self.noAutoHeight then return end
|
yellowfive@57
|
211 self:SetHeight((height or 0) + (self.borderoffset + 23))
|
yellowfive@57
|
212 end,
|
yellowfive@57
|
213
|
yellowfive@57
|
214 ["SetVisible"] = function(self, visible)
|
yellowfive@57
|
215 if visible then
|
yellowfive@57
|
216 self.frame:Show()
|
yellowfive@57
|
217 else
|
yellowfive@57
|
218 self.frame:Hide()
|
yellowfive@57
|
219 end
|
yellowfive@57
|
220 end
|
yellowfive@57
|
221 }
|
yellowfive@57
|
222
|
yellowfive@57
|
223 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
224 Constructor
|
yellowfive@57
|
225 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
226 local function Constructor()
|
yellowfive@57
|
227 local num = AceGUI:GetNextWidgetNum(Type)
|
yellowfive@57
|
228 local frame = CreateFrame("Frame",nil,UIParent)
|
yellowfive@57
|
229 frame:SetHeight(100)
|
yellowfive@57
|
230 frame:SetWidth(100)
|
yellowfive@57
|
231 frame:SetFrameStrata("FULLSCREEN_DIALOG")
|
yellowfive@57
|
232
|
yellowfive@57
|
233 local border = CreateFrame("Frame", nil, frame)
|
yellowfive@57
|
234 local borderoffset = 30
|
yellowfive@57
|
235 border:SetPoint("TOPLEFT", 0, -borderoffset)
|
yellowfive@57
|
236 border:SetPoint("BOTTOMRIGHT", 0, 3)
|
yellowfive@57
|
237
|
yellowfive@57
|
238 local line = border:CreateTexture(nil, "ARTWORK")
|
yellowfive@57
|
239 line:Hide()
|
yellowfive@81
|
240 line:SetColorTexture(1, 1, 1, 1)
|
yellowfive@57
|
241 line:SetHeight(4)
|
yellowfive@57
|
242
|
yellowfive@57
|
243 local content = CreateFrame("Frame", nil, border)
|
yellowfive@57
|
244 content:SetPoint("TOPLEFT", 0, 0)
|
yellowfive@57
|
245 content:SetPoint("BOTTOMRIGHT", 0, 0)
|
yellowfive@57
|
246
|
yellowfive@57
|
247 local widget = {
|
yellowfive@57
|
248 num = num,
|
yellowfive@57
|
249 frame = frame,
|
yellowfive@57
|
250 localstatus = {},
|
yellowfive@57
|
251 alignoffset = 18,
|
yellowfive@57
|
252 border = border,
|
yellowfive@57
|
253 borderoffset = borderoffset,
|
yellowfive@57
|
254 tabs = {},
|
yellowfive@57
|
255 tabSelector = line,
|
yellowfive@57
|
256 content = content,
|
yellowfive@57
|
257 type = Type
|
yellowfive@57
|
258 }
|
yellowfive@57
|
259 for method, func in pairs(methods) do
|
yellowfive@57
|
260 widget[method] = func
|
yellowfive@57
|
261 end
|
yellowfive@57
|
262
|
yellowfive@57
|
263 return AceGUI:RegisterAsContainer(widget)
|
yellowfive@57
|
264 end
|
yellowfive@57
|
265
|
yellowfive@57
|
266 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|