#ifndef MENUS_H
#define MENUS_H
#include "Menu.h"

Menu mainGUI=Menu(0,0,SCREEN_W-10,SCREEN_H-10);

Menu login=Menu(225,300,150,175);
Menu backpack=Menu(485,40,150,300);
Menu trade=Menu(40,40,500,300);
Menu paperdoll=Menu(280,40,350,400);
Menu nimgui=Menu(510,150,120,300);
Menu loadmenu=Menu(225,300,150,175);

/*
void setup_login()
{
	login.textboxs[0].Set_selceted(true);//selected by defalt

}
*/

int draw_nimgui(BITMAP* bmp,Inventory inven,ItemList itemsl,UnitItems &tempitems)
{


	nimgui.textboxs[0].Set_lable( " Units 1-25 ");
	nimgui.textboxs[0].Set_x(nimgui.Get_x()+5);
	nimgui.textboxs[0].Set_y(nimgui.Get_y()+20);
	nimgui.textboxs[0].Set_w(100);
	nimgui.textboxs[0].Set_h(25);
	nimgui.buttons[0].Set_lable( " Start Game");
	

	nimgui.buttons[0].Set_x(nimgui.Get_x()+5);
	nimgui.buttons[0].Set_y(nimgui.textboxs[0].Get_y()+40);
	nimgui.buttons[0].Set_w(100);
	nimgui.buttons[0].Set_h(25);
	nimgui.buttons[0].Set_scolor(255,0,255);
	nimgui.buttons[0].Set_ecolor(255,0,0);

	
	nimgui.buttons[1].Set_lable( " Exit Game");
	
	
	nimgui.buttons[1].Set_x(nimgui.Get_x()+5);
	nimgui.buttons[1].Set_y(nimgui.buttons[0].Get_y()+40);
	nimgui.buttons[1].Set_w(100);
	nimgui.buttons[1].Set_h(25);
	nimgui.buttons[1].Set_scolor(255,0,255);
	nimgui.buttons[1].Set_ecolor(255,0,0);




	
	nimgui.buttons[2].Set_lable( " End Turn");
	
	nimgui.buttons[2].Set_x(nimgui.Get_x()+5);
	nimgui.buttons[2].Set_y(nimgui.buttons[1].Get_y()+40);
	nimgui.buttons[2].Set_w(100);
	nimgui.buttons[2].Set_h(25);
	nimgui.buttons[2].Set_scolor(255,0,255);
	nimgui.buttons[2].Set_ecolor(255,0,0);


	nimgui.draw(bmp);
	tospawunit = StringToNumber(nimgui.textboxs[0].draw(bmp));
	nimgui.buttons[0].draw(bmp);
	nimgui.buttons[1].draw(bmp);
	nimgui.buttons[2].draw(bmp);
/*
username =	nimgui.textboxs[0].draw(bmp); //returns username
password = 	nimgui.textboxs[1].draw(bmp); //returns password
serverIP = 	nimgui.textboxs[2].draw(bmp); //returns serverIP
*/
if (!(mouse_b & 1))
{
nimgui.mx = mouse_x;
nimgui.my = mouse_y;
}
	nimgui.mouse[0].draw(bmp);
	if (mouse_b & 1 && clicked==false)
		//if (is_doubleclick())
		{
			
			if(nimgui.is_collision( nimgui.mouse[0]))
			{
				if(!nimgui.buttons[0].is_collision( nimgui.mouse[0]))
				{
					if(!nimgui.buttons[1].is_collision( nimgui.mouse[0]))
					{
						if(!nimgui.textboxs[2].is_collision( nimgui.mouse[0]))
						{

						
								//nimgui.Set_x( mouse_x );
								//nimgui.Set_y( mouse_y );
										nimgui.mov=mouse_x -nimgui.mx;
										nimgui.mov2=mouse_y - nimgui.my;
										nimgui.mx = mouse_x;
										nimgui.my = mouse_y;
										
										nimgui.Set_x( nimgui.Get_x()+nimgui.mov);
										nimgui.Set_y( nimgui.Get_y()+nimgui.mov2);
										
										nimgui.mov = 0;
										nimgui.mov2 = 0;
										//mouse_x = nimgui.mov + nimgui.Get_x();
										//mouse_y = nimgui.mov2 + nimgui.Get_y();
						}
					
					}
				}
			}
			
		if(nimgui.buttons[0].is_collision( nimgui.mouse[0]))
			{
			clicked=true;
				nimgui.buttons[0].Set_state(1);
				//do this buttons stuff nimgui
				//send startsingle to outbox
					inboxbuffer +="0|" + NumberToString(charnetId) + "|012|" + NumberToString(computerId)+ ","+"1"+","+NumberToString(tospawunit)+ "`~";//rig

					

				return 1;
			}
			else
			{
				nimgui.buttons[0].Set_state(0);
			}
			if(nimgui.buttons[1].is_collision( nimgui.mouse[0]))
			{
				clicked=true;
				nimgui.buttons[1].Set_state(1);
inboxbuffer +="0|" + NumberToString(charnetId) + "|012|" + NumberToString(charnetId)+ ","+"3"+","+NumberToString(tospawunit)+ "`~";//rig

				//send endsingle to outbox
				//do this buttons stuff new acount

			}
			else
			{
				nimgui.buttons[1].Set_state(0);

			}

			if(nimgui.buttons[2].is_collision( nimgui.mouse[0]))
			{
				clicked=true;
				nimgui.buttons[2].Set_state(1);
					//send endturnsingle to outbox


				inboxbuffer +="0|" + NumberToString(charnetId) + "|012|" + NumberToString(charnetId)+ ","+"2"+","+NumberToString(tospawunit)+ "`~";//rig

				return -1;//are you done drawing
			}
			else
			{
				nimgui.buttons[2].Set_state(0);
			}

					if(nimgui.textboxs[0].is_collision( nimgui.mouse[0]))
			{
				clicked=true;
				nimgui.textboxs[0].Set_selceted(true);
				//username text box has keybord

			}	
		}
	else if(!(mouse_b &2)&&!(mouse_b &1))
	{
		clicked=false;
	}
return 0; //are you done drawing
}


int draw_paperdoll(BITMAP* bmp,Inventory inven,ItemList itemsl,UnitItems &tempitems,Statss *atts)
{
textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+20, makecol(255, 255, 255),"EXP:%1d      ", atts->Getexp());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+35, makecol(255, 255, 255),"level:%d    ", atts->Getlevel());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+50, makecol(255, 255, 255),"HP:%d		  ", atts->Gethp());
textprintf_centre(bmp, font, paperdoll.Get_x()+125, paperdoll.Get_y()+50, makecol(255, 255, 255),"/:%d		  ", atts->Gethp_max());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+65, makecol(255, 255, 255),"MP:%d		  ", atts->Getmp());
textprintf_centre(bmp, font, paperdoll.Get_x()+125, paperdoll.Get_y()+65, makecol(255, 255, 255),"/:%d		  ", atts->Getmp_max());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+80, makecol(255, 255, 255),"  Attack:%d   ", atts->Getminattack_power());
textprintf_centre(bmp, font, paperdoll.Get_x()+125, paperdoll.Get_y()+80, makecol(255, 255, 255),"- %d   ", atts->Getattack_power());


textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+95, makecol(255, 255, 255),"accuracy:%1d", atts->Getaccuracy());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+110, makecol(255, 255, 255),"agility:%1d  ", atts->Getagility());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+125, makecol(255, 255, 255),"AP:%1d      ", atts->Getap());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+140, makecol(255, 255, 255),"atc Bonce:%1d", atts->Getbonceattack_power());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+155, makecol(255, 255, 255),"defense:%1d  " , atts->Getdefense());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+170, makecol(255, 255, 255),"evasion:%1d  ", atts->Getevasion());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+185, makecol(255, 255, 255),"Gold:%1d     ", atts->Getgold());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+200, makecol(255, 255, 255),"immun_sys:%1d", atts->Getimmun_system());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+215, makecol(255, 255, 255)," KI:%1d      ", atts->Getki());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+230, makecol(255, 255, 255),"Wheigt:%1d   ", atts->Getlbs());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+245, makecol(255, 255, 255),"luck:%1d     ", atts->Getluck());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+260, makecol(255, 255, 255)," magic:%1d    ", atts->Getmagic());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+275, makecol(255, 255, 255),"magic_def:%1d", atts->Getmagic_defense());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+290, makecol(255, 255, 255),"magcPower:%1d", atts->Getmagic_power());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+305, makecol(255, 255, 255),"psi_attc:%1d ", atts->Getpsi_attack());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+320, makecol(255, 255, 255),"psi_def:%1d  ", atts->Getpsi_defense());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+335, makecol(255, 255, 255),"speed:%1d    ", atts->Getspeed());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+350, makecol(255, 255, 255),"  strength:%d ", atts->Getstrength());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+365, makecol(255, 255, 255),"wisdom:%1d   ",	 atts->Getwisdom());

textprintf_centre(bmp, font, paperdoll.Get_x()+50, paperdoll.Get_y()+380, makecol(255, 255, 255),"Range:%1d   ",	 atts->range);

/*
	paperdoll.buttons[0].Set_lable( "   Logon");
	paperdoll.buttons[0].Set_x(paperdoll.Get_x()+50);
	paperdoll.buttons[0].Set_y(paperdoll.Get_y()+40);
	paperdoll.buttons[0].Set_w(100);
	paperdoll.buttons[0].Set_h(25);
	paperdoll.buttons[1].Set_lable( "Make New");
	paperdoll.buttons[1].Set_x(paperdoll.Get_x()+100);
	paperdoll.buttons[1].Set_y(paperdoll.Get_y()+130);
	paperdoll.buttons[1].Set_w(100);
	paperdoll.buttons[1].Set_h(25);

	paperdoll.buttons[2].Set_lable( "   Exit");
	paperdoll.buttons[2].Set_x(paperdoll.Get_x()+100);
	paperdoll.buttons[2].Set_y(paperdoll.Get_y()+170);
	paperdoll.buttons[2].Set_w(100);
	paperdoll.buttons[2].Set_h(25);

	paperdoll.textboxs[0].Set_lable( "Enter Uesrname");
	paperdoll.textboxs[0].Set_x(paperdoll.Get_x()+160);
	paperdoll.textboxs[0].Set_y(paperdoll.Get_y()+20);
	paperdoll.textboxs[0].Set_w(100);
	paperdoll.textboxs[0].Set_h(25);
	

	paperdoll.textboxs[1].Set_lable( "Enter PassWord");
	paperdoll.textboxs[1].Set_x(paperdoll.Get_x()+160);
	paperdoll.textboxs[1].Set_y(paperdoll.Get_y()+60);
	paperdoll.textboxs[1].Set_w(100);
	paperdoll.textboxs[1].Set_h(25);


	paperdoll.textboxs[2].Set_lable( "Server IP");
	paperdoll.textboxs[2].Set_x(paperdoll.Get_x()+18);
	paperdoll.textboxs[2].Set_y(paperdoll.Get_y()+92);
	paperdoll.textboxs[2].Set_w(185);
	paperdoll.textboxs[2].Set_h(25);
	paperdoll.textboxs[2].Set_defaltText(serverIP);

*/

	paperdoll.draw(bmp);
/*
	paperdoll.buttons[0].draw(bmp);
	paperdoll.buttons[1].draw(bmp);
	paperdoll.buttons[2].draw(bmp);

username =	paperdoll.textboxs[0].draw(bmp); //returns username
password = 	paperdoll.textboxs[1].draw(bmp); //returns password
serverIP = 	paperdoll.textboxs[2].draw(bmp); //returns serverIP
*/
if (!(mouse_b & 1))
{
//paperdoll.mx = mouse_x;
//paperdoll.my = mouse_y;
}
	paperdoll.mouse[0].draw(bmp);
	if (mouse_b & 1&&clicked==false)
		//if (is_doubleclick())
		{

/*
			if(paperdoll.is_collision( paperdoll.mouse[0]))
			{
				if(!paperdoll.buttons[0].is_collision( paperdoll.mouse[0]))
				{
					if(!paperdoll.buttons[1].is_collision( paperdoll.mouse[0]))
					{
						if(!paperdoll.textboxs[0].is_collision( paperdoll.mouse[0]))
						{
							if(!paperdoll.textboxs[1].is_collision( paperdoll.mouse[0]))
							{
								if(!paperdoll.textboxs[2].is_collision( paperdoll.mouse[0]))
								{
								*/
								//paperdoll.Set_x( mouse_x );
								//paperdoll.Set_y( mouse_y );
									//	paperdoll.mov=mouse_x -paperdoll.mx;
									//	paperdoll.mov2=mouse_y - paperdoll.my;
									//	paperdoll.mx = mouse_x;
									//	paperdoll.my = mouse_y;
										
									//	paperdoll.Set_x( paperdoll.Get_x()+paperdoll.mov);
									//	paperdoll.Set_y( paperdoll.Get_y()+paperdoll.mov2);
										
									//	paperdoll.mov = 0;
									//	paperdoll.mov2 = 0;
							/*			//mouse_x = paperdoll.mov + paperdoll.Get_x();
										//mouse_y = paperdoll.mov2 + paperdoll.Get_y();
								}
							}
						}
					}
				}
			}
			*/
			/*
		if(paperdoll.buttons[0].is_collision( paperdoll.mouse[0]))
			{
				paperdoll.buttons[0].Set_state(1);
				//do this buttons stuff paperdoll
				//sub menu get username and password 
				//need to give chances to enter that mean we need sever conection here
				//contiual on to game 
				
				return 1;
			}
			else
			{
				paperdoll.buttons[0].Set_state(0);
			}
			if(paperdoll.buttons[1].is_collision( paperdoll.mouse[0]))
			{
				paperdoll.buttons[1].Set_state(1);
				//do this buttons stuff new acount

			}
			else
			{
				paperdoll.buttons[1].Set_state(0);

			}

			if(paperdoll.buttons[2].is_collision( paperdoll.mouse[0]))
			{
				paperdoll.buttons[2].Set_state(1);
				//do this buttons stuff exit
				return -1;//are you done drawing
			}
			else
			{
				paperdoll.buttons[2].Set_state(0);
			}

			if(paperdoll.textboxs[0].is_collision( paperdoll.mouse[0]))
			{
				
				paperdoll.textboxs[0].Set_selceted(true);
				paperdoll.textboxs[1].Set_selceted(false);
				paperdoll.textboxs[2].Set_selceted(false);
				//username text box has keybord

			}
			if(paperdoll.textboxs[1].is_collision( paperdoll.mouse[0]))
			{

				paperdoll.textboxs[0].Set_selceted(false);
				paperdoll.textboxs[1].Set_selceted(true);
				paperdoll.textboxs[2].Set_selceted(false);
				//passWord text box has keybord

			}
			if(paperdoll.textboxs[2].is_collision( paperdoll.mouse[0]))
			{
				paperdoll.textboxs[0].Set_selceted(false);
				paperdoll.textboxs[1].Set_selceted(false);
				paperdoll.textboxs[2].Set_selceted(true);
				//passWord text box has keybord

			}*/
		}
		else if(!(mouse_b &2)&&!(mouse_b &1))
	{
		clicked=false;
	}


return 0; //are you done drawing
}



