SquareMinimapButtons.lua 21.1 KB
Newer Older
Azilroka's avatar
Azilroka committed
1
local PA = _G.ProjectAzilroka
Azilroka's avatar
Azilroka committed
2
local SMB = PA:NewModule('SquareMinimapButtons', 'AceEvent-3.0', 'AceHook-3.0', 'AceTimer-3.0')
Azilroka's avatar
Azilroka committed
3
PA.SMB, _G.SquareMinimapButtons = SMB, SMB
Azilroka's avatar
Azilroka committed
4

Azilroka's avatar
Azilroka committed
5 6
SMB.Title = 'Square Minimap Buttons'
SMB.Header = PA.ACL['|cFF16C3F2Square|r |cFFFFFFFFMinimap Buttons|r']
7
SMB.Description = PA.ACL['Minimap Button Bar / Minimap Button Skinning']
Azilroka's avatar
Azilroka committed
8
SMB.Authors = 'Azilroka    NihilisticPandemonium    Sinaris    Omega    Durc'
Azilroka's avatar
Azilroka committed
9
SMB.isEnabled = false
Azilroka's avatar
Azilroka committed
10

Azilroka's avatar
Azilroka committed
11
local _G = _G
Azilroka's avatar
Azilroka committed
12 13 14 15 16 17 18 19 20 21
local strsub = strsub
local strlen = strlen
local strfind = strfind
local strmatch = strmatch
local strlower = strlower
local tinsert = tinsert
local pairs = pairs
local unpack = unpack
local select = select
local tContains = tContains
Azilroka's avatar
Azilroka committed
22 23
local tostring = tostring
local floor = floor
Azilroka's avatar
Azilroka committed
24 25 26

local InCombatLockdown = InCombatLockdown
local C_PetBattles = C_PetBattles
Azilroka's avatar
Azilroka committed
27
local Minimap = Minimap
Azilroka's avatar
Azilroka committed
28 29 30 31 32 33 34 35 36

local rad = math.rad
local cos = math.cos
local sin = math.sin
local sqrt = math.sqrt
local max = math.max
local min = math.min
local deg = math.deg
local atan2 = math.atan2
Azilroka's avatar
Azilroka committed
37

Azilroka's avatar
Azilroka committed
38 39 40 41 42 43
local CreateFrame = CreateFrame
local GameTooltip = GameTooltip
local GetCursorPosition = GetCursorPosition
local HasNewMail = HasNewMail
local MinimapMailFrameUpdate = MinimapMailFrameUpdate

44
SMB.Buttons = {}
Azilroka's avatar
Azilroka committed
45

Azilroka's avatar
Azilroka committed
46
SMB.IgnoreButton = {
47
	'HelpOpenWebTicketButton',
Azilroka's avatar
Azilroka committed
48 49
	'MiniMapVoiceChatFrame',
	'TimeManagerClockButton',
Azilroka's avatar
Azilroka committed
50 51 52 53
	'BattlefieldMinimap',
	'ButtonCollectFrame',
	'GameTimeFrame',
	'QueueStatusMinimapButton',
54 55 56
	'GarrisonLandingPageMinimapButton',
	'MiniMapMailFrame',
	'MiniMapTracking',
Azilroka's avatar
Azilroka committed
57 58
	'MinimapZoomIn',
	'MinimapZoomOut',
Azilroka's avatar
Azilroka committed
59 60
	'TukuiMinimapZone',
	'TukuiMinimapCoord',
Azilroka's avatar
Azilroka committed
61
	'RecipeRadarMinimapButtonFrame',
Azilroka's avatar
Azilroka committed
62 63
}

Azilroka's avatar
Azilroka committed
64
SMB.GenericIgnore = {
Azilroka's avatar
Azilroka committed
65 66 67 68 69
	'Archy',
	'GatherMatePin',
	'GatherNote',
	'GuildInstance',
	'HandyNotesPin',
Azilroka's avatar
Azilroka committed
70
	'MiniMap',
Azilroka's avatar
Azilroka committed
71 72 73
	'Spy_MapNoteList_mini',
	'ZGVMarker',
	'poiMinimap',
Azilroka's avatar
Azilroka committed
74 75 76 77
	'GuildMap3Mini',
	'LibRockConfig-1.0_MinimapButton',
	'NauticusMiniIcon',
	'WestPointer',
78
	'Cork',
Azilroka's avatar
1.21  
Azilroka committed
79
	'DugisArrowMinimapPoint',
Azilroka's avatar
Azilroka committed
80
	'QuestieFrame',
Azilroka's avatar
Azilroka committed
81 82
}

Azilroka's avatar
Azilroka committed
83
SMB.PartialIgnore = { 'Node', 'Pin', 'POI' }
Azilroka's avatar
Azilroka committed
84 85

SMB.OverrideTexture = {
Azilroka's avatar
Cleanup  
Azilroka committed
86 87 88 89
	BagSync_MinimapButton = 'Interface/AddOns/BagSync/media/icon',
	DBMMinimapButton = 'Interface/Icons/INV_Helmet_87',
	SmartBuff_MiniMapButton = 'Interface/Icons/Spell_Nature_Purge',
	VendomaticButtonFrame = 'Interface/Icons/INV_Misc_Rabbit_2',
Azilroka's avatar
Azilroka committed
90
	OutfitterMinimapButton = '',
Azilroka's avatar
Cleanup  
Azilroka committed
91
	RecipeRadar_MinimapButton = 'Interface/Icons/INV_Scroll_03',
Azilroka's avatar
Azilroka committed
92
	GameTimeFrame = ''
Azilroka's avatar
Cleanup  
Azilroka committed
93 94 95 96 97
}

