SquareMinimapButtons.lua 16.9 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

5
SMB.Title = '|cFF16C3F2Square|r |cFFFFFFFFMinimap Buttons|r'
6
SMB.Description = 'Minimap Button Bar / Minimap Button Skinning'
Azilroka's avatar
Azilroka committed
7
SMB.Authors = 'Azilroka    Whiro    Sinaris    Omega    Durc'
Azilroka's avatar
Azilroka committed
8

Azilroka's avatar
Azilroka committed
9
local strsub, strlen, strfind, ceil = strsub, strlen, strfind, ceil
Azilroka's avatar
Azilroka committed
10
local tinsert, pairs, unpack, select, tContains = tinsert, pairs, unpack, select, tContains
Azilroka's avatar
Azilroka committed
11
local InCombatLockdown, C_PetBattles = InCombatLockdown, C_PetBattles
Azilroka's avatar
Azilroka committed
12
local Minimap = Minimap
Azilroka's avatar
Azilroka committed
13

14
SMB.Buttons = {}
Azilroka's avatar
Azilroka committed
15 16 17

local ignoreButtons = {
	'GameTimeFrame',
18
	'HelpOpenWebTicketButton',
Azilroka's avatar
Azilroka committed
19 20
	'MiniMapVoiceChatFrame',
	'TimeManagerClockButton',
Azilroka's avatar
Azilroka committed
21 22 23 24
	'BattlefieldMinimap',
	'ButtonCollectFrame',
	'GameTimeFrame',
	'QueueStatusMinimapButton',
25 26 27
	'GarrisonLandingPageMinimapButton',
	'MiniMapMailFrame',
	'MiniMapTracking',
Azilroka's avatar
Azilroka committed
28 29
	'MinimapZoomIn',
	'MinimapZoomOut',
Azilroka's avatar
Azilroka committed
30 31
	'TukuiMinimapZone',
	'TukuiMinimapCoord',
Azilroka's avatar
Azilroka committed
32 33 34 35 36 37 38 39
}

local GenericIgnores = {
	'Archy',
	'GatherMatePin',
	'GatherNote',
	'GuildInstance',
	'HandyNotesPin',
Azilroka's avatar
Azilroka committed
40
	'MiniMap',
Azilroka's avatar
Azilroka committed
41 42 43
	'Spy_MapNoteList_mini',
	'ZGVMarker',
	'poiMinimap',
Azilroka's avatar
Azilroka committed
44 45 46 47
	'GuildMap3Mini',
	'LibRockConfig-1.0_MinimapButton',
	'NauticusMiniIcon',
	'WestPointer',
48
	'Cork',
Azilroka's avatar
1.21  
Azilroka committed
49
	'DugisArrowMinimapPoint',
Azilroka's avatar
Azilroka committed
50 51
}

Azilroka's avatar
Azilroka committed
52
local PartialIgnores = { 'Node', 'Note', 'Pin', 'POI' }
Azilroka's avatar
Azilroka committed
53

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

Azilroka's avatar
Azilroka committed
56
function SMB:LockButton(Button)
Azilroka's avatar
Azilroka committed
57 58 59
	for _, Function in pairs(ButtonFunctions) do
		Button[Function] = PA.Noop
	end
Azilroka's avatar
Azilroka committed
60 61 62
end

function SMB:UnlockButton(Button)
Azilroka's avatar
Azilroka committed
63 64 65
	for _, Function in pairs(ButtonFunctions) do
		Button[Function] = nil
	end
Azilroka's avatar
Azilroka committed
66 67
end

Azilroka's avatar
Azilroka committed
68
function SMB:HandleBlizzardButtons()
Azilroka's avatar
Azilroka committed
69 70 71 72 73
	if not self.db['BarEnabled'] then return end

	if self.db['HideGarrison'] then
		GarrisonLandingPageMinimapButton:UnregisterAllEvents()
		GarrisonLandingPageMinimapButton:SetParent(self.Hider)
74
		GarrisonLandingPageMinimapButton:Hide()
Azilroka's avatar
Azilroka committed
75 76
	elseif self.db["MoveGarrison"] and not GarrisonLandingPageMinimapButton.SMB then
		GarrisonLandingPageMinimapButton:SetParent(Minimap)
