PageRenderTime 381ms CodeModel.GetById 101ms app.highlight 90ms RepoModel.GetById 99ms app.codeStats 35ms

/Tukui/modules/maps/minimap.lua

http://github.com/Asphyxia/Tukui
Lua | 300 lines | 231 code | 37 blank | 32 comment | 32 complexity | 84c8f3775f4700ca54403b90d47a1545 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2--------------------------------------------------------------------
  3-- Tukui Minimap Script
  4--------------------------------------------------------------------
  5
  6local TukuiMinimap = CreateFrame("Frame", "TukuiMinimap", UIParent)
  7TukuiMinimap:CreatePanel("Default", 1, 1, "CENTER", UIParent, "CENTER", 0, 0)
  8TukuiMinimap:CreateShadow("Default")
  9TukuiMinimap:RegisterEvent("ADDON_LOADED")
 10TukuiMinimap:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
 11TukuiMinimap:RegisterEvent("UPDATE_PENDING_MAIL")
 12TukuiMinimap:RegisterEvent("PLAYER_ENTERING_WORLD")
 13TukuiMinimap:Point("TOPRIGHT", UIParent, "TOPRIGHT", -34, -8)
 14TukuiMinimap:Size(153)
 15TukuiMinimap:SetClampedToScreen(true)
 16TukuiMinimap:SetMovable(true)
 17TukuiMinimap.text = T.SetFontString(TukuiMinimap, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 18TukuiMinimap.text:SetPoint("CENTER")
 19TukuiMinimap.text:SetText(L.move_minimap)
 20
 21-- kill the minimap cluster
 22MinimapCluster:Kill()
 23
 24-- Parent Minimap into our Map frame.
 25Minimap:SetParent(TukuiMinimap)
 26Minimap:ClearAllPoints()
 27Minimap:Size(153)
 28Minimap:Point("TOPLEFT", 2, -2)
 29Minimap:Point("BOTTOMRIGHT", -2, 2)
 30
 31-- Hide Border
 32MinimapBorder:Hide()
 33MinimapBorderTop:Hide()
 34
 35-- Hide Zoom Buttons
 36MinimapZoomIn:Hide()
 37MinimapZoomOut:Hide()
 38
 39-- Hide Voice Chat Frame
 40MiniMapVoiceChatFrame:Hide()
 41
 42-- Hide North texture at top
 43MinimapNorthTag:SetTexture(nil)
 44
 45-- Hide Zone Frame
 46MinimapZoneTextButton:Hide()
 47
 48-- Hide Tracking Button
 49MiniMapTracking:Hide()
 50
 51-- Hide Calendar Button
 52GameTimeFrame:Hide()
 53
 54-- Hide Mail Button
 55MiniMapMailFrame:ClearAllPoints()
 56MiniMapMailFrame:Point("TOPRIGHT", Minimap, 3, 3)
 57MiniMapMailBorder:Hide()
 58MiniMapMailIcon:SetTexture("Interface\\AddOns\\Tukui\\medias\\textures\\mail")
 59
 60-- Move battleground icon
 61MiniMapBattlefieldFrame:ClearAllPoints()
 62MiniMapBattlefieldFrame:Point("BOTTOMRIGHT", Minimap, 3, -3)
 63MiniMapBattlefieldBorder:Hide()
 64
 65-- Ticket Frame
 66local TukuiTicket = CreateFrame("Frame", "TukuiTicket", TukuiMinimap)
 67TukuiTicket:CreatePanel("Default", 1, 1, "CENTER", TukuiMinimap, "CENTER", 0, 0)
 68TukuiTicket:Size(TukuiMinimap:GetWidth() - 4, 24)
 69TukuiTicket:SetFrameStrata("MEDIUM")
 70TukuiTicket:SetFrameLevel(20)
 71TukuiTicket:Point("TOP", 0, -2)
 72TukuiTicket:FontString("Text", C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 73TukuiTicket.Text:SetPoint("CENTER")
 74TukuiTicket.Text:SetText(T.datacolor.."Edit My Ticket")
 75TukuiTicket:SetBackdropBorderColor(255/255, 243/255, 82/255)
 76TukuiTicket.Text:SetTextColor(255/255, 243/255, 82/255)
 77TukuiTicket:SetAlpha(0)
 78
 79HelpOpenTicketButton:SetParent(TukuiTicket)
 80HelpOpenTicketButton:SetFrameLevel(TukuiTicket:GetFrameLevel() + 1)
 81HelpOpenTicketButton:SetFrameStrata(TukuiTicket:GetFrameStrata())
 82HelpOpenTicketButton:ClearAllPoints()
 83HelpOpenTicketButton:SetAllPoints()
 84HelpOpenTicketButton:SetHighlightTexture(nil)
 85HelpOpenTicketButton:SetAlpha(0)
 86HelpOpenTicketButton:HookScript("OnShow", function(self) TukuiTicket:SetAlpha(1) end)
 87HelpOpenTicketButton:HookScript("OnHide", function(self) TukuiTicket:SetAlpha(0) end)
 88
 89-- Hide world map button
 90MiniMapWorldMapButton:Hide()
 91
 92-- shitty 3.3 flag to move
 93MiniMapInstanceDifficulty:ClearAllPoints()
 94MiniMapInstanceDifficulty:SetParent(Minimap)
 95MiniMapInstanceDifficulty:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 0, 8)
 96
 97-- 4.0.6 Guild instance difficulty
 98GuildInstanceDifficulty:ClearAllPoints()
 99GuildInstanceDifficulty:SetParent(Minimap)
100GuildInstanceDifficulty:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 0, 8)
101
102-- Reposition lfg icon at bottom-left
103local function UpdateLFG()
104	MiniMapLFGFrame:ClearAllPoints()
105	MiniMapLFGFrame:Point("BOTTOMRIGHT", Minimap, "BOTTOMRIGHT", 2, -3)
106	MiniMapLFGFrameBorder:Hide()
107end
108hooksecurefunc("MiniMapLFG_UpdateIsShown", UpdateLFG)
109
110-- reskin LFG dropdown
111LFDSearchStatus:SetTemplate("Default")
112
113-- for t13+, if we move map we need to point LFDSearchStatus according to our Minimap position.
114local function UpdateLFGTooltip()
115	local position = TukuiMinimap:GetPoint()
116	LFDSearchStatus:ClearAllPoints()
117	if position:match("BOTTOMRIGHT") then
118		LFDSearchStatus:SetPoint("BOTTOMRIGHT", MiniMapLFGFrame, "BOTTOMLEFT", 0, 0)
119	elseif position:match("BOTTOM") then
120		LFDSearchStatus:SetPoint("BOTTOMLEFT", MiniMapLFGFrame, "BOTTOMRIGHT", 4, 0)
121	elseif position:match("LEFT") then		
122		LFDSearchStatus:SetPoint("TOPLEFT", MiniMapLFGFrame, "TOPRIGHT", 4, 0)
123	else
124		LFDSearchStatus:SetPoint("TOPRIGHT", MiniMapLFGFrame, "TOPLEFT", 0, 0)	
125	end
126end
127LFDSearchStatus:HookScript("OnShow", UpdateLFGTooltip)
128
129-- Enable mouse scrolling
130Minimap:EnableMouseWheel(true)
131Minimap:SetScript("OnMouseWheel", function(self, d)
132	if d > 0 then
133		_G.MinimapZoomIn:Click()
134	elseif d < 0 then
135		_G.MinimapZoomOut:Click()
136	end
137end)
138
139-- Set Square Map Mask
140Minimap:SetMaskTexture(C.media.blank)
141
142-- For others mods with a minimap button, set minimap buttons position in square mode.
143function GetMinimapShape() return "SQUARE" end
144
145-- do some stuff on addon loaded or player login event
146TukuiMinimap:SetScript("OnEvent", function(self, event, addon)
147	if addon == "Blizzard_TimeManager" then
148		-- Hide Game Time
149		TimeManagerClockButton:Kill()
150	else
151		local inv = CalendarGetNumPendingInvites()
152		local mail = HasNewMail()
153		if inv > 0 and mail then -- New invites and mail
154			TukuiMinimap:SetBackdropBorderColor(1, .5, 0)
155			if TukuiMinimapStatsLeft then
156				TukuiMinimapStatsLeft:SetBackdropBorderColor(1, .5, 0)
157			end
158			if TukuiMinimapStatsRight then
159				TukuiMinimapStatsRight:SetBackdropBorderColor(1, .5, 0)
160			end
161		elseif inv > 0 and not mail then -- New invites and no mail
162			TukuiMinimap:SetBackdropBorderColor(1, 30/255, 60/255)
163			if TukuiMinimapStatsLeft then
164				TukuiMinimapStatsLeft:SetBackdropBorderColor(1, 30/255, 60/255)
165			end
166			if TukuiMinimapStatsRight then
167				TukuiMinimapStatsRight:SetBackdropBorderColor(1, 30/255, 60/255)
168			end
169		elseif inv==0 and mail then -- No invites and new mail
170			TukuiMinimap:SetBackdropBorderColor(0, 1, 0)
171			if TukuiMinimapStatsLeft then
172				TukuiMinimapStatsLeft:SetBackdropBorderColor(0, 1, 0)
173			end
174			if TukuiMinimapStatsRight then
175				TukuiMinimapStatsRight:SetBackdropBorderColor(0, 1, 0)
176			end
177		else -- None of the above
178			TukuiMinimap:SetBackdropBorderColor(unpack(C.media.bordercolor))
179			if TukuiMinimapStatsLeft then
180				TukuiMinimapStatsLeft:SetBackdropBorderColor(unpack(C.media.bordercolor))
181			end
182			if TukuiMinimapStatsRight then
183				TukuiMinimapStatsRight:SetBackdropBorderColor(unpack(C.media.bordercolor))
184			end
185		end
186	end
187end)
188
189----------------------------------------------------------------------------------------
190-- Map menus, right/middle click
191----------------------------------------------------------------------------------------
192
193Minimap:SetScript("OnMouseUp", function(self, btn)
194	local xoff = 0
195	local position = TukuiMinimap:GetPoint()
196	
197	if btn == "RightButton" then	
198		if position:match("RIGHT") then xoff = T.Scale(-16) end
199		ToggleDropDownMenu(1, nil, MiniMapTrackingDropDown, TukuiMinimap, xoff, T.Scale(-2))
200	elseif btn == "MiddleButton" then
201		if not TukuiMicroMenu then return end
202		if position:match("RIGHT") then xoff = T.Scale(-14) end
203		ToggleDropDownMenu(1, nil, TukuiMicroMenu, TukuiMinimap, xoff, T.Scale(-2))
204	else
205		Minimap_OnClick(self)
206	end
207end)
208
209----------------------------------------------------------------------------------------
210-- Mouseover map, displaying zone and coords
211----------------------------------------------------------------------------------------
212
213local m_zone = CreateFrame("Frame",nil,TukuiMinimap)
214m_zone:CreatePanel("Transparent", 0, 20, "TOPLEFT", TukuiMinimap, "TOPLEFT", 2,-2)
215m_zone:SetFrameLevel(5)
216m_zone:SetFrameStrata("LOW")
217m_zone:Point("TOPRIGHT",TukuiMinimap,-2,-2)
218m_zone:SetAlpha(0)
219
220local m_zone_text = m_zone:CreateFontString(nil,"Overlay")
221m_zone_text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
222m_zone_text:Point("TOP", 0, -1)
223m_zone_text:SetPoint("BOTTOM")
224m_zone_text:Height(12)
225m_zone_text:Width(m_zone:GetWidth()-6)
226m_zone_text:SetAlpha(0)
227
228local m_coord = CreateFrame("Frame",nil,TukuiMinimap)
229m_coord:CreatePanel("Transparent", 40, 20, "BOTTOMLEFT", TukuiMinimap, "BOTTOMLEFT", 2,2)
230m_coord:SetFrameStrata("LOW")
231m_coord:SetAlpha(0)
232
233local m_coord_text = m_coord:CreateFontString(nil,"Overlay")
234m_coord_text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
235m_coord_text:Point("Center",-1,0)
236m_coord_text:SetAlpha(0)
237m_coord_text:SetText("00,00")
238
239Minimap:SetScript("OnEnter",function()
240	m_zone:SetAlpha(1)
241	m_zone_text:SetAlpha(1)
242	m_coord:SetAlpha(1)
243	m_coord_text:SetAlpha(1)
244end)
245
246Minimap:SetScript("OnLeave",function()
247	m_zone:SetAlpha(0)
248	m_zone_text:SetAlpha(0)
249	m_coord:SetAlpha(0)
250	m_coord_text:SetAlpha(0)
251end)
252 
253local ela = 0
254local coord_Update = function(self,t)
255	ela = ela - t
256	if ela > 0 then return end
257	local x,y = GetPlayerMapPosition("player")
258	local xt,yt
259	x = math.floor(100 * x)
260	y = math.floor(100 * y)
261	if x == 0 and y == 0 then
262		m_coord_text:SetText("X _ X")
263	else
264		if x < 10 then
265			xt = "0"..x
266		else
267			xt = x
268		end
269		if y < 10 then
270			yt = "0"..y
271		else
272			yt = y
273		end
274		m_coord_text:SetText(xt..","..yt)
275	end
276	ela = .2
277end
278m_coord:SetScript("OnUpdate",coord_Update)
279 
280local zone_Update = function()
281	local pvp = GetZonePVPInfo()
282	m_zone_text:SetText(GetMinimapZoneText())
283	if pvp == "friendly" then
284		m_zone_text:SetTextColor(0.1, 1.0, 0.1)
285	elseif pvp == "sanctuary" then
286		m_zone_text:SetTextColor(0.41, 0.8, 0.94)
287	elseif pvp == "arena" or pvp == "hostile" then
288		m_zone_text:SetTextColor(1.0, 0.1, 0.1)
289	elseif pvp == "contested" then
290		m_zone_text:SetTextColor(1.0, 0.7, 0.0)
291	else
292		m_zone_text:SetTextColor(1.0, 1.0, 1.0)
293	end
294end
295 
296m_zone:RegisterEvent("PLAYER_ENTERING_WORLD")
297m_zone:RegisterEvent("ZONE_CHANGED_NEW_AREA")
298m_zone:RegisterEvent("ZONE_CHANGED")
299m_zone:RegisterEvent("ZONE_CHANGED_INDOORS")
300m_zone:SetScript("OnEvent",zone_Update)