SMB.DoNotCrop = {
	ZygorGuidesViewerMapIcon = true,
	ItemRackMinimapFrame = true,
Azilroka's avatar
Azilroka committed
98
	Narci_MinimapButton = true,
Azilroka's avatar
Azilroka committed
99 100 101 102 103
}

SMB.UnrulyButtons = {
	'WIM3MinimapButton',
	'RecipeRadar_MinimapButton',
Azilroka's avatar
Azilroka committed
104
}
Azilroka's avatar
Azilroka committed
105

Azilroka's avatar
Azilroka committed
106 107
local ButtonFunctions = { 'SetParent', 'ClearAllPoints', 'SetPoint', 'SetSize', 'SetScale', 'SetFrameStrata', 'SetFrameLevel' }

Azilroka's avatar
Azilroka committed
108 109 110
local RemoveTextureID = {
	[136430] = true,
	[136467] = true,
Azilroka's avatar
Azilroka committed
111
	[136468] = true,
Azilroka's avatar
Azilroka committed
112 113 114
	[130924] = true,
}

Azilroka's avatar
Azilroka committed
115 116 117 118 119 120
local RemoveTextureFile = {
	["interface/minimap/minimap-trackingborder"] = true,
	["interface/minimap/ui-minimap-border"] = true,
	["interface/minimap/ui-minimap-background"] = true,
}

Azilroka's avatar
Azilroka committed
121
function SMB:LockButton(Button)
Azilroka's avatar
Azilroka committed
122 123 124
	for _, Function in pairs(ButtonFunctions) do
		Button[Function] = PA.Noop
	end
Azilroka's avatar
Azilroka committed
125 126 127
end

function SMB:UnlockButton(Button)
Azilroka's avatar
Azilroka committed
128 129 130
	for _, Function in pairs(ButtonFunctions) do
		Button[Function] = nil
	end
Azilroka's avatar
Azilroka committed
131 132
end

Azilroka's avatar
Azilroka committed
133 134 135 136 137 138 139 140 141 142
function SMB:OnUpdate()
	local mx, my = Minimap:GetCenter()
	local px, py = GetCursorPosition()
	local scale = Minimap:GetEffectiveScale()

	px, py = px / scale, py / scale

	local pos = deg(atan2(py - my, px - mx)) % 360
	local angle = rad(pos or 225)
	local x, y = cos(angle), sin(angle)
Azilroka's avatar
Azilroka committed
143 144
	local w = (Minimap:GetWidth() + SMB.db.IconSize) / 2
	local h = (Minimap:GetHeight() + SMB.db.IconSize) / 2
Azilroka's avatar
Azilroka committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	local diagRadiusW = sqrt(2*(w)^2)-10
	local diagRadiusH = sqrt(2*(h)^2)-10

	x = max(-w, min(x*diagRadiusW, w))
	y = max(-h, min(y*diagRadiusH, h))

	self:ClearAllPoints()
	self:SetPoint("CENTER", Minimap, "CENTER", x, y)
end

function SMB:OnDragStart()
	self:SetScript("OnUpdate", SMB.OnUpdate)
end

function SMB:OnDragStop()
	self:SetScript("OnUpdate", nil)
end

Azilroka's avatar
Azilroka committed
163
function SMB:HandleBlizzardButtons()
Azilroka's avatar
Azilroka committed
164 165
	if not SMB.db.BarEnabled then return end
	local Size = SMB.db.IconSize
Azilroka's avatar
Azilroka committed
166

Azilroka's avatar
Azilroka committed
167 168 169
	if SMB.db.MoveMail and not _G.MiniMapMailFrame.SMB then
		local Frame = CreateFrame('Frame', 'SMB_MailFrame', SMB.Bar)
		Frame:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
170
		PA:SetTemplate(Frame)
Azilroka's avatar
Azilroka committed
171 172
		Frame.Icon = Frame:CreateTexture(nil, 'ARTWORK')
		Frame.Icon:SetPoint('CENTER')
Azilroka's avatar
Azilroka committed
173
		Frame.Icon:SetSize(18, 18)
Azilroka's avatar
Azilroka committed
174
		Frame.Icon:SetTexture(_G.MiniMapMailIcon:GetTexture())
Azilroka's avatar
Azilroka committed
175
		Frame:EnableMouse(true)
Azilroka's avatar
Azilroka committed
176
		Frame:HookScript('OnEnter', function(s)
Azilroka's avatar
Azilroka committed
177
			if HasNewMail() then
Azilroka's avatar
Azilroka committed
178 179
				GameTooltip:SetOwner(s, "ANCHOR_BOTTOMRIGHT")
				if GameTooltip:IsOwned(s) then
Azilroka's avatar
Azilroka committed
180 181 182
					MinimapMailFrameUpdate()
				end
			end
Azilroka's avatar
Azilroka committed
183
			s:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
184 185 186 187
			if SMB.Bar:IsShown() then
				UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
			end
		end)
Azilroka's avatar
Azilroka committed
188
		Frame:HookScript('OnLeave', function(s)
Azilroka's avatar
Azilroka committed
189
			GameTooltip:Hide()
Azilroka's avatar
Azilroka committed
190 191
			PA:SetTemplate(s)
			if SMB.Bar:IsShown() and SMB.db.BarMouseOver then
Azilroka's avatar
Azilroka committed
192 193 194
				UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
			end
		end)
Azilroka's avatar
Azilroka committed
195

