-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
133 lines (114 loc) · 3.88 KB
/
Core.lua
File metadata and controls
133 lines (114 loc) · 3.88 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
local addonName, addon = ...
-- Global settings table (accessible by other modules)
addon.Settings = {}
addon.lastCompletedCount = 0
addon.hadListPreviously = false
addon.needsUpdate = false
local function InitializeSettings()
if not CHETTHelperDB then
CHETTHelperDB = {}
for _, q in ipairs(addon.QUESTS) do
if CHETTHelperDB[q.key] == nil then
CHETTHelperDB[q.key] = q.default
end
end
CHETTHelperDB.autoTake = true
CHETTHelperDB.skipGossip = true
CHETTHelperDB.skipDrills = true
CHETTHelperDB.fontSize = addon.DEFAULT_FONT_SIZE
CHETTHelperDB.growDirection = "DOWN"
end
-- Migration for new settings
if not CHETTHelperDB.fontSize then
CHETTHelperDB.fontSize = addon.DEFAULT_FONT_SIZE
end
if not CHETTHelperDB.growDirection then
CHETTHelperDB.growDirection = "DOWN"
end
-- Copy to working table
for k, v in pairs(CHETTHelperDB) do
addon.Settings[k] = v
end
end
-- Save frame position
function addon:SaveFramePosition()
if not self.CHETTHelper then return end
local point, _, _, x, y = self.CHETTHelper:GetPoint()
if point then
CHETTHelperDB.framePos = {
point = point,
x = x,
y = y
}
end
end
-- Load frame position
function addon:LoadFramePosition()
if CHETTHelperDB.framePos then
local pos = CHETTHelperDB.framePos
self.CHETTHelper:ClearAllPoints()
self.CHETTHelper:SetPoint(pos.point, UIParent, pos.point, pos.x, pos.y)
end
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("BAG_UPDATE_DELAYED")
frame:RegisterEvent("QUEST_LOG_UPDATE")
frame:RegisterEvent("QUEST_WATCH_UPDATE")
frame:RegisterEvent("GOSSIP_SHOW")
frame:RegisterEvent("MERCHANT_SHOW")
frame:RegisterEvent("MERCHANT_CLOSED")
frame:RegisterEvent("MERCHANT_UPDATE")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
frame:RegisterEvent("QUEST_TURNED_IN")
frame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
InitializeSettings()
addon.hadListPreviously = addon:HasCHETTList()
addon:CreateUI()
addon:LoadFramePosition() -- Restore position after creating UI
addon:CreateConfig()
addon:UpdateQuestList()
elseif event == "PLAYER_REGEN_ENABLED" then
if addon.needsUpdate then
addon:UpdateQuestList()
end
elseif event == "GOSSIP_SHOW" then
addon:ProcessGossip()
elseif event == "MERCHANT_SHOW" or event == "MERCHANT_UPDATE" then
addon:UpdateRepButton()
elseif event == "MERCHANT_CLOSED" then
if not InCombatLockdown() then
if addon.CHETTHelper.buyRepBtn then addon.CHETTHelper.buyRepBtn:Hide() end
if addon.CHETTHelper.openListBtn then addon.CHETTHelper.openListBtn:Show() end
end
elseif event == "QUEST_TURNED_IN" then
local questID = ...
if addon:CheckQuestInList(questID) then
addon:CacheQuestCompletion(questID)
end
if InCombatLockdown() then
addon.needsUpdate = true
else
C_Timer.After(0.2, function() addon:UpdateQuestList() end)
end
else
if InCombatLockdown() then
addon.needsUpdate = true
else
addon:UpdateQuestList()
end
end
end)
-- Slash commands
SLASH_CHETTHELPER1 = "/chb"
SLASH_CHETTHELPER2 = "/chetthelper"
SlashCmdList["CHETTHELPER"] = function()
if addon.settingsCategory then
Settings.OpenToCategory(addon.settingsCategory:GetID())
else
print("|cffffd100CHETT Helper:|r Settings not loaded yet")
end
end
print("|cffffd100CHETT Helper|r loaded. Type /chb for options.")