PageRenderTime 328ms CodeModel.GetById 225ms app.highlight 11ms RepoModel.GetById 28ms app.codeStats 36ms

/Tukui/modules/maps/location_panel.lua

http://github.com/Asphyxia/Tukui
Lua | 92 lines | 82 code | 9 blank | 1 comment | 9 complexity | 24f96c1a3a96005000e5e6969eee0566 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2if not C.map.location_panel then return end
 3local font, fsize, fstyle = C.media.pixelfont, C.datatext.fontsize, "MONOCHROMEOUTLINE"
 4
 5local locpanel = CreateFrame("Frame", "TukuiLocationPanel", UIParent)
 6locpanel:CreatePanel("Default", 70, 23, "TOP", UIParent, "TOP", 0, -8)
 7locpanel:CreateShadow("Default")
 8locpanel:CreateOverlay(locpanel)
 9locpanel:SetFrameLevel(4)
10locpanel:EnableMouse(true)
11
12local xcoords = CreateFrame("Frame", "TukuiXCoordsPanel", locpanel)
13xcoords:CreatePanel("Default", 35, 19, "RIGHT", locpanel, "LEFT", 1, 0)
14xcoords:CreateShadow("Default")
15xcoords:CreateOverlay(xcoords)
16xcoords:SetFrameLevel(2)
17
18local ycoords = CreateFrame("Frame", "TukuiYCoordsPanel", locpanel)
19ycoords:CreatePanel("Default", 35, 19, "LEFT", locpanel, "RIGHT", -1, 0)
20ycoords:CreateShadow("Default")
21ycoords:CreateOverlay(ycoords)
22ycoords:SetFrameLevel(2)
23
24-- Set font
25local locFS = locpanel:CreateFontString(nil, "OVERLAY")
26locFS:SetFont(font, fsize, fstyle)
27
28local xFS = xcoords:CreateFontString(nil, "OVERLAY")
29xFS:SetFont(font, fsize, fstyle)
30
31local yFS = ycoords:CreateFontString(nil, "OVERLAY")
32yFS:SetFont(font, fsize, fstyle)
33
34local function SetLocColor(frame, pvpT)
35	if (pvpT == "arena" or pvpT == "combat") then
36		frame:SetTextColor(1, 0, 0)
37	elseif pvpT == "friendly" then
38		frame:SetTextColor(0, 1, 0)
39	elseif pvpT == "contested" then
40		frame:SetTextColor(1, 1, 0)
41	elseif pvpT == "hostile" then
42		frame:SetTextColor(1, 0, 0)
43	elseif pvpT == "sanctuary" then
44		frame:SetTextColor(0, .9, .9)
45	else
46		frame:SetTextColor(0, 1, 0)
47	end
48end
49
50local function OnEvent()
51	location = GetMinimapZoneText()
52	pvpType = GetZonePVPInfo();
53	locFS:SetText(location)
54	locpanel:SetWidth(locFS:GetStringWidth() + 40)
55	SetLocColor(locFS, pvpType)
56	locFS:SetPoint("CENTER", locpanel, "CENTER", 1, 1)
57	locFS:SetJustifyH("CENTER")
58end
59local function xUpdate()
60	posX, posY = GetPlayerMapPosition("player");
61	posX = math.floor(100 * posX)
62	xFS:SetText(T.datacolor..posX)
63	xFS:SetPoint("CENTER", xcoords, "CENTER", 1, 1)
64end
65local function yUpdate()
66	posX, posY = GetPlayerMapPosition("player");
67	posY = math.floor(100 * posY)
68	yFS:SetText(T.datacolor..posY)
69	yFS:SetPoint("CENTER", ycoords, "CENTER", 1, 1)
70end
71locpanel:SetScript("OnMouseDown", function()
72	if WorldMapFrame:IsShown() then
73			WorldMapFrame:Hide()
74	else
75			WorldMapFrame:Show()
76	end
77end)
78
79locpanel:SetScript("OnEnter", function()
80	locFS:SetTextColor(1, 1, 1)
81end)
82locpanel:SetScript("OnLeave", function()
83	pvpType = GetZonePVPInfo();
84	SetLocColor(locFS, pvpType)	
85end)
86locpanel:RegisterEvent("ZONE_CHANGED")
87locpanel:RegisterEvent("PLAYER_ENTERING_WORLD")
88locpanel:RegisterEvent("ZONE_CHANGED_INDOORS")
89locpanel:RegisterEvent("ZONE_CHANGED_NEW_AREA")
90locpanel:SetScript("OnEvent", OnEvent)
91xcoords:SetScript("OnUpdate", xUpdate)
92ycoords:SetScript("OnUpdate", yUpdate)