This repository was archived by the owner on Apr 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.lua
More file actions
270 lines (209 loc) · 7.41 KB
/
main.lua
File metadata and controls
270 lines (209 loc) · 7.41 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
MAGNIFY_MIN_ZOOM = 1.0
MAGNIFY_MAX_ZOOM = 1.6
MAGNIFY_ZOOM_STEP = 0.2
MAGNIFY_PLAYER_FLASH_INTERVAL = 0.25
MAGNIFY_PLAYER_FLASH_COUNT = 10
local WorldMapPlayerModel = nil
-- upvalues
local abs = math.abs
local cos, sin = math.cos, math.sin
local min, max = math.min, math.max
local rad = math.rad
local sqrt = math.sqrt
local GetCursorPosition = GetCursorPosition
local GetPlayerMapPosition = GetPlayerMapPosition
function WorldMapFrameScrollFrame_OnMouseDown()
if arg1 == 'LeftButton' and this.zoomedIn then
this.panning = true
local x, y = GetCursorPosition()
this.cursorX = x
this.cursorY = y
this.x = this:GetHorizontalScroll()
this.y = this:GetVerticalScroll()
this.moved = false
end
end
function WorldMapFrameScrollFrame_OnMouseUp()
this.panning = false
if not this.moved then
WorldMapButton_OnClick(arg1)
WorldMapDetailFrame:SetScale(MAGNIFY_MIN_ZOOM)
this:SetHorizontalScroll(0)
this:SetVerticalScroll(0)
this.zoomedIn = false
end
this.moved = false
end
function WorldMapFrameScrollFrame_OnMouseWheel()
local oldScrollH = this:GetHorizontalScroll()
local oldScrollV = this:GetVerticalScroll()
local cursorX, cursorY = GetCursorPosition()
cursorX = cursorX / this:GetEffectiveScale()
cursorY = cursorY / this:GetEffectiveScale()
local frameX = cursorX - this:GetLeft()
local frameY = this:GetTop() - cursorY
local oldScale = WorldMapDetailFrame:GetScale()
local newScale
newScale = oldScale + arg1 * MAGNIFY_ZOOM_STEP
newScale = max(MAGNIFY_MIN_ZOOM, newScale)
newScale = min(MAGNIFY_MAX_ZOOM, newScale)
WorldMapDetailFrame:SetScale(newScale)
this.maxX = ((WorldMapDetailFrame:GetWidth() * newScale) - this:GetWidth()) / newScale
this.maxY = ((WorldMapDetailFrame:GetHeight() * newScale) - this:GetHeight()) / newScale
this.zoomedIn = WorldMapDetailFrame:GetScale() > MAGNIFY_MIN_ZOOM
local centerX = -oldScrollH + frameX / oldScale
local centerY = oldScrollV + frameY / oldScale
local newScrollH = centerX - frameX / newScale
local newScrollV = centerY - frameY / newScale
newScrollH = min(newScrollH, this.maxX)
newScrollH = max(0, newScrollH)
newScrollV = min(newScrollV, this.maxY)
newScrollV = max(0, newScrollV)
this:SetHorizontalScroll(-newScrollH)
this:SetVerticalScroll(newScrollV)
end
local function WorldMapFrameScrollFrame_OnPan(cursorX, cursorY)
local dX = WorldMapFrameScrollFrame.cursorX - cursorX
local dY = cursorY - WorldMapFrameScrollFrame.cursorY
dX = dX / this:GetEffectiveScale()
dY = dY / this:GetEffectiveScale()
if abs(dX) >= 1 or abs(dY) >= 1 then
WorldMapFrameScrollFrame.moved = true
local x
x = max(0, dX - WorldMapFrameScrollFrame.x)
x = min(x, WorldMapFrameScrollFrame.maxX)
WorldMapFrameScrollFrame:SetHorizontalScroll(-x)
local y
y = max(0, dY + WorldMapFrameScrollFrame.y)
y = min(y, WorldMapFrameScrollFrame.maxY)
WorldMapFrameScrollFrame:SetVerticalScroll(y)
end
end
local WorldMapButton_OldOnUpdate = WorldMapButton:GetScript('OnUpdate')
local function WorldMapButton_OnUpdate()
WorldMapButton_OldOnUpdate()
-- reposition player and ping indicators
local x, y = GetPlayerMapPosition('player')
if x == 0 and y == 0 then
WorldMapPlayer.Icon:Hide()
else
WorldMapPlayer.Icon:Show()
x = x * this:GetWidth()
y = -y * this:GetHeight()
WorldMapPlayer:SetPoint('CENTER', this, 'TOPLEFT', x, y)
-- scale arrow inversely to map zoom so it doesn't grow when zoomed in
local mapScale = WorldMapDetailFrame:GetScale()
local baseSize = 24 * (Magnify_Settings['arrow_scale'] or 1)
local scaledSize = baseSize / mapScale
WorldMapPlayer.Icon:SetWidth(scaledSize)
WorldMapPlayer.Icon:SetHeight(scaledSize)
-- credit: https://wowwiki-archive.fandom.com/wiki/SetTexCoord_Transformations
local s = sqrt(2)
local r = WorldMapPlayerModel:GetFacing()
local LRx, LRy = 0.5 + cos(r + 0.25 * math.pi) / s, 0.5 + sin(r + 0.25 * math.pi) / s
local LLx, LLy = 0.5 + cos(r + 0.75 * math.pi) / s, 0.5 + sin(r + 0.75 * math.pi) / s
local ULx, ULy = 0.5 + cos(r + 1.25 * math.pi) / s, 0.5 + sin(r + 1.25 * math.pi) / s
local URx, URy = 0.5 + cos(r - 0.25 * math.pi) / s, 0.5 + sin(r - 0.25 * math.pi) / s
WorldMapPlayerIcon:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
if WorldMapFrameScrollFrame.panning then
WorldMapFrameScrollFrame_OnPan(GetCursorPosition())
end
end
end
local function WorldMapPlayer_OnUpdate()
this.Elapsed = this.Elapsed + arg1
if this.Elapsed > MAGNIFY_PLAYER_FLASH_INTERVAL then
this.Elapsed = 0
if this.Flashes < MAGNIFY_PLAYER_FLASH_COUNT then
this.Flashes = this.Flashes + 1
if this:GetAlpha() == 1 then
this:SetAlpha(0)
else
this:SetAlpha(1)
end
else
this.Flashes = 0
this:SetAlpha(1)
this:SetScript('OnUpdate', nil)
end
end
end
local WorldMapFrame_OldOnShow = WorldMapFrame:GetScript('OnShow')
local function WorldMapFrame_OnShow()
WorldMapFrame_OldOnShow()
if Magnify_Settings['arrow_flash'] then
WorldMapPlayer:SetScript('OnUpdate', WorldMapPlayer_OnUpdate)
else
WorldMapPlayer:SetAlpha(1)
end
end
local WorldMapFrame_OldOnHide = WorldMapFrame:GetScript('OnHide')
local function WorldMapFrame_OnHide()
WorldMapFrame_OldOnHide()
WorldMapFrameScrollFrame.panning = false
WorldMapPlayer.Flashes = 0
WorldMapPlayer:SetScript('OnUpdate', nil)
if Magnify_Settings['zoom_reset'] then
Magnify_ResetZoom()
end
end
local function HandleEvent()
if not Magnify_Settings then
Magnify_Settings = {
['arrow_flash'] = true,
['arrow_scale'] = 1,
['max_zoom'] = 1.6,
['zoom_reset'] = false
}
end
MAGNIFY_MAX_ZOOM = (Magnify_Settings['max_zoom'] or MAGNIFY_MAX_ZOOM)
if WORLDMAP_WINDOWED then
if WORLDMAP_WINDOWED == 1 then
WorldMapFrame_Minimize()
else
WorldMapFrame_Maximize()
end
end
-- adjust map zone text position
WorldMapFrameAreaFrame:SetParent(WorldMapFrame)
WorldMapFrameAreaFrame:ClearAllPoints()
WorldMapFrameAreaFrame:SetPoint('TOP', WorldMapFrame, 0, -60)
WorldMapFrameAreaFrame:SetFrameStrata('FULLSCREEN_DIALOG')
WorldMapButton:SetParent(WorldMapDetailFrame)
WorldMapButton:SetFrameLevel(0)
-- hide player indicator and ping model
-- credit: https://github.com/Road-block/Cartographer
local children = { WorldMapFrame:GetChildren() }
for _, v in ipairs(children) do
if v:GetFrameType() == 'Model' and not v:GetName() then
v:SetScript('OnShow', function() this:Hide() end)
WorldMapPlayerModel = v
break
end
end
WorldMapPing.Show = function() return end
WorldMapPing:SetModelScale(0)
-- replace player indicator model with a better solution
local size = 24 * (Magnify_Settings['arrow_scale'] or 1)
WorldMapPlayer.Icon = WorldMapPlayer:CreateTexture('WorldMapPlayerIcon', 'ARTWORK')
WorldMapPlayer.Icon:SetWidth(size)
WorldMapPlayer.Icon:SetHeight(size)
WorldMapPlayer.Icon:SetPoint('CENTER', WorldMapPlayer)
WorldMapPlayer.Icon:SetTexture('Interface\\AddOns\\Magnify\\assets\\WorldMapArrow')
WorldMapPlayer.Icon:SetTexCoord(0, 0, 1, 1)
WorldMapPlayer.Flashes = 0
WorldMapPlayer.Elapsed = 0
-- override scripts
WorldMapButton:SetScript('OnUpdate', WorldMapButton_OnUpdate)
WorldMapFrame:SetScript('OnShow', WorldMapFrame_OnShow)
WorldMapFrame:SetScript('OnHide', WorldMapFrame_OnHide)
end
local handler = CreateFrame('Frame')
handler:RegisterEvent('VARIABLES_LOADED')
handler:SetScript('OnEvent', HandleEvent)
function Magnify_ResetZoom()
WorldMapDetailFrame:SetScale(MAGNIFY_MIN_ZOOM)
WorldMapFrameScrollFrame:SetHorizontalScroll(0)
WorldMapFrameScrollFrame:SetVerticalScroll(0)
WorldMapFrameScrollFrame.zoomedIn = false
end