Skip to content

Commit 41935a3

Browse files
Merge pull request #9 from johnson-christopher/override-show-method
Refactor to prevent zoning from toggling it back on
2 parents b629940 + 2961e75 commit 41935a3

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

HideExpansionButton.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1+
-- Used to store a backup of the original "Show" method to restore it later if needed.
2+
local originalShowFunction = nil
3+
14
local frame = CreateFrame("FRAME", "HideExpansionButtonFrame")
25
frame:RegisterEvent("ADDON_LOADED")
3-
frame:RegisterEvent("COVENANT_CALLINGS_UPDATED")
4-
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
6+
frame:RegisterEvent("PLAYER_LOGIN")
57

68
frame:SetScript("OnEvent", function(self, event, ...)
79
if event == "ADDON_LOADED" then
810
local addonName = ...
911
if addonName == "HideExpansionButton" and ExpansionButtonVisible == nil then
1012
ExpansionButtonVisible = false
11-
SetButtonState()
1213
frame:UnregisterEvent("ADDON_LOADED")
1314
end
14-
elseif event == "COVENANT_CALLINGS_UPDATED" then
15-
-- Something fires this event and then turns the button back on after.
16-
-- Since it doesn't seem to fire another event when it's done we just
17-
-- have to wait an arbitrary amount of time.
18-
C_Timer.After(5, SetButtonState)
1915
else
2016
SetButtonState()
2117
end
@@ -28,9 +24,19 @@ function SlashCmdList.HIDEEXPANSIONBUTTON(msg, editbox)
2824
end
2925

3026
function SetButtonState()
27+
-- Before we hide the button we save its `Show` method and then override it.
28+
-- Otherwise everytime you zone to a new expansion WoW will just turn it back on.
29+
-- When we need to show it again we just restore the method before calling it.
3130
if ExpansionButtonVisible then
31+
if originalShowFunction ~= nil then
32+
ExpansionLandingPageMinimapButton.Show = originalShowFunction
33+
end
3234
ExpansionLandingPageMinimapButton:Show()
3335
else
3436
ExpansionLandingPageMinimapButton:Hide()
37+
if originalShowFunction == nil then
38+
originalShowFunction = ExpansionLandingPageMinimapButton.Show
39+
end
40+
ExpansionLandingPageMinimapButton.Show = function() end
3541
end
3642
end

HideExpansionButton.toc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## Interface: 110002
1+
## Interface: 110005
22
## Title: Hide Expansion Button
3-
## Notes: Hides the expansion button for the current expansion
3+
## Notes: Hides the expansion minimap button
44
## Author: Chris Johnson
5-
## Version: 1.0.9
5+
## Version: 1.1.0
66
## SavedVariablesPerCharacter: ExpansionButtonVisible
77

88
HideExpansionButton.lua

0 commit comments

Comments
 (0)