-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKrowi_WorldMapButtons.lua
More file actions
139 lines (115 loc) · 3.81 KB
/
Copy pathKrowi_WorldMapButtons.lua
File metadata and controls
139 lines (115 loc) · 3.81 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
--[[
Copyright (c) 2020 Krowi
Licensed under the terms of the LICENSE file in this repository.
]]
---@diagnostic disable: undefined-global
local lib, oldminor = LibStub:NewLibrary('Krowi_WorldMapButtons-1.4', 11);
if not lib then
return;
end
local version = (GetBuildInfo());
local major = string.match(version, "(%d+)%.(%d+)%.(%d+)(%w?)");
major = tonumber(major);
-- WoW Forever reports a 1.x build but ships the retail world map
lib.IsForever = major <= 3 and WorldMapTrackingPinButtonMixin ~= nil;
lib.HasNoOverlay = major <= 3 and not lib.IsForever;
lib.IsMainline = major >= 11 or lib.IsForever;
-- Forever moves the map pin button to the top-left corner, so the buttons stack from there
if lib.IsForever then
lib.AnchorPoint, lib.XOffset, lib.YOffset = "TOPLEFT", 3, 0;
else
lib.AnchorPoint, lib.XOffset, lib.YOffset = "TOPRIGHT", 4, -2;
end
function lib:SetOffsets(xOffset, yOffset)
self.XOffset = xOffset or self.XOffset;
self.YOffset = yOffset or self.YOffset;
end
local function SetButtonPoint(button, xOffset, yOffset)
button:ClearAllPoints();
button:SetPoint(lib.AnchorPoint, button.relativeFrame, lib.AnchorPoint == "TOPLEFT" and xOffset or -xOffset, yOffset);
end
function lib.SetPoints()
local xOffset, yOffset = lib.XOffset, lib.YOffset;
for _, button in next, lib.Buttons do
if button:IsShown() then
SetButtonPoint(button, xOffset, yOffset);
if lib.IsMainline then
yOffset = yOffset - 32;
else
xOffset = xOffset + 32;
end
end
end
end
local function IsTrackingOptionsButton(f)
return WorldMapTrackingOptionsButtonMixin and f.OnLoad == WorldMapTrackingOptionsButtonMixin.OnLoad;
end
local function HookDefaultButtons()
if WorldMapFrame.overlayFrames == nil then
lib.HookedDefaultButtons = true;
return;
end
for _, f in next, WorldMapFrame.overlayFrames do
-- Forever keeps the tracking options button next to the nav bar
if not lib.IsForever and IsTrackingOptionsButton(f) then
tinsert(lib.Buttons, f);
end
if WorldMapTrackingPinButtonMixin and f.OnLoad == WorldMapTrackingPinButtonMixin.OnLoad then
tinsert(lib.Buttons, f);
end
end
lib.HookedDefaultButtons = true;
end
local function AddButton(button)
local xOffset, yOffset = lib.XOffset, lib.YOffset;
if lib.IsMainline then
yOffset = yOffset - #lib.Buttons * 32;
else
xOffset = xOffset + #lib.Buttons * 32;
end
button.relativeFrame = WorldMapFrame:GetCanvasContainer();
SetButtonPoint(button, xOffset, yOffset);
hooksecurefunc(WorldMapFrame, "OnMapChanged", function()
button:Refresh();
lib.SetPoints();
end);
tinsert(lib.Buttons, button);
return button;
end
function lib:Add(templateName, templateType)
if self.Buttons == nil then
self.Buttons = {};
end
if not self.HookedDefaultButtons then
HookDefaultButtons();
end
local button = CreateFrame(templateType, "Krowi_WorldMapButtons" .. (#self.Buttons + 1), lib.HasNoOverlay and WorldMapFrame.ScrollContainer or WorldMapFrame, templateName);
if lib.HasNoOverlay then
button:SetFrameStrata("TOOLTIP");
end
return AddButton(button);
end
-- handle upgrades
if oldminor and oldminor == 1 then
lib.Buttons = lib.buttons;
end
if oldminor and oldminor == 3 then
if lib.HasNoOverlay then
for _, button in next, lib.Buttons do
button:SetParent(WorldMapFrame.ScrollContainer);
button:SetFrameStrata("TOOLTIP");
end
end
end
-- Older minors treated Forever as Classic Era: they adopted the tracking options button and parented buttons to the ScrollContainer
if oldminor and oldminor < 11 and lib.IsForever and lib.Buttons then
for i = #lib.Buttons, 1, -1 do
local button = lib.Buttons[i];
if IsTrackingOptionsButton(button) then
tremove(lib.Buttons, i);
elseif button:GetParent() == WorldMapFrame.ScrollContainer then
button:SetParent(WorldMapFrame);
button:SetFrameStrata("HIGH"); -- same strata as Blizzard's map buttons
end
end
end