Azilroka's avatar
Azilroka committed
196 197 198
		_G.MiniMapMailFrame:HookScript('OnShow', function() Frame.Icon:SetVertexColor(0, 1, 0)	end)
		_G.MiniMapMailFrame:HookScript('OnHide', function() Frame.Icon:SetVertexColor(1, 1, 1) end)
		_G.MiniMapMailFrame:EnableMouse(false)
Azilroka's avatar
Azilroka committed
199

Azilroka's avatar
Azilroka committed
200
		if _G.MiniMapMailFrame:IsShown() then
Azilroka's avatar
Azilroka committed
201 202 203
			Frame.Icon:SetVertexColor(0, 1, 0)
		end

Azilroka's avatar
Azilroka committed
204
		-- Hide Icon & Border
Azilroka's avatar
Azilroka committed
205 206
		_G.MiniMapMailIcon:Hide()
		_G.MiniMapMailBorder:Hide()
207

Azilroka's avatar
Azilroka committed
208 209 210 211
		if SMB.db.Shadows then
			PA:CreateShadow(Frame)
		end

Azilroka's avatar
Azilroka committed
212 213
		_G.MiniMapMailFrame.SMB = true
		tinsert(SMB.Buttons, Frame)
214 215
	end

Azilroka's avatar
Azilroka committed
216
	if PA.Retail then
Azilroka's avatar
Azilroka committed
217 218 219 220 221 222 223 224 225 226 227 228 229
		if SMB.db.HideGarrison then
			_G.GarrisonLandingPageMinimapButton:UnregisterAllEvents()
			_G.GarrisonLandingPageMinimapButton:SetParent(SMB.Hider)
			_G.GarrisonLandingPageMinimapButton:Hide()
		elseif SMB.db.MoveGarrison and not _G.GarrisonLandingPageMinimapButton.SMB then
			_G.GarrisonLandingPageMinimapButton:SetParent(Minimap)
			_G.GarrisonLandingPageMinimapButton_OnLoad(_G.GarrisonLandingPageMinimapButton)
			_G.GarrisonLandingPageMinimapButton_UpdateIcon(_G.GarrisonLandingPageMinimapButton)
			_G.GarrisonLandingPageMinimapButton:Show()
			_G.GarrisonLandingPageMinimapButton:SetScale(1)
			_G.GarrisonLandingPageMinimapButton:SetHitRectInsets(0, 0, 0, 0)
			_G.GarrisonLandingPageMinimapButton:SetScript('OnEnter', function(s)
				s:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
230 231 232 233
				if SMB.Bar:IsShown() then
					UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
				end
			end)
Azilroka's avatar
Azilroka committed
234 235 236
			_G.GarrisonLandingPageMinimapButton:SetScript('OnLeave', function(s)
				PA:SetTemplate(s)
				if SMB.Bar:IsShown() and SMB.db.BarMouseOver then
Azilroka's avatar
Azilroka committed
237 238 239
					UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
				end
			end)
Azilroka's avatar
Azilroka committed
240

Azilroka's avatar
Azilroka committed
241
			_G.GarrisonLandingPageMinimapButton.SMB = true
Azilroka's avatar
Azilroka committed
242

Azilroka's avatar
Azilroka committed
243
			if SMB.db.Shadows then
Azilroka's avatar
Azilroka committed
244
				PA:CreateShadow(_G.GarrisonLandingPageMinimapButton)
Azilroka's avatar
Azilroka committed
245
			end
Azilroka's avatar
Azilroka committed
246

Azilroka's avatar
Azilroka committed
247
			tinsert(SMB.Buttons, _G.GarrisonLandingPageMinimapButton)
Azilroka's avatar
Azilroka committed
248
		end
Azilroka's avatar
Azilroka committed
249

Azilroka's avatar
Azilroka committed
250 251
		if SMB.db.MoveTracker and not _G.MiniMapTrackingButton.SMB then
			_G.MiniMapTracking.Show = nil
252

Azilroka's avatar
Azilroka committed
253
			_G.MiniMapTracking:Show()
254

Azilroka's avatar
Azilroka committed
255 256
			_G.MiniMapTracking:SetParent(SMB.Bar)
			_G.MiniMapTracking:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
257

Azilroka's avatar
Azilroka committed
258 259
			_G.MiniMapTrackingIcon:ClearAllPoints()
			_G.MiniMapTrackingIcon:SetPoint('CENTER')
Azilroka's avatar
Azilroka committed
260

Azilroka's avatar
Azilroka committed
261 262 263
			_G.MiniMapTrackingBackground:SetAlpha(0)
			_G.MiniMapTrackingIconOverlay:SetAlpha(0)
			_G.MiniMapTrackingButton:SetAlpha(0)
Azilroka's avatar
Azilroka committed
264

Azilroka's avatar
Azilroka committed
265 266 267
			_G.MiniMapTrackingButton:SetParent(_G.MinimapTracking)
			_G.MiniMapTrackingButton:ClearAllPoints()
			_G.MiniMapTrackingButton:SetAllPoints(_G.MiniMapTracking)
Azilroka's avatar
Azilroka committed
268

Azilroka's avatar
Azilroka committed
269 270
			_G.MiniMapTrackingButton:SetScript('OnMouseDown', nil)
			_G.MiniMapTrackingButton:SetScript('OnMouseUp', nil)
271

Azilroka's avatar
Azilroka committed
272 273
			_G.MiniMapTrackingButton:HookScript('OnEnter', function()
				_G.MiniMapTracking:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
274 275 276 277
				if SMB.Bar:IsShown() then
					UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
				end
			end)
Azilroka's avatar
Azilroka committed
278 279 280
			_G.MiniMapTrackingButton:HookScript('OnLeave', function()
				PA:SetTemplate(_G.MiniMapTracking)
				if SMB.Bar:IsShown() and SMB.db.BarMouseOver then
Azilroka's avatar
Azilroka committed
281 282 283 284
					UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
				end
			end)

