-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MountJournalEnhanced.lua
135 lines (121 loc) · 4.99 KB
/
MountJournalEnhanced.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
local ADDON_NAME, ADDON = ...
-- see: https://www.townlong-yak.com/framexml/live/Blizzard_SharedXML/CallbackRegistry.lua
ADDON.Events = CreateFromMixins(EventRegistry)
ADDON.Events:OnLoad()
ADDON.Events:SetUndefinedEventsAllowed(true)
local function InitUI()
local updateUI = function ()
if CollectionsJournal:IsShown() then
ADDON:FilterMounts()
end
end
ADDON.Events:RegisterFrameEventAndCallback("ZONE_CHANGED", updateUI, 'init')
ADDON.Events:RegisterFrameEventAndCallback("ZONE_CHANGED_INDOORS", updateUI, 'init')
ADDON.Events:RegisterFrameEventAndCallback("MOUNT_JOURNAL_USABILITY_CHANGED", updateUI, 'init')
ADDON.Events:RegisterFrameEventAndCallback("MOUNT_JOURNAL_SEARCH_UPDATED", updateUI, 'init')
MountJournal.searchBox:SetScript("OnTextChanged", function()
SearchBoxTemplate_OnTextChanged(MountJournal.searchBox)
ADDON:FilterMounts()
end)
end
function ADDON:ResetIngameFilter()
-- reset default filter settings
C_MountJournal.SetCollectedFilterSetting(LE_MOUNT_JOURNAL_FILTER_COLLECTED, true)
C_MountJournal.SetCollectedFilterSetting(LE_MOUNT_JOURNAL_FILTER_NOT_COLLECTED, true)
C_MountJournal.SetCollectedFilterSetting(LE_MOUNT_JOURNAL_FILTER_UNUSABLE, true)
C_MountJournal.SetAllSourceFilters(true)
C_MountJournal.SetSearch("")
C_MountJournal.SetAllTypeFilters(true)
end
ADDON:ResetIngameFilter()
local function intersectTableKeys(tbl, keysToKeep)
local result = {}
for key, val in pairs(tbl) do
if type(key) == "string" and type(val) == "table" then
local subResult = intersectTableKeys(val, keysToKeep)
if not TableIsEmpty(subResult) then
result[key] = subResult
end
elseif nil ~= keysToKeep[key] then
result[key] = val
end
end
return result
end
local function CleanupDatabase()
local mountIds = C_MountJournal.GetMountIDs()
mountIds = CopyValuesAsKeys(mountIds)
ADDON.DB.Colors = intersectTableKeys(ADDON.DB.Colors, mountIds)
ADDON.DB.Customization = intersectTableKeys(ADDON.DB.Customization, mountIds)
ADDON.DB.Family = intersectTableKeys(ADDON.DB.Family, mountIds)
ADDON.DB.Restrictions = intersectTableKeys(ADDON.DB.Restrictions, mountIds)
ADDON.DB.Tradable = intersectTableKeys(ADDON.DB.Tradable, mountIds)
end
local loggedIn = false
local function initialize()
if MountJournal then
ADDON.Events:UnregisterFrameEvent("ADDON_LOADED")
ADDON.Events:TriggerEvent("OnJournalLoaded")
ADDON.Events:UnregisterEvents({"OnJournalLoaded"})
end
if not loggedIn and IsLoggedIn() then
loggedIn = true
CleanupDatabase()
ADDON:ResetIngameFilter()
ADDON.Events:TriggerEvent("OnInit")
ADDON.Events:TriggerEvent("OnLogin")
ADDON.Events:UnregisterEvents({"OnInit", "OnLogin"})
ADDON.Events:UnregisterFrameEvent("PLAYER_ENTERING_WORLD")
end
end
ADDON.Events:RegisterFrameEventAndCallback("PLAYER_ENTERING_WORLD", function(_, isLogin, isReload)
if isLogin or isReload then
initialize()
if not MountJournal then
ADDON.Events:RegisterFrameEventAndCallback("ADDON_LOADED", initialize, 'init')
end
end
end, "init")
EventRegistry:RegisterCallback("MountJournal.OnShow", function()
-- MountJournal gets always initially shown before switching to the actual tab.
if CollectionsJournal.selectedTab == COLLECTIONS_JOURNAL_TAB_INDEX_MOUNTS and not ADDON.initialized then
InitUI()
ADDON.initialized = true
C_Timer.After(0, function()
-- EventRegistry might crash when removing an callback while looping through all callbacks
EventRegistry:UnregisterCallback("MountJournal.OnShow", ADDON_NAME)
end)
ADDON.Events:TriggerEvent("preloadUI")
ADDON.Events:TriggerEvent("loadUI")
ADDON.Events:TriggerEvent("postloadUI")
ADDON.Events:UnregisterEvents({"preloadUI", "loadUI", "postloadUI"})
local selected = ADDON.Api:GetSelected()
if selected == nil or selected == select(12, C_MountJournal.GetDisplayedMountInfo(1)) then
local dataprovider = ADDON.Api:GetDataProvider()
if dataprovider:GetSize() > 0 then
ADDON.Api:SetSelected(dataprovider:Find(1).mountID)
end
end
end
end, ADDON_NAME)
StaticPopupDialogs["MJE_COPY"] = {
text = ADDON.L.COPY_POPUP,
button1 = CLOSE,
OnShow = function(self, data)
local function close(editBox) editBox:GetParent():Hide() end
self.editBox:SetScript("OnEscapePressed", close)
self.editBox:SetScript("OnEnterPressed", close)
self.editBox:SetScript("OnKeyUp", function(editBox, key)
if IsControlKeyDown() and key == "C" then
close(editBox)
end
end)
self.editBox:SetText(data)
self.editBox:HighlightText()
end,
hasEditBox = true,
editBoxWidth = 300,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}