Azilroka's avatar
Azilroka committed
77 78
		GarrisonLandingPageMinimapButton_OnLoad(GarrisonLandingPageMinimapButton)
		GarrisonLandingPageMinimapButton_UpdateIcon(GarrisonLandingPageMinimapButton)
Azilroka's avatar
Azilroka committed
79
		GarrisonLandingPageMinimapButton:Show()
Azilroka's avatar
Azilroka committed
80
		GarrisonLandingPageMinimapButton:SetScale(1)
Azilroka's avatar
Azilroka committed
81
		GarrisonLandingPageMinimapButton:SetHitRectInsets(0, 0, 0, 0)
Azilroka's avatar
Azilroka committed
82
		GarrisonLandingPageMinimapButton:SetScript('OnEnter', function(self)
Azilroka's avatar
Azilroka committed
83
			self:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
84 85 86 87
			if SMB.Bar:IsShown() then
				UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
			end
		end)
Azilroka's avatar
Azilroka committed
88
		GarrisonLandingPageMinimapButton:SetScript('OnLeave', function(self)
89
			PA:SetTemplate(self)
Azilroka's avatar
Azilroka committed
90 91 92 93 94
			if SMB.Bar:IsShown() and SMB.db['BarMouseOver'] then
				UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
			end
		end)

Azilroka's avatar
Azilroka committed
95
		GarrisonLandingPageMinimapButton.SMB = true
Azilroka's avatar
Azilroka committed
96 97 98 99 100

		if SMB.db.Shadows then
			PA:CreateShadow(GarrisonLandingPageMinimapButton)
		end

Azilroka's avatar
Azilroka committed
101
		tinsert(self.Buttons, GarrisonLandingPageMinimapButton)
102 103
	end

Azilroka's avatar
Azilroka committed
104
	if self.db["MoveMail"] and not MiniMapMailFrame.SMB then
Azilroka's avatar
Azilroka committed
105 106
		local Frame = CreateFrame('Frame', 'SMB_MailFrame', self.Bar)
		Frame:SetSize(SMB.db['IconSize'], SMB.db['IconSize'])
Azilroka's avatar
Azilroka committed
107
		PA:SetTemplate(Frame)
Azilroka's avatar
Azilroka committed
108 109
		Frame.Icon = Frame:CreateTexture(nil, 'ARTWORK')
		Frame.Icon:SetPoint('CENTER')
Azilroka's avatar
Azilroka committed
110
		Frame.Icon:SetSize(18, 18)
Azilroka's avatar
Azilroka committed
111 112 113 114
		Frame.Icon:SetTexture(MiniMapMailIcon:GetTexture())
		Frame:EnableMouse(true)
		Frame:HookScript('OnEnter', function(self)
			if HasNewMail() then
Azilroka's avatar
Azilroka committed
115
				GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
Azilroka's avatar
Azilroka committed
116 117 118 119
				if GameTooltip:IsOwned(self) then
					MinimapMailFrameUpdate()
				end
			end
Azilroka's avatar
Azilroka committed
120
			self:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
121 122 123 124 125 126
			if SMB.Bar:IsShown() then
				UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
			end
		end)
		Frame:HookScript('OnLeave', function(self)
			GameTooltip:Hide()
Azilroka's avatar
Azilroka committed
127
			PA:SetTemplate(self)
Azilroka's avatar
Azilroka committed
128 129 130 131
			if SMB.Bar:IsShown() and SMB.db['BarMouseOver'] then
				UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
			end
		end)
Azilroka's avatar
Azilroka committed
132

Azilroka's avatar
Azilroka committed
133 134 135
		MiniMapMailFrame:HookScript('OnShow', function() Frame.Icon:SetVertexColor(0, 1, 0)	end)
		MiniMapMailFrame:HookScript('OnHide', function() Frame.Icon:SetVertexColor(1, 1, 1) end)

Azilroka's avatar
Azilroka committed
136 137 138 139
		if MiniMapMailFrame:IsShown() then
			Frame.Icon:SetVertexColor(0, 1, 0)
		end

Azilroka's avatar
Azilroka committed
140
		-- Hide Icon & Border
141
		MiniMapMailIcon:Hide()
Azilroka's avatar
Azilroka committed
142
		MiniMapMailBorder:Hide()
143

