Quantcast
local _, ns = ...

local pMinimap = CreateFrame('Frame')
pMinimap:SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
pMinimap:RegisterEvent('PLAYER_LOGIN')

local DEFAULTS = {
	minimap = {
		scale = 0.9,
		level = 2,
		strata = 'BACKGROUND',
		borderSize = 1,
		borderColors = {0, 0, 0, 1},
		position = 'TOPRIGHT\031-15\031-15',
	},
	objects = {
		Zone = {point = 'TOP', shown = false},
		Difficulty = {point = 'BOTTOM', shown = false},
		Battlefield = {point = 'TOPRIGHT', shown = true},
		Dungeon = {point = 'TOPRIGHT', shown = true},
		Tracking = {point = 'TOPLEFT', shown = true},
		Clock = {point = 'BOTTOM', shown = true},
		Mail = {point = 'BOTTOMRIGHT', shown = true},
	},
	font = {
		name = LibStub('LibSharedMedia-3.0'):GetDefault('font'),
		size = 12,
		shadow = 'OUTLINE',
		monochrome = false,
	},
}

function pMinimap:PLAYER_LOGIN()
	pMinimapDB = setmetatable(pMinimapDB or {}, {__index = DEFAULTS})

	MinimapZoomIn:Hide()
	MinimapZoomOut:Hide()
	Minimap:EnableMouseWheel()
	Minimap:SetScript('OnMouseWheel', function(self, direction)
		if(direction > 0) then
			MinimapZoomIn:Click()
		else
			MinimapZoomOut:Click()
		end
	end)

	Minimap:SetMovable(true)
	Minimap:SetClampedToScreen()
	Minimap:RegisterForDrag('LeftButton')
	Minimap:SetMaskTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
	Minimap:SetScript('OnDragStart', function(self)
		if(not ns.UNLOCKED) then return end
		self:StartMoving()
	end)
	Minimap:SetScript('OnDragStop', function(self)
		if(not ns.UNLOCKED) then return end
		self:StopMovingOrSizing()
		ns.UpdatePosition(true)
	end)

	MinimapCluster:EnableMouse(false)
	MinimapBorder:SetTexture(nil)
	MinimapBorderTop:Hide()
	MinimapNorthTag:SetAlpha(0)
	MiniMapWorldMapButton:Hide()
	GameTimeFrame:Hide()

	MiniMapTracking:SetParent(Minimap)
	MiniMapTrackingBackground:Hide()
	MiniMapTrackingButtonBorder:SetTexture(nil)
	MiniMapTrackingButton:SetHighlightTexture(nil)
	MiniMapTrackingIconOverlay:SetTexture(nil)
	MiniMapTrackingIcon:SetTexCoord(0.065, 0.935, 0.065, 0.935)

	MiniMapLFGFrame:SetParent(Minimap)
	MiniMapLFGFrame:SetHighlightTexture(nil)
	MiniMapLFGFrameBorder:Hide()
	LFDSearchStatus:SetClampedToScreen(true)

	MiniMapBattlefieldFrame:SetParent(Minimap)
	MiniMapBattlefieldBorder:SetTexture(nil)
	BattlegroundShine:Hide()

	MiniMapMailFrame:SetParent(Minimap)
	MiniMapMailBorder:SetTexture(nil)

	MinimapZoneTextButton:SetParent(Minimap)
	MinimapZoneText:SetShadowOffset(0, 0)

	TimeManager_LoadUI()
	TimeManagerClockButton:GetRegions():Hide()
	TimeManagerClockButton:SetSize(40, 14)
	TimeManagerClockTicker:SetPoint('CENTER', TimeManagerClockButton)
	TimeManagerClockTicker:SetShadowOffset(0, 0)

	ns.UNLOCKED = false
	ns.UpdatePosition()
	ns.UpdateObjects()
	ns.UpdateCore()
	ns.UpdateFont()

	SLASH_pMinimap1 = '/pmm'
	SLASH_pMinimap2 = '/pminimap'
	SlashCmdList.pMinimap = function()
		InterfaceOptionsFrame_OpenToCategory('pMinimap')
	end
end

-- http://wowwiki.com/GetMinimapShape
function GetMinimapShape()
	return 'SQUARE'
end