-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltinator.lua
More file actions
282 lines (236 loc) · 9.45 KB
/
Altinator.lua
File metadata and controls
282 lines (236 loc) · 9.45 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
local AddonName, AltinatorNS = ...
local C = AltinatorNS.C
local L = LibStub("AceLocale-3.0"):GetLocale(AddonName)
local AltinatorDB = AltinatorNS.AltinatorDB
local AltinatorLDB = AltinatorNS.AltinatorLDB
local icon = LibStub("LibDBIcon-1.0")
local AltinatorFrame
AltinatorNS.AltinatorCache = {}
local AltinatorAddon = LibStub("AceAddon-3.0"):NewAddon(AddonName, "AceEvent-3.0", "AceTimer-3.0")
AltinatorNS.AltinatorAddon = AltinatorAddon
SLASH_ALTINATOR1, SLASH_ALTINATOR2 = "/alt", "/altinator"
SlashCmdList.ALTINATOR = function(msg, editBox)
if msg == "options" or msg == "o" then
Settings.OpenToCategory(AltinatorNS.AltinatorOptions.Category:GetID())
else
AltinatorAddon:ToggleFrame()
end
end
function AltinatorAddon:OnInitialize()
AltinatorDB = LibStub("AceDB-3.0"):New("AltinatorDB", {
profile = {
minimap = {
hide = false,
},
settings = {
hideRecipeTooltips = false,
}
},
global = {
characters = {},
hiddenCharacters = {}
}
})
AltinatorNS.AltinatorDB = AltinatorDB
icon:Register(AddonName, AltinatorLDB, AltinatorDB.profile.minimap)
if AltinatorDB.global.dbversion ~= C["MajorDBVersion"] then
AltinatorDB.global.characters = {}
AltinatorDB.global.hiddenCharacters = {}
AltinatorDB.global.dbversion = C["MajorDBVersion"]
end
AltinatorAddon.CurrentCharacter = {}
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_LOGOUT")
self:RegisterEvent("TIME_PLAYED_MSG")
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
self:RegisterEvent("PLAYER_MONEY")
self:RegisterEvent("PLAYER_LEVEL_UP")
self:RegisterEvent("PLAYER_XP_UPDATE")
self:RegisterEvent("PLAYER_UPDATE_RESTING")
self:RegisterEvent("PLAYER_GUILD_UPDATE")
self:RegisterEvent("TRADE_SKILL_SHOW")
self:RegisterEvent("TRADE_SKILL_UPDATE")
self:RegisterEvent("CRAFT_UPDATE")
self:RegisterEvent("BANKFRAME_OPENED")
AltinatorNS.AltinatorOptions:Initialize()
RequestTimePlayed()
AltinatorNS.AltinatorGameTooltip:Initialize()
hooksecurefunc("DoTradeSkill", function()
AltinatorNS.AltinatorCache.updateCooldowns = true
end)
end
function AltinatorAddon:OnDisable()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
self:UnregisterEvent("PLAYER_LOGOUT")
self:UnregisterEvent("TIME_PLAYED_MSG")
self:UnregisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
self:UnregisterEvent("PLAYER_MONEY")
self:UnregisterEvent("PLAYER_LEVEL_UP")
self:UnregisterEvent("PLAYER_XP_UPDATE")
self:UnregisterEvent("PLAYER_UPDATE_RESTING")
self:UnregisterEvent("PLAYER_GUILD_UPDATE")
self:UnregisterEvent("TRADE_SKILL_SHOW")
self:UnregisterEvent("TRADE_SKILL_UPDATE")
self:UnregisterEvent("CRAFT_UPDATE")
self:UnregisterEvent("BANKFRAME_OPENED")
end
function AltinatorAddon:PLAYER_ENTERING_WORLD(self, isLogin, isReload)
if isLogin or isReload then
AltinatorNS.AltinatorData:SavePlayerDataLogin()
end
end
function AltinatorAddon:PLAYER_LOGOUT()
AltinatorNS.AltinatorData:SavePlayerDataLogout()
end
function AltinatorAddon:PLAYER_INTERACTION_MANAGER_FRAME_HIDE(self, type)
if(type == 17) then
AltinatorNS.AltinatorData:ClearPlayerMailData()
end
end
function AltinatorAddon:TIME_PLAYED_MSG(self, total, level)
AltinatorNS.AltinatorData:SavePlayerTimePlayed(total, level)
end
function AltinatorAddon:PLAYER_MONEY()
AltinatorNS.AltinatorData:SavePlayerMoney()
end
function AltinatorAddon:PLAYER_LEVEL_UP()
AltinatorNS.AltinatorData:SavePlayerXP()
end
function AltinatorAddon:PLAYER_XP_UPDATE()
AltinatorNS.AltinatorData:SavePlayerXP()
end
function AltinatorAddon:PLAYER_UPDATE_RESTING()
AltinatorNS.AltinatorData:SavePlayerResting()
end
function AltinatorAddon:PLAYER_GUILD_UPDATE()
AltinatorNS.AltinatorData:SavePlayerGuild()
end
function AltinatorAddon:PLAYER_GUILD_UPDATE()
AltinatorNS.AltinatorData:SavePlayerGuild()
end
function AltinatorAddon:PLAYER_GUILD_UPDATE()
AltinatorNS.AltinatorData:SavePlayerGuild()
end
function AltinatorAddon:TRADE_SKILL_SHOW()
AltinatorAddon:ScheduleTimer(AltinatorNS.AltinatorData.ScanTradeSkills, 0.5)
end
function AltinatorAddon:TRADE_SKILL_UPDATE()
if AltinatorNS.AltinatorCache.updateCooldowns then
AltinatorNS.AltinatorData:ScanCooldowns()
AltinatorNS.AltinatorCache.updateCooldowns = false
end
end
function AltinatorAddon:CRAFT_UPDATE()
AltinatorAddon:ScheduleTimer(AltinatorNS.AltinatorData.ScanEnchantingRecipes, 0.5)
end
function AltinatorAddon:BANKFRAME_OPENED()
AltinatorAddon:ScheduleTimer(AltinatorNS.AltinatorData.ScanBank, 0.5)
end
function AltinatorAddon:GetMainFrame()
return AltinatorFrame or AltinatorAddon:CreateMainFrame()
end
function AltinatorAddon:ToggleFrame()
local frame = AltinatorAddon:GetMainFrame()
frame:SetShown(not frame:IsShown())
if frame:IsShown() then
for i = 1, #AltinatorNS.Tabs do
local tab = AltinatorNS.Tabs[i]
if tab.content:IsShown() and tab.content.Refresh then
tab.content:Refresh(tab.content)
end
end
end
end
local function Tab_OnClick(self)
PanelTemplates_SetTab(self:GetParent(), self:GetID())
for i = 1, #AltinatorNS.Tabs do
local tab = AltinatorNS.Tabs[i]
if tab.content:IsShown() then
tab.content:Hide()
end
end
SetTitle("Altinator - " .. self.Name)
self.content:LoadContent(self.content)
self.content:Show()
end
local function CreateTabs(frame, ...)
local args = {...}
AltinatorNS.Tabs = AltinatorNS.Tabs or {}
local frameName = frame:GetName()
for i, name in ipairs(args) do
local tab = CreateFrame("Button", frameName.."Tab"..i, frame, "CharacterFrameTabButtonTemplate")
tab:SetID(i)
tab:SetText(name)
tab.Name = name
tab:SetScript("OnClick", Tab_OnClick)
tab.content = CreateFrame("Frame", nil, frame)
tab.content:SetSize(C["Width"], C["Height"])
tab.content:SetPoint("TOPLEFT", frame, "TOPLEFT", 8, -28)
tab.content:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 6)
tab.content:Hide()
table.insert(AltinatorNS.Tabs, tab)
if(i==1) then
tab:SetPoint("TOPLEFT", AltinatorFrame, "BOTTOMLEFT", 0, 2)
else
tab:SetPoint("TOPLEFT", AltinatorNS.Tabs[i-1], "TOPRIGHT", -14, 0)
end
end
frame.numTabs = #AltinatorNS.Tabs
return unpack(AltinatorNS.Tabs)
end
function SetTitle(title)
AltinatorFrame.Title:SetText(title)
end
function AltinatorAddon:CreateMainFrame()
AltinatorFrame = CreateFrame("Frame", "AltinatorFrame", UIParent, "BasicFrameTemplateWithInset")
AltinatorFrame:SetSize(C["Width"], C["Height"])
AltinatorFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
AltinatorFrame:SetToplevel(true)
AltinatorFrame:SetClampedToScreen(true)
AltinatorFrame:EnableMouse(true)
AltinatorFrame:SetMovable(true)
AltinatorFrame:RegisterForDrag("LeftButton")
AltinatorFrame:SetScript("OnDragStart", function(self)
AltinatorFrame:StartMoving()
end)
AltinatorFrame:SetScript("OnDragStop", function(self)
AltinatorFrame:StopMovingOrSizing()
end)
AltinatorFrame:SetScript("OnShow", function()
PlaySound(808)
end)
AltinatorFrame:SetScript("OnHide", function()
PlaySound(808)
end)
AltinatorNS.AltinatorTooltip = CreateFrame("GameTooltip", "AltinatorTooltipFrame", AltinatorFrame, "GameTooltipTemplate")
AltinatorNS.AltinatorTooltip:SetFrameStrata("TOOLTIP")
AltinatorFrame.TitleBg:SetHeight(30)
AltinatorFrame.Title = AltinatorFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
AltinatorFrame.Title:SetPoint("CENTER", AltinatorFrame.TitleBg, "CENTER", 0, 6)
SetTitle(AddonName)
AltinatorFrame.OptionsButton = AltinatorFrame.OptionsButton or CreateFrame("Button", nil, AltinatorFrame, "GameMenuButtonTemplate");
AltinatorFrame.OptionsButton:SetPoint("TOPRIGHT", AltinatorFrame, "TOPRIGHT", -23, 2);
AltinatorFrame.OptionsButton:SetSize(24, 24);
AltinatorFrame.OptionsButton:SetText("|TInterface\\Buttons\\UI-OptionsButton:0|t");
AltinatorFrame.OptionsButton:SetNormalFontObject("GameFontNormal");
AltinatorFrame.OptionsButton:SetHighlightFontObject("GameFontHighlight");
AltinatorFrame.OptionsButton:SetScript("OnClick", function(button)
Settings.OpenToCategory(AltinatorNS.AltinatorOptions.Category:GetID())
end)
local overView, activityView, professionView, gearView, AttunementView, searchView = CreateTabs(AltinatorFrame, L["Overview"], L["Activity"], L["Professions"], L["Gear"], L["Attunement"], L["Search"])
overView.content.LoadContent = AltinatorNS.AltinatorOverviewFrame.Initialize
overView.content.Refresh = AltinatorNS.AltinatorOverviewFrame.Initialize
activityView.content.LoadContent = AltinatorNS.AltinatorActivityFrame.Initialize
activityView.content.Refresh = AltinatorNS.AltinatorActivityFrame.Initialize
professionView.content.LoadContent = AltinatorNS.AltinatorProfessionFrame.Initialize
professionView.content.Refresh = AltinatorNS.AltinatorProfessionFrame.Initialize
gearView.content.LoadContent = AltinatorNS.AltinatorGearFrame.Initialize
gearView.content.Refresh = AltinatorNS.AltinatorGearFrame.Initialize
AttunementView.content.LoadContent = AltinatorNS.AltinatorAttunementFrame.Initialize
AttunementView.content.Refresh = AltinatorNS.AltinatorAttunementFrame.Initialize
searchView.content.LoadContent = AltinatorNS.AltinatorSearchFrame.Initialize
Tab_OnClick(overView)
tinsert(UISpecialFrames, "AltinatorFrame");
AltinatorFrame:Hide()
return AltinatorFrame
end