vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | SW_TabbedFrameInfo = {}; |
||
3 | -- 1.5 added FrameOrder |
||
4 | SW_TabbedFrameOrder = {}; |
||
5 | |||
6 | SW_ChkParentInfo = {}; |
||
7 | SW_ChkInfo = {}; |
||
8 | SW_ChkOptInfo = {}; |
||
9 | |||
10 | -- tab colors |
||
11 | SW_COLOR_ACT = {["r"]=0.7, ["g"]=0.7, ["b"]=1}; |
||
12 | SW_COLOR_DIS = {["r"]=1, ["g"]=1, ["b"]=1}; |
||
13 | |||
14 | local function SW_FrameSetText(itemName, itemText, addWidth) |
||
15 | local oItem = getglobal(itemName); |
||
16 | local txtName = getglobal(itemName.."_Text"); |
||
17 | txtName:SetText(itemText); |
||
18 | oItem:SetWidth(txtName:GetStringWidth() + addWidth); |
||
19 | end |
||
20 | function SW_TabSetText(tabName, tabText) |
||
21 | SW_FrameSetText(tabName, tabText, 30); |
||
22 | end |
||
23 | |||
24 | function SW_TitleSetText(titleName, titleText) |
||
25 | SW_FrameSetText(titleName, titleText, 100); |
||
26 | local txtName = getglobal(titleName.."_Text"); |
||
27 | txtName:SetTextColor(1,1,1); |
||
28 | end |
||
29 | function SW_ChkClick(oChk, saveTarget, silent) |
||
30 | |||
31 | if saveTarget == nil then |
||
32 | saveTarget = SW_Settings; |
||
33 | end |
||
34 | |||
35 | if oChk.SW_optGroup ~= nil then |
||
36 | if not silent then |
||
37 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
38 | end |
||
39 | for _,v in SW_ChkOptInfo[oChk.SW_optGroup] do |
||
40 | getglobal(v):SetChecked(0); |
||
41 | end |
||
42 | oChk:SetChecked(1); |
||
43 | saveTarget[oChk.SW_optGroup] = oChk:GetName(); |
||
44 | else |
||
45 | if ( oChk:GetChecked() ) then |
||
46 | if not silent then |
||
47 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
48 | end |
||
49 | saveTarget[ SW_ChkInfo[oChk:GetName()] ] = 1; |
||
50 | else |
||
51 | if not silent then |
||
52 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
53 | end |
||
54 | saveTarget[ SW_ChkInfo[oChk:GetName()] ] = nil; |
||
55 | end |
||
56 | end |
||
57 | |||
58 | -- this really shouldn't be here.. but its easy.. |
||
59 | SW_EI_ALLOFF = not (SW_Settings["EI_ShowRegEx"] or SW_Settings["EI_ShowMatch"] |
||
60 | or SW_Settings["EI_ShowEvent"] or SW_Settings["EI_ShowOrigStr"]); |
||
61 | end |
||
62 | |||
63 | function SW_SetChkStates() |
||
64 | if SW_Settings == nil then return; end |
||
65 | for k,v in pairs(SW_ChkInfo) do |
||
66 | if SW_Settings[v] == 1 then |
||
67 | getglobal(k):SetChecked(1); |
||
68 | else |
||
69 | -- if its not on, no need to save it |
||
70 | SW_Settings[v] = nil; |
||
71 | end |
||
72 | end |
||
73 | for k,v in pairs(SW_ChkOptInfo) do |
||
74 | SW_printStr(v); |
||
75 | for _,opt in ipairs(v) do |
||
76 | if SW_Settings[k] == opt then |
||
77 | getglobal(opt):SetChecked(1); |
||
78 | else |
||
79 | getglobal(opt):SetChecked(0); |
||
80 | end |
||
81 | end |
||
82 | end |
||
83 | end |
||
84 | function SetButtonText(bName, str) |
||
85 | getglobal(bName):SetText(str); |
||
86 | end |
||
87 | function SW_ChkRegister(oChk, linkedSetting, isAnchor, optGroupName) |
||
88 | local pName = oChk:GetParent():GetName(); |
||
89 | |||
90 | if SW_ChkParentInfo[pName] == nil then SW_ChkParentInfo[pName] = {}; end |
||
91 | if isAnchor then |
||
92 | SW_ChkParentInfo[pName][0] = oChk:GetName(); |
||
93 | end |
||
94 | table.insert(SW_ChkParentInfo[pName], oChk:GetName()); |
||
95 | SW_ChkInfo[oChk:GetName()] = linkedSetting; |
||
96 | |||
97 | if optGroupName ~= nil then |
||
98 | if SW_ChkOptInfo[optGroupName] == nil then |
||
99 | SW_ChkOptInfo[optGroupName] = {}; |
||
100 | end |
||
101 | table.insert(SW_ChkOptInfo[optGroupName], oChk:GetName()); |
||
102 | oChk.SW_optGroup = optGroupName; |
||
103 | end |
||
104 | end |
||
105 | |||
106 | function SW_ChkLayoutRegisterd() |
||
107 | local oStart; |
||
108 | local posX = 0; |
||
109 | local currX = 0; |
||
110 | local posY = 0; |
||
111 | local incY = 0; |
||
112 | local boxWidth = 0; |
||
113 | local spacerX = 0; |
||
114 | |||
115 | local chkPerRow =0; |
||
116 | local oChkText; |
||
117 | local oChk; |
||
118 | |||
119 | local iCol=0; |
||
120 | local colMax = {}; |
||
121 | for fName, children in pairs(SW_ChkParentInfo) do |
||
122 | colMax = {}; |
||
123 | chkPerRow = getglobal(fName).chkPerRow; |
||
124 | if chkPerRow == nil then chkPerRow = 2; end |
||
125 | |||
126 | if children[0] == nil then |
||
127 | oStart = getglobal(children[1]); |
||
128 | else |
||
129 | oStart = getglobal(children[0]); |
||
130 | end |
||
131 | |||
132 | |||
133 | posX = oStart.swoX; |
||
134 | |||
135 | if posX == nil then posX=0; end |
||
136 | posY = oStart.swoY; |
||
137 | if posY == nil then posY=0; end |
||
138 | |||
139 | incY = oStart:GetHeight(); |
||
140 | boxWidth = oStart:GetWidth(); |
||
141 | spacerX = boxWidth / 2; |
||
142 | iCol = 0; |
||
143 | -- first we need max text width per column |
||
144 | for i,v in ipairs(children) do |
||
145 | iCol = iCol + 1; |
||
146 | oChkText = getglobal(v.."Text"); |
||
147 | if colMax[iCol] == nil then |
||
148 | colMax[iCol] = oChkText:GetStringWidth(); |
||
149 | else |
||
150 | if oChkText:GetStringWidth() > colMax[iCol] then |
||
151 | colMax[iCol] = oChkText:GetStringWidth(); |
||
152 | end |
||
153 | end |
||
154 | |||
155 | if floor (iCol / chkPerRow) == 1 then |
||
156 | iCol = 0; |
||
157 | end |
||
158 | end |
||
159 | iCol = 0; |
||
160 | for i,v in ipairs(children) do |
||
161 | iCol = iCol + 1; |
||
162 | oChk = getglobal(v); |
||
163 | if iCol == 1 then |
||
164 | currX = posX; |
||
165 | else |
||
166 | currX = currX + colMax[iCol-1] + spacerX + boxWidth; |
||
167 | end |
||
168 | oChk:SetPoint("TOPLEFT",fName,"TOPLEFT",currX,posY); |
||
169 | |||
170 | if floor (iCol / chkPerRow) == 1 then |
||
171 | iCol = 0; |
||
172 | posY = posY - incY; |
||
173 | end |
||
174 | end |
||
175 | end |
||
176 | end |
||
177 | function SW_TabRegister(oTab, linkedFrameName, activated) |
||
178 | local pName = oTab:GetParent():GetName(); |
||
179 | if activated then |
||
180 | oTab.IsSelectedTab = true; |
||
181 | oTab:SetBackdropBorderColor(SW_COLOR_ACT["r"],SW_COLOR_ACT["g"],SW_COLOR_ACT["b"],1); |
||
182 | getglobal(oTab:GetName().."_Text"):SetTextColor(SW_COLOR_ACT["r"],SW_COLOR_ACT["g"],SW_COLOR_ACT["b"]); |
||
183 | oTab:SetFrameLevel(oTab:GetParent():GetFrameLevel() +1); |
||
184 | else |
||
185 | oTab.IsSelectedTab = nil; |
||
186 | oTab:SetBackdropBorderColor(SW_COLOR_DIS["r"],SW_COLOR_DIS["g"],SW_COLOR_DIS["b"],1); |
||
187 | getglobal(oTab:GetName().."_Text"):SetTextColor(SW_COLOR_DIS["r"],SW_COLOR_DIS["g"],SW_COLOR_DIS["b"]); |
||
188 | oTab:SetFrameLevel(oTab:GetParent():GetFrameLevel() -1); |
||
189 | end |
||
190 | oTab:Show(); |
||
191 | if SW_TabbedFrameInfo[pName] == nil then SW_TabbedFrameInfo[pName] = {}; end |
||
192 | SW_TabbedFrameInfo[pName][oTab:GetName()] = linkedFrameName; |
||
193 | if SW_TabbedFrameOrder[pName] == nil then SW_TabbedFrameOrder[pName] = {}; end |
||
194 | table.insert(SW_TabbedFrameOrder[pName], oTab:GetName()); |
||
195 | end |
||
196 | |||
197 | --[[ this will space all registered tabs in relation to their parent, |
||
198 | if there are to many tabs or the parent frame ist to small |
||
199 | this can have odd visuals |
||
200 | don't forget - in one language it may work, in another not |
||
201 | the "original" width is set through SW_TabSetText and depends on the string displayed |
||
202 | ]]-- |
||
203 | local function SW_TabLayoutRegisterd() |
||
204 | local pos=0; |
||
205 | local oTab; |
||
206 | for k,v in pairs(SW_TabbedFrameInfo) do |
||
207 | pos=5; |
||
208 | --[[ |
||
209 | for t,_ in pairs(v) do |
||
210 | oTab = getglobal(t); |
||
211 | oTab:SetPoint("BOTTOMLEFT",k,"BOTTOMLEFT",pos,-25) |
||
212 | pos = pos + oTab:GetWidth() - 2; |
||
213 | end |
||
214 | --]] |
||
215 | for _,t in ipairs(SW_TabbedFrameOrder[k]) do |
||
216 | oTab = getglobal(t); |
||
217 | oTab:SetPoint("BOTTOMLEFT",k,"BOTTOMLEFT",pos,-25) |
||
218 | pos = pos + oTab:GetWidth() - 2; |
||
219 | end |
||
220 | end |
||
221 | end |
||
222 | |||
223 | function SW_TabClick(oTab) |
||
224 | local pFrameL = oTab:GetParent():GetFrameLevel(); |
||
225 | local tabName = oTab:GetName(); |
||
226 | local tmpTab; |
||
227 | |||
228 | for t,frameName in pairs(SW_TabbedFrameInfo[oTab:GetParent():GetName()]) do |
||
229 | tmpTab = getglobal(t); |
||
230 | if tmpTab:GetName() == tabName then |
||
231 | oTab:SetFrameLevel(pFrameL +1); |
||
232 | local tmpCol = {unpack(SW_Settings["Colors"]["Backdrops"])}; |
||
233 | tmpCol[4] = 1; |
||
234 | oTab:SetBackdropBorderColor(unpack(tmpCol)); |
||
235 | getglobal(tabName.."_Text"):SetTextColor(unpack(tmpCol)); |
||
236 | getglobal(frameName):Show(); |
||
237 | oTab.IsSelectedTab = true; |
||
238 | else |
||
239 | --[[ |
||
240 | 0.96 |
||
241 | for some odd reason pFrameL can be 0 and a negative frame level raises an error |
||
242 | --]] |
||
243 | if pFrameL > 0 then |
||
244 | tmpTab:SetFrameLevel(pFrameL -1); |
||
245 | end |
||
246 | oTab.IsSelectedTab = nil; |
||
247 | tmpTab:SetBackdropBorderColor(SW_COLOR_DIS["r"],SW_COLOR_DIS["g"],SW_COLOR_DIS["b"],1); |
||
248 | getglobal(tmpTab:GetName().."_Text"):SetTextColor(SW_COLOR_DIS["r"],SW_COLOR_DIS["g"],SW_COLOR_DIS["b"]); |
||
249 | getglobal(frameName):Hide(); |
||
250 | end |
||
251 | end |
||
252 | end |
||
253 | function SW_UpdateIconPos() |
||
254 | local ang = 20; |
||
255 | local r = 80; |
||
256 | if SW_Settings["SW_IconPos"] ~= nil then |
||
257 | ang = SW_Settings["SW_IconPos"]; |
||
258 | end |
||
259 | if SW_Settings["SW_IconPosR"] ~= nil then |
||
260 | r = SW_Settings["SW_IconPosR"]; |
||
261 | end |
||
262 | |||
263 | SW_IconFrame:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", 58 - (r * cos(ang)), (r * sin(ang)) - 58); |
||
264 | end |
||
265 | function SW_DoLayout() |
||
266 | SW_TabLayoutRegisterd(); |
||
267 | SW_ChkLayoutRegisterd(); |
||
268 | SW_UpdateIconPos() |
||
269 | end |
||
270 | |||
271 | function SW_InitColorSwatch(cs) |
||
272 | cs.lbl = getglobal(cs:GetName().."_Text"); |
||
273 | cs.colTexture = getglobal(cs:GetName().."_Button_Color"); |
||
274 | function cs:SetText(txt) |
||
275 | self.lbl:SetText(txt); |
||
276 | end |
||
277 | function cs:SetColor(color, what) |
||
278 | if type(color) == "table" then |
||
279 | self.colTexture:SetVertexColor(unpack(color)); |
||
280 | else |
||
281 | |||
282 | local bfc = SW_GetBarSettings(color)[what]; |
||
283 | if bfc[1]==1 and bfc[2]==0 and bfc[3]==0 and bfc[4]==1 then |
||
284 | self.colTexture:SetVertexColor(unpack(SW_Settings["Colors"]["TitleBars"])); |
||
285 | else |
||
286 | self.colTexture:SetVertexColor(unpack(bfc)); |
||
287 | end |
||
288 | |||
289 | end |
||
290 | end |
||
291 | end |
||
292 | |||
293 | function SW_UpdateTextSetting(newText, info) |
||
294 | local barSettings = SW_GetBarSettings(info[1]); |
||
295 | barSettings[ info[2] ] = newText; |
||
296 | if info[2] == "OT" or info[2] == "OTF" then |
||
297 | SW_OptUpdateText(info[1]); |
||
298 | end |
||
299 | end |
||
300 | |||
301 | function SW_InitEditBox(ef) |
||
302 | function ef:ChangeText() |
||
303 | local info = SW_GS_EditBoxes[ef:GetName()]; |
||
304 | if info == nil then return; end |
||
305 | getglobal(ef:GetName().."_Button"):SetText(info[1]); |
||
306 | getglobal(ef:GetName().."_Text"):SetText(info[2]..self.CurrentVal); |
||
307 | self.PopupText = info[3]; |
||
308 | end |
||
309 | end |
||
310 | function SW_SetSliderPreText(slname, str) |
||
311 | local sl = getglobal(slname); |
||
312 | if sl ~= nil then |
||
313 | sl.preTxt = str; |
||
314 | end |
||
315 | end |
||
316 | function SW_InitSlider(sl, min, max, setting) |
||
317 | sl.linkedSetting = setting; |
||
318 | getglobal(sl:GetName().."Low"):SetText(min); |
||
319 | getglobal(sl:GetName().."High"):SetText(max); |
||
320 | this:SetMinMaxValues(min, max); |
||
321 | this:SetValueStep(1); |
||
322 | end |
||
323 | function SW_SetColorSwatchText(csname, str) |
||
324 | local cs = getglobal(csname); |
||
325 | if cs ~= nil then |
||
326 | cs:SetText(str); |
||
327 | end |
||
328 | end |
||
329 | function SW_InitRoundButton(b) |
||
330 | b.NormalF = getglobal(b:GetName().."_Normal"); |
||
331 | b.HighlightF = getglobal(b:GetName().."_Highlight"); |
||
332 | b.NormalT = getglobal(b:GetName().."_Normal_Texture"); |
||
333 | b.HighlightT = getglobal(b:GetName().."_Highlight_Texture"); |
||
334 | b.NormalText = getglobal(b:GetName().."_Normal_Text"); |
||
335 | b.HighlightText = getglobal(b:GetName().."_Highlight_Text"); |
||
336 | b.NormalIcon = getglobal(b:GetName().."_Normal_TextureIcon"); |
||
337 | b.HighlightIcon = getglobal(b:GetName().."_Highlight_TextureIcon"); |
||
338 | b.NormalT:SetVertexColor(0,1,0,1); |
||
339 | b.HighlightT:SetVertexColor(0,1,0,1); |
||
340 | b.NormalIcon:Hide(); |
||
341 | b.HighlightIcon:Hide(); |
||
342 | |||
343 | b.SetIcons = function(self, normalTex, highlightTex) |
||
344 | if normalTex == nil then return; end |
||
345 | self.NormalIcon:SetTexture(normalTex); |
||
346 | |||
347 | if highlightTex == nil then |
||
348 | self.NormalIcon:SetTexture(normalTex); |
||
349 | else |
||
350 | self.HighlightIcon:SetTexture(highlightTex); |
||
351 | end |
||
352 | self.NormalIcon:Show(); |
||
353 | self.HighlightIcon:Show(); |
||
354 | self.NormalText:Hide(); |
||
355 | self.HighlightText:Hide(); |
||
356 | end |
||
357 | |||
358 | end |
||
359 | function SW_RoundButtonRegister(b, vColor, txt, fColor, fHeight, fForeColor) |
||
360 | SW_InitRoundButton(b); |
||
361 | if vColor ~= nil then |
||
362 | b.NormalT:SetVertexColor(unpack(vColor)); |
||
363 | b.HighlightT:SetVertexColor(unpack(vColor)); |
||
364 | end |
||
365 | if txt ~= nil then |
||
366 | b.NormalText:SetText(txt); |
||
367 | b.HighlightText:SetText(txt); |
||
368 | end |
||
369 | if fColor ~= nil then |
||
370 | b.NormalText:SetVertexColor(unpack(fColor)); |
||
371 | b.HighlightText:SetVertexColor(unpack(fColor)); |
||
372 | end |
||
373 | if fHeight ~= nil then |
||
374 | b.NormalText:SetTextHeight(fHeight); |
||
375 | b.HighlightText:SetTextHeight(fHeight); |
||
376 | end |
||
377 | if fForeColor == nil then |
||
378 | b.NormalText:SetTextColor(1,1,1,1); |
||
379 | b.HighlightText:SetTextColor(1,1,1,1); |
||
380 | else |
||
381 | b.NormalText:SetTextColor(unpack(fForeColor)); |
||
382 | b.HighlightText:SetTextColor(unpack(fForeColor)); |
||
383 | end |
||
384 | end |
||
385 | |||
386 | function SW_InitIconMenu() |
||
387 | for k, v in ipairs(SW_MiniIconMenu) do |
||
388 | |||
389 | if v["checkFrame"] ~= nil then |
||
390 | if getglobal(v["checkFrame"]):IsVisible() then |
||
391 | v["text"] = v["textHide"]; |
||
392 | else |
||
393 | v["text"] = v["textShow"]; |
||
394 | end |
||
395 | end |
||
396 | UIDropDownMenu_AddButton(v); |
||
397 | |||
398 | end |
||
399 | --UIDropDownMenu_AddButton(SW_MiniIconMenu[1]); |
||
400 | end |
||
401 | function SW_ToggleIconMenu() |
||
402 | SW_IconFrame_Menu.point = "TOPRIGHT"; |
||
403 | --SW_IconFrame_Menu.relativePoint = "BOTTOMLEFT"; |
||
404 | ToggleDropDownMenu(1, nil, SW_IconFrame_Menu); |
||
405 | end |
||
406 | function SW_IconMenuInit() |
||
407 | UIDropDownMenu_Initialize(getglobal("SW_IconFrame_Menu"), SW_InitIconMenu, "MENU"); |
||
408 | end |