------------------------------------------------------------
-- MiniMap.lua (All rights reserved for KG-Emulator)
------------------------------------------------------------

-- if true, the native overlay is turned off (only ours is visible)
local EXCLUSIVE_OVERLAY = true

-- apariencia del borde
local BORDER_ALPHA = 0.70      -- transparencia del borde (0..1)
local COLOR_BORDER = {1, 1, 1} -- color del borde (RGB 0..1)

-- helpers mínimos
local function mapToScreen(mx, my)
  local sx, sy = Minimap_MapToScreen(mx, my)
  return sx, sy
end

local function drawPoint(mx, my, size, r, g, b, a)
  local sx, sy = mapToScreen(mx, my)
  Minimap_DrawPoint(sx + ReturnWideScreenX(), sy, size, r, g, b, a)
end

local function drawCross(mx, my, size, r, g, b, a)
  local sx, sy = mapToScreen(mx, my)
  local h = size * 0.5
  Minimap_DrawPoint(sx - h, sy,   1, r, g, b, a)
  Minimap_DrawPoint(sx + h, sy,   1, r, g, b, a)
  Minimap_DrawPoint(sx,     sy-h, 1, r, g, b, a)
  Minimap_DrawPoint(sx,     sy+h, 1, r, g, b, a)
  Minimap_DrawPoint(sx,     sy,   1, r, g, b, a)
end

local function drawBorder()
  local r, g, b = COLOR_BORDER[1], COLOR_BORDER[2], COLOR_BORDER[3]
  local N = 256  -- mapa lógico 256x256
  
  -- superior e inferior
  for x = 0, N, 2 do
    drawPoint(x,   0, 2, r, g, b, 0.70)
    drawPoint(x, 256, 2, r, g, b, 0.70)
  end
  -- laterales
  for y = 0, N, 2 do
    drawPoint(  0, y, 2, r, g, b, 0.70)
    drawPoint(256, y, 2, r, g, b, 0.70)
  end
  -- esquinas
  drawCross(  0,   0, 18.0, r, g, b, 0.70)
  drawCross(256,   0, 18.0, r, g, b, 0.70)
  drawCross(  0, 256, 18.0, r, g, b, 0.70)
  drawCross(256, 256, 18.0, r, g, b, 0.70)
end

function MiniMap_OnLayout(mapNumber) 
	if(GetWideScreenStatus() == 1) then
		Minimap_SetRect(50, 50, 480.0, 480.0) 
	end
end

function MiniMap_OnRender(mapNumber)
  -- toma control exclusivo del overlay
  local x, y, w, h = Minimap_GetRect()
  
  x = x + ReturnWideScreenX();
  
  ---Minimap_Enable(EXCLUSIVE_OVERLAY)
  SetBlend(true)
  
  -- punto baul test
  RenderImage2(0xF2038, x + 50, y + 50, 20, 20, 0,0,1,1, 1,1,1)

  -- 2) bordeado del mapa (puntos + cruces en esquinas)
  drawBorder()
  SetBlend(false)
end