Azilroka's avatar
Azilroka committed
285
			_G.MiniMapTrackingButton.SMB = true
Azilroka's avatar
Azilroka committed
286 287

			if SMB.db.Shadows then
Azilroka's avatar
Azilroka committed
288
				PA:CreateShadow(_G.MiniMapTracking)
Azilroka's avatar
Azilroka committed
289 290
			end

Azilroka's avatar
Azilroka committed
291
			tinsert(SMB.Buttons, _G.MiniMapTracking)
Azilroka's avatar
Azilroka committed
292 293
		end

Azilroka's avatar
Azilroka committed
294 295
		if SMB.db["MoveQueue"] and not _G.QueueStatusMinimapButton.SMB then
			local Frame = CreateFrame('Frame', 'SMB_QueueFrame', SMB.Bar)
Azilroka's avatar
Azilroka committed
296
			PA:SetTemplate(Frame)
Azilroka's avatar
Azilroka committed
297
			Frame:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
298
			Frame.Icon = Frame:CreateTexture(nil, 'ARTWORK')
Azilroka's avatar
Azilroka committed
299
			Frame.Icon:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
300
			Frame.Icon:SetPoint('CENTER')
Azilroka's avatar
Cleanup  
Azilroka committed
301
			Frame.Icon:SetTexture('Interface/LFGFrame/LFG-Eye')
Azilroka's avatar
Azilroka committed
302 303
			Frame.Icon:SetTexCoord(0, 64 / 512, 0, 64 / 256)
			Frame:SetScript('OnMouseDown', function()
Azilroka's avatar
Azilroka committed
304 305
				if _G.PVEFrame:IsShown() then
					_G.HideUIPanel(_G.PVEFrame)
Azilroka's avatar
Azilroka committed
306
				else
Azilroka's avatar
Azilroka committed
307 308
					_G.ShowUIPanel(_G.PVEFrame)
					_G.GroupFinderFrame_ShowGroupFrame()
Azilroka's avatar
Azilroka committed
309 310
				end
			end)
Azilroka's avatar
Azilroka committed
311 312
			Frame:HookScript('OnEnter', function(s)
				s:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
313 314 315 316
				if SMB.Bar:IsShown() then
					UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
				end
			end)
Azilroka's avatar
Azilroka committed
317 318 319
			Frame:HookScript('OnLeave', function(s)
				PA:SetTemplate(s)
				if SMB.Bar:IsShown() and SMB.db.BarMouseOver then
Azilroka's avatar
Azilroka committed
320 321 322
					UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
				end
			end)
Azilroka's avatar
Azilroka committed
323

Azilroka's avatar
Azilroka committed
324 325 326 327
			_G.QueueStatusMinimapButton:SetParent(SMB.Bar)
			_G.QueueStatusMinimapButton:SetFrameLevel(Frame:GetFrameLevel() + 2)
			_G.QueueStatusMinimapButton:ClearAllPoints()
			_G.QueueStatusMinimapButton:SetPoint("CENTER", Frame, "CENTER", 0, 0)
Azilroka's avatar
Azilroka committed
328

Azilroka's avatar
Azilroka committed
329
			_G.QueueStatusMinimapButton:SetHighlightTexture(nil)
Azilroka's avatar
Azilroka committed
330

Azilroka's avatar
Azilroka committed
331 332 333
			_G.QueueStatusMinimapButton:HookScript('OnShow', function() Frame:EnableMouse(false) end)
			_G.QueueStatusMinimapButton:HookScript('PostClick', _G.QueueStatusMinimapButton_OnLeave)
			_G.QueueStatusMinimapButton:HookScript('OnHide', function() Frame:EnableMouse(true) end)
Azilroka's avatar
Azilroka committed
334

Azilroka's avatar
Azilroka committed
335
			_G.QueueStatusMinimapButton.SMB = true
Azilroka's avatar
Azilroka committed
336

Azilroka's avatar
Azilroka committed
337 338 339 340
			if SMB.db.Shadows then
				PA:CreateShadow(Frame)
			end

Azilroka's avatar
Azilroka committed
341
			tinsert(SMB.Buttons, Frame)
Azilroka's avatar
Azilroka committed
342
		end
Azilroka's avatar
Azilroka committed
343 344
	else
		-- MiniMapTrackingFrame
Azilroka's avatar
Azilroka committed
345
		if SMB.db.MoveGameTimeFrame and not _G.GameTimeFrame.SMB then
Azilroka's avatar
Azilroka committed
346 347 348 349
			local STEP = 5.625 -- 256 * 5.625 = 1440M = 24H
			local PX_PER_STEP = 0.00390625 -- 1 / 256
			local l, r, offset

Azilroka's avatar
Azilroka committed
350 351
			PA:SetTemplate(_G.GameTimeFrame)
			_G.GameTimeTexture:SetTexture('')
Azilroka's avatar
Azilroka committed
352

Azilroka's avatar
Azilroka committed
353 354 355
			_G.GameTimeFrame.DayTimeIndicator = _G.GameTimeFrame:CreateTexture(nil, "BACKGROUND", nil, 1)
			_G.GameTimeFrame.DayTimeIndicator:SetTexture("Interface/Minimap/HumanUITile-TimeIndicator", true)
			PA:SetInside(_G.GameTimeFrame.DayTimeIndicator)
Azilroka's avatar
Azilroka committed
356

Azilroka's avatar
Azilroka committed
357
			_G.GameTimeFrame:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
358

