-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathORB_Module.lua
More file actions
454 lines (370 loc) · 13.7 KB
/
ORB_Module.lua
File metadata and controls
454 lines (370 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then
return
end
------------------------------------------------------------------
-- Local config
local NoTextureText = "(none)";
------------------------------------------------------------------
ORB_Module = {};
--
-- Change strata level for this module. Used when entering/leaving combat
--
function ORB_Module:ChangeStrata(strata)
if( self.frame) then
self.frame:SetFrameStrata(strata);
end
end
--
-- Create a module.
-- Use:
-- local myModule = ORB_Module:create("SomeName");
-- function myModule:OnInit() (do stuff) end
-- OneRuneBar:RegisterModule(myModule);
--
function ORB_Module:create(name)
local n = {};
setmetatable(n, { __index = ORB_Module } );
n.name = name;
return n;
end
function ORB_Module:setConfig()
if( not self.cfg ) then
self.cfg = ORB_Config[self.name];
end
end
--
-- Init the module, Modules should use Enable
--
function ORB_Module:init()
if( self.isRunning ) then return; end
if( not self.cfg ) then
self.cfg = ORB_Config[self.name];
end
-- Now we are ready to enable this module
if( self.OnInit ) then self:OnInit(); end
self.isRunning = true;
self:Print((self.name or "Unknown").." module enabled.");
end
function ORB_Module:CreateTexture(f)
local tex = f:CreateTexture(nil, "BACKGROUND");
return tex;
end
function ORB_Module:CreateBar(name, parent)
local Bar = CreateFrame("StatusBar", name, parent);
Bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar");
Bar:GetStatusBarTexture():SetHorizTile(true);
Bar:SetMinMaxValues(0, 100);
Bar:SetValue(100);
Bar.bg = Bar:CreateTexture(nil, "BACKGROUND");
Bar.bg:SetAllPoints(Bar);
Bar.bg:SetColorTexture(0.25, 0.25, 0.25, 0.5);
-- Create text on bar
local text = Bar:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
--text:SetFont(ElvUI[1]["media"].normFont, 12, "" );
text:SetFont("Fonts\\FRIZQT__.TTF", self:Config_GetFontSize(), "");
text:SetPoint("CENTER", Bar, "CENTER", 0, 0);
Bar.text = text;
return Bar;
end
function ORB_Module:CreateMoveFrame()
local f = CreateFrame("frame", nil, self.frame);
f.parent = self.frame;
f:SetAllPoints(f.parent);
f.parent:SetMovable(true);
f:EnableMouse(true);
f:RegisterForDrag("LeftButton");
f:SetScript("OnDragStart", function(frame) frame.parent:StartMoving() end );
f:SetScript("OnDragStop", function(frame) frame.parent:StopMovingOrSizing(); frame.parent.owner:SavePosition() end );
f.bg = f:CreateTexture(nil, "ARTWORK");
f.bg:SetAllPoints(f);
f.bg:SetColorTexture(0.8,0.8,0.8, 0.4);
f:SetFrameStrata("HIGH");
f:Hide();
self.moveFrame = f;
end
function ORB_Module:CreateBorderTexture(f, from, to)
local t = self:CreateTexture(f);
t:SetPoint(from, f, to, 0, 0);
t:SetPoint(to, f, from, 0, 0);
t:SetColorTexture( 0.0, 0.0, 0.0 );
return t;
end
function ORB_Module:CreateBorder(f)
f.t = self:CreateBorderTexture( f, "TOPLEFT", "TOPRIGHT" );
f.b = self:CreateBorderTexture( f, "BOTTOMLEFT", "BOTTOMRIGHT" );
f.l = self:CreateBorderTexture( f, "TOPLEFT", "BOTTOMLEFT" );
f.r = self:CreateBorderTexture( f, "TOPRIGHT", "BOTTOMRIGHT" );
end
function ORB_Module:UpdateBorderSizes( f )
local borderSize = self:Config_GetBorderSize();
f.t:SetHeight( borderSize );
f.b:SetHeight( borderSize );
f.l:SetWidth( borderSize );
f.r:SetWidth( borderSize );
end
function ORB_Module:Disable()
if( not self.isRunning ) then return; end -- Not running
-- Hide frame and unregister all events
if( self.frame ) then
self.frame:Hide();
self.frame:UnregisterAllEvents();
end
if( self.OnDisable ) then self:OnDisable(); end
self.isRunning = nil;
self:Print(self.name.." module disabled.");
end
function ORB_Module:ChangeVisibility(show)
if( not self.isRunning ) then return; end
if( self.frame ) then
if( show ) then
self.frame:Show();
else
self.frame:Hide();
end
end
end
function ORB_Module:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("ORB: "..msg);
end
function ORB_Module:SavePosition()
if( not self.frame ) then return; end
-- ORB_Config[self.name].Position = { self.frame:GetPoint() };
-- Save position
self.cfg.Position = { self.frame:GetPoint() };
end
function ORB_Module:LoadPosition()
if( not self.frame ) then return; end -- if no frame exists no position exists.
if( self.cfg and self.cfg.Position ) then
local p, _, _, ox, oy = unpack(self.cfg.Position);
self.frame:SetPoint( p, ox, oy );
else
self:Error("Failed to load position for module "..self.name);
end
if( self.OnLoadPosition ) then
self:OnLoadPosition();
end
end
function ORB_Module:Error(msg)
DEFAULT_CHAT_FRAME:AddMessage("ORB Error: "..msg);
end
function ORB_Module:ResetConfig()
-- Create new empty table
ORB_Config[self.name] = nil; self.cfg = nil;
ORB_Config[self.name] = {};
-- Copy default values needed for this module
for k,v in pairs(ORB_Config_Defaults[self.name]) do
ORB_Config[self.name][k] = v;
end
-- Set it as our config
self.cfg = ORB_Config[self.name];
end
function ORB_Module:InitOptions(parent)
-- Make sure we have our configuration settings available
if( not ORB_Config[self.name] ) then
self:ResetConfig();
end
local panel = CreateFrame("frame", self.name.."_OptionsPanel", parent);
panel.name = self.name;
panel.parent = parent.name;
panel.owner = self;
panel.okay = function(self) self.owner._OnOkay(self.owner); end
panel.default = function(self) self.owner._OnDefault(self.owner); end
--
-- Module panel
--
local xoff, yoff = 20, -20;
local header = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge");
header:SetPoint("TOPLEFT", panel, "TOPLEFT", xoff, yoff);
header:SetText(parent.name.." - "..panel.name );
panel.header = header;
-- Module disable checkbox
local cb = CreateFrame("CheckButton", "ORB_DisableModule_"..self.name, panel, "InterfaceOptionsCheckButtonTemplate");
cb:SetPoint("TOPLEFT", header, "TOPLEFT", 0, yoff);
cb.text = _G[cb:GetName().."Text"];
cb.text:SetText("Enable "..self.name.." module");
local v = true;
if( ORB_Config.disabled_modules and ORB_Config.disabled_modules[self.name] and ORB_Config.disabled_modules[self.name] == true ) then
v = false;
end
cb:SetChecked( v );
self.CB_Disabled = cb;
-- Texture options
local textureText = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
textureText:SetPoint("TOPLEFT", cb, "BOTTOMLEFT", 0, yoff);
textureText:SetText("Texture");
local textureDD = CreateFrame("frame", "ORB_ModuleTextureDD_"..self.name, panel, "UIDropDownMenuTemplate");
textureDD:ClearAllPoints();
textureDD:SetPoint("TOPLEFT", textureText, "BOTTOMLEFT", -20, 0);
textureDD:SetScript("OnShow", function(self)
UIDropDownMenu_SetSelectedValue(self, ORB_Config[self.owner.name].Texture or NoTextureText);
UIDropDownMenu_SetText(self, ORB_Config[self.owner.name].Texture or NoTextureText);
end
);
textureDD:Show();
textureDD.owner = self;
self.TextureDD = textureDD;
UIDropDownMenu_Initialize(
textureDD,
function(self, level)
local OnClick =
function(self)
UIDropDownMenu_SetSelectedID(self.owner, self:GetID());
if( self.owner.owner.SetBarTexture and self.isRunning ) then self.owner.owner:SetBarTexture(self.value); end
end;
local info = UIDropDownMenu_CreateInfo();
info.text = NoTextureText;
info.value = nil;
info.owner = self;
info.func = OnClick;
UIDropDownMenu_AddButton(info, level);
local BarTextures = {};
if( SM ) then
BarTextures = SM:List("statusbar");
end
for k,v in pairs(BarTextures) do
info = UIDropDownMenu_CreateInfo();
info.text = v;
info.value = v;
info.owner = self;
info.func = OnClick;
UIDropDownMenu_AddButton(info, level);
end
end
);
UIDropDownMenu_SetWidth(textureDD, 100);
UIDropDownMenu_SetButtonWidth(textureDD, 124);
UIDropDownMenu_JustifyText(textureDD, "LEFT");
local borderSizeLabel = self:CreateLabel( panel, "Border Size:");
borderSizeLabel:SetPoint("TOPLEFT", textureDD, "BOTTOMLEFT", 20, yoff);
local borderSizeBox = self:CreateEditBox( panel, "ORB_ModuleBorderSizeEditBox_"..self.name,
function(self) return self:Config_GetBorderSize(); end,
function(self, value) self:Config_SetBorderSize(value); end );
borderSizeBox:SetPoint("TOPLEFT", borderSizeLabel, "TOPRIGHT", 4, 0);
borderSizeBox:SetPoint("BOTTOMLEFT", borderSizeLabel, "BOTTOMRIGHT", 0, 0);
local barWidthLabel = self:CreateLabel( panel, "Bar Width:");
barWidthLabel:SetPoint("TOPLEFT", borderSizeLabel, "BOTTOMLEFT", 0, yoff);
local barWidthBox = self:CreateEditBox( panel, "ORB_ModuleBarWidthEditBox_"..self.name,
function(self) return self:Config_GetBarSize()[1]; end,
function(self, value) self:Config_SetBarSize(value, self:Config_GetBarSize()[2]); end );
barWidthBox:SetPoint("TOPLEFT", barWidthLabel, "TOPRIGHT", 4, 0);
barWidthBox:SetPoint("BOTTOMLEFT", barWidthLabel, "BOTTOMRIGHT", 0, 0);
local barHeightLabel = self:CreateLabel( panel, "Height:");
barHeightLabel:SetPoint("TOPLEFT", barWidthBox, "TOPRIGHT", 4, 0);
local barHeightBox = self:CreateEditBox( panel, "ORB_ModuleBarHeightEditBox_"..self.name,
function(self) return self:Config_GetBarSize()[2]; end,
function(self, value) self:Config_SetBarSize(self:Config_GetBarSize()[1], value); end );
barHeightBox:SetPoint("TOPLEFT", barHeightLabel, "TOPRIGHT", 4, 0);
barHeightBox:SetPoint("BOTTOMLEFT", barHeightLabel, "BOTTOMRIGHT", 0, 0);
local fontSizeLabel = self:CreateLabel( panel, "Font Size:");
fontSizeLabel:SetPoint("TOPLEFT", barWidthLabel, "BOTTOMLEFT", 0, yoff);
local fontSizeBox = self:CreateEditBox( panel, "ORB_ModuleBarFontSizeEditBox_"..self.name,
function(self) return self:Config_GetFontSize(); end,
function(self, value) self:Config_SetFontSize(value); end );
fontSizeBox:SetPoint("TOPLEFT", fontSizeLabel, "TOPRIGHT", 4, 0);
fontSizeBox:SetPoint("BOTTOMLEFT", fontSizeLabel, "BOTTOMRIGHT", 0, 0);
if( self.OnInitOptions ) then self:OnInitOptions(panel, fontSizeLabel ); end
--
-- Add panel to blizzards addon config
--
self.panel = panel;
InterfaceOptions_AddCategory(self.panel);
end
function ORB_Module:CreateColorButtonOption(panel, name)
local btn = CreateFrame("button", self.name..name.."button", panel, "UIPanelButtonTemplate");
btn.owner = self;
btn.orbcolorname = name;
btn:SetWidth(80);
btn:SetHeight(22);
btn:SetText(name);
btn:SetScript("OnClick", function(self)
ColorPickerFrame.previousValues = { self.owner:GetConfigColor(self.owner, self.orbcolorname) };
ColorPickerFrame.func = function() self.owner:SetBarColor(self.owner, self.orbcolorname, ColorPickerFrame:GetColorRGB()) end;
ColorPickerFrame.opacityFunc = function() self.owner:SetBarColor(self.owner, self.orbcolorname, ColorPickerFrame:GetColorRGB()); end;
ColorPickerFrame.cancelFunc = function() self.owner:SetBarColor(self.owner, self.orbcolorname, unpack(ColorPickerFrame.previousValues)); end;
ColorPickerFrame:SetColorRGB( self.owner:GetConfigColor(self.owner, self.orbcolorname) );
ColorPickerFrame:SetFrameStrata("DIALOG");
ColorPickerFrame:Show();
end);
local tex = panel:CreateTexture(nil, "BACKGROUND");
tex:SetWidth(20);
tex:SetHeight(20);
tex:SetPoint("LEFT", btn, "RIGHT", 10, 0);
tex:SetColorTexture( self:GetConfigColor(self, name) );
if( not panel.barcolor ) then
panel.barcolor = {};
end
panel.barcolor[name] = tex;
return btn, tex;
end
function ORB_Module:CreateLabel( panel, labelText )
local label = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
label:SetText(labelText);
return label
end
function ORB_Module:CreateEditBox( panel, name, getConfigFunc, setConfigFunc )
local box = CreateFrame( "editbox", name, panel, "InputBoxTemplate");
box.owner = self;
box:SetHeight(30);
box:SetWidth(30);
box:SetAutoFocus(false);
box:SetMaxLetters(3);
box:SetNumeric(true);
box:SetScript("OnShow", function(self) self:SetText(getConfigFunc(self.owner)); self:SetCursorPosition(0); end);
box:SetScript("OnEscapePressed", function(self) self:SetText(getConfigFunc(self.owner)); self:ClearFocus(); end);
box:SetScript("OnEnterPressed", function(self) local val = self:GetNumber(); setConfigFunc(self.owner, val); self:ClearFocus(); end);
return box;
end
function ORB_Module:_OnOkay()
-- Disable/Enable
local status = self.CB_Disabled:GetChecked();
if( status and not self.isRunning ) then
--self:Print(self.name.." module activated.");
ORB_Config.disabled_modules[self.name] = nil;
elseif( not status and self.isRunning ) then
--self:Print(self.name.." module deactivated.");
if( not ORB_Config.disabled_modules ) then ORB_Config.disabled_modules = {}; end
ORB_Config.disabled_modules[self.name] = true;
end
end
function ORB_Module:_OnDefault()
self:ResetConfig();
-- Load default value
local v = true;
if( ORB_Config_Defaults.disabled_modules and ORB_Config_Defaults.disabled_modules[self.name] and ORB_Config_Defaults.disabled_modules[self.name] == true ) then
v = false;
end
self.CB_Disabled:SetChecked( v );
if( self.OnDefault ) then
self:OnDefault();
end
if( v == true ) then
self:init();
else
self:Disable();
end
end
function ORB_Module:Config_GetBorderSize()
return ORB_Config[self.name].BorderSize or ORB_Config_Defaults[self.name].BorderSize;
end
function ORB_Module:Config_SetBorderSize(val)
ORB_Config[self.name].BorderSize = val;
if( self.PositionFrame ) then
self:PositionFrame();
end
end
function ORB_Module:Config_GetBarSize()
return ORB_Config[self.name].BarSize or ORB_Config_Defaults[self.name].BarSize;
end
function ORB_Module:Config_SetBarSize(width, height)
ORB_Config[self.name].BarSize = { width, height };
if( self.PositionFrame ) then
self:PositionFrame();
end
end
function ORB_Module:Config_GetFontSize()
return ORB_Config[self.name].FontSize or ORB_Config_Defaults[self.name].FontSize;
end
function ORB_Module:Config_SetFontSize(val)
ORB_Config[self.name].FontSize = val;
self.Bar.text:SetFont("Fonts\\FRIZQT__.TTF", val, "");
end