vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -----------------------------------------------------------------------------------------
2 -- Nurfed Options Menu
3 -----------------------------------------------------------------------------------------
4  
5 local utility = Nurfed_Utility:New();
6 local framelib = Nurfed_Frames:New();
7  
8 local menus = {};
9 local activemenu = nil;
10  
11 StaticPopupDialogs["NRF_RELOADUI"] = {
12 text = "Reload User Interface?",
13 button1 = TEXT(ACCEPT),
14 button2 = TEXT(CANCEL),
15 OnAccept = function()
16 ReloadUI();
17 end,
18 timeout = 10,
19 whileDead = 1,
20 hideOnEscape = 1,
21 };
22  
23 local templates = {
24 nrf_menu_button = {
25 type = "Button",
26 size = { 80, 14 },
27 TextFontObject = "GameFontNormalSmall",
28 TextColor = { 0.5, 0.5, 0.5 },
29 HighlightTextColor = { 1, 1, 1 },
30 DisabledTextColor = { 1, 1, 1 },
31 PushedTextOffset = { 1, -1 },
32 children = {
33 NormalTexture = {
34 type = "Texture",
35 layer = "BACKGROUND",
36 Anchor = "all",
37 Texture = NRF_IMG.."statusbar8",
38 Gradient = { "VERTICAL", 1, 0.5, 0, 0.2, 0, 0 },
39 },
40 DisabledTexture = {
41 type = "Texture",
42 layer = "BACKGROUND",
43 Anchor = "all",
44 Texture = NRF_IMG.."statusbar8",
45 Gradient = { "VERTICAL", 0, 0.75, 1, 0, 0, 0.2 },
46 },
47 },
48 },
49 nrf_options = {
50 type = "Frame",
51 size = { 411, 271 },
52 Anchor = { "TOPRIGHT", "$parentheader", "BOTTOMRIGHT", 1, 0 },
53 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 8, insets = { left = 2, right = 2, top = 2, bottom = 2 }, },
54 BackdropColor = { 0, 0, 0, 0.95 },
55 Alpha = 0,
56 Hide = true,
57 },
58 nrf_addon_row = {
59 type = "Frame",
60 size = { 400, 14 },
61 children = {
62 check = {
63 type = "CheckButton",
64 size = { 16, 16 },
65 uitemp = "UICheckButtonTemplate",
66 Anchor = { "BOTTOMLEFT", "$parent", "BOTTOMLEFT", 2, 0 },
67 OnClick = function() Nurfed_ToggleAddOn() end,
68 },
69 name = {
70 type = "FontString",
71 layer = "ARTWORK",
72 size = { 190, 14 },
73 Anchor = { "LEFT", "$parentcheck", "RIGHT", 5, 0 },
74 FontObject = "GameFontNormal",
75 JustifyH = "LEFT",
76 TextColor = { 1, 1, 1 },
77 },
78 loaded = {
79 type = "FontString",
80 layer = "ARTWORK",
81 size = { 105, 14 },
82 Anchor = { "LEFT", "$parentname", "RIGHT", 5, 0 },
83 FontObject = "GameFontNormal",
84 JustifyH = "LEFT",
85 TextColor = { 1, 1, 1 },
86 },
87 reload = {
88 type = "FontString",
89 layer = "ARTWORK",
90 size = { 100, 14 },
91 Anchor = { "LEFT", "$parentloaded", "RIGHT", 5, 0 },
92 FontObject = "GameFontNormal",
93 JustifyH = "LEFT",
94 TextColor = { 1, 0, 0 },
95 },
96 },
97 },
98 nrf_button = {
99 type = "Button",
100 size = { 30, 18 },
101 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 8, insets = { left = 2, right = 2, top = 2, bottom = 2 }, },
102 BackdropColor = { 0, 0, 0, 0.75 },
103 Font = { "Fonts\\ARIALN.TTF", 10, "NONE" },
104 TextColor = { 0.65, 0.65, 0.65 },
105 HighlightTextColor = { 1, 1, 1 },
106 PushedTextOffset = { 1, -1 },
107 OnShow = function() Nurfed_Options_buttonOnShow() end,
108 },
109 nrf_check = {
110 type = "CheckButton",
111 size = { 20, 20 },
112 uitemp = "UICheckButtonTemplate",
113 OnShow = function() Nurfed_Options_OnShow() end,
114 OnClick = function() Nurfed_Options_checkOnClick() end,
115 },
116 nrf_smallcheck = {
117 type = "CheckButton",
118 size = { 16, 16 },
119 uitemp = "UICheckButtonTemplate",
120 OnShow = function() Nurfed_Options_OnShow() end,
121 OnClick = function() Nurfed_Options_checkOnClick() end,
122 },
123 nrf_radio = {
124 type = "CheckButton",
125 size = { 14, 14 },
126 uitemp = "UIRadioButtonTemplate",
127 OnShow = function() Nurfed_Options_OnShow() end,
128 OnClick = function() Nurfed_Options_radioOnClick() end,
129 },
130 nrf_slider = {
131 type = "Slider",
132 uitemp = "OptionsSliderTemplate",
133 children = {
134 value = {
135 type = "FontString",
136 layer = "ARTWORK",
137 FontObject = "GameFontNormalSmall",
138 JustifyH = "CENTER",
139 TextColor = { 0, 1, 0 },
140 },
141 },
142 OnShow = function() Nurfed_Options_OnShow() end,
143 OnMouseUp = function() Nurfed_Options_sliderOnMouseUp() end,
144 OnValueChanged = function() Nurfed_Options_sliderOnValueChanged() end,
145 },
146 nrf_editbox = {
147 type = "EditBox",
148 AutoFocus = false,
149 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 8, insets = { left = 2, right = 2, top = 2, bottom = 2 }, },
150 BackdropColor = { 0, 0, 0.2, 0.75 },
151 FontObject = "GameFontNormalSmall",
152 TextColor = { 1, 1, 1 },
153 TextInsets = { 3, 9, 0, 0 },
154 OnEscapePressed = function() this:ClearFocus() end,
155 OnEditFocusLost = function() this:HighlightText(0, 0) end,
156 OnEditFocusGained = function() this:HighlightText() end,
157 },
158 nrf_input = {
159 type = "Frame",
160 size = { 130, 30 },
161 children = {
162 Text = {
163 type = "FontString",
164 layer = "ARTWORK",
165 Anchor = { "TOPLEFT", "$parent", "TOPLEFT", 3, 0 },
166 FontObject = "GameFontNormalSmall",
167 JustifyH = "LEFT",
168 },
169 input = {
170 template = "nrf_editbox",
171 size = { 100, 18 },
172 Anchor = { "BOTTOMLEFT", "$parent", "BOTTOMLEFT", 0, 0 },
173 OnEnterPressed = function() Nurfed_Options_inputOnClick() end,
174 },
175 set = {
176 template = "nrf_button",
177 Anchor = { "LEFT", "$parentinput", "RIGHT", 1, 0 },
178 OnClick = function() Nurfed_Options_inputOnClick() end,
179 vars = { text = "Set" },
180 },
181 },
182 OnShow = function() Nurfed_Options_inputOnShow() end,
183 },
184 nrf_color = {
185 type = "Button",
186 size = { 18, 18 },
187 children = {
188 bg = {
189 type = "Texture",
190 Texture = "Interface\\ChatFrame\\ChatFrameColorSwatch",
191 layer = "BACKGROUND",
192 Anchor = "all",
193 VertexColor = { 1, 1, 1 },
194 },
195 Text = {
196 type = "FontString",
197 layer = "ARTWORK",
198 Anchor = { "LEFT", "$parent", "RIGHT", 1, 0 },
199 FontObject = "GameFontNormalSmall",
200 JustifyH = "LEFT",
201 },
202 },
203 OnShow = function() Nurfed_Options_swatchOnShow() end,
204 OnClick = function() Nurfed_Options_swatchOpenColorPicker() end,
205 },
206 nrf_scroll = {
207 type = "ScrollFrame",
208 Anchor = "all",
209 uitemp = "FauxScrollFrameTemplate",
210 OnVerticalScroll = function() FauxScrollFrame_OnVerticalScroll(100, Nurfed_Options_ScrollMenu) end,
211 OnShow = function() Nurfed_Options_ScrollMenu() end,
212 },
213 nrf_optionpane = {
214 type = "Frame",
215 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 8, insets = { left = 2, right = 2, top = 2, bottom = 2 }, },
216 BackdropColor = { 0, 0, 0, 0.5 },
217 BackdropBorderColor = { 0.75, 0.75, 0.75, 1 },
218 children = {
219 title = {
220 type = "FontString",
221 layer = "ARTWORK",
222 Anchor = { "BOTTOMLEFT", "$parent", "TOPLEFT", 10, -2 },
223 FontObject = "GameFontNormalSmall",
224 JustifyH = "LEFT",
225 },
226 },
227 OnShow = function() Nurfed_Options_paneOnShow() end,
228 },
229 nrf_paneeditbox = {
230 type = "EditBox",
231 AutoFocus = false,
232 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = nil, tile = true, tileSize = 16, edgeSize = 8, insets = { left = 2, right = 2, top = 2, bottom = 2 }, },
233 BackdropColor = { 0.5, 0.5, 0.5, 0.85 },
234 FontObject = "GameFontNormalSmall",
235 TextColor = { 1, 1, 0 },
236 TextInsets = { 3, 9, 0, 0 },
237 OnEscapePressed = function() this:ClearFocus() end,
238 OnEditFocusLost = function() this:HighlightText(0, 0) end,
239 OnEditFocusGained = function() this:HighlightText() end,
240 OnEnterPressed = function() Nurfed_Options_paneAddOption() end,
241 },
242 nrf_panescroll = {
243 type = "ScrollFrame",
244 Anchor = "all",
245 uitemp = "FauxScrollFrameTemplate",
246 Scale = 0.75,
247 OnVerticalScroll = function() FauxScrollFrame_OnVerticalScroll(13, Nurfed_Options_ScrollPane) end,
248 OnShow = function() Nurfed_Options_ScrollPane() end,
249 },
250 nrf_pane_row = {
251 type = "Button",
252 children = {
253 text = {
254 type = "FontString",
255 layer = "ARTWORK",
256 Anchor = "all",
257 FontObject = "GameFontNormalSmall",
258 JustifyH = "LEFT",
259 TextColor = { 0, 1, 1 },
260 },
261 HighlightTexture = {
262 type = "Texture",
263 layer = "BACKGROUND",
264 Texture = "Interface\\QuestFrame\\UI-QuestTitleHighlight",
265 BlendMode = "ADD",
266 Anchor = "all",
267 },
268 },
269 OnClick = function() Nurfed_Options_PaneSelect() end,
270 },
271 };
272  
273 local layout = {
274 type = "Frame",
275 size = { 500, 300 },
276 FrameStrata = "LOW",
277 Anchor = { "CENTER", "$parent", "CENTER", 0, 0 },
278 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 5, right = 4, top = 5, bottom = 4 }, },
279 BackdropColor = { 0, 0, 0, 0.25 },
280 children = {
281 header = {
282 type = "Frame",
283 size = { 490, 20 },
284 Anchor = { "TOP", "$parent", "TOP", 0, -5 },
285 children = {
286 bg = {
287 type = "Texture",
288 layer = "BACKGROUND",
289 Anchor = "all",
290 Texture = NRF_IMG.."statusbar8",
291 Gradient = { "HORIZONTAL", 0, 0.75, 1, 0, 0, 0.2 },
292 },
293 title = {
294 type = "FontString",
295 layer = "ARTWORK",
296 Anchor = "all",
297 Font = { "Fonts\\FRIZQT__.TTF", 13, "OUTLINE" },
298 JustifyH = "LEFT",
299 TextColor = { 1, 1, 1 },
300 },
301 version = {
302 type = "FontString",
303 layer = "ARTWORK",
304 Anchor = "all",
305 Font = { "Fonts\\MORPHEUS.ttf", 13, "NONE" },
306 JustifyH = "RIGHT",
307 TextColor = { 1, 1, 1 },
308 },
309 border = {
310 type = "Texture",
311 size = { 490, 3 },
312 layer = "OVERLAY",
313 Anchor = { "TOP", "$parent", "BOTTOM", 0, 1 },
314 Texture = "Interface\\ClassTrainerFrame\\UI-ClassTrainer-HorizontalBar",
315 TexCoord = { 0.2, 1, 0, 0.25 },
316 },
317 },
318 },
319 menubg = {
320 type = "Frame",
321 FrameStrata = "BACKGROUND",
322 size = { 85, 278 },
323 Anchor = { "TOPLEFT", "$parentheader", "BOTTOMLEFT", -3, 5 },
324 Backdrop = { bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 8, insets = { left = 3, right = 2, top = 3, bottom = 2 }, },
325 BackdropColor = { 0, 0, 0, 0.95 },
326 },
327 button1 = {
328 template = "nrf_menu_button",
329 Anchor = { "TOPLEFT", "$parentheader", "BOTTOMLEFT", 0, 0 },
330 Text = "AddOns",
331 OnClick = function() Nurfed_MenuClick(this.id) end,
332 vars = {
333 id = 1,
334 },
335 },
336 button2 = {
337 template = "nrf_menu_button",
338 Anchor = { "TOPLEFT", "$parentbutton1", "BOTTOMLEFT", 0, -1 },
339 Text = "Profiles",
340 OnClick = function() Nurfed_MenuClick(this.id) end,
341 vars = {
342 id = 2,
343 },
344 },
345 },
346 Hide = true,
347 };
348  
349 function Nurfed_OptionsInit()
350 for k, v in pairs(templates) do
351 framelib:CreateTemplate(k, v);
352 end
353  
354 local count = GetNumAddOns();
355 local add = {};
356  
357 for i = 1, count do
358 local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(i);
359 local loaded = IsAddOnLoaded(i);
360 if (string.find(name, "^Nurfed") and loaded) then
361 local text = string.gsub(name, "Nurfed_", "");
362 if (Nurfed_OptionsMenus[text]) then
363 table.insert(add, text);
364 end
365 end
366 end
367  
368 for k, v in pairs(add) do
369 layout.children["button"..k + 2] = {
370 template = "nrf_menu_button",
371 Anchor = { "TOPLEFT", "$parentbutton"..k + 1, "BOTTOMLEFT", 0, -1 },
372 OnClick = function() Nurfed_MenuClick(this.id) end,
373 Text = v,
374 vars = {
375 id = k + 2,
376 },
377 };
378 end
379  
380 local last = table.getn(add) + 2;
381 layout.children["reloadui"] = {
382 template = "nrf_menu_button",
383 Anchor = { "TOPLEFT", "$parentbutton"..last, "BOTTOMLEFT", 0, -1 },
384 OnClick = function() StaticPopup_Show("NRF_RELOADUI") end,
385 Text = "Reload UI",
386 };
387 layout.children["close"] = {
388 template = "nrf_menu_button",
389 Anchor = { "TOPLEFT", "$parentreloadui", "BOTTOMLEFT", 0, -1 },
390 OnClick = function() HideUIPanel(this:GetParent()) end,
391 Text = CLOSE,
392 };
393  
394 local frame = framelib:ObjectInit("Nurfed_OptionsFrame", layout);
395 UIPanelWindows["Nurfed_OptionsFrame"] = { area = "center", pushable = 0, whileDead = 1 };
396 Nurfed_OptionsFrameheadertitle:SetText("Nurfed Options Menu");
397 Nurfed_OptionsFrameheaderversion:SetText(GetAddOnMetadata("Nurfed_Options", "Version"));
398  
399 templates = nil;
400 layout = nil;
401 end
402  
403 function Nurfed_MenuClick(id)
404 this:Disable();
405 local i = 1;
406 local name = string.gsub(this:GetName(), id, "");
407 local button = getglobal(name..i);
408 while (button) do
409 if (button.id ~= id and button:IsEnabled() == 0) then
410 button:Enable();
411 Nurfed_HideMenu(button:GetText());
412 end
413 i = i + 1;
414 button = getglobal(name..i);
415 end
416 Nurfed_ShowMenu(this:GetText());
417 end
418  
419 function Nurfed_ShowMenu(menu)
420 if (not menus[menu]) then
421 local opt = framelib:ObjectInit("Nurfed_OptionsFrame"..menu, Nurfed_OptionsMenus[menu], Nurfed_OptionsFrame);
422 menus[menu] = opt;
423 Nurfed_OptionsMenus[menu] = nil;
424 if (menu == "AddOns") then
425 Nurfed_GenerateAddOnsMenu();
426 end
427 local scroll = getglobal(opt:GetName().."scrollScrollBar");
428 if (scroll) then
429 scroll:SetPoint("RIGHT", scroll:GetParent():GetName(), "RIGHT", -25, 0);
430 end
431 end
432  
433 PlaySound("igAbiliityPageTurn");
434 activemenu = menu;
435 menus[menu]:Show();
436 UIFrameFadeIn(menus[menu], 0.25);
437 end
438  
439 function Nurfed_HideMenu(menu)
440 menus[menu]:SetAlpha(0);
441 menus[menu]:Hide();
442 end
443  
444 -----------------------------------------------------------------------------------------
445 -- Nurfed AddOns Menu
446 -----------------------------------------------------------------------------------------
447  
448 function Nurfed_GenerateAddOnsMenu()
449 for i = 1, 19 do
450 local row = framelib:ObjectInit("Nurfed_AddOnsRow"..i, "nrf_addon_row", Nurfed_OptionsFrameAddOns);
451 if (i == 1) then
452 row:SetPoint("TOPLEFT", "Nurfed_OptionsFrameAddOns", "TOPLEFT", 0, -3);
453 else
454 row:SetPoint("TOPLEFT", "Nurfed_AddOnsRow"..i - 1, "BOTTOMLEFT", 0, 0);
455 end
456 end
457 end
458  
459 function Nurfed_ToggleAddOn()
460 if (this:GetChecked()) then
461 EnableAddOn(this:GetID());
462 PlaySound("igMainMenuOptionCheckBoxOn");
463 else
464 DisableAddOn(this:GetID());
465 PlaySound("igMainMenuOptionCheckBoxOff");
466 end
467 local reload = getglobal(this:GetParent():GetName().."reload");
468 reload:SetText("(Reload UI)");
469 end
470  
471 function Nurfed_ScrollAddOns()
472 local line, offset, row;
473 local function format_row(row, num)
474 local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(num);
475 local loaded = IsAddOnLoaded(num);
476 local text = name;
477 if (title) then
478 text = title;
479 end
480 local check = getglobal(row.."check");
481 local na = getglobal(row.."name");
482 local load = getglobal(row.."loaded");
483  
484 na:SetText(text);
485 if (enabled) then
486 na:SetTextColor(1, 1, 1);
487 else
488 na:SetTextColor(0.5, 0.5, 0.5);
489 end
490  
491 if (name == "Nurfed_Options") then
492 check:Hide();
493 else
494 check:Show();
495 check:SetChecked(enabled);
496 check:SetID(num);
497 end
498 if (loaded) then
499 load:SetText("Loaded");
500 load:SetTextColor(1, 1, 1);
501 elseif (loadable) then
502 load:SetText("On Demand");
503 load:SetTextColor(1, 1, 1);
504 else
505 local y = getglobal("ADDON_"..reason);
506 load:SetText(y);
507 load:SetTextColor(0.5, 0.5, 0.5);
508 end
509 end
510  
511 local count = GetNumAddOns();
512 FauxScrollFrame_Update(this, count, 19, 14);
513 for line = 1, 19 do
514 offset = line + FauxScrollFrame_GetOffset(this);
515 row = getglobal("Nurfed_AddOnsRow"..line);
516 if offset < count then
517 format_row("Nurfed_AddOnsRow"..line, offset);
518 row:Show();
519 else
520 row:Hide();
521 end
522 end
523 end
524  
525 -----------------------------------------------------------------------------------------
526 -- Nurfed Options Functions
527 -----------------------------------------------------------------------------------------
528  
529 -- scroll
530 function Nurfed_Options_ScrollMenu()
531 FauxScrollFrame_Update(this, this.pages, 1, 100);
532 local page = FauxScrollFrame_GetOffset(this) + 1;
533 local children = { this:GetParent():GetChildren() };
534 for _, child in ipairs(children) do
535 if (not string.find(child:GetName(), "scroll", 1, true)) then
536 if (child.page == page) then
537 child:Show();
538 else
539 child:Hide();
540 end
541 end
542 end
543 end
544  
545 -- display
546 function Nurfed_Options_OnShow()
547 local text = getglobal(this:GetName().."Text");
548 text:SetText(this.text);
549 if (this.right) then
550 text:ClearAllPoints()
551 text:SetPoint("RIGHT", this:GetName(), "LEFT", -1, 1);
552 end
553 if (this.color) then
554 text:SetTextColor(unpack(this.color));
555 end
556 if (this.option) then
557 local objtype = this:GetObjectType();
558 local option = utility:GetOption(activemenu, this.option);
559 if (objtype == "CheckButton") then
560 this:SetChecked(option);
561 elseif (objtype == "Slider") then
562 local low = getglobal(this:GetName().."Low");
563 local high = getglobal(this:GetName().."High");
564 low:SetText(this.low);
565 high:SetText(this.high);
566 this:SetMinMaxValues(this.min, this.max);
567 this:SetValueStep(this.step);
568 this:SetValue(option);
569 end
570 end
571 this:SetScript("OnShow", nil);
572  
573 end
574  
575 local function optionInit()
576 local text = getglobal(this:GetName().."Text");
577 text:SetText(this.text);
578 if (this.right) then
579 text:ClearAllPoints()
580 text:SetPoint("RIGHT", this:GetName(), "LEFT", -1, 1);
581 end
582 if (this.color) then
583 text:SetTextColor(unpack(this.color));
584 end
585 if (this.option and not this.id) then
586 return utility:GetOption(activemenu, this.option);
587 end
588 end
589  
590 -- buttons
591 function Nurfed_Options_buttonOnShow()
592 this:SetText(this.text);
593 local width = string.len(this.text);
594 this:SetWidth(width*6 + 10);
595 end
596  
597 -- checks
598 function Nurfed_Options_checkOnClick()
599 local value = 0;
600 local func = this.func;
601 if (this:GetChecked()) then
602 value = 1;
603 PlaySound("igMainMenuOptionCheckBoxOn");
604 else
605 PlaySound("igMainMenuOptionCheckBoxOff");
606 end
607 if (this.id and not this:GetParent().selected) then
608 return;
609 end
610 utility:SetOption(activemenu, this.option, value, this.id, this:GetParent().selected);
611 if (this.id) then
612 func = this:GetParent().func;
613 end
614 if (func) then
615 func();
616 end
617 end
618  
619 -- sliders
620 function Nurfed_Options_sliderOnMouseUp()
621 local value = this:GetValue();
622 local func = this.func;
623 if (this.id and not this:GetParent().selected) then
624 return;
625 end
626 utility:SetOption(activemenu, this.option, value, this.id, this:GetParent().selected);
627 if (this.id) then
628 func = this:GetParent().func;
629 end
630 if (func) then
631 func();
632 end
633 end
634  
635 function Nurfed_Options_sliderOnValueChanged()
636 local value = this:GetValue();
637 local text = getglobal(this:GetName().."value");
638  
639 text:ClearAllPoints();
640 if (value > (this.max / 2)) then
641 text:SetPoint("LEFT", this:GetName(), "LEFT", 1, 1);
642 else
643 text:SetPoint("RIGHT", this:GetName(), "RIGHT", -1, 1);
644 end
645 text:SetText("("..format(this.format, value)..")");
646 end
647  
648 -- editbox
649 function Nurfed_Options_inputOnShow()
650 local option = optionInit();
651 if (not option) then
652 return;
653 end
654 local inputtext = getglobal(this:GetName().."input");
655 inputtext:SetText(option);
656 end
657  
658 function Nurfed_Options_inputOnClick()
659 local inputtext = getglobal(this:GetParent():GetName().."input");
660 if (not inputtext:GetText() or inputtext:GetText() == "") then
661 return;
662 end
663 utility:SetOption(activemenu, this:GetParent().option, inputtext:GetText());
664 inputtext:ClearFocus();
665 if (this:GetParent().func) then
666 this:GetParent().func();
667 end
668 end
669  
670 -- color swatches
671 function Nurfed_Options_swatchSetColor(frame)
672 local option = frame.option;
673 local r,g,b = ColorPickerFrame:GetColorRGB();
674 local a = OpacitySliderFrame:GetValue();
675 local swatch = getglobal(frame:GetName().."bg");
676 swatch:SetVertexColor(r, g, b);
677 frame.r = r;
678 frame.g = g;
679 frame.b = b;
680 utility:SetOption(activemenu, frame.option, { r, g, b, a });
681 if (frame.func) then
682 frame.func();
683 end
684 end
685  
686 function Nurfed_Options_swatchCancelColor(frame, prev)
687 local option = frame.option;
688 local r = prev.r;
689 local g = prev.g;
690 local b = prev.b;
691 local a = prev.a;
692 local swatch = getglobal(frame:GetName().."bg");
693 swatch:SetVertexColor(r, g, b);
694 frame.r = r;
695 frame.g = g;
696 frame.b = b;
697 utility:SetOption(activemenu, frame.option, { r, g, b, a });
698 if (frame.func) then
699 frame.func();
700 end
701 end
702  
703 function Nurfed_Options_swatchOnShow()
704 if (this:IsShown()) then
705 local option = optionInit();
706 if (not option) then
707 return;
708 end
709 local frame = this;
710 local swatch = getglobal(this:GetName().."bg");
711 swatch:SetVertexColor(option[1], option[2], option[3]);
712  
713 this.r = option[1];
714 this.g = option[2];
715 this.b = option[3];
716 this.swatchFunc = function() Nurfed_Options_swatchSetColor(frame) end;
717 this.cancelFunc = function(x) Nurfed_Options_swatchCancelColor(frame, x) end;
718 if (frame.opacity) then
719 this.hasOpacity = frame.opacity;
720 this.opacityFunc = function() Nurfed_Options_swatchSetColor(frame) end;
721 this.opacity = option[4];
722 end
723 end
724 end
725  
726 function Nurfed_Options_swatchOpenColorPicker()
727 CloseMenus();
728 ColorPickerFrame.func = this.swatchFunc;
729 ColorPickerFrame.hasOpacity = this.hasOpacity;
730 ColorPickerFrame.opacityFunc = this.opacityFunc;
731 ColorPickerFrame.opacity = this.opacity;
732 ColorPickerFrame:SetColorRGB(this.r, this.g, this.b);
733 ColorPickerFrame.previousValues = {r = this.r, g = this.g, b = this.b, a = this.opacity};
734 ColorPickerFrame.cancelFunc = this.cancelFunc;
735 ColorPickerFrame:Show();
736 end
737  
738 -- radios
739 function Nurfed_Options_radioOnClick(frame, index, noupdate)
740 if (not index) then
741 index = this.index;
742 end
743 if (not frame) then
744 frame = this:GetParent();
745 end
746 local children = { frame:GetChildren() };
747 for _, child in ipairs(children) do
748 if (child.index == index) then
749 child:SetChecked(1);
750 else
751 child:SetChecked(nil);
752 end
753 end
754 PlaySound("igMainMenuOptionCheckBoxOn");
755  
756 if (not frame:GetParent().selected or noupdate) then
757 return;
758 end
759 utility:SetOption(activemenu, frame.option, index, frame.id, frame:GetParent().selected);
760 local func = frame:GetParent().func;
761 if (func) then
762 func();
763 end
764 end
765  
766 function Nurfed_Options_radioGetSelected(frame)
767 if (not frame) then
768 frame = this:GetParent();
769 end
770 local children = { frame:GetChildren() };
771 for _, child in ipairs(children) do
772 if (child:GetChecked()) then
773 return child.index;
774 end
775 end
776 end
777  
778 -- panes
779 function Nurfed_Options_paneOnShow()
780 local title = getglobal(this:GetName().."title");
781 if (this.text) then
782 title:SetText(this.text);
783 end
784 local scroll = getglobal(this:GetName().."scrollScrollBar");
785 if (scroll) then
786 scroll:SetPoint("RIGHT", scroll:GetParent():GetName(), "RIGHT", -26, 0);
787 end
788 local children = { this:GetChildren() };
789 for _, child in ipairs(children) do
790 local objtype = child:GetObjectType();
791 if (objtype == "CheckButton") then
792 child:SetChecked(child.default);
793 elseif (objtype == "Slider") then
794 local low = getglobal(child:GetName().."Low");
795 local high = getglobal(child:GetName().."High");
796 low:SetText(child.low);
797 high:SetText(child.high);
798 child:SetMinMaxValues(child.min, child.max);
799 child:SetValueStep(child.step);
800 child:SetValue(child.default);
801 elseif (objtype == "Frame" and child.isradio) then
802 Nurfed_Options_radioOnClick(child, child.default, true);
803 end
804 child.option = this.option;
805 end
806 this:SetScript("OnShow", nil);
807 end
808  
809 function Nurfed_Options_paneUpdateOptions(frame)
810 local option = utility:GetOption(activemenu, frame.option);
811 local selected = option[frame.selected];
812 local children = { frame:GetChildren() };
813 for _, child in ipairs(children) do
814 local objtype = child:GetObjectType();
815 if (objtype == "CheckButton") then
816 child:SetChecked(selected[child.id]);
817 elseif (objtype == "Slider") then
818 child:SetValue(selected[child.id]);
819 elseif (objtype == "Frame" and child.isradio) then
820 Nurfed_Options_radioOnClick(child, selected[child.id], true);
821 end
822 end
823 end
824  
825 function Nurfed_Options_paneGetOptions()
826 local tbl = {};
827 local children = { this:GetParent():GetChildren() };
828 for _, child in ipairs(children) do
829 if (child.id) then
830 local objtype = child:GetObjectType();
831 if (objtype == "Slider") then
832 tbl[child.id] = child:GetValue();
833 elseif (objtype == "CheckButton") then
834 if (child:GetChecked()) then
835 tbl[child.id] = 1;
836 else
837 tbl[child.id] = 0;
838 end
839 elseif (objtype == "Frame" and child.isradio) then
840 tbl[child.id] = Nurfed_Options_radioGetSelected(child);
841 end
842 end
843 end
844 return tbl;
845 end
846  
847 function Nurfed_Options_paneAddOption()
848 local frame = this:GetParent();
849 local objtype = this:GetObjectType();
850 if (objtype == "EditBox") then
851 if (this:GetText() and this:GetText() ~= "") then
852 if (frame.up) then
853 this:SetText(string.gsub(this:GetText(), "^%l", string.upper));
854 end
855 if (frame.notbl) then
856 utility:SetOption(activemenu, frame.option, true, this:GetText());
857 else
858 local tbl = Nurfed_Options_paneGetOptions();
859 utility:SetOption(activemenu, frame.option, tbl, this:GetText());
860 end
861 end
862 this:ClearFocus();
863 this:SetText("");
864 else
865 local option = utility:GetOption(activemenu, frame.option);
866 local name = table.getn(option) + 1;
867 local tbl = Nurfed_Options_paneGetOptions();
868 utility:SetOption(activemenu, frame.option, tbl, name);
869 end
870 Nurfed_Options_ScrollPane(frame);
871 if (frame.func) then
872 frame.func();
873 end
874 end
875  
876 function Nurfed_Options_paneRemoveOption()
877 local frame = this:GetParent();
878 if (frame.selected) then
879 utility:SetOption(activemenu, frame.option, nil, frame.selected);
880 frame.selected = nil;
881 end
882 Nurfed_Options_ScrollPane(frame);
883 if (frame.func) then
884 frame.func();
885 end
886 end
887  
888 function Nurfed_Options_ScrollPane(frame)
889 if (not frame) then
890 frame = this:GetParent();
891 else
892 this = getglobal(frame:GetName().."scroll");
893 end
894 local rows = frame.rows;
895 local selected = frame.selected;
896 local line, offset, row, text, count, temp;
897 local option = utility:GetOption(activemenu, frame.option);
898  
899 if (table.getn(option) > 0) then
900 count = table.getn(option);
901 else
902 temp = {};
903 for k in pairs(option) do
904 table.insert(temp, k);
905 end
906 count = table.getn(temp);
907 end
908 FauxScrollFrame_Update(this, count, rows, 13);
909 for line = 1, rows do
910 offset = line + FauxScrollFrame_GetOffset(this);
911 row = getglobal(frame:GetName().."row"..line);
912 text = getglobal(row:GetName().."text");
913 if offset <= count then
914 if (temp) then
915 text:SetText(temp[offset]);
916 if (selected == temp[offset]) then
917 row:LockHighlight();
918 else
919 row:UnlockHighlight();
920 end
921 else
922 text:SetText(frame.prefix.." "..offset);
923 row.id = offset;
924 if (selected == offset) then
925 row:LockHighlight();
926 else
927 row:UnlockHighlight();
928 end
929 end
930 row:Show();
931 else
932 row:Hide();
933 end
934 end
935 end
936  
937 function Nurfed_Options_PaneSelect()
938 local frame = this:GetParent();
939 local selected = frame.selected;
940 if (this.id) then
941 if (selected == this.id) then
942 frame.selected = nil;
943 this:UnlockHighlight();
944 else
945 frame.selected = this.id;
946 this:LockHighlight();
947 end
948 else
949 local text = getglobal(this:GetName().."text"):GetText();
950 if (selected == text) then
951 frame.selected = nil;
952 this:UnlockHighlight();
953 else
954 frame.selected = text;
955 this:LockHighlight();
956 end
957 end
958 if (frame.selected) then
959 Nurfed_Options_paneUpdateOptions(frame);
960 end
961 Nurfed_Options_ScrollPane(frame);
962 end