Azilroka's avatar
Azilroka committed
359 360 361 362 363
			_G.GameTimeFrame.timeOfDay = 0
			local function OnUpdate(s, elapsed)
				s.elapsed = (s.elapsed or 1) + elapsed
				if s.elapsed > 1 then
					local hour, minute = _G.GetGameTime()
Azilroka's avatar
Azilroka committed
364
					local time = hour * 60 + minute
Azilroka's avatar
Azilroka committed
365
					if time ~= s.timeOfDay then
Azilroka's avatar
Azilroka committed
366 367 368 369 370 371 372 373
						offset = PX_PER_STEP * floor(time / STEP)

						l = 0.25 + offset -- 64 / 256
						if l >= 1.25 then l = 0.25 end

						r = 0.75 + offset -- 192 / 256
						if r >= 1.75 then r = 0.75 end

Azilroka's avatar
Azilroka committed
374
						s.DayTimeIndicator:SetTexCoord(l, r, 0, 1)
Azilroka's avatar
Azilroka committed
375

Azilroka's avatar
Azilroka committed
376
						s.timeOfDay = time
Azilroka's avatar
Azilroka committed
377 378
					end

Azilroka's avatar
Azilroka committed
379
					s.elapsed = 0
Azilroka's avatar
Azilroka committed
380 381 382
				end
			end

Azilroka's avatar
Azilroka committed
383 384 385
			_G.GameTimeFrame:SetScript("OnUpdate", OnUpdate)
			_G.GameTimeFrame.SMB = true
			tinsert(SMB.Buttons, _G.GameTimeFrame)
Azilroka's avatar
Azilroka committed
386
		end
387
	end
Azilroka's avatar
Azilroka committed
388

Azilroka's avatar
Azilroka committed
389
	SMB:Update()
Azilroka's avatar
Azilroka committed
390 391
end

Azilroka's avatar
Azilroka committed
392
function SMB:SkinMinimapButton(Button)
Azilroka's avatar
Azilroka committed
393
	if (not Button) or Button.isSkinned then return end
Azilroka's avatar
Azilroka committed
394

Azilroka's avatar
Azilroka committed
395
	local Name = Button.GetName and Button:GetName()
Azilroka's avatar
Azilroka committed
396 397
	if not Name then return end

Azilroka's avatar
Azilroka committed
398
	if tContains(SMB.IgnoreButton, Name) then return end
Azilroka's avatar
Azilroka committed
399

Azilroka's avatar
Azilroka committed
400 401
	for i = 1, #SMB.GenericIgnore do
		if strsub(Name, 1, strlen(SMB.GenericIgnore[i])) == SMB.GenericIgnore[i] then return end
Azilroka's avatar
Azilroka committed
402
	end
Azilroka's avatar
Cleanup  
Azilroka committed
403

Azilroka's avatar
Azilroka committed
404
	for i = 1, #SMB.PartialIgnore do
Azilroka's avatar
Azilroka committed
405
		if strmatch(Name, SMB.PartialIgnore[i]) ~= nil then return end
Azilroka's avatar
Azilroka committed
406
	end
Azilroka's avatar
Azilroka committed
407

Azilroka's avatar
Azilroka committed
408 409
	for i = 1, Button:GetNumRegions() do
		local Region = select(i, Button:GetRegions())
Azilroka's avatar
Azilroka committed
410
		if Region.IsObjectType and Region:IsObjectType('Texture') then
Azilroka's avatar
Azilroka committed
411
			local Texture = Region.GetTextureFileID and Region:GetTextureFileID()
Azilroka's avatar
Azilroka committed
412

Azilroka's avatar
Azilroka committed
413
			if RemoveTextureID[Texture] then
Azilroka's avatar
Azilroka committed
414
				Region:SetTexture()
Azilroka's avatar
Azilroka committed
415
			else
Azilroka's avatar
Azilroka committed
416
				Texture = strlower(tostring(Region:GetTexture()))
Azilroka's avatar
Cleanup  
Azilroka committed
417
				if RemoveTextureFile[Texture] or strfind(Texture, 'interface/characterframe') or (strfind(Texture, 'interface/minimap') and not strfind(Texture, 'interface/minimap/tracking')) or strfind(Texture, 'border') or strfind(Texture, 'background') or strfind(Texture, 'alphamask') or strfind(Texture, 'highlight') then
Azilroka's avatar
Azilroka committed
418
					Region:SetTexture()
Azilroka's avatar
Azilroka committed
419 420 421 422 423
					Region:SetAlpha(0)
				else
					if SMB.OverrideTexture[Name] then
						Region:SetTexture(SMB.OverrideTexture[Name])
					end
Azilroka's avatar
Azilroka committed
424

Azilroka's avatar
Azilroka committed
425 426 427
					Region:ClearAllPoints()
					Region:SetDrawLayer('ARTWORK')
					PA:SetInside(Region)
Azilroka's avatar
Azilroka committed
428

Azilroka's avatar
Cleanup  
Azilroka committed
429
					if not SMB.DoNotCrop[Name] and not Button.ignoreCrop then
Azilroka's avatar
Azilroka committed
430 431
						Region:SetTexCoord(unpack(PA.TexCoords))
						Button:HookScript('OnLeave', function() Region:SetTexCoord(unpack(PA.TexCoords)) end)
Azilroka's avatar
Azilroka committed
432
					end
Azilroka's avatar
Azilroka committed
433

Azilroka's avatar
Azilroka committed
434 435
					Region.SetPoint = function() return end
				end
Azilroka's avatar
Azilroka committed
436 437 438 439
			end
		end
	end