Azilroka's avatar
Azilroka committed
144 145 146 147
		if SMB.db.Shadows then
			PA:CreateShadow(Frame)
		end

Azilroka's avatar
Azilroka committed
148
		MiniMapMailFrame.SMB = true
Azilroka's avatar
Azilroka committed
149
		tinsert(self.Buttons, Frame)
150 151
	end

Azilroka's avatar
Azilroka committed
152
	if self.db["MoveTracker"] and not MiniMapTrackingButton.SMB then
Azilroka's avatar
Azilroka committed
153 154 155 156 157 158 159 160 161 162
		MiniMapTracking.Show = nil

		MiniMapTracking:Show()

		MiniMapTracking:SetParent(self.Bar)
		MiniMapTracking:SetSize(self.db['IconSize'], self.db['IconSize'])

		MiniMapTrackingIcon:ClearAllPoints()
		MiniMapTrackingIcon:SetPoint('CENTER')

Azilroka's avatar
Azilroka committed
163 164 165
		MiniMapTrackingBackground:SetAlpha(0)
		MiniMapTrackingIconOverlay:SetAlpha(0)
		MiniMapTrackingButton:SetAlpha(0)
166

Azilroka's avatar
Azilroka committed
167 168 169
		MiniMapTrackingButton:SetParent(MinimapTracking)
		MiniMapTrackingButton:ClearAllPoints()
		MiniMapTrackingButton:SetAllPoints(MiniMapTracking)
170

Azilroka's avatar
Azilroka committed
171 172 173 174
		MiniMapTrackingButton:SetScript('OnMouseDown', nil)
		MiniMapTrackingButton:SetScript('OnMouseUp', nil)

		MiniMapTrackingButton:HookScript('OnEnter', function(self)
Azilroka's avatar
Azilroka committed
175
			MiniMapTracking:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
176 177 178 179 180
			if SMB.Bar:IsShown() then
				UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
			end
		end)
		MiniMapTrackingButton:HookScript('OnLeave', function(self)
Azilroka's avatar
Azilroka committed
181
			PA:SetTemplate(MiniMapTracking)
Azilroka's avatar
Azilroka committed
182 183 184 185 186
			if SMB.Bar:IsShown() and SMB.db['BarMouseOver'] then
				UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
			end
		end)

Azilroka's avatar
Azilroka committed
187
		MiniMapTrackingButton.SMB = true
Azilroka's avatar
Azilroka committed
188 189 190 191 192

		if SMB.db.Shadows then
			PA:CreateShadow(MiniMapTracking)
		end

Azilroka's avatar
Azilroka committed
193
		tinsert(self.Buttons, MiniMapTracking)
194 195
	end

Azilroka's avatar
Azilroka committed
196
	if self.db["MoveQueue"] and not QueueStatusMinimapButton.SMB then
Azilroka's avatar
Azilroka committed
197
		local Frame = CreateFrame('Frame', 'SMB_QueueFrame', self.Bar)
Azilroka's avatar
Azilroka committed
198
		PA:SetTemplate(Frame)
Azilroka's avatar
Azilroka committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
		Frame:SetSize(SMB.db['IconSize'], SMB.db['IconSize'])
		Frame.Icon = Frame:CreateTexture(nil, 'ARTWORK')
		Frame.Icon:SetSize(SMB.db['IconSize'], SMB.db['IconSize'])
		Frame.Icon:SetPoint('CENTER')
		Frame.Icon:SetTexture([[Interface\LFGFrame\LFG-Eye]])
		Frame.Icon:SetTexCoord(0, 64 / 512, 0, 64 / 256)
		Frame:SetScript('OnMouseDown', function()
			if PVEFrame:IsShown() then
				HideUIPanel(PVEFrame)
			else
				ShowUIPanel(PVEFrame)
				GroupFinderFrame_ShowGroupFrame()
			end
		end)
		Frame:HookScript('OnEnter', function(self)
Azilroka's avatar
Azilroka committed
214
			self:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
Azilroka committed
215 216 217 218 219
			if SMB.Bar:IsShown() then
				UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
			end
		end)
		Frame:HookScript('OnLeave', function(self)
Azilroka's avatar
Azilroka committed
220
			PA:SetTemplate(self)
Azilroka's avatar
Azilroka committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
			if SMB.Bar:IsShown() and SMB.db['BarMouseOver'] then
				UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
			end
		end)

		QueueStatusMinimapButton:SetParent(self.Bar)
		QueueStatusMinimapButton:SetFrameLevel(Frame:GetFrameLevel() + 2)
		QueueStatusMinimapButton:ClearAllPoints()
		QueueStatusMinimapButton:SetPoint("CENTER", Frame, "CENTER", 0, 0)

		QueueStatusMinimapButton:SetHighlightTexture(nil)

		QueueStatusMinimapButton:HookScript('OnShow', function(self)
			Frame:EnableMouse(false)
		end)
		QueueStatusMinimapButton:HookScript('PostClick', QueueStatusMinimapButton_OnLeave)
		QueueStatusMinimapButton:HookScript('OnHide', function(self)
			Frame:EnableMouse(true)
		end)

