-
Notifications
You must be signed in to change notification settings - Fork 3
/
ItemUpgradeTip.lua
184 lines (152 loc) · 5.57 KB
/
ItemUpgradeTip.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
-- ----------------------------------------------------------------------------
-- AddOn Namespace
-- ----------------------------------------------------------------------------
local AddOnFolderName = ... ---@type string
local private = select(2, ...) ---@class PrivateNamespace
---@type Localizations
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnFolderName)
---@class ItemUpgradeTip: AceAddon, AceConsole-3.0, AceEvent-3.0
ItemUpgradeTip = LibStub("AceAddon-3.0"):NewAddon(AddOnFolderName, "AceConsole-3.0", "AceEvent-3.0")
ItemUpgradeTip.Version = C_AddOns.GetAddOnMetadata(AddOnFolderName, "Version");
ItemUpgradeTip.L = L;
private.allFrames = {}
ItemUpgradeTip.Skins = {}
function ItemUpgradeTip:GetAllFrames()
return private.allFrames
end
function ItemUpgradeTip:RegisterSkinListener(callback)
if not private.skinListeners then
private.skinListeners = {}
end
table.insert(private.skinListeners, callback)
end
function ItemUpgradeTip:AddSkinnableFrame(frameType, frame, extraInfo)
if not frame.added then
local details = {frameType = frameType, frame = frame, extraInfo = extraInfo}
table.insert(private.allFrames, details)
if private.skinListeners then
for _, listener in ipairs(private.skinListeners) do
xpcall(listener, CallErrorHandler, details)
end
end
frame.added = true
end
end
-- Toggle the upgrade pane
function ItemUpgradeTip:ToggleView()
---@diagnostic disable-next-line: need-check-nil
IUTView:SetShown(not IUTView:IsShown())
end
-- Return the Mythic+ info
---@return Array<MythicPlusInfo>
function ItemUpgradeTip:GetMythicPlusInfo()
return private.mythicPlusInfo
end
-- Return the Raid info
---@return Array<RaidInfo>
function ItemUpgradeTip:GetRaidInfo()
return private.raidInfo
end
-- Return the Raid currency info
---@return RaidCurrencyInfo
function ItemUpgradeTip:GetRaidCurrencyInfo()
return private.raidCurrencyInfo
end
-- Return the Upgrade info
---@return Array<UpgradeTrackInfo>
function ItemUpgradeTip:GetUpgradeTrackInfo()
return private.upgradeTrackInfo
end
-- Return the Crafting info
---@return Array<CraftingInfo>
function ItemUpgradeTip:GetCraftingInfo()
return private.craftingInfo
end
-- Return the Currency info from cache
---@param currencyId integer
---@return CurrencyInfo
function ItemUpgradeTip:GetCurrencyInfo(currencyId)
return private.currencyInfo[currencyId]
end
-- Core initialisation
function ItemUpgradeTip:OnInitialize()
local DB = private.Preferences:InitializeDatabase()
private.DB = DB
private.Preferences:SetupOptions()
self:RegisterChatCommand("itemupgradetip", "ChatCommand")
self:RegisterChatCommand("iut", "ChatCommand")
end
-- Ran during PLAYER_LOGIN
function ItemUpgradeTip:OnEnable()
for currencyId, _ in pairs(private.currencyIndexes) do
private.currencyInfo[currencyId] = C_CurrencyInfo.GetCurrencyInfo(currencyId)
end
self:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
CreateFrame("Frame", "IUTView", UIParent, "ItemUpgradeTipUpgradeTemplate")
end
-- Not super useful just now, but might be in the future
function ItemUpgradeTip:OnDisable()
self:UnregisterEvent("CURRENCY_DISPLAY_UPDATE")
self:UnregisterChatCommand("itemupgradetip")
self:UnregisterChatCommand("iut")
end
---Currency updated
---@diagnostic disable: unused-local
---@param event string
---@param currencyType number?
---@param quantity number?
---@param quantityChange number?
---@param quantityGainSource number?
---@param quantityLostSource number?
function ItemUpgradeTip:CURRENCY_DISPLAY_UPDATE(event, currencyType, quantity, quantityChange, quantityGainSource, quantityLostSource)
if currencyType and quantity then
if private.currencyIndexes[currencyType] then
-- Refresh the entire currency info in case there's info other than quantity that also updated
private.currencyInfo[currencyType] = C_CurrencyInfo.GetCurrencyInfo(currencyType)
end
end
end
local SUBCOMMAND_FUNCS = {
["SETTINGS"] = function()
local settingsPanel = SettingsPanel
if settingsPanel:IsVisible() then
settingsPanel:Hide()
else
---@diagnostic disable-next-line: undefined-field
Settings.OpenToCategory(private.Preferences.OptionsFrame.ID)
end
end
}
---@param input string
function ItemUpgradeTip:ChatCommand(input)
local subcommand, arguments = self:GetArgs(input, 2)
if subcommand then
local func = SUBCOMMAND_FUNCS[subcommand:upper()]
if func then
func(arguments or "")
end
else
self:ToggleView()
end
end
function ItemUpgradeTip_OnAddonCompartmentEnter(_, menuButtonFrame)
GameTooltip:SetOwner(menuButtonFrame, "ANCHOR_NONE");
GameTooltip:SetPoint("TOPRIGHT", menuButtonFrame, "BOTTOMRIGHT", 0, 0);
GameTooltip:ClearLines();
GameTooltip:AddDoubleLine(AddOnFolderName, ItemUpgradeTip.Version);
GameTooltip_AddBlankLineToTooltip(GameTooltip);
GameTooltip:AddLine(L["LEFT_CLICK"] .. " " .. L["LEFT_CLICK_DESC"]:SetColorAddonBlue());
GameTooltip:AddLine(L["RIGHT_CLICK"] .. " " .. L["RIGHT_CLICK_DESC"]:SetColorAddonBlue());
GameTooltip:Show();
end
function ItemUpgradeTip_OnAddonCompartmentLeave(addonName, button)
GameTooltip:Hide();
end
function ItemUpgradeTip_OnAddonCompartmentClick(addonName, button)
if (button == "LeftButton") then
ItemUpgradeTip:ToggleView()
elseif (button == "RightButton") then
---@diagnostic disable-next-line: undefined-field
Settings.OpenToCategory(private.Preferences.OptionsFrame.ID)
end
end