Azilroka's avatar
Azilroka committed
440 441
	Button:SetFrameLevel(Minimap:GetFrameLevel() + 10)
	Button:SetFrameStrata(Minimap:GetFrameStrata())
Azilroka's avatar
Azilroka committed
442
	Button:SetSize(SMB.db.IconSize, SMB.db.IconSize)
Azilroka's avatar
Azilroka committed
443

Azilroka's avatar
Azilroka committed
444 445 446 447 448 449
	if not Button.ignoreTemplate then
		PA:SetTemplate(Button)

		if SMB.db.Shadows then
			PA:CreateShadow(Button)
		end
Azilroka's avatar
Azilroka committed
450 451
	end

Azilroka's avatar
Azilroka committed
452 453 454
	--Button:SetScript('OnDragStart', SMB.OnDragStart)
	--Button:SetScript('OnDragStop', SMB.OnDragStop)

Azilroka's avatar
Azilroka committed
455
	Button:HookScript('OnEnter', function()
Azilroka's avatar
1.09  
Azilroka committed
456 457 458 459
		if SMB.Bar:IsShown() then
			UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
		end
	end)
Azilroka's avatar
Azilroka committed
460 461
	Button:HookScript('OnLeave', function(s)
		PA:SetTemplate(s)
Azilroka's avatar
Azilroka committed
462
		if SMB.Bar:IsShown() and SMB.db.BarMouseOver then
Azilroka's avatar
1.09  
Azilroka committed
463 464 465
			UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
		end
	end)
Azilroka's avatar
Azilroka committed
466 467

	Button.isSkinned = true
Azilroka's avatar
Azilroka committed
468
	tinsert(SMB.Buttons, Button)
Azilroka's avatar
Azilroka committed
469 470
end

Azilroka's avatar
Azilroka committed
471
function SMB:GrabMinimapButtons()
Azilroka's avatar
Azilroka committed
472
	if (InCombatLockdown() or C_PetBattles and C_PetBattles.IsInBattle()) then return end
Azilroka's avatar
Azilroka committed
473

Azilroka's avatar
Azilroka committed
474 475 476 477 478 479
	for _, Button in pairs(SMB.UnrulyButtons) do
		if _G[Button] then
			_G[Button]:SetParent(Minimap)
		end
	end

Azilroka's avatar
Azilroka committed
480
	local UpdateBar
Azilroka's avatar
Azilroka committed
481
	for _, Frame in pairs({ Minimap, _G.MinimapBackdrop, _G.MinimapCluster }) do
Azilroka's avatar
Azilroka committed
482
		local NumChildren = Frame:GetNumChildren()
Azilroka's avatar
Azilroka committed
483 484 485 486 487 488 489 490 491
		if NumChildren > (Frame.SMBNumChildren or 0) then
			for i = 1, NumChildren do
				local object = select(i, Frame:GetChildren())
				if object then
					local name = object:GetName()
					local width = object:GetWidth()
					if name and width > 15 and width < 60 and (object:IsObjectType('Button') or object:IsObjectType('Frame')) then
						SMB:SkinMinimapButton(object)
					end
Azilroka's avatar
Azilroka committed
492 493
				end
			end
Azilroka's avatar
Azilroka committed
494

Azilroka's avatar
Azilroka committed
495 496 497
			Frame.SMBNumChildren = NumChildren
			UpdateBar = true
		end
Azilroka's avatar
Azilroka committed
498
	end
Azilroka's avatar
Azilroka committed
499

Azilroka's avatar
Azilroka committed
500 501 502
	if UpdateBar then
		SMB:Update()
	end
Azilroka's avatar
Azilroka committed
503 504
end

Azilroka's avatar
Azilroka committed
505
function SMB:Update()
506
	if not SMB.db.BarEnabled or not SMB.db.Enable then return end
Azilroka's avatar
Azilroka committed
507

Azilroka's avatar
Azilroka committed
508
	local AnchorX, AnchorY = 0, 1
Azilroka's avatar
Azilroka committed
509 510 511
	local ButtonsPerRow = SMB.db.ButtonsPerRow or 12
	local Spacing = SMB.db.ButtonSpacing or 2
	local Size = SMB.db.IconSize or 27
Azilroka's avatar
Azilroka committed
512 513
	local ActualButtons, Maxed = 0

Azilroka's avatar
Azilroka committed
514 515
	local Anchor, DirMult = 'TOPLEFT', 1

Azilroka's avatar
Azilroka committed
516
	if SMB.db.ReverseDirection then
Azilroka's avatar
Azilroka committed
517 518 519
		Anchor, DirMult = 'TOPRIGHT', -1
	end

Azilroka's avatar
Azilroka committed
520 521
	for _, Button in pairs(SMB.Buttons) do
		if Button:IsVisible() then
Azilroka's avatar
Azilroka committed
522 523
			AnchorX, ActualButtons = AnchorX + 1, ActualButtons + 1

Azilroka's avatar
Azilroka committed
524
			if (AnchorX % (ButtonsPerRow + 1)) == 0 then
Azilroka's avatar
Azilroka committed
525
				AnchorY, AnchorX, Maxed = AnchorY + 1, 1, true
Azilroka's avatar
Azilroka committed
526 527
			end

Azilroka's avatar
Azilroka committed
528 529
			SMB:UnlockButton(Button)

Azilroka's avatar
Azilroka committed
530
			PA:SetTemplate(Button)
Azilroka's avatar
Azilroka committed
531

Azilroka's avatar
Azilroka committed
532
			Button:SetParent(SMB.Bar)
Azilroka's avatar
Azilroka committed
533
			Button:ClearAllPoints()