Azilroka's avatar
Azilroka committed
241
		QueueStatusMinimapButton.SMB = true
Azilroka's avatar
Azilroka committed
242 243 244 245 246

		if SMB.db.Shadows then
			PA:CreateShadow(Frame)
		end

Azilroka's avatar
Azilroka committed
247
		tinsert(self.Buttons, Frame)
248
	end
Azilroka's avatar
Azilroka committed
249 250

	self:Update()
Azilroka's avatar
Azilroka committed
251 252
end

Azilroka's avatar
Azilroka committed
253
function SMB:SkinMinimapButton(Button)
Azilroka's avatar
Azilroka committed
254
	if (not Button) or Button.isSkinned then return end
Azilroka's avatar
Azilroka committed
255 256 257 258

	local Name = Button:GetName()
	if not Name then return end

Azilroka's avatar
Azilroka committed
259
	if tContains(ignoreButtons, Name) then return end
Azilroka's avatar
Azilroka committed
260

Azilroka's avatar
Azilroka committed
261 262 263
	for i = 1, #GenericIgnores do
		if strsub(Name, 1, strlen(GenericIgnores[i])) == GenericIgnores[i] then return end
	end
Azilroka's avatar
Cleanup  
Azilroka committed
264

Azilroka's avatar
Azilroka committed
265 266
	for i = 1, #PartialIgnores do
		if strfind(Name, PartialIgnores[i]) ~= nil then return end
Azilroka's avatar
Azilroka committed
267
	end
Azilroka's avatar
Azilroka committed
268

Azilroka's avatar
Azilroka committed
269 270
	for i = 1, Button:GetNumRegions() do
		local Region = select(i, Button:GetRegions())
Azilroka's avatar
Azilroka committed
271
		if Region.IsObjectType and Region:IsObjectType('Texture') then
Azilroka's avatar
Azilroka committed
272
			local Texture = strlower(tostring(Region:GetTexture()))
Azilroka's avatar
Azilroka committed
273

