-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.lua
More file actions
213 lines (172 loc) · 8.55 KB
/
Copy pathoptions.lua
File metadata and controls
213 lines (172 loc) · 8.55 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
local folderName, Addon = ...
local CONFIG_DEFAULTS = {
resetMapAfter = 15,
autoCentering = false,
zoomTimeSeconds = 0.3,
autoCenterEnabled = true,
doubleClickTime = 0.25,
showReadingEmote = true,
}
local addonLoadedFrame = CreateFrame("Frame")
addonLoadedFrame:RegisterEvent("ADDON_LOADED")
addonLoadedFrame:SetScript("OnEvent", function(self, event, arg1)
if arg1 ~= folderName then return end
PWM_config = PWM_config or {}
-- Remove obsolete values from saved variables.
for k in pairs(PWM_config) do
if CONFIG_DEFAULTS[k] == nil then
PWM_config[k] = nil
end
end
-- Fill missing values. Use an explicit nil check so boolean false values from
-- the saved variables are preserved and not treated as "missing".
for k, v in pairs(CONFIG_DEFAULTS) do
if PWM_config[k] == nil then
PWM_config[k] = v
end
end
end)
-- Create a custom tooltip frame that we control
local customTooltip = CreateFrame("GameTooltip", "PWM_CustomTooltip", UIParent, "GameTooltipTemplate")
customTooltip:SetFrameStrata("TOOLTIP")
customTooltip:Hide()
local customTooltipHideTimer = nil
local customTooltipActive = false
local function ShowCustomTooltip(anchorFrame, title, text)
if customTooltipHideTimer then
customTooltipHideTimer:Cancel()
customTooltipHideTimer = nil
end
customTooltip:SetOwner(anchorFrame, "ANCHOR_RIGHT")
customTooltip:ClearLines()
GameTooltip_SetTitle(customTooltip, title)
GameTooltip_AddNormalLine(customTooltip, text)
customTooltip:Show()
customTooltipActive = true
end
-- Hide tooltip after a delay, so it closes simultaneously with the submenu.
local function HideCustomTooltipDelayed(delay)
if customTooltipHideTimer then
customTooltipHideTimer:Cancel()
end
customTooltipHideTimer = C_Timer.NewTimer(delay or 0.33, function()
customTooltip:Hide()
customTooltipActive = false
customTooltipHideTimer = nil
end)
end
-- Hide tooltip immediately if another submenu opens
local function HideCustomTooltipImmediately()
if customTooltipHideTimer then
customTooltipHideTimer:Cancel()
customTooltipHideTimer = nil
end
customTooltipActive = false
customTooltip:Hide()
end
-- Function to call in the OnEnter handler of each submenu button.
local function OnEnterSubmenuFunction(frame, desc, title, tooltipText)
HideCustomTooltipImmediately()
desc:ForceOpenSubmenu()
ShowCustomTooltip(frame, title, tooltipText)
end
Addon.OpenOptionsMenu = function()
MenuUtil.CreateContextMenu(UIParent, function(button, mainMenu)
mainMenu:CreateTitle("Persistent World Map")
mainMenu:CreateDivider()
local submenu = mainMenu:CreateButton("Reset closed map")
submenu:SetOnEnter(function(frame, desc)
OnEnterSubmenuFunction(frame, desc, "Reset closed map", "How long the map should remember its zoom and position after closing. Set to 'Never' to reset the map every time it is opened; like the game's default behavior.")
end)
submenu:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
submenu:CreateTitle("Reset closed map")
submenu:CreateRadio("Instantly", function() return PWM_config.resetMapAfter == 0 end, function() PWM_config.resetMapAfter = 0; return MenuResponse.Refresh end)
submenu:CreateRadio("After 5 seconds", function() return PWM_config.resetMapAfter == 5 end, function() PWM_config.resetMapAfter = 5; return MenuResponse.Refresh end)
submenu:CreateRadio("After 15 seconds", function() return PWM_config.resetMapAfter == 15 end, function() PWM_config.resetMapAfter = 15; return MenuResponse.Refresh end)
submenu:CreateRadio("After 30 seconds", function() return PWM_config.resetMapAfter == 30 end, function() PWM_config.resetMapAfter = 30; return MenuResponse.Refresh end)
submenu:CreateRadio("After 60 seconds", function() return PWM_config.resetMapAfter == 60 end, function() PWM_config.resetMapAfter = 60; return MenuResponse.Refresh end)
submenu:CreateRadio("Never", function() return PWM_config.resetMapAfter == 86400 end, function() PWM_config.resetMapAfter = 86400; return MenuResponse.Refresh end)
submenu = mainMenu:CreateButton("Auto-Center")
submenu:SetOnEnter(function(frame, desc)
OnEnterSubmenuFunction(frame, desc, "Auto-Center", "When enabled, the map automatically keeps your character centered while zoomed in. Activate by double-clicking the map or clicking the lock button.")
end)
submenu:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
submenu:CreateTitle("Auto-Center")
submenu:CreateCheckbox(
"Enabled",
function()
return PWM_config.autoCenterEnabled
end,
function()
PWM_config.autoCenterEnabled = not PWM_config.autoCenterEnabled
Addon.UpdateAutoCenterLockButton()
end
)
local subsubmenu = submenu:CreateButton("Double-click sensitivity")
subsubmenu:SetEnabled(function() return PWM_config.autoCenterEnabled end) -- Disable (grey out) this submenu when auto-centering is disabled.
subsubmenu:SetOnEnter(function(frame, desc)
local tooltipText = PWM_config.autoCenterEnabled and "Adjust sensitivity for double-click auto-center" or "Enable Auto-Center to change double-click sensitivity"
OnEnterSubmenuFunction(frame, desc, "Double-click sensitivity", tooltipText)
end)
subsubmenu:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
subsubmenu:CreateRadio("Slow", function() return PWM_config.doubleClickTime == 0.5 end, function() PWM_config.doubleClickTime = 0.5; return MenuResponse.Refresh end)
subsubmenu:CreateRadio("Medium", function() return PWM_config.doubleClickTime == 0.25 end, function() PWM_config.doubleClickTime = 0.25; return MenuResponse.Refresh end)
subsubmenu:CreateRadio("Fast", function() return PWM_config.doubleClickTime == 0.2 end, function() PWM_config.doubleClickTime = 0.2; return MenuResponse.Refresh end)
submenu = mainMenu:CreateButton("Smooth zoom")
submenu:SetOnEnter(function(frame, desc)
OnEnterSubmenuFunction(frame, desc, "Smooth zoom", "Controls the animation speed when zooming in or out with the mouse wheel. Set to 'Disabled' for instant zoom without animation.")
end)
submenu:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
submenu:CreateTitle("Smooth zoom")
submenu:CreateRadio("Slow", function() return PWM_config.zoomTimeSeconds == 0.6 end, function() PWM_config.zoomTimeSeconds = 0.6; return MenuResponse.Refresh end)
submenu:CreateRadio("Medium", function() return PWM_config.zoomTimeSeconds == 0.3 end, function() PWM_config.zoomTimeSeconds = 0.3; return MenuResponse.Refresh end)
submenu:CreateRadio("Fast", function() return PWM_config.zoomTimeSeconds == 0.15 end, function() PWM_config.zoomTimeSeconds = 0.15; return MenuResponse.Refresh end)
submenu:CreateRadio("Disabled", function() return PWM_config.zoomTimeSeconds == 0 end, function() PWM_config.zoomTimeSeconds = 0; return MenuResponse.Refresh end)
submenu = mainMenu:CreateButton("Miscellaneous")
submenu:SetOnEnter(function(frame, desc)
OnEnterSubmenuFunction(frame, desc, "Miscellaneous", "Additional settings for minor visual details.")
end)
submenu:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
submenu:CreateTitle("Miscellaneous")
local emoteCheckbox = submenu:CreateCheckbox(
"Show reading emote",
function()
return PWM_config.showReadingEmote
end,
function()
PWM_config.showReadingEmote = not PWM_config.showReadingEmote
if WorldMapFrame:IsShown() then
local isInstance, instanceType = IsInInstance()
local inPvP = isInstance and instanceType == "pvp"
if PWM_config.showReadingEmote and not inPvP then
C_ChatInfo.PerformEmote("READ", nil, true)
else
C_ChatInfo.CancelEmote()
end
end
end
)
emoteCheckbox:SetOnEnter(function(frame, desc)
ShowCustomTooltip(frame, "Show reading emote", "When opening the world map, your character performs a map-reading animation. Uncheck to disable it.\n\nNote: This animation is always suppressed inside battlegrounds to avoid a World of Warcraft restriction that would otherwise cause an error.")
end)
emoteCheckbox:SetOnLeave(function(frame)
HideCustomTooltipDelayed(0.33)
end)
end)
end
-- Close the options context menu when the world map closes.
WorldMapFrame:HookScript("OnHide", function()
if Menu and Menu.GetManager then
Menu.GetManager():CloseMenus()
end
end)