dofile ("lua/database.lua")
winLib = {}
cur = Image.load ("lua/images/curseur.png", VRAM)
  
function newWindow (larg, haut)
  winLib.choix = {}   
  winLib.choix.w = larg
  winLib.choix.h = haut
end

function newSWindow (w, ch1, ch2, ch3, ch4)
  winLibchoix = {}
  if ch2==nil and ch3==nil and ch4==nil then
    winLibchoix.a = ch1
    winLibchoix.b = ""
    winLibchoix.c = ""
    winLibchoix.d = ""
  elseif ch3==nil and ch4==nil then  
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ""
    winLibchoix.d = ""
  elseif ch4==nil then
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ch3
    winLibchoix.d = ""
  else 
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ch3
    winLibchoix.d = ch4
  end
  winLib.choix = {}   
  winLib.choix.w = w
  winLib.choix.h = 50
end

function newBWindow (w, h, ch1, ch2, ch3, ch4)
  winLibchoix = {}
  if ch2==nil and ch3==nil and ch4==nil then
    winLibchoix.a = ch1
    winLibchoix.b = ""
    winLibchoix.c = ""
    winLibchoix.d = ""
  elseif ch3==nil and ch4==nil then  
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ""
    winLibchoix.d = ""
  elseif ch4==nil then
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ch3
    winLibchoix.d = ""
  else 
    winLibchoix.a = ch1
    winLibchoix.b = ch2
    winLibchoix.c = ch3
    winLibchoix.d = ch4
  end
  winLib.choix = {}   
  winLib.choix.w = w
  winLib.choix.h = h
end

function initWindow (scrw, x, y)
  xb = x + winLib.choix.w
  yb = y + winLib.choix.h
  screen.drawGradientRect (scrw, x, y, xb, yb, blanc, bleu_clair, bleu_clair, bleu_fonce)
  winLib.x = x
  winLib.y = y
end

function initSWindow (scrw, x, y)
  xb = x + winLib.choix.w
  yb = y + winLib.choix.h
  screen.drawGradientRect (scrw, x, y, xb, yb, blanc, bleu_clair, bleu_clair, bleu_fonce)
  winLib.x = x
  winLib.y = y
  stxwx = winLib.x + 20
  stxwy = winLib.y + 15
  if chmax==2 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
  elseif chmax==3 then  
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
  elseif chmax==4 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  else     
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  end
  if Keys.newPress.Up then
    if choix > 1 then
      choix = choix - 1
    else 
      choix = chmax
    end
  elseif Keys.newPress.Down then
    if choix < chmax then
      choix = choix + 1
    else
      choix = 1
    end
  end
  chx = stxwx-Image.width (cur)-2
  chy = stxwy-11+(11*choix)
  if choix~=0 then
    screen.blit (scrw, chx, chy, cur)
  end
end

function initSWindow2 (scrw, x, y)
  xb = x + winLib.choix.w
  yb = y + winLib.choix.h
  screen.drawGradientRect (scrw, x, y, xb, yb, blanc, bleu_clair, bleu_clair, bleu_fonce)
  winLib.xsk = x
  winLib.ysk = y
  stxwx = winLib.xsk + 20
  stxwy = winLib.ysk + 15
  if chmax==2 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
  elseif chmax==3 then  
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
  elseif chmax==4 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  else     
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  end
  if Keys.newPress.Up then
    if choixSkills > 1 then
      choixSkills = choixSkills - 1
    else 
      choixSkills = chmax
    end
  elseif Keys.newPress.Down then
    if choixSkills < chmax then
      choixSkills = choixSkills + 1
    else
      choixSkills = 1
    end
  end
  chx = stxwx-Image.width (cur)-2
  chy = stxwy-11+(11*choixSkills)
  if choixSkills~=0 then
    screen.blit (scrw, chx, chy, cur)
  end
end

function initBWindow (scrw, x, y)
  xb = x + winLib.choix.w
  yb = y + winLib.choix.h
  screen.drawGradientRect (scrw, x, y, xb, yb, blanc, bleu_clair, bleu_clair, bleu_fonce)
  winLib.x = x
  winLib.y = y
  stxwx = winLib.x + 10
  stxwy = winLib.y + 10
  if chmax==2 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
  elseif chmax==3 then  
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
  elseif chmax==4 then
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  else     
    screen.print (scrw, stxwx, stxwy, winLibchoix.a)
    screen.print (scrw, stxwx, stxwy+11, winLibchoix.b)
    screen.print (scrw, stxwx, stxwy+22, winLibchoix.c)
    screen.print (scrw, stxwx, stxwy+33, winLibchoix.d)
  end
  if Keys.newPress.Up then
    if choix > 1 then
      choix = choix - 1
    else 
      choix = chmax
    end
  elseif Keys.newPress.Down then
    if choix < chmax then
      choix = choix + 1
    else
      choix = 1
    end
  end
  chx = stxwx-Image.width (cur)-2
  chy = stxwy-11+(11*choix)
  if choix~=0 then
    screen.blit (scrw, chx, chy, cur)
  end
end

function drawWindowText (scr, txt)
  txwx = winLib.x + 20
  txwy = winLib.y + 20
  screen.print (scr, txwx, txwy, txt)
end

