#include<stdio.h>
#include<allegro.h>
#include"graph.h"
#include"error.h"
#include"consts.h"
#include"player.h"
#include"game.h"
#include"globals.h"
#include"keyconf.h"

void dr_menu(int c)
{
 clear(screen2);
 char str[16];
 int mid,scr;
 scr=SCREEN_W/2; mid=SCREEN_H/2;
 blit((BITMAP *)graph[title].dat,screen2,0,0,0,0,640,100);
 textout(screen2,font,"copyright 1998-1999 toni ylisirnio",5,SCREEN_H-9,makecol(0,50,0));
 if (c!=1) textout_centre(screen2,font,"play",scr,mid,makecol(100,100,100));
 if (c==1) textout_centre(screen2,font,"PLAY",scr,mid,makecol(200,200,200));
 sprintf(str,"players %i",gmstat.numpl);
 if (c!=2) textout_centre(screen2,font,str,scr,mid+15,makecol(100,100,100));
 if (c==2)
 {
  sprintf(str,"PLAYERS %i",gmstat.numpl);
  textout_centre(screen2,font,str,scr,mid+15,makecol(200,200,200));
 }

 // didn't have time to make them work!
/* if (c!=3) textout_centre(screen2,font,"select music",scr,mid+60,makecol(100,100,100));
 if (c==3) textout_centre(screen2,font,"SELECT MUSIC",scr,mid+60,makecol(200,200,200));
 if (c!=4) textout_centre(screen2,font,"keysetup",scr,mid+75,makecol(100,100,100));
 if (c==4) textout_centre(screen2,font,"KEYSETUP",scr,mid+75,makecol(200,200,200));*/
 if (c!=3) textout_centre(screen2,font,"quit",scr,mid+90,makecol(100,100,100));
 if (c==3) textout_centre(screen2,font,"QUIT",scr,mid+90,makecol(200,200,200));
}


int menu()
{
 char ch;
 int choise=1;
 gmstat.numpl=1;

 clear_keybuf();
 bool ok=false;
 while (!ok)
 {
  dr_menu(choise);
  blit(screen2,screen,0,0,0,0,SCREEN_W,SCREEN_H);
  ch=readkey()>>8;

  if (ch==KEY_DOWN) choise++;
  if (ch==KEY_UP) choise--;
  if (choise==0) choise=1;
  if (choise==4) choise=3;

  if ((ch==KEY_ENTER)&&(choise==3)) ok=true;
  if ((ch==KEY_ENTER)&&(choise==1)) ok=true;

  if ((ch==KEY_LEFT)&&(choise==2)) gmstat.numpl--;
  if ((ch==KEY_RIGHT)&&(choise==2)) gmstat.numpl++;
/*  if ((ch==KEY_ENTER)&&(choise==4))
  {
   set_keys();
  }*/
  if (gmstat.numpl>4) gmstat.numpl=4;
  if (gmstat.numpl<1) gmstat.numpl=1;
 }

 gmstat.level_w=SCREEN_W;
 gmstat.level_h=SCREEN_H;

 return choise;
}
