forked from kaytotes/ImprovedBlizzardUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
165 lines (130 loc) · 4.42 KB
/
core.lua
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
-- Create Ace3 Addon.
ImpUI = LibStub('AceAddon-3.0'):NewAddon('ImprovedBlizzardUI', 'AceConsole-3.0', 'AceHook-3.0');
-- Get Localisation
local L = LibStub('AceLocale-3.0'):GetLocale('ImprovedBlizzardUI');
-- LibSharedMedia-3.0
LSM = LibStub('LibSharedMedia-3.0');
--[[
Opens the Improved Blizzard UI options panel.
Yes this really does call the exact same function twice. This is due to a Blizzard
bug that has existed ever since InterfaceOptionsFrame_OpenToCategory was put in
the game. Since it's been years and would take someone 2 minutes to fix, we
can only assume Blizzard just doesn't care and won't ever fix it.
@ return void
]]
function OpenImprovedUIOptions()
InterfaceOptionsFrame_OpenToCategory(ImpUI.optionsFrame);
InterfaceOptionsFrame_OpenToCategory(ImpUI.optionsFrame);
end
local isEditing = false;
--[[
Gets the Draggable UI Elements
]]
local function GetDraggables()
local draggables = {
'ImpUI_OSD',
'ImpUI_Killfeed',
'ImpUI_Player',
'ImpUI_Target',
'ImpUI_CastBar',
'ImpUI_Buffs',
'ImpUI_Performance',
'ImpUI_Party',
};
if (Helpers.IsRetail()) then
table.insert(draggables, 'ImpUI_TalkingHead');
end
if (Helpers.IsRetail() or Helpers.IsTBC()) then
table.insert(draggables, 'ImpUI_Focus');
end
return draggables;
end
--[[
Unlocks all of the UI draggable frames.
]]
local function UnlockFrames()
if (isEditing) then return; end
for i, module in pairs (GetDraggables()) do
local m = ImpUI:GetModule(module);
m:Unlock();
end
isEditing = true;
end
--[[
Locks all of the UI draggable frames.
]]
local function LockFrames()
if (isEditing == false) then return; end
for i, module in pairs (GetDraggables()) do
local m = ImpUI:GetModule(module);
m:Lock();
end
isEditing = false;
end
--[[
Just prints the addons configuration options.
@ return void
]]
local function PrintConfig()
ImpUI:Print(L['/imp - Open the configuration panel.']);
ImpUI:Print(L['/imp grid - Toggle a grid to aid in interface element placement.']);
ImpUI:Print(L['/imp unlock - Unlocks the interfaces movable frames. Locking them saves position.']);
ImpUI:Print(L['/imp lock - Locks the interfaces movable frames.']);
end
--[[
Handles the /imp slash command.
For now just opens options.
@ return void
]]
function ImpUI:HandleSlash(input)
-- Nothing provided. Just open options and print config commands.
if (not input or input:trim() == '') then
OpenImprovedUIOptions();
PrintConfig();
end
local command = input:trim();
-- Grid
if (command == 'grid') then
local grid = ImpUI:GetModule('ImpUI_Grid');
grid:ToggleGrid();
return;
end
-- Unlock
if (command == 'unlock') then
UnlockFrames();
end
-- Lock
if (command == 'lock') then
LockFrames();
end
end
--[[
Called when active profile is changed.
For now just forces a UI Reload.
]]
function ImpUI:RefreshConfig()
ReloadUI();
end
--[[
Fires when the Addon is Initialised.
@ return void
]]
function ImpUI:OnInitialize()
-- Set up Improved Blizzard UI font.
LSM:Register(LSM.MediaType.FONT, 'Improved Blizzard UI', [[Interface\AddOns\ImprovedBlizzardUI\media\ImprovedBlizzardUI.ttf]]);
-- Set up DB
self.db = LibStub('AceDB-3.0'):New('ImpBlizzardUI_DB', ImpUI_Config.defaults, true);
-- Enable Profile Management
ImpUI_Config.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db);
-- Make sure new settings take effect whenever active profile is changed, currently by Reloading UI.
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
-- Register Config
LibStub('AceConfig-3.0'):RegisterOptionsTable('ImprovedBlizzardUI', ImpUI_Config.options);
-- Add to Blizz Config
self.optionsFrame = LibStub('AceConfigDialog-3.0'):AddToBlizOptions('ImprovedBlizzardUI', 'Improved Blizzard UI');
-- Register Slash Command
self:RegisterChatCommand('imp', 'HandleSlash');
print(format('|cffffff00Improved Blizzard UI %s - %s (%s) Mode Initialized.', GetAddOnMetadata('ImprovedBlizzardUI', 'Version'), Helpers.GetEnvironment(), Helpers.GetSupportedBuild()));
end