Azilroka's avatar
Azilroka committed
534 535
			Button:SetPoint(Anchor, SMB.Bar, Anchor, DirMult * (Spacing + ((Size + Spacing) * (AnchorX - 1))), (- Spacing - ((Size + Spacing) * (AnchorY - 1))))
			Button:SetSize(Size, Size)
Azilroka's avatar
Azilroka committed
536
			Button:SetScale(1)
Azilroka's avatar
Azilroka committed
537
			Button:SetFrameStrata('MEDIUM')
Azilroka's avatar
Azilroka committed
538
			Button:SetFrameLevel(SMB.Bar:GetFrameLevel() + 1)
Azilroka's avatar
Azilroka committed
539 540
			Button:SetScript('OnDragStart', nil)
			Button:SetScript('OnDragStop', nil)
Azilroka's avatar
Azilroka committed
541
			--Button:SetScript('OnEvent', nil)
Azilroka's avatar
Azilroka committed
542 543

			SMB:LockButton(Button)
Azilroka's avatar
Azilroka committed
544

Azilroka's avatar
Azilroka committed
545 546 547
			if Maxed then ActualButtons = ButtonsPerRow end
		end
	end
Azilroka's avatar
Azilroka committed
548

Azilroka's avatar
Azilroka committed
549 550 551
	local BarWidth = Spacing + (Size * ActualButtons) + (Spacing * (ActualButtons - 1)) + Spacing
	local BarHeight = Spacing + (Size * AnchorY) + (Spacing * (AnchorY - 1)) + Spacing

Azilroka's avatar
Azilroka committed
552
	SMB.Bar:SetSize(BarWidth, BarHeight)
Azilroka's avatar
SMB  
Azilroka committed
553

Azilroka's avatar
Azilroka committed
554 555
	if SMB.db.Backdrop then
		PA:SetTemplate(SMB.Bar)
Azilroka's avatar
Azilroka committed
556
	else
Azilroka's avatar
Azilroka committed
557
		SMB.Bar:SetBackdrop(nil)
Azilroka's avatar
Azilroka committed
558 559
	end

Azilroka's avatar
Azilroka committed
560
	if ActualButtons == 0 then
Azilroka's avatar
Azilroka committed
561
		SMB.Bar:Hide()
Azilroka's avatar
Azilroka committed
562
	else
Azilroka's avatar
Azilroka committed
563
		SMB.Bar:Show()
Azilroka's avatar
Azilroka committed
564
	end
Azilroka's avatar
SMB  
Azilroka committed
565

Azilroka's avatar
Azilroka committed
566 567
	if SMB.db.BarMouseOver then
		UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
Azilroka's avatar
1.09  
Azilroka committed
568
	else
Azilroka's avatar
Azilroka committed
569
		UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
Azilroka's avatar
1.09  
Azilroka committed
570
	end
Azilroka's avatar
Azilroka committed
571 572
end

