stateDebugMenu = {}

require "scenes.characterselect.controller"

local bannerAnim = 0

function stateDebugMenu:init(previous)
  assets:setBackground( "back" )
end

function stateDebugMenu:enter(previous)
  assets:setBackground( "back" )
  menus:reset()
  assets:clearFonts()
  assets:addFont("small", "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ", 1)
  assets:addFont("medium", "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|} ", 1)
  assets:addFont("large", " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ", 1)
  assets:silence()
  assets:setMusic("options.ogg")
  assets:playMusic()

  assets:clearSprites()
  assets:addSprite("emblem", 330, 192)
  assets.sprites["emblem"]:newAnimation(1, 1, 0.08)
  assets:addSprite("banner", 480, 34)
  assets.sprites["banner"]:newAnimation(1, 1, 0.08)
  assets:addSprite("hborder", 48, 32)
  assets.sprites["hborder"]:newAnimation(1, 1, 0.08)
  assets.sprites["hborder"]:newAnimation(1, 2, 0.08)

  assets:clearTextBox()
  assets:addTextBox("bluetextbox")
end

function stateDebugMenu:update(dt)
  lovebird.update()
  menus:update()
  bannerAnim = (bannerAnim + (dt*32*1.5)) % 32
end

function stateDebugMenu:keyreleased(key, code)
  menus:keyreleased(key, code)
end

function stateDebugMenu:mousemoved(x, y, dx, dy)
  local x, y = CScreen.project(x, y)
  local dx, dy = CScreen.project(dx, dy)
  menus:mousemoved(x, y, dx, dy)
end

function stateDebugMenu:mousepressed( x, y, button, istouch )
  local x, y = CScreen.project(x, y)
  menus:mousepressed( x, y, button, istouch )
end

function stateDebugMenu:draw(dt)
  CScreen:apply()
  assets:drawBackground()
  assets.sprites["emblem"]:draw(1, 240, 272/2-32, 0, 1, 1, 330/2, 192/2)


  for i=1,12 do
    assets.sprites["hborder"]:draw(1, 16, (i*32)-64+bannerAnim)
    assets.sprites["hborder"]:draw(2, 480-16, (i*32)-64-bannerAnim, 0, -1, 1)
  end
  love.graphics.setColor(170, 0, 0)
  love.graphics.rectangle("fill", 0, 0, 16, 272)
  love.graphics.setColor(0, 170, 0)
  love.graphics.rectangle("fill", 480-16, 0, 16, 272)
  resetColor()

  assets.fonts["large"]:set()
  assets.sprites["banner"]:draw(1, 0, 8)
  love.graphics.printf(debugmenu.label, 0, 14, 480, "center")


  menus:draw()

  assets.fonts["small"]:set()
  assets.fonts["small"]:setLineHeight(1.2)
  assets.textbox["bluetextbox"]:draw(120, 216, 240, 42)
  love.graphics.printf(debugmenu.description, 120, 216, 240, "left")
  CScreen:cease()
end