int draw_backpack(BITMAP* bmp,Inventory inven,ItemList itemsl,UnitItems &tempitems)
{

for(int i=0; i <tempitems.slotsperpage;i++)
{
	if(tempitems.items[i].something_in_slot==true)
	{
		backpack.buttons[i].Set_lable( NumberToString(tempitems.items[i].nuberofitems) +" "+itemsl.Items[tempitems.items[i].itemid]->Get_name());
	}
	else
	{
		backpack.buttons[i].Set_lable( " empty slot");
	}

	backpack.buttons[i].Set_x(backpack.Get_x()+5);
	if(i==0)
	{
		backpack.buttons[i].Set_y(backpack.Get_y()+20);
	}
	else
	{
		backpack.buttons[i].Set_y(backpack.buttons[i-1].Get_y()+40);
	}
	backpack.buttons[i].Set_w(100);
	backpack.buttons[i].Set_h(25);
	backpack.buttons[i].Set_scolor(255,0,255);
	backpack.buttons[i].Set_ecolor(255,0,0);
}
/*
	if(tempitems.items[0].something_in_slot==true)
	{
		backpack.buttons[0].Set_lable( NumberToString(tempitems.items[0].nuberofitems) +" "+itemsl.Items[tempitems.items[0].itemid]->Get_name());
	}
	else
	{
		backpack.buttons[0].Set_lable( " empty slot");
	}

	backpack.buttons[0].Set_x(backpack.Get_x()+5);
	backpack.buttons[0].Set_y(backpack.Get_y()+20);
	backpack.buttons[0].Set_w(100);
	backpack.buttons[0].Set_h(25);
	backpack.buttons[0].Set_scolor(255,0,255);
	backpack.buttons[0].Set_ecolor(255,0,0);

	if(tempitems.items[1].something_in_slot==true)
	{
		backpack.buttons[1].Set_lable( NumberToString(tempitems.items[1].nuberofitems) +" "+itemsl.Items[tempitems.items[1].itemid]->Get_name());
	}
	else
	{
		backpack.buttons[1].Set_lable( " empty slot");
	}
	
	backpack.buttons[1].Set_x(backpack.Get_x()+5);
	backpack.buttons[1].Set_y(backpack.buttons[0].Get_y()+40);
	backpack.buttons[1].Set_w(100);
	backpack.buttons[1].Set_h(25);
	backpack.buttons[1].Set_scolor(255,0,255);
	backpack.buttons[1].Set_ecolor(255,0,0);



	if(tempitems.items[2].something_in_slot==true)
	{
		backpack.buttons[2].Set_lable( NumberToString(tempitems.items[2].nuberofitems) +" "+itemsl.Items[tempitems.items[2].itemid]->Get_name());
	}
	else
	{
		backpack.buttons[2].Set_lable( " empty slot");
	}
	backpack.buttons[2].Set_x(backpack.Get_x()+5);
	backpack.buttons[2].Set_y(backpack.buttons[1].Get_y()+40);
	backpack.buttons[2].Set_w(100);
	backpack.buttons[2].Set_h(25);
	backpack.buttons[2].Set_scolor(255,0,255);
	backpack.buttons[2].Set_ecolor(255,0,0);
*/
	backpack.draw(bmp);
for( i=0; i <tempitems.slotsperpage;i++)
{
	backpack.buttons[i].draw(bmp);
}
/*
	backpack.buttons[1].draw(bmp);
	backpack.buttons[2].draw(bmp);
*/
/*
username =	backpack.textboxs[0].draw(bmp); //returns username
password = 	backpack.textboxs[1].draw(bmp); //returns password
serverIP = 	backpack.textboxs[2].draw(bmp); //returns serverIP
*/
if (!(mouse_b & 1))
{
backpack.mx = mouse_x;
backpack.my = mouse_y;
}
	backpack.mouse[0].draw(bmp);
	if (mouse_b & 1 && clicked==false)
		//if (is_doubleclick())
		{
			
			
				bool col=false;

			if(backpack.is_collision( backpack.mouse[0]))
			{
				for( i=0; i <tempitems.slotsperpage;i++)
				{
					if(!backpack.buttons[0].is_collision( backpack.mouse[0]))
					{
						col=false;
						break;
					}
					else
					{
						col=true;

					}



				}
				if(col==true)
				{
					
				//backpack.Set_x( mouse_x );
				//backpack.Set_y( mouse_y );
						backpack.mov=mouse_x -backpack.mx;
						backpack.mov2=mouse_y - backpack.my;
						backpack.mx = mouse_x;
						backpack.my = mouse_y;
						
						backpack.Set_x( backpack.Get_x()+backpack.mov);
						backpack.Set_y( backpack.Get_y()+backpack.mov2);
						
						backpack.mov = 0;
						backpack.mov2 = 0;
						//mouse_x = backpack.mov + backpack.Get_x();
						//mouse_y = backpack.mov2 + backpack.Get_y();
				}
				
			}
			

		for( i=0; i <tempitems.slotsperpage;i++)
		{

			if(backpack.buttons[i].is_collision( backpack.mouse[0]))
			{
				clicked=true;
				backpack.buttons[i].Set_state(1);
				//do this buttons stuff backpack
				
				
					if(tempitems.useitem(i)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(tempitems.items[i].itemid)+ "`~";//rig
	//sleep(9999);
					//	}
					}

				return i;;
			}

		}


/*
		if(backpack.buttons[0].is_collision( backpack.mouse[0]))
		{
			clicked=true;
				backpack.buttons[0].Set_state(1);
				//do this buttons stuff backpack
				
				
					if(tempitems.useitem(0)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(tempitems.items[0].itemid)+ "`~";//rig
	//sleep(9999);
					//	}
					}

				return 1;
			}
			if(backpack.buttons[1].is_collision( backpack.mouse[0]))
			{
				clicked=true;
				backpack.buttons[1].Set_state(1);
				//do this buttons stuff new acount
					if(tempitems.useitem(1)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(tempitems.items[1].itemid)+ "`~";//rig
						//sleep(9999);
					//	}
					}
			}
		
			if(backpack.buttons[2].is_collision( backpack.mouse[0]))
			{
				clicked=true;
				backpack.buttons[2].Set_state(1);
				//do this buttons stuff exit
				return -1;//are you done drawing
			}
			
*/
			
		}
	else if(!(mouse_b &2)&&!(mouse_b &1))
	{
		for( i=0; i <tempitems.slotsperpage;i++)
		{
			backpack.buttons[i].Set_state(0);
		}
	//	backpack.buttons[1].Set_state(0);
	//	backpack.buttons[2].Set_state(0);
		clicked=false;
	}
return 0; //are you done drawing
}