Azilroka's avatar
Azilroka committed
573
function SMB:GetOptions()
Azilroka's avatar
Azilroka committed
574 575 576 577
	PA.Options.args.SquareMinimapButtons = PA.ACH:Group(SMB.Title, SMB.Description, nil, nil, function(info) return SMB.db[info[#info]] end, function(info, value) SMB.db[info[#info]] = value SMB:Update() end)
	PA.Options.args.SquareMinimapButtons.args.Header = PA.ACH:Header(SMB.Header, 0)
	PA.Options.args.SquareMinimapButtons.args.Enable = PA.ACH:Toggle(PA.ACL['Enable'], nil, 1, nil, nil, nil, nil, function(info, value) SMB.db[info[#info]] = value if (not SMB.isEnabled) then SMB:Initialize() else _G.StaticPopup_Show('PROJECTAZILROKA_RL') end end)
	PA.Options.args.SquareMinimapButtons.args.General = PA.ACH:Group(PA.ACL['General'], nil, 2)
Azilroka's avatar
Azilroka committed
578
	PA.Options.args.SquareMinimapButtons.args.General.inline = true
Azilroka's avatar
Azilroka committed
579 580

	PA.Options.args.SquareMinimapButtons.args.General.args.MBB = PA.ACH:Group(PA.ACL['Minimap Buttons / Bar'], nil, 1)
Azilroka's avatar
Azilroka committed
581
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.inline = true
Azilroka's avatar
Azilroka committed
582 583 584 585 586 587 588 589 590 591
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.BarEnabled = PA.ACH:Toggle(PA.ACL['Enable Bar'], nil, 1)
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.BarMouseOver = PA.ACH:Toggle(PA.ACL['Bar MouseOver'], nil, 2)
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.Backdrop = PA.ACH:Toggle(PA.ACL['Bar Backdrop'], nil, 3)
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.IconSize = PA.ACH:Range(PA.ACL['Icon Size'], nil, 4, { min = 12, max = 48, step = 1 })
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.ButtonSpacing = PA.ACH:Range(PA.ACL['Button Spacing'], nil, 5, { min = 0, max = 10, step = 1 })
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.ButtonsPerRow = PA.ACH:Range(PA.ACL['Buttons Per Row'], nil, 6, { min = 1, max = 100, step = 1 })
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.Shadows = PA.ACH:Toggle(PA.ACL['Shadows'], nil, 7)
	PA.Options.args.SquareMinimapButtons.args.General.args.MBB.args.ReverseDirection = PA.ACH:Toggle(PA.ACL['Reverse Direction'], nil, 8)

	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard = PA.ACH:Group(PA.ACL['Blizzard'], nil, 2, nil, nil, function(info, value) SMB.db[info[#info]] = value SMB:HandleBlizzardButtons() end)
Azilroka's avatar
Azilroka committed
592
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.inline = true
Azilroka's avatar
Azilroka committed
593 594 595 596 597 598 599 600 601
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.HideGarrison = PA.ACH:Toggle(PA.ACL['Hide Garrison'], nil, nil, nil, nil, nil, nil, nil, function() return SMB.db.MoveGarrison end, function() return PA.Classic end)
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.MoveGarrison = PA.ACH:Toggle(PA.ACL['Move Garrison Icon'], nil, nil, nil, nil, nil, nil, nil, function() return SMB.db.HideGarrison end, function() return PA.Classic end)
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.MoveMail = PA.ACH:Toggle(PA.ACL['Move Mail Icon'])
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.MoveGameTimeFrame = PA.ACH:Toggle(PA.ACL['Move Game Time Frame'], nil, nil, nil, nil, nil, nil, nil, nil, function() return PA.Retail end)
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.MoveTracker = PA.ACH:Toggle(PA.ACL['Move Tracker Icon'], nil, nil, nil, nil, nil, nil, nil, nil, function() return PA.Classic end)
	PA.Options.args.SquareMinimapButtons.args.General.args.Blizzard.args.MoveQueue = PA.ACH:Toggle(PA.ACL['Move Queue Status Icon'], nil, nil, nil, nil, nil, nil, nil, nil, function() return PA.Classic end)

	PA.Options.args.SquareMinimapButtons.args.AuthorHeader = PA.ACH:Header(PA.ACL['Authors:'], -2)
	PA.Options.args.SquareMinimapButtons.args.Authors = PA.ACH:Description(SMB.Authors, -1, 'large')
Azilroka's avatar
Update  
Azilroka committed
602
end
Azilroka's avatar
Azilroka committed
603

Azilroka's avatar
Azilroka committed
604
function SMB:BuildProfile()
Azilroka's avatar
Azilroka committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
	PA.Defaults.profile.SquareMinimapButtons = {
		Enable = true,
		BarMouseOver = false,
		BarEnabled = true,
		Backdrop = true,
		IconSize = 20,
		ButtonsPerRow = 12,
		ButtonSpacing = 2,
		HideGarrison = false,
		MoveGarrison = true,
		MoveMail = true,
		MoveTracker = true,
		MoveQueue = true,
		MoveGameTimeFrame = true,
		Shadows = true,
		ReverseDirection = false,
Azilroka's avatar
Azilroka committed
621
	}
Azilroka's avatar
Azilroka committed
622
end
Azilroka's avatar
Update  
Azilroka committed
623

Azilroka's avatar
Azilroka committed
624
function SMB:UpdateSettings()
Azilroka's avatar
Azilroka committed
625
	SMB.db = PA.db.SquareMinimapButtons
Azilroka's avatar
Azilroka committed
626 627 628 629
end

function SMB:Initialize()
	SMB:UpdateSettings()
Azilroka's avatar
Azilroka committed
630 631 632 633 634

	if SMB.db.Enable ~= true then
		return
	end

Azilroka's avatar
Azilroka committed
635 636
	SMB.isEnabled = true

Azilroka's avatar
Azilroka committed
637
	SMB.Hider = CreateFrame("Frame", nil, _G.UIParent)
Azilroka's avatar
Azilroka committed
638

Azilroka's avatar
Azilroka committed
639
	SMB.Bar = CreateFrame('Frame', 'SquareMinimapButtonBar', _G.UIParent)
Azilroka's avatar
Azilroka committed
640
	SMB.Bar:Hide()
Azilroka's avatar
Azilroka committed
641
	SMB.Bar:SetPoint('RIGHT', _G.UIParent, 'RIGHT', -45, 0)
Azilroka's avatar
Azilroka committed
642 643
	SMB.Bar:SetFrameStrata('MEDIUM')
	SMB.Bar:SetFrameLevel(1)
Azilroka's avatar
Azilroka committed
644 645 646 647
	SMB.Bar:SetClampedToScreen(true)
	SMB.Bar:SetMovable(true)
	SMB.Bar:EnableMouse(true)
	SMB.Bar:SetSize(SMB.db.IconSize, SMB.db.IconSize)
Azilroka's avatar
Azilroka committed
648
	PA:SetTemplate(SMB.Bar)
Azilroka's avatar
Azilroka committed
649

Azilroka's avatar
Azilroka committed
650 651 652 653
	SMB.Bar:SetScript('OnEnter', function(s) UIFrameFadeIn(s, 0.2, s:GetAlpha(), 1) end)
	SMB.Bar:SetScript('OnLeave', function(s)
		if SMB.db.BarMouseOver then
			UIFrameFadeOut(s, 0.2, s:GetAlpha(), 0)
Azilroka's avatar
Update  
Azilroka committed
654 655 656
		end
	end)

Azilroka's avatar
1.16  
Azilroka committed
657
	if PA.Tukui then
Azilroka's avatar
Azilroka committed
658
		_G.Tukui[1]['Movers']:RegisterFrame(SMB.Bar)
Azilroka's avatar
1.16  
Azilroka committed
659
	elseif PA.ElvUI then
Azilroka's avatar
Azilroka committed
660
		_G.ElvUI[1]:CreateMover(SMB.Bar, 'SquareMinimapButtonBarMover', 'SquareMinimapButtonBar Anchor', nil, nil, nil, 'ALL,GENERAL')
Azilroka's avatar
Update  
Azilroka committed
661 662
	end

Azilroka's avatar
1.25  
Azilroka committed
663 664
	SMB:ScheduleRepeatingTimer('GrabMinimapButtons', 6)
	SMB:ScheduleTimer('HandleBlizzardButtons', 7)
Merathilis's avatar
Merathilis committed
665
end