forked from taxidriveer/Examiner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodcore.lua
More file actions
225 lines (197 loc) · 6.42 KB
/
modcore.lua
File metadata and controls
225 lines (197 loc) · 6.42 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
local ex = Examiner;
local gtt = GameTooltip;
local ModuleCore = {};
ModuleCore.__index = ModuleCore;
ex.ModuleCore = ModuleCore;
-- Tables
ex.modules = {};
ex.buttons = {};
--------------------------------------------------------------------------------------------------------
-- Helper Functions --
--------------------------------------------------------------------------------------------------------
-- Returns the Module with given "token"
function ex:GetModuleFromToken(token)
for index, mod in ipairs(ex.modules) do
if (mod.token == token) then
return mod, index;
end
end
end
-- Creates a new Module
function ex:CreateModule(token,title)
local mod = setmetatable({ token = token, title = title, hasData = true, index = #ex.modules + 1 },ModuleCore);
ex.modules[#ex.modules + 1] = mod;
return mod;
end
-- Send Module Event
function ex:SendModuleEvent(event,...)
for index, mod in ipairs(self.modules) do
if (mod[event]) then
mod[event](mod,...);
end
end
end
--------------------------------------------------------------------------------------------------------
-- Detail Object --
--------------------------------------------------------------------------------------------------------
local DetailObject = {};
DetailObject.__index = DetailObject;
function ex:CreateDetailObject()
return setmetatable({ entries = LibTableRecycler:New() },DetailObject);
end
function DetailObject:Update()
ex:SendModuleEvent("OnDetailsUpdate");
end
function DetailObject:Add(label,value,tip)
local tbl = self.entries:Fetch();
tbl.label = label;
tbl.value = value;
tbl.tip = tip;
end
function DetailObject:Clear()
self.entries:Recycle();
end
--------------------------------------------------------------------------------------------------------
-- Button Functions --
--------------------------------------------------------------------------------------------------------
-- Buttons: OnClick
local function Buttons_OnClick(self,button,down)
local id = self.id;
local module = ex.modules[id];
if (module.hasData) then
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON); -- "igMainMenuOptionCheckBoxOn"
-- Call Module OnButtonClick
if (module.OnButtonClick) then
module:OnButtonClick(self,button,down);
end
-- Unmodified Left Clicks
if (not IsModifierKeyDown()) then
if (button == "LeftButton") and (module.page) then
ex:ShowModulePage(id);
AzDropDown:HideMenu();
elseif (module.MenuInit and module.MenuSelect) then
self.initFunc = module.MenuInit;
self.selectValueFunc = module.MenuSelect;
AzDropDown:ToggleMenu(self,"TOPLEFT","BOTTOMLEFT");
end
end
end
end
-- Buttons: OnEnter
local function Buttons_OnEnter(self,motion)
local module = ex.modules[self.id];
gtt:SetOwner(self,"ANCHOR_NONE");
gtt:SetPoint("BOTTOMLEFT",self,"TOPLEFT");
gtt:AddLine(module.title);
gtt:AddLine(module.help,1,1,1);
gtt:Show();
end
-- Create Button
local function CreateModuleButton(label,tipHeader,tipText)
local btn = CreateFrame("Button",nil,ex,"UIPanelButtonGrayTemplate");
btn:SetSize(75,21);
btn:SetFrameLevel(btn:GetFrameLevel() + 2);
btn:RegisterForClicks("AnyUp");
btn:SetScript("OnClick",Buttons_OnClick);
btn:SetScript("OnEnter",Buttons_OnEnter);
btn:SetScript("OnLeave",ex.HideGTT);
ex.buttons[#ex.buttons + 1] = btn;
return btn;
end
--------------------------------------------------------------------------------------------------------
-- Meta Functions --
--------------------------------------------------------------------------------------------------------
-- Adds an option table to the Examiner options
function ModuleCore:AddOption(option)
ex.options[#ex.options + 1] = option;
end
-- Is the module the current shown page?
function ModuleCore:IsShown()
return (ex.cfg.activePage == self.index);
end
-- Returns if module is allowed to cache
function ModuleCore:CanCache()
return self.canCache and ex.cfg.caching.Core and ex.cfg.caching[self.token];
end
-- Tells if this module has data available for Examiner to show
function ModuleCore:HasData(value)
self.hasData = (value and true or nil);
if (value) then
if (self.button) then
self.button:Enable();
end
else
if (self.page) then
self.page:Hide();
end
if (self.button) then
self.button:Disable();
end
end
end
-- Has Button
function ModuleCore:HasButton(value)
self.hasButton = value;
-- Position Module Buttons
local numBtn = 0;
for index, mod in ipairs(ex.modules) do
if (mod.hasButton) then
numBtn = (numBtn + 1);
local btn = ex.buttons[numBtn] or CreateModuleButton();
if (numBtn > 1) then
btn:SetPoint("LEFT",ex.buttons[numBtn - 1],"RIGHT",1,0);
else
btn:SetPoint("BOTTOMLEFT",24,13);
end
btn:Enable();
btn.id = index;
btn:SetText(mod.token);
mod.button = btn;
--mod.hasData = nil;
end
end
-- Resize Buttons
local btnWidth = ((ex.model:GetWidth() - 4) / numBtn - 1);
for index, btn in ipairs(ex.buttons) do
if (index <= numBtn) then
btn:SetWidth(btnWidth);
btn:Show();
else
btn:Hide();
end
end
end
-- Backdrop
local backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
-- backdropColor = CreateColor(0.06,0.132,0.21,0.7),
-- backdropBorderColor = CreateColor(0.7,0.7,0.8,1),
backdropColor = CreateColor(0.06,0.132,0.21,0.7),
backdropBorderColor = CreateColor(0.7,0.7,0.8,0.2),
};
ModuleCore.backdrop = backdrop;
-- Creates a Default Module Page
function ModuleCore:CreatePage(full,header)
local page = CreateFrame("Frame",nil,ex.model);
page:SetSize(full and 320 or 235,full and 330 or 288);
page:SetPoint("TOP");
page:SetBackdrop(backdrop);
page:SetBackdropColor(backdrop.backdropColor:GetRGBA());
page:SetBackdropBorderColor(backdrop.backdropBorderColor:GetRGBA());
page:Hide();
if (header) then
page.header = page:CreateFontString(nil,"ARTWORK");
page.header:SetFont(GameFontNormal:GetFont(),16,"THICKOUTLINE");
page.header:SetTextColor(0.5,0.75,1);
page.header:SetPoint("TOP",0,-14);
page.header:SetText(header);
end
self.page = page;
self.showItems = (not full or nil);
return page;
end