#include "wou.h"

int CORNER_X, CORNER_Y;
BITMAP *vbuffer;
BITMAP *gamearea;
/* ALGO DE MUITO ERRADO SE PASSA, N CONSIGO METER ESTE BMP COMO OS OUTROS
	OS OUTROS TAO COM DEFINE NO WOU.H... MERDA!!! REVER ISTO!!! E TIRAR A INCIALIZAÇAO
	NESTE FICHEIRO!!
*/
BITMAP *charsBMP;
DATAFILE *images;
DATAFILE *fonts;
DATAFILE *tiles;

int MOUSE_NUM;

int display_init() {
	int gfx_mode;

	// some window setup
	set_window_title("World of Ultima");
	set_color_depth(8);

	// load images
	if ((images = data_load("data/images.dat"))==NULL) return -1;
	if ((fonts = data_load("data/fonts.dat"))==NULL) return -1;
	if ((tiles = data_load("data/tiles.dat"))==NULL) return -1;

	// TIRAR DAQUI ISTO ##################################################
	charsBMP = (BITMAP*)tiles[TILES_CHARACTERS].dat;

	// set the screen
	if (get_config_int("misc", "fullscreen", 0))
	    gfx_mode = GFX_AUTODETECT;
	else
	    gfx_mode = GFX_AUTODETECT_WINDOWED;

	// start screen device
  if (set_gfx_mode(gfx_mode, WINDOW_W, WINDOW_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
		return -1;
	}

	// alguns settings da janela
	set_display_switch_mode(SWITCH_BACKGROUND);
	LOCK_FUNCTION(close_button_handler);
	set_close_button_callback(close_button_handler);

	// double buffer and game area screen
	vbuffer = create_bitmap(SCREEN_W, SCREEN_H);
	gamearea = create_bitmap(GAMEPLAY_W, GAMEPLAY_H);
	clear(vbuffer);
	return 0;
}

void intro_screen(int s) {
  char *copyright = "Copyright (c) 2005 OpSiSoft Systems, Inc. and Ricardo Santos";
	set_palette(black_palette);
	rest(500);
	// draw the screen
	draw_sprite(vbuffer, (BITMAP*)images[s].dat, 0, 0);
	blit(vbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
	if (s<SCREEN_MENU) {
    fade_in((RGB*)images[PALETTE_INTRO].dat, 2);
    rest(1000);
		fade_out(2);
	}
	else {
    fade_in((RGB*)images[PALETTE_MENU].dat, 2);
    textout_centre_ex(vbuffer, _smallFONT, copyright, SCREEN_W/2, SCREEN_H-12, makecol(40,40,70), -1);
    rest(150);
		textprintf_right_ex(vbuffer, _smallFONT, 495, 175, makecol(35,35,70), -1,"WoU v%.2f", VERSION);
		blit(vbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
	}
}

void display_destroy() {
  unload_datafile(images);
  unload_datafile(fonts);
  destroy_bitmap(vbuffer);
  destroy_bitmap(gamearea);
}

void display_drawHud() {
	draw_sprite(vbuffer, (BITMAP*)images[SCREEN_HUD].dat, 0, 0);
	blit(vbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
}

void diaplay_drawChat() {
	//textprintf_ex(vbuffer, (FONT*)fonts[FONT_04B11].dat, 415, 458, 40, -1,"TESTE: %c", input.text[0]);
	//blitBuffer(vbuffer);
}