Azilroka's avatar
1.34  
Azilroka committed
274
			if (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
275 276 277 278
				Region:SetTexture(nil)
				Region:SetAlpha(0)
			else
				if Name == 'BagSync_MinimapButton' then
Azilroka's avatar
1.34  
Azilroka committed
279
					Region:SetTexture([[Interface\AddOns\BagSync\media\icon]])
Azilroka's avatar
Azilroka committed
280
				elseif Name == 'DBMMinimapButton' then
Azilroka's avatar
1.34  
Azilroka committed
281
					Region:SetTexture([[Interface\Icons\INV_Helmet_87]])
Azilroka's avatar
Azilroka committed
282
				elseif Name == 'OutfitterMinimapButton' then
Azilroka's avatar
1.34  
Azilroka committed
283
					if Texture == [[interface\addons\outfitter\textures\minimapbutton]] then
Azilroka's avatar
Azilroka committed
284
						Region:SetTexture(nil)
Azilroka's avatar
Azilroka committed
285
					end
Azilroka's avatar
Azilroka committed
286
				elseif Name == 'SmartBuff_MiniMapButton' then
Azilroka's avatar
1.34  
Azilroka committed
287
					Region:SetTexture([[Interface\Icons\Spell_Nature_Purge]])
Azilroka's avatar
Azilroka committed
288
				elseif Name == 'VendomaticButtonFrame' then
Azilroka's avatar
1.34  
Azilroka committed
289
					Region:SetTexture([[Interface\Icons\INV_Misc_Rabbit_2]])
Azilroka's avatar
Azilroka committed
290
				end
Azilroka's avatar
Azilroka committed
291
				Region:ClearAllPoints()
Azilroka's avatar
Azilroka committed
292
				PA:SetInside(Region)
Azilroka's avatar
Azilroka committed
293 294 295 296
				Region:SetTexCoord(unpack(self.TexCoords))
				Button:HookScript('OnLeave', function() Region:SetTexCoord(unpack(self.TexCoords)) end)
				Region:SetDrawLayer('ARTWORK')
				Region.SetPoint = function() return end
Azilroka's avatar
Azilroka committed
297 298 299 300 301
			end
		end
	end

	Button:SetFrameLevel(Minimap:GetFrameLevel() + 5)
Azilroka's avatar
Azilroka committed
302
	Button:SetSize(SMB.db['IconSize'], SMB.db['IconSize'])
Azilroka's avatar
Azilroka committed
303
	PA:SetTemplate(Button)
Azilroka's avatar
Azilroka committed
304 305 306 307 308

	if SMB.db.Shadows then
		PA:CreateShadow(Button)
	end

Azilroka's avatar
1.09  
Azilroka committed
309
	Button:HookScript('OnEnter', function(self)
Azilroka's avatar
Azilroka committed
310
		self:SetBackdropBorderColor(unpack(PA.ClassColor))
Azilroka's avatar
1.09  
Azilroka committed
311 312 313 314 315
		if SMB.Bar:IsShown() then
			UIFrameFadeIn(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 1)
		end
	end)
	Button:HookScript('OnLeave', function(self)
Azilroka's avatar
Azilroka committed
316
		PA:SetTemplate(self)
Azilroka's avatar
1.09  
Azilroka committed
317 318 319 320
		if SMB.Bar:IsShown() and SMB.db['BarMouseOver'] then
			UIFrameFadeOut(SMB.Bar, 0.2, SMB.Bar:GetAlpha(), 0)
		end
	end)
Azilroka's avatar
Azilroka committed
321 322

	Button.isSkinned = true
323
	tinsert(self.Buttons, Button)
Azilroka's avatar
Azilroka committed
324 325
end

Azilroka's avatar
Azilroka committed
326
function SMB:GrabMinimapButtons()
Azilroka's avatar
Azilroka committed
327
	if (InCombatLockdown() or C_PetBattles.IsInBattle()) then return end
Azilroka's avatar
Azilroka committed
328

329
	for _, Frame in pairs({ Minimap, MinimapBackdrop }) do
Azilroka's avatar
Azilroka committed
330 331 332
		local NumChildren = Frame:GetNumChildren()
		if NumChildren < (Frame.SMBNumChildren or 0) then return end
		for i = 1, NumChildren do
333 334 335
			local object = select(i, Frame:GetChildren())
			if object then
				local name = object:GetName()
Azilroka's avatar
Azilroka committed
336
				local width = object:GetWidth()
Azilroka's avatar
Azilroka committed
337
				if name and width > 15 and width < 40 and (object:IsObjectType('Button') or object:IsObjectType('Frame')) then
Azilroka's avatar
Azilroka committed
338 339 340 341
					self:SkinMinimapButton(object)
				end
			end
		end
Azilroka's avatar
Azilroka committed
342
		Frame.SMBNumChildren = NumChildren
Azilroka's avatar
Azilroka committed
343
	end
Azilroka's avatar
Azilroka committed
344 345

	self:Update()
Azilroka's avatar
Azilroka committed
346 347
end

Azilroka's avatar
Azilroka committed
348 349
function SMB:Update()
	if not SMB.db['BarEnabled'] then return end
Azilroka's avatar
Azilroka committed
350

Azilroka's avatar
Azilroka committed
351
	local AnchorX, AnchorY = 0, 1
Azilroka's avatar
Azilroka committed
352
	local ButtonsPerRow = SMB.db['ButtonsPerRow'] or 12
Azilroka's avatar
Azilroka committed
353
	local Spacing, Mult = SMB.db['ButtonSpacing'] or 2, PA.Multiple
Azilroka's avatar
Azilroka committed
354
	local Size = SMB.db['IconSize'] or 27
Azilroka's avatar
Azilroka committed
355 356
	local ActualButtons, Maxed = 0

Azilroka's avatar
Azilroka committed
357 358
	for _, Button in pairs(SMB.Buttons) do
		if Button:IsVisible() then
Azilroka's avatar
Azilroka committed
359 360
			AnchorX = AnchorX + 1
			ActualButtons = ActualButtons + 1
Azilroka's avatar
Azilroka committed
361
			if (AnchorX % (ButtonsPerRow + 1)) == 0 then
Azilroka's avatar
Azilroka committed
362 363 364 365 366
				AnchorY = AnchorY + 1
				AnchorX = 1
				Maxed = true
			end

Azilroka's avatar
Azilroka committed
367 368
			SMB:UnlockButton(Button)

Azilroka's avatar
Azilroka committed
369
			PA:SetTemplate(Button)
Azilroka's avatar
Azilroka committed
370 371 372 373 374 375 376 377 378
			Button:SetParent(self.Bar)
			Button:ClearAllPoints()
			Button:SetPoint('TOPLEFT', self.Bar, 'TOPLEFT', (Spacing + ((Size + Spacing) * (AnchorX - 1))), (- Spacing - ((Size + Spacing) * (AnchorY - 1))))
			Button:SetSize(SMB.db['IconSize'], SMB.db['IconSize'])
			Button:SetScale(1)
			Button:SetFrameStrata('LOW')
			Button:SetFrameLevel(self.Bar:GetFrameLevel() + 1)
			Button:SetScript('OnDragStart', nil)
			Button:SetScript('OnDragStop', nil)
Azilroka's avatar
Azilroka committed
379
			--Button:SetScript('OnEvent', nil)
Azilroka's avatar
Azilroka committed
380 381

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

Azilroka's avatar
Azilroka committed
383 384 385
			if Maxed then ActualButtons = ButtonsPerRow end
		end
	end
Azilroka's avatar
Azilroka committed
386

Azilroka's avatar
SMB  
Azilroka committed
387 388 389 390
	local BarWidth = (Spacing + ((Size * (ActualButtons * Mult)) + ((Spacing * (ActualButtons - 1)) * Mult) + (Spacing * Mult)))
	local BarHeight = (Spacing + ((Size * (AnchorY * Mult)) + ((Spacing * (AnchorY - 1)) * Mult) + (Spacing * Mult)))
	self.Bar:SetSize(BarWidth, BarHeight)

Azilroka's avatar
Azilroka committed
391
	if self.db.Backdrop then
Azilroka's avatar
Azilroka committed
392
		PA:SetTemplate(self.Bar)
Azilroka's avatar
Azilroka committed
393 394 395 396
	else
		self.Bar:SetBackdrop(nil)
	end

Azilroka's avatar
Azilroka committed
397 398 399 400 401
	if ActualButtons == 0 then
		self.Bar:Hide()
	else
		self.Bar:Show()
	end
Azilroka's avatar
SMB  
Azilroka committed
402

Azilroka's avatar
1.09  
Azilroka committed
403 404 405 406 407
	if self.db['BarMouseOver'] then
		UIFrameFadeOut(self.Bar, 0.2, self.Bar:GetAlpha(), 0)
	else
		UIFrameFadeIn(self.Bar, 0.2, self.Bar:GetAlpha(), 1)
	end
Azilroka's avatar
Azilroka committed
408 409
end

Azilroka's avatar
Azilroka committed
410 411 412
function SMB:GetOptions()
	local Options = {
		type = 'group',
413
		name = SMB.Title,
414 415 416
		desc = SMB.Description,
		get = function(info) return SMB.db[info[#info]] end,
		set = function(info, value) SMB.db[info[#info]] = value SMB:Update() end,
Azilroka's avatar
Azilroka committed
417
		args = {
418
			Header = {
Azilroka's avatar
1.22  
Azilroka committed
419
				order = 1,
420 421 422
				type = 'header',
				name = PA:Color(SMB.Title),
			},
Azilroka's avatar
Azilroka committed
423
			mbb = {
Azilroka's avatar
1.22  
Azilroka committed
424
				order = 2,
Azilroka's avatar
Azilroka committed
425
				type = 'group',
426
				name = PA.ACL['Minimap Buttons / Bar'],
Azilroka's avatar
Azilroka committed
427 428 429 430 431
				guiInline = true,
				args = {
					BarEnabled = {
						order = 1,
						type = 'toggle',
432
						name = PA.ACL['Enable Bar'],
Azilroka's avatar
Azilroka committed
433 434 435 436
					},
					BarMouseOver = {
						order = 2,
						type = 'toggle',
437
						name = PA.ACL['Bar MouseOver'],
Azilroka's avatar
Azilroka committed
438
					},
Azilroka's avatar
Azilroka committed
439 440 441 442 443
					Backdrop = {
						order = 3,
						type = 'toggle',
						name = PA.ACL['Bar Backdrop'],
					},
Azilroka's avatar
Azilroka committed
444 445 446
					IconSize = {
						order = 4,
						type = 'range',
447
						name = PA.ACL['Icon Size'],
Azilroka's avatar
Azilroka committed
448 449 450
						min = 12, max = 48, step = 1,
					},
					ButtonSpacing = {
Azilroka's avatar
Cleanup  
Azilroka committed
451 452
						order = 5,
						type = 'range',
453
						name = PA.ACL['Button Spacing'],
Azilroka's avatar
Azilroka committed
454 455 456 457 458
						min = 0, max = 10, step = 1,
					},
					ButtonsPerRow = {
						order = 6,
						type = 'range',
459
						name = PA.ACL['Buttons Per Row'],
Azilroka's avatar
Azilroka committed
460
						min = 1, max = 100, step = 1,
Azilroka's avatar
Cleanup  
Azilroka committed
461
					},
Azilroka's avatar
Azilroka committed
462 463 464 465 466
					Shadows = {
						order = 3,
						type = 'toggle',
						name = PA.ACL['Shadows'],
					},
Azilroka's avatar
Cleanup  
Azilroka committed
467
				},
Azilroka's avatar
Azilroka committed
468
			},
469
			blizzard = {
470 471
				type = 'group',
				name = PA.ACL['Blizzard'],
472
				guiInline = true,
473
				set = function(info, value) SMB.db[info[#info]] = value SMB:Update() SMB:HandleBlizzardButtons() end,
Azilroka's avatar
Update  
Azilroka committed
474
				order = 2,
475 476
				args = {
					HideGarrison  = {
477 478
						type = 'toggle',
						name = PA.ACL['Hide Garrison'],
479
						order = 1,
480
						disabled = function() return SMB.db.MoveGarrison end,
481 482
					},
					MoveGarrison  = {
483 484
						type = 'toggle',
						name = PA.ACL['Move Garrison Icon'],
485
						order = 2,
486
						disabled = function() return SMB.db.HideGarrison end,
487 488
					},
					MoveMail  = {
489 490
						type = 'toggle',
						name = PA.ACL['Move Mail Icon'],
491 492 493
						order = 3,
					},
					MoveTracker  = {
494 495
						type = 'toggle',
						name = PA.ACL['Move Tracker Icon'],
496 497 498
						order = 3,
					},
					MoveQueue  = {
499 500
						type = 'toggle',
						name = PA.ACL['Move Queue Status Icon'],
501 502 503 504 505 506
						order = 3,
					},
				},
			},
			AuthorHeader = {
				order = 3,
Azilroka's avatar
Update  
Azilroka committed
507
				type = 'header',
508
				name = PA.ACL['Authors:'],
Azilroka's avatar
Update  
Azilroka committed
509 510
			},
			Authors = {
511
				order = 4,
Azilroka's avatar
Update  
Azilroka committed
512 513 514
				type = 'description',
				name = SMB.Authors,
				fontSize = 'large',
Azilroka's avatar
Azilroka committed
515 516 517 518
			},
		},
	}

Azilroka's avatar
Azilroka committed
519
	PA.Options.args.SquareMinimapButton = Options
Azilroka's avatar
Update  
Azilroka committed
520
end
Azilroka's avatar
Azilroka committed
521

Azilroka's avatar
Azilroka committed
522
function SMB:BuildProfile()
Azilroka's avatar
Azilroka committed
523 524 525 526 527 528 529 530 531 532 533 534 535
	PA.Defaults.profile['SquareMinimapButtons'] = {
		['Enable'] = true,
		['BarMouseOver'] = false,
		['BarEnabled'] = false,
		['Backdrop'] = false,
		['IconSize'] = 27,
		['ButtonsPerRow'] = 12,
		['ButtonSpacing'] = 2,
		['HideGarrison'] = false,
		['MoveGarrison'] = true,
		['MoveMail'] = true,
		['MoveTracker'] = true,
		['MoveQueue'] = true,
Azilroka's avatar
Azilroka committed
536
		['Shadows'] = true,
Azilroka's avatar
Azilroka committed
537
	}
Azilroka's avatar
Azilroka committed
538 539 540 541 542 543

	PA.Options.args.general.args.SquareMinimapButtons = {
		type = 'toggle',
		name = SMB.Title,
		desc = SMB.Description,
	}
Azilroka's avatar
Azilroka committed
544
end
Azilroka's avatar
Update  
Azilroka committed
545

Azilroka's avatar
Azilroka committed
546
function SMB:Initialize()
Azilroka's avatar
Azilroka committed
547 548 549 550 551 552
	SMB.db = PA.db['SquareMinimapButtons']

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

Azilroka's avatar
Azilroka committed
553 554
	if PA.ElvUI and PA.SLE then
		if ElvUI[1].private.sle.minimap.mapicons.enable then
Azilroka's avatar
Azilroka committed
555 556 557 558 559 560
			StaticPopupDialogs["PROJECTAZILROKA"].text = 'Square Minimap Buttons and S&L MiniMap Buttons are incompatible. You will have to choose one. This will reload the interface.'
			StaticPopupDialogs["PROJECTAZILROKA"].button1 = 'Square Minimap Buttons'
			StaticPopupDialogs["PROJECTAZILROKA"].button2 = 'S&L MiniMap Buttons'
			StaticPopupDialogs["PROJECTAZILROKA"].OnAccept = function() ElvUI[1].private.sle.minimap.mapicons.enable = false ReloadUI() end
			StaticPopupDialogs["PROJECTAZILROKA"].OnCancel = function() PA.db['SquareMinimapButtons']['Enable'] = false ReloadUI() end
			StaticPopup_Show("PROJECTAZILROKA")
Azilroka's avatar
Azilroka committed
561 562 563 564
			return
		end
	end

Azilroka's avatar
Azilroka committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
	SMB:GetOptions()

	SMB.Hider = CreateFrame("Frame", nil, UIParent)

	SMB.Bar = CreateFrame('Frame', 'SquareMinimapButtonBar', UIParent)
	SMB.Bar:Hide()
	SMB.Bar:SetPoint('RIGHT', UIParent, 'RIGHT', -45, 0)
	SMB.Bar:SetFrameStrata('LOW')
	SMB.Bar:SetClampedToScreen(true)
	SMB.Bar:SetMovable(true)
	SMB.Bar:EnableMouse(true)
	SMB.Bar:SetSize(SMB.db.IconSize, SMB.db.IconSize)

	SMB.Bar:SetScript('OnEnter', function(self) UIFrameFadeIn(self, 0.2, self:GetAlpha(), 1) end)
	SMB.Bar:SetScript('OnLeave', function(self)
Azilroka's avatar
Update  
Azilroka committed
580 581 582 583 584
		if SMB.db['BarMouseOver'] then
			UIFrameFadeOut(self, 0.2, self:GetAlpha(), 0)
		end
	end)

Azilroka's avatar
1.16  
Azilroka committed
585
	if PA.Tukui then
Azilroka's avatar
Azilroka committed
586
		Tukui[1]['Movers']:RegisterFrame(SMB.Bar)
Azilroka's avatar
1.16  
Azilroka committed
587
	elseif PA.ElvUI then
Azilroka's avatar
Azilroka committed
588
		ElvUI[1]:CreateMover(SMB.Bar, 'SquareMinimapButtonBarMover', 'SquareMinimapButtonBar Anchor', nil, nil, nil, 'ALL,GENERAL')
Azilroka's avatar
Update  
Azilroka committed
589 590
	end

Azilroka's avatar
Azilroka committed
591
	SMB.TexCoords = PA.TexCoords
Azilroka's avatar
Update  
Azilroka committed
592

Azilroka's avatar
1.25  
Azilroka committed
593 594
	SMB:ScheduleRepeatingTimer('GrabMinimapButtons', 6)
	SMB:ScheduleTimer('HandleBlizzardButtons', 7)
Merathilis's avatar
Merathilis committed
595
end