int draw_login(BITMAP* bmp)
{

	login.buttons[0].Set_lable( "NEW GAME");
	login.buttons[0].Set_x(login.Get_x()+25);
	login.buttons[0].Set_y(login.Get_y()+40);
	login.buttons[0].Set_w(100);
	login.buttons[0].Set_h(25);
	login.buttons[1].Set_lable("   LOAD");
	login.buttons[1].Set_x(login.Get_x()+25);
	login.buttons[1].Set_y(login.Get_y()+80);
	login.buttons[1].Set_w(100);
	login.buttons[1].Set_h(25);

	login.buttons[2].Set_lable( "   Exit");
	login.buttons[2].Set_x(login.Get_x()+25);
	login.buttons[2].Set_y(login.buttons[1].Get_y()+50);
	login.buttons[2].Set_w(100);
	login.buttons[2].Set_h(25);




	login.draw(bmp);

	login.buttons[0].draw(bmp);
	login.buttons[1].draw(bmp);
	login.buttons[2].draw(bmp);

//username =	
//login.textboxs[0].draw(bmp); //returns username
//password = 	
//login.textboxs[1].draw(bmp); //returns password
//serverIP = 	
//login.textboxs[2].draw(bmp); //returns serverIP

if (!(mouse_b & 1))
{
login.mx = mouse_x;
login.my = mouse_y;
}
	login.mouse[0].draw(bmp);
	if (mouse_b & 1&&clicked==false)
		//if (is_doubleclick())
		{
			
			if(login.is_collision( login.mouse[0]))
			{
				if(!login.buttons[0].is_collision( login.mouse[0]))
				{
					if(!login.buttons[1].is_collision( login.mouse[0]))
					{
					
								//login.Set_x( mouse_x );
								//login.Set_y( mouse_y );
										login.mov=mouse_x -login.mx;
										login.mov2=mouse_y - login.my;
										login.mx = mouse_x;
										login.my = mouse_y;
										
										login.Set_x( login.Get_x()+login.mov);
										login.Set_y( login.Get_y()+login.mov2);
										
										login.mov = 0;
										login.mov2 = 0;
										//mouse_x = login.mov + login.Get_x();
										//mouse_y = login.mov2 + login.Get_y();
							
					}
				}
			}
			
		if(login.buttons[0].is_collision( login.mouse[0]))
			{
				clicked=true;
				login.buttons[0].Set_state(1);
					

			
				return 1;//new game menu
			}
			else
			{
				login.buttons[0].Set_state(0);
			}
			if(login.buttons[1].is_collision( login.mouse[0]))
			{
				clicked=true;
				login.buttons[1].Set_state(1);
				
					return 2;//load game menu
			}
			else
			{
				login.buttons[1].Set_state(0);

			}

			if(login.buttons[2].is_collision( login.mouse[0]))
			{
				clicked=true;
				login.buttons[2].Set_state(1);
				//do this buttons stuff exit
				return -1;//Exit game
			}
			else
			{
				login.buttons[2].Set_state(0);
			}

			
		}
	else if(!(mouse_b &2)&&!(mouse_b &1))
	{
		clicked=false;
	}
return 0; //are you done drawing
}





int draw_loadmenu(BITMAP* bmp)
{

	loadmenu.buttons[0].Set_lable( "  Jordy");
	loadmenu.buttons[0].Set_x(loadmenu.Get_x()+25);
	loadmenu.buttons[0].Set_y(loadmenu.Get_y()+40);
	loadmenu.buttons[0].Set_w(100);
	loadmenu.buttons[0].Set_h(25);

	loadmenu.buttons[1].Set_lable(" Piccolo");
	loadmenu.buttons[1].Set_x(loadmenu.Get_x()+25);
	loadmenu.buttons[1].Set_y(loadmenu.Get_y()+80);
	loadmenu.buttons[1].Set_w(100);
	loadmenu.buttons[1].Set_h(25);

	loadmenu.buttons[2].Set_lable( "  NO DATA");
	loadmenu.buttons[2].Set_x(loadmenu.Get_x()+25);
	loadmenu.buttons[2].Set_y(loadmenu.buttons[1].Get_y()+50);
	loadmenu.buttons[2].Set_w(100);
	loadmenu.buttons[2].Set_h(25);




	loadmenu.draw(bmp);

	loadmenu.buttons[0].draw(bmp);
	loadmenu.buttons[1].draw(bmp);
	loadmenu.buttons[2].draw(bmp);



if (!(mouse_b & 1))
{
	loadmenu.mx = mouse_x;
	loadmenu.my = mouse_y;
}
	loadmenu.mouse[0].draw(bmp);
	if (mouse_b & 1&&clicked==false)
		//if (is_doubleclick())
		{
			
			if(loadmenu.is_collision( loadmenu.mouse[0]))
			{
				if(!loadmenu.buttons[0].is_collision( loadmenu.mouse[0]))
				{
					if(!loadmenu.buttons[1].is_collision( loadmenu.mouse[0]))
					{
					
								//login.Set_x( mouse_x );
								//login.Set_y( mouse_y );
										loadmenu.mov=mouse_x -loadmenu.mx;
										loadmenu.mov2=mouse_y - loadmenu.my;
										loadmenu.mx = mouse_x;
										loadmenu.my = mouse_y;
										
										loadmenu.Set_x( loadmenu.Get_x()+loadmenu.mov);
										loadmenu.Set_y( loadmenu.Get_y()+loadmenu.mov2);
										
										loadmenu.mov = 0;
										loadmenu.mov2 = 0;
										//mouse_x = login.mov + login.Get_x();
										//mouse_y = login.mov2 + login.Get_y();
							
					}
				}
			}
			
		if(loadmenu.buttons[0].is_collision( loadmenu.mouse[0]))
			{
				clicked=true;
				loadmenu.buttons[0].Set_state(1);
					

			
				return 1;//new game menu
			}
			
			if(loadmenu.buttons[1].is_collision( loadmenu.mouse[0]))
			{
				clicked=true;
				loadmenu.buttons[1].Set_state(1);
				
					return 2;//load game menu
			}
			

			if(loadmenu.buttons[2].is_collision( loadmenu.mouse[0]))
			{
				clicked=true;
				loadmenu.buttons[2].Set_state(1);
				//do this buttons stuff exit
				return -1;//Exit game
			}
			
			
		}
else if(!(mouse_b &2)&&!(mouse_b &1))
	{
loadmenu.buttons[0].Set_state(0);
loadmenu.buttons[1].Set_state(0);
loadmenu.buttons[2].Set_state(0);
		clicked=false;
	}
return 0; //are you done drawing
}




/*
struct BoundingBox
{
    // Data


    int x,y,w,h;
	int button;
    int color;

    // Methods
    void draw(BITMAP *bmp)
    {
		bom1 = load_bitmap("bm1.bmp", NULL);
		bom2 = load_bitmap("buttons.bmp",NULL);
if (button ==1)
{ 
bt=bom1;
}
else
{
 bt=bom2;
}

		//this colors both boxs


	//	bm1 = load_bitmap("bm1.bmp", NULL);
		//blit(bt , bufferd , 0 , 0 , 0 , 0 , 0 , 0 );
		blit(bt , bmp , 0 , 0 , x , y , 88 , 24 );
        //rectfill(bmp, x,y,x+w-1,y+h-1,color);
		//this outlines both boxs
        rect(bmp, x,y,x+w-1,y+h-1,makecol(255,255,255));
    };

    void undraw(BITMAP *bmp)
    {

       rectfill(bmp, x,y,x+w-1,y+h-1,0);
    };
};


int is_collision(BoundingBox a, BoundingBox b)
{
    if ((a.x > b.x + b.w -1) || // is a on the right side
        (a.y > b.y + b.h -1) || // is a under
        (b.x > a.x + a.w -1) || // is b on the right side
        (b.y > a.y + a.h -1))   // is b under
    {
        // this means that there is no collision
        return 0; // means no colide
    }

    return 1; // means colide
}





void menus()
{
if (guimenu==1)
        {
    BoundingBox mobile,immobile,immobile2;
    BITMAP *bufferd;

  

gui=load_datafile("gui.dat");
//set_palette((RGB*)gui[MY_PAL2].dat);

    srand(time(NULL));
    text_mode(-1);

    bufferd=create_bitmap(SCREEN_W,SCREEN_H);
    clear_bitmap(bufferd);

    // let's create an immoblie box
    immobile.x = 400;
    immobile.y = 300;
    immobile.w =88;
    immobile.h =24;
    immobile.color = makecol(0,0,255);

 // let's create an immoblie box
	immobile2.x =300;
    immobile2.y =200;
    immobile2.w =88;
    immobile2.h =24;
    immobile2.color = makecol(0,0,255);

    // our mobile box uses the mouse coordinates
    mobile.w = 2;
    mobile.h = 2;
    //mobile.color = makecol(0,255,0);

    // so the mobile doesn't move beyond the screen
    set_mouse_range(0,0,SCREEN_W-mobile.w,SCREEN_H-mobile.h);

    while (!key[KEY_F12])
    {
        mobile.x = mouse_x;
        mobile.y = mouse_y;

        immobile.draw(bufferd);

		immobile2.draw(bufferd);

if (mouse_b & 1)
		{
			
			
if (is_collision(mobile, immobile))
        {
immobile.button =2;
            immobile.color = makecol(255,0,0);
        }
       
}
 else
        {
immobile.button =1;
            immobile.color = makecol(0,0,255);
        }
*/

/*
        if (is_collision(mobile, immobile))
        {
            immobile.color = makecol(255,0,0);
        }
        else
        {
            immobile.color = makecol(0,0,255);
        }
*/
/*
if (mouse_b & 1)
		{
		if (is_collision(mobile, immobile2))
        {
immobile2.button =2;
            immobile2.color = makecol(255,0,0);
        }
}
        else
        {
immobile2.button =1;
            immobile2.color = makecol(0,0,255);
        }

        textout(bufferd,font,"Bounding Boxes",4,4,makecol(255,255,255));



        //mobile.draw(bufferd);

do_trans(bufferd);
        //acquire_screen();

		//blit(bufferd,bufferd,0,0,0,0,SCREEN_W,SCREEN_H);
        masked_blit(bufferd,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		     //  release_screen();
show_mouse( screen );
        //mobile.undraw(bufferd);
//destroy_bitmap(bm1);

    };
	
		if (key[KEY_ESC])
		{

unload_datafile(gui);
destroy_bitmap(bufferd);        
destroy_bitmap(bom1);
destroy_bitmap(bom2);
destroy_bitmap(bt);
 
		}

		}
		
}

*/


/*
//later
int guimenu;
//MakeTrans(Need_this_one_trans);

BITMAP *bom1;
BITMAP *bom2;
BITMAP *bt;
BITMAP *bufferd;
struct BoundingBox
{
    // Data


    int x,y,w,h;
    int color,button;

    // Methods
    void draw(BITMAP *bmp) 
    {
		//this colors both boxs


		bom1 = load_bitmap("bm1.bmp", NULL);
		bom2 = load_bitmap("buttons.bmp",NULL);
if (button ==1)
{ 
bt=bom1;
}
else
{
 bt=bom2;
}

	masked_blit( bt, bufferd , 0 , 0 , x , y , 88 , 24 );

      //  rectfill(bmp, x,y,x+w-1,y+h-1,color);
		//this outlines both boxs
        //rect(bmp, x,y,x+w-1,y+h-1,makecol(255,255,255));
    };
/*
    void undraw(BITMAP *bmp)
    {

        rectfill(bmp, x,y,x+w-1,y+h-1,0);
    };
*/
/*	
};


int is_collision(BoundingBox a, BoundingBox b)
{
    if ((a.x > b.x + b.w -1) || // is a on the right side
        (a.y > b.y + b.h -1) || // is a under
        (b.x > a.x + a.w -1) || // is b on the right side
        (b.y > a.y + a.h -1))   // is b under
    {
        // this means that there is no collision
        return 0; // means no colide
    }; 

    return 1; // means colide
};




void menus()
{
if (guimenu==1)
        {
    BoundingBox mobile,immobile,immobile2;
    //BITMAP *bufferd;
 
    

    //srand(time(NULL));
    //text_mode(-1);

    //bufferd=create_bitmap(SCREEN_W,SCREEN_H);
   // clear_bitmap(bufferd);

    // let's create an immoblie box
    immobile.x =
    immobile.y =
    immobile.w =88;
    immobile.h = 24;
	immobile.button = 2;
    immobile.color = makecol(0,0,255);

 // let's create an immoblie box
    immobile2.x =300;
    immobile2.y =200;
    immobile2.w =88;
    immobile2.h =24;
	immobile2.button = 2;
    immobile2.color = makecol(0,0,255);

    // our mobile box uses the mouse coordinates
    mobile.w = 
    mobile.h = 10;
	mobile.button = 2;

    //mobile.color = makecol(0,255,0);

    // so the mobile doesn't move beyond the screen
    set_mouse_range(0,0,SCREEN_W-mobile.w,SCREEN_H-mobile.h);
//if (guimenu==1)
  //  {
   while (guimenu==1)
    {
        mobile.x = mouse_x;
        mobile.y = mouse_y;

     // immobile.draw(bufferd);

	immobile2.draw(bufferd);

if (mouse_b & 1)
		{
			
			
if (is_collision(mobile, immobile))
        {
immobile.button =1;
           // immobile.color = makecol(255,0,0);
        }
       
}
 else
        {
immobile.button =2;
            immobile.color = makecol(0,0,255);
        }


/*
        if (is_collision(mobile, immobile))
        {
            immobile.color = makecol(255,0,0);
        }
        else
        {
            immobile.color = makecol(0,0,255);
        }

		if (is_collision(mobile, immobile2))
        {

           immobile2.color = makecol(255,0,0);
        }
        else
        {
            immobile2.color = makecol(0,0,255);
        }
};
       // textout(bufferd,font,"Bounding Boxes",4,4,makecol(255,255,255));

       //mobile.draw(bufferd);
//do_trans2(screen);
//show_mouse( screen );
        //acquire_screen();
        masked_blit(bufferd,buffer,0,0,0,0,SCREEN_W,SCREEN_H);
        //release_screen();

       // mobile.undraw(bufferd);



}
if (guimenu==0)
        {

destroy_bitmap(bufferd);        
destroy_bitmap(bom1);
destroy_bitmap(bom2);
destroy_bitmap(bt);
   
       }
    }

  
//}

*/
int draw_mainGUI(BITMAP* bmp)
{

	mainGUI.buttons[0].Set_lable( " Stats");
	mainGUI.buttons[0].Set_x(mainGUI.Get_x()+370);
	mainGUI.buttons[0].Set_y(mainGUI.Get_y()+10);
	mainGUI.buttons[0].Set_w(75);
	mainGUI.buttons[0].Set_h(25);
	mainGUI.buttons[0].Set_scolor(255,0,255);
	mainGUI.buttons[0].Set_ecolor(255,0,0);

	mainGUI.buttons[1].Set_lable(" Itmes");
	mainGUI.buttons[1].Set_x(mainGUI.buttons[0].Get_x()+80);
	mainGUI.buttons[1].Set_y(mainGUI.Get_y()+10);
	mainGUI.buttons[1].Set_w(75);
	mainGUI.buttons[1].Set_h(25);
	mainGUI.buttons[1].Set_scolor(255,0,255);
	mainGUI.buttons[1].Set_ecolor(255,0,0);


	mainGUI.buttons[2].Set_lable( "  Map");
	mainGUI.buttons[2].Set_x(mainGUI.buttons[1].Get_x()+80);
	mainGUI.buttons[2].Set_y(mainGUI.Get_y()+10);
	mainGUI.buttons[2].Set_w(75);
	mainGUI.buttons[2].Set_h(25);
	mainGUI.buttons[2].Set_scolor(255,0,255);
	mainGUI.buttons[2].Set_ecolor(255,0,0);
///comands

	mainGUI.buttons[3].Set_lable( " ");
	mainGUI.buttons[3].Set_img("trade.bmp");
	mainGUI.buttons[3].Set_x(mainGUI.Get_x()+555);
	mainGUI.buttons[3].Set_y(mainGUI.Get_y()+430);
	mainGUI.buttons[3].Set_w(40);
	mainGUI.buttons[3].Set_h(40);
	mainGUI.buttons[3].Set_scolor(255,0,255);
	mainGUI.buttons[3].Set_ecolor(255,0,0);

	mainGUI.buttons[4].Set_lable( " ");
	mainGUI.buttons[4].Set_img("potrol.bmp");
	mainGUI.buttons[4].Set_x(mainGUI.buttons[3].Get_x()+42);
	mainGUI.buttons[4].Set_y(mainGUI.Get_y()+430);
	mainGUI.buttons[4].Set_w(40);
	mainGUI.buttons[4].Set_h(40);
	mainGUI.buttons[4].Set_scolor(255,0,255);
	mainGUI.buttons[4].Set_ecolor(255,0,0);


	mainGUI.buttons[5].Set_lable( " ");
	mainGUI.buttons[5].Set_img("move.bmp");
	mainGUI.buttons[5].Set_x(mainGUI.Get_x()+470);
	mainGUI.buttons[5].Set_y(mainGUI.Get_y()+390);
	mainGUI.buttons[5].Set_w(40);
	mainGUI.buttons[5].Set_h(40);
	mainGUI.buttons[5].Set_scolor(255,0,255);
	mainGUI.buttons[5].Set_ecolor(255,0,0);

	mainGUI.buttons[6].Set_lable( " ");
	mainGUI.buttons[6].Set_img("stop.bmp");
	mainGUI.buttons[6].Set_x(mainGUI.buttons[5].Get_x()+42);
	mainGUI.buttons[6].Set_y(mainGUI.Get_y()+390);
	mainGUI.buttons[6].Set_w(40);
	mainGUI.buttons[6].Set_h(40);
	mainGUI.buttons[6].Set_scolor(255,0,255);
	mainGUI.buttons[6].Set_ecolor(255,0,0);


	mainGUI.buttons[7].Set_lable( " ");
	mainGUI.buttons[7].Set_img("hold.bmp");
	mainGUI.buttons[7].Set_x(mainGUI.buttons[6].Get_x()+42);
	mainGUI.buttons[7].Set_y(mainGUI.Get_y()+390);
	mainGUI.buttons[7].Set_w(40);
	mainGUI.buttons[7].Set_h(40);
	mainGUI.buttons[7].Set_scolor(255,0,255);
	mainGUI.buttons[7].Set_ecolor(255,0,0);


	mainGUI.buttons[8].Set_lable( " ");
	mainGUI.buttons[8].Set_img("attack.bmp");
	mainGUI.buttons[8].Set_x(mainGUI.buttons[7].Get_x()+42);
	mainGUI.buttons[8].Set_y(mainGUI.Get_y()+390);
	mainGUI.buttons[8].Set_w(40);
	mainGUI.buttons[8].Set_h(40);
	mainGUI.buttons[8].Set_scolor(255,0,255);
	mainGUI.buttons[8].Set_ecolor(255,0,0);




	mainGUI.draw(bmp);

	mainGUI.buttons[0].draw(bmp);
	mainGUI.buttons[1].draw(bmp);
	mainGUI.buttons[2].draw(bmp);
	if(show_comands==true)
	{

	mainGUI.buttons[3].draw(bmp);
	mainGUI.buttons[4].draw(bmp);
	mainGUI.buttons[5].draw(bmp);
	mainGUI.buttons[6].draw(bmp);
	mainGUI.buttons[7].draw(bmp);
	mainGUI.buttons[8].draw(bmp);
	}
//username =	
//mainGUI.textboxs[0].draw(bmp); //returns username
//password = 	
//mainGUI.textboxs[1].draw(bmp); //returns password
//serverIP = 	
//mainGUI.textboxs[2].draw(bmp); //returns serverIP

if (!(mouse_b & 1))
{
//mainGUI.mx = mouse_x;
//mainGUI.my = mouse_y;
}




	mainGUI.mouse[0].draw(bmp);
	if (mouse_b & 1 && clicked==false)
		//if (is_doubleclick())
		{
		
			if(mainGUI.is_collision( mainGUI.mouse[0]))
			{
				if(!mainGUI.buttons[0].is_collision( mainGUI.mouse[0]))
				{
					if(!mainGUI.buttons[1].is_collision( mainGUI.mouse[0]))
					{
						if(!mainGUI.buttons[2].is_collision( mainGUI.mouse[0]))
						{
							if(!mainGUI.buttons[3].is_collision( mainGUI.mouse[0]))
							{
								if(!mainGUI.buttons[4].is_collision( mainGUI.mouse[0]))
								{
									if(!mainGUI.buttons[5].is_collision( mainGUI.mouse[0]))
									{
										if(!mainGUI.buttons[6].is_collision( mainGUI.mouse[0]))
										{
											if(!mainGUI.buttons[7].is_collision( mainGUI.mouse[0]))
											{
												if(!mainGUI.buttons[8].is_collision( mainGUI.mouse[0]))
												{

								//mainGUI.Set_x( mouse_x );
								//mainGUI.Set_y( mouse_y );
										//mainGUI.mov=mouse_x -mainGUI.mx;
										//mainGUI.mov2=mouse_y - mainGUI.my;
										//mainGUI.mx = mouse_x;
									//	mainGUI.my = mouse_y;
										
										//mainGUI.Set_x( mainGUI.Get_x()+mainGUI.mov);
									//	mainGUI.Set_y( mainGUI.Get_y()+mainGUI.mov2);
										
									//	mainGUI.mov = 0;
									//	mainGUI.mov2 = 0;
										//mouse_x = mainGUI.mov + mainGUI.Get_x();
									//mouse_y = mainGUI.mov2 + mainGUI.Get_y();
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			
		if(mainGUI.buttons[0].is_collision( mainGUI.mouse[0]))
			{
			clicked=true;
				mainGUI.buttons[0].Set_state(1);
					
				if(equiped==true)
				{
					equiped=false;
				}
				else
				{
					equiped=true;
				}
			
				return 1;//new game menu
			}
			
			if(mainGUI.buttons[1].is_collision( mainGUI.mouse[0]))
			{
			clicked=true;
				mainGUI.buttons[1].Set_state(1);

				if(invnetomenu==true)
				{
					invnetomenu=false;
				}
				else
				{
					invnetomenu=true;
				}				
				return 2;

			}
			

			if(mainGUI.buttons[2].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[2].Set_state(1);
				if(miniMaponc==true)
				{
					miniMaponc=false;
				}
				else
				{
					miniMaponc=true;
				}				
				return -1;
			}
			if(mainGUI.buttons[3].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[3].Set_state(1);
				if(miniMaponc==true)
				{
					miniMaponc=false;
				}
				else
				{
					miniMaponc=true;
				}				
				return -1;
			}
			if(mainGUI.buttons[4].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[4].Set_state(1);
				if(miniMaponc==true)
				{
					miniMaponc=false;
				}
				else
				{
					miniMaponc=true;
				}				
				return -1;
			}
			if(mainGUI.buttons[5].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[5].Set_state(1);
				mousePointer=1;		
				return -1;
			}
			if(mainGUI.buttons[6].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[6].Set_state(1);
				mousePointer=0;				
				return -1;
			}
			if(mainGUI.buttons[7].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[7].Set_state(1);
				if(miniMaponc==true)
				{
					miniMaponc=false;
				}
				else
				{
					miniMaponc=true;
				}				
				return -1;
			}
			if(mainGUI.buttons[8].is_collision( mainGUI.mouse[0]))
			{
				clicked=true;
				mainGUI.buttons[8].Set_state(1);

outboxbuffer += charnetId+"|0|014|"+ NumberToString(charnetId)+','+ "4"+'~';
				/*if(miniMaponc==true)
				{
					miniMaponc=false;
				}
				else
				{
					miniMaponc=true;
				}*/				
				return -1;
			}

			
			
		}
		else if(!(mouse_b &2)&&!(mouse_b &1))
		{
			
			mainGUI.buttons[0].Set_state(0);
			mainGUI.buttons[1].Set_state(0);
			mainGUI.buttons[2].Set_state(0);
			mainGUI.buttons[3].Set_state(0);
			mainGUI.buttons[4].Set_state(0);
			mainGUI.buttons[5].Set_state(0);
			mainGUI.buttons[6].Set_state(0);
			mainGUI.buttons[7].Set_state(0);
			mainGUI.buttons[8].Set_state(0);
			clicked=false;
	}

return 0; //are you done drawing
}






int draw_trade(BITMAP* bmp,ItemList itemsl,Character *player1,Character *player2)
{

for(int i=0; i <player1->itembag.slotsperpage;i++)
{
	if(player1->itembag.items[i].something_in_slot==true)
	{
		trade.buttons[i].Set_lable( NumberToString(player1->itembag.items[i].nuberofitems) +" "+itemsl.Items[player1->itembag.items[i].itemid]->Get_name());
	}
	else
	{
		trade.buttons[i].Set_lable( " empty slot");
	}

	trade.buttons[i].Set_x(trade.Get_x()+10);
	if(i==0)
	{
		trade.buttons[i].Set_y(trade.Get_y()+20);
	}
	else
	{
		trade.buttons[i].Set_y(trade.buttons[i-1].Get_y()+40);
	}
	trade.buttons[i].Set_w(100);
	trade.buttons[i].Set_h(25);
	trade.buttons[i].Set_scolor(255,0,255);
	trade.buttons[i].Set_ecolor(255,0,0);
}


for( i=player1->itembagtotrade.slotsperpage; i <player1->itembagtotrade.slotsperpage*2;i++)
{
	if(player1->itembagtotrade.items[i-5].something_in_slot==true)
	{
		trade.buttons[i].Set_lable( NumberToString(player1->itembagtotrade.items[i-5].nuberofitems) +" "+itemsl.Items[player1->itembagtotrade.items[i-5].itemid]->Get_name());
	}
	else
	{
		trade.buttons[i].Set_lable( " empty slot");
	}

	trade.buttons[i].Set_x(trade.buttons[i-5].Get_x()+105);
	if(i==5)
	{
		trade.buttons[i].Set_y(trade.Get_y()+20);
	}
	else
	{
		trade.buttons[i].Set_y(trade.buttons[i-1].Get_y()+40);
	}
	trade.buttons[i].Set_w(100);
	trade.buttons[i].Set_h(25);
	trade.buttons[i].Set_scolor(255,0,255);
	trade.buttons[i].Set_ecolor(255,0,0);
}

for( i=player2->itembagtotrade.slotsperpage*2; i <player2->itembagtotrade.slotsperpage*3;i++)
{
	if(player2->itembagtotrade.items[i-10].something_in_slot==true)
	{
		trade.buttons[i].Set_lable( NumberToString(player2->itembagtotrade.items[i-10].nuberofitems) +" "+itemsl.Items[player2->itembagtotrade.items[i-10].itemid]->Get_name());
	}
	else
	{
		trade.buttons[i].Set_lable( " empty slot");
	}

	trade.buttons[i].Set_x(trade.buttons[i-5].Get_x()+165);
	if(i==10)
	{
		trade.buttons[i].Set_y(trade.Get_y()+20);
	}
	else
	{
		trade.buttons[i].Set_y(trade.buttons[i-1].Get_y()+40);
	}
	trade.buttons[i].Set_w(100);
	trade.buttons[i].Set_h(25);
	trade.buttons[i].Set_scolor(255,0,255);
	trade.buttons[i].Set_ecolor(255,0,0);
}

for( i=player2->itembag.slotsperpage*3; i <player2->itembag.slotsperpage*4;i++)
{
	if(player2->itembag.items[i-15].something_in_slot==true)
	{
		trade.buttons[i].Set_lable( NumberToString(player2->itembag.items[i-15].nuberofitems) +" "+itemsl.Items[player2->itembag.items[i-15].itemid]->Get_name());
	}
	else
	{
		trade.buttons[i].Set_lable( " empty slot");
	}

	trade.buttons[i].Set_x(trade.buttons[i-5].Get_x()+105);
	if(i==15)
	{
		trade.buttons[i].Set_y(trade.Get_y()+20);
	}
	else
	{
		trade.buttons[i].Set_y(trade.buttons[i-1].Get_y()+40);
	}
	trade.buttons[i].Set_w(100);
	trade.buttons[i].Set_h(25);
	trade.buttons[i].Set_scolor(255,0,255);
	trade.buttons[i].Set_ecolor(255,0,0);
}

	trade.buttons[20].Set_lable( NumberToString(player1->get_attributess()->Getgold())+" Gold");
	trade.buttons[20].Set_x(trade.Get_x()+10);
	trade.buttons[20].Set_y(trade.buttons[19].Get_y()+40);
	trade.buttons[20].Set_w(100);
	trade.buttons[20].Set_h(25);
	trade.buttons[20].Set_scolor(255,0,255);
	trade.buttons[20].Set_ecolor(255,0,0);

	trade.buttons[21].Set_lable( NumberToString(player1->get_attributess()->goldtotrade)+" Gold");
	trade.buttons[21].Set_x(trade.buttons[20].Get_x() +105);
	trade.buttons[21].Set_y(trade.buttons[20].Get_y());
	trade.buttons[21].Set_w(100);
	trade.buttons[21].Set_h(25);
	trade.buttons[21].Set_scolor(255,0,255);
	trade.buttons[21].Set_ecolor(255,0,0);

	trade.buttons[22].Set_lable( NumberToString(player2->get_attributess()->goldtotrade)+" Gold");
	trade.buttons[22].Set_x(trade.buttons[21].Get_x()+165);
	trade.buttons[22].Set_y(trade.buttons[20].Get_y());
	trade.buttons[22].Set_w(100);
	trade.buttons[22].Set_h(25);
	trade.buttons[22].Set_scolor(255,0,255);
	trade.buttons[22].Set_ecolor(255,0,0);

	trade.buttons[23].Set_lable( NumberToString(player2->get_attributess()->Getgold())+" Gold");
	trade.buttons[23].Set_x(trade.buttons[22].Get_x()+105 );
	trade.buttons[23].Set_y(trade.buttons[20].Get_y());
	trade.buttons[23].Set_w(100);
	trade.buttons[23].Set_h(25);
	trade.buttons[23].Set_scolor(255,0,255);
	trade.buttons[23].Set_ecolor(255,0,0);





	trade.buttons[24].Set_lable( " OK ");
	trade.buttons[24].Set_x(trade.Get_x()+115);
	trade.buttons[24].Set_y(trade.Get_y()+255);
	trade.buttons[24].Set_w(100);
	trade.buttons[24].Set_h(25);
	trade.buttons[24].Set_scolor(255,0,255);
	trade.buttons[24].Set_ecolor(255,0,0);

	trade.buttons[25].Set_lable( "Cancel ");
	trade.buttons[25].Set_x(trade.buttons[24].Get_x() +165);
	trade.buttons[25].Set_y(trade.buttons[24].Get_y());
	trade.buttons[25].Set_w(100);
	trade.buttons[25].Set_h(25);
	trade.buttons[25].Set_scolor(255,0,255);
	trade.buttons[25].Set_ecolor(255,0,0);




	trade.draw(bmp);
for( i=0; i <(player1->itembag.slotsperpage*4)+6;i++)
{
	trade.buttons[i].draw(bmp);
}

if (!(mouse_b & 1))
{
trade.mx = mouse_x;
trade.my = mouse_y;
}
	trade.mouse[0].draw(bmp);
	if (mouse_b & 1 && clicked==false)
		//if (is_doubleclick())
		{
			
			
				bool col=false;

			if(trade.is_collision( trade.mouse[0]))
			{
				for( i=0; i <(player1->itembag.slotsperpage *4)+6;i++)
				{
					if(!trade.buttons[0].is_collision( trade.mouse[0]))
					{
						col=false;
						break;
					}
					else
					{
						col=true;

					}



				}
				if(col==true)
				{
					
				//trade.Set_x( mouse_x );
				//trade.Set_y( mouse_y );
						trade.mov=mouse_x -trade.mx;
						trade.mov2=mouse_y - trade.my;
						trade.mx = mouse_x;
						trade.my = mouse_y;
						
						trade.Set_x( trade.Get_x()+trade.mov);
						trade.Set_y( trade.Get_y()+trade.mov2);
						
						trade.mov = 0;
						trade.mov2 = 0;
						//mouse_x = trade.mov + trade.Get_x();
						//mouse_y = trade.mov2 + trade.Get_y();
				}
				
			}

for( i=0; i <player1->itembag.slotsperpage;i++)
{
	if(player1->itembagtotrade.items[i].something_in_slot==true)
	{
		if(trade.buttons[i].is_collision( trade.mouse[0]))
		{
			clicked=true;
			trade.buttons[i].Set_state(1);
			if(player1->itembag.items[i].something_in_slot==false)
			{
				player1->itembag.items[i].something_in_slot=true;
				player1->itembag.items[i].itemid=player1->itembagtotrade.items[i].itemid;
			}
			
			player1->itembagtotrade.items[i].nuberofitems--;
			player1->itembag.items[i].nuberofitems++;
			if(player1->itembagtotrade.items[i].nuberofitems==0)
			{
				player1->itembagtotrade.items[i].something_in_slot=false;
			}
		return i;
		}
	
	
	
	}
	
	


}			
for( i=player1->itembagtotrade.slotsperpage; i <player1->itembagtotrade.slotsperpage*2;i++)
{
	if(player1->itembag.items[i-5].something_in_slot==true)
	{
		if(trade.buttons[i].is_collision( trade.mouse[0]))
		{
			trade.buttons[i].Set_state(1);
			clicked=true;
			if(player1->itembagtotrade.items[i-5].something_in_slot==false)
			{
				player1->itembagtotrade.items[i-5].something_in_slot=true;
				player1->itembagtotrade.items[i-5].itemid=player1->itembag.items[i-5].itemid;
			}
			
			player1->itembag.items[i-5].nuberofitems--;
			player1->itembagtotrade.items[i-5].nuberofitems++;
			if(player1->itembag.items[i-5].nuberofitems==0)
			{
				player1->itembag.items[i-5].something_in_slot=false;
			}
		return i;
		}
	
	
	
	}
	
	


}

			
for( i=player2->itembagtotrade.slotsperpage*2; i <player2->itembagtotrade.slotsperpage*3;i++)
{
	if(player2->itembag.items[i-10].something_in_slot==true)
	{
		if(trade.buttons[i].is_collision( trade.mouse[0]))
		{
			trade.buttons[i].Set_state(1);
			clicked=true;
			if(player2->itembagtotrade.items[i-10].something_in_slot==false)
			{
				player2->itembagtotrade.items[i-10].something_in_slot=true;
				player2->itembagtotrade.items[i-10].itemid=player2->itembag.items[i-10].itemid;
			}
			
			player2->itembag.items[i-10].nuberofitems--;
			player2->itembagtotrade.items[i-10].nuberofitems++;
			if(player2->itembag.items[i-10].nuberofitems==0)
			{
				player2->itembag.items[i-10].something_in_slot=false;
			}
		return i;
		}
	
	
	
	}
	
	


}



for( i=player2->itembagtotrade.slotsperpage*3; i <player2->itembag.slotsperpage*4;i++)
{
	if(player2->itembagtotrade.items[i-15].something_in_slot==true)
	{
		if(trade.buttons[i].is_collision( trade.mouse[0]))
		{
			clicked=true;
			trade.buttons[i].Set_state(1);
			if(player2->itembag.items[i-15].something_in_slot==false)
			{
				player2->itembag.items[i-15].something_in_slot=true;
				player2->itembag.items[i-15].itemid=player2->itembagtotrade.items[i-15].itemid;
			}
			
			player2->itembagtotrade.items[i-15].nuberofitems--;
			player2->itembag.items[i-15].nuberofitems++;
			if(player2->itembagtotrade.items[i-15].nuberofitems==0)
			{
				player2->itembagtotrade.items[i-15].something_in_slot=false;
			}
		return i;
		}
	
	
	
	}


}




	if(player1->get_attributess()->Getgold()>0)
	{
		if(trade.buttons[21].is_collision( trade.mouse[0]))
		{
			clicked=true;
		trade.buttons[21].Set_state(1);
			
			player1->get_attributess()->Setgold(player1->get_attributess()->Getgold()-1);
			player1->get_attributess()->goldtotrade++;
			
		return i;
		}
	}

	if(player1->get_attributess()->goldtotrade>0)
	{
		if(trade.buttons[20].is_collision( trade.mouse[0]))
		{
			clicked=true;
		trade.buttons[20].Set_state(1);
			
			
			player1->get_attributess()->goldtotrade--;
			player1->get_attributess()->Setgold(player1->get_attributess()->Getgold()+1);
			
		return i;
		}
	}

if(player2->get_attributess()->Getgold()>0)
	{
		if(trade.buttons[22].is_collision( trade.mouse[0]))
		{
			clicked=true;
		
			trade.buttons[22].Set_state(1);
			player2->get_attributess()->Setgold(player2->get_attributess()->Getgold()-1);
			player2->get_attributess()->goldtotrade++;
			
		return i;
		}
	}

	if(player2->get_attributess()->goldtotrade>0)
	{
		if(trade.buttons[23].is_collision( trade.mouse[0]))
		{
			clicked=true;
		
			trade.buttons[23].Set_state(1);
			
			player2->get_attributess()->goldtotrade--;
			player2->get_attributess()->Setgold(player1->get_attributess()->Getgold()+1);
			
		return i;
		}
	}


if(trade.buttons[24].is_collision( trade.mouse[0]))
{
			clicked=true;
		trade.buttons[24].Set_state(1);
			
		
		return -2;
}


if(trade.buttons[25].is_collision( trade.mouse[0]))
{
			clicked=true;
		
		trade.buttons[25].Set_state(1);	
		
			
	return -1;
}










/*
		for( i=0; i <player1->itembag.slotsperpage;i++)
		{

			if(trade.buttons[i].is_collision( trade.mouse[0]))
			{
				clicked=true;
				trade.buttons[i].Set_state(1);
				//do this buttons stuff trade
				
				
					if(player1->itembag.useitem(i)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(player1->itembag.items[i].itemid)+ "`~";//rig
	//sleep(9999);
					//	}
					}

				return i;
			}

		}

*/
/*
		if(trade.buttons[0].is_collision( trade.mouse[0]))
		{
			clicked=true;
				trade.buttons[0].Set_state(1);
				//do this buttons stuff trade
				
				
					if(player1->itembag.useitem(0)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(player1->itembag.items[0].itemid)+ "`~";//rig
	//sleep(9999);
					//	}
					}

				return 1;
			}
			if(trade.buttons[1].is_collision( trade.mouse[0]))
			{
				clicked=true;
				trade.buttons[1].Set_state(1);
				//do this buttons stuff new acount
					if(player1->itembag.useitem(1)==true)
					{
						//if(computerId!=0)
						//{
							
							inboxbuffer +="0|" + NumberToString(charnetId) + "|011|" + NumberToString(charnetId)+ ","+NumberToString(player1->itembag.items[1].itemid)+ "`~";//rig
						//sleep(9999);
					//	}
					}
			}
		
			if(trade.buttons[2].is_collision( trade.mouse[0]))
			{
				clicked=true;
				trade.buttons[2].Set_state(1);
				//do this buttons stuff exit
				return -1;//are you done drawing
			}
			
*/
			
		}
	else if(!(mouse_b &2)&&!(mouse_b &1))
	{
		for( i=0; i <(player1->itembag.slotsperpage*4)+6;i++)
		{
			trade.buttons[i].Set_state(0);
		}
	//	trade.buttons[1].Set_state(0);
	//	trade.buttons[2].Set_state(0);
		clicked=false;
	}
return 0; //are you done drawing
}




#endif






