Exemple #1
0
static void show_main_dialog(void)
{
   int focus = 1;

   /* Prepare dialog.  */
   set_dialog_color(main_dialog, black, white);
   centre_dialog(main_dialog);

   /* Parse input.  */
   while (1) {
      focus = do_dialog(main_dialog, focus);
      switch (focus) {
	 case 3:
	    /* Setup all key mappings.  */
	    setup_all_keys();
	    break;
	 case 4:
	    /* Test key mappings.  */
	    test_key_map();
	    break;
	 case 5:
	    /* Save and quit.  */
	    save_key_map();
	    return;
	 case 6:
	    /* Just exit.  */
	    return;
      }
   }
}
Exemple #2
0
/* handle the setup command */
static void setup_all_keys(void)
{
   int focus = 2;
   int i;

   /* Prepare dialog.  */
   set_dialog_color(keymap_dialog, black, white);
   centre_dialog(keymap_dialog);

   /* Parse input.  */
   while (1) {
      focus = do_dialog(keymap_dialog, focus);
      switch (focus) {
	 case 2:
	 case 4:

	    textprintf_centre_ex (screen, font,
	       keymap_dialog[7].x, keymap_dialog[7].y, red, -1,
	       "Press a key to map to the current scancode");
	    textprintf_centre_ex (screen, font,
	       keymap_dialog[7].x, keymap_dialog[7].y + 8, red, -1,
	       "(or a mouse button to leave it unchanged)");

	    /* Wait for new key press.  */
	    new_keycode = -1;
	    waiting_for_key = 1;

	    do {
	       poll_keyboard();
	       poll_mouse();

	       if (mouse_b)
		  waiting_for_key = 0;
	    }
	    while (waiting_for_key);

	    /* Save keycode to scancode mapping.  */
	    if ((new_keycode >= 0) && (new_keycode < 256)) {
	       keycode_to_scancode[new_keycode] = keymap_dialog[2].d1 + 1;
	    }

	    clear_keybuf();

	    break;
	 case 5:
	    return;
	 case 6:
	    for (i = 0; i < 256; i++) {
               if (keycode_to_scancode[i] >= 0)
		  _xwin.keycode_to_scancode[i] = keycode_to_scancode[i];
            }
	    return;
      }
   }
}
Exemple #3
0
void display_text_file(char * title, char * filename, int startpos)
{
    FILE * fp;

    // what makes this next block of code unique is that i wrote it,
    // compiled it with no errors, and it worked properly the first
    // time it was run...  unheard-of, really...
    // i've since simplified it by removing references to sys/stat 
    // for file sizes, and replaced them with allegro's file_size()

    text_file_dialog[2].d2 = startpos;
    if (exists(filename))
    {
	if (text_file_buffer)
	    free(text_file_buffer);
#if 0 // GN: hmm?
	sprintf(text_file_dialog[1].dp, title);
#endif
	text_file_buffer = (char *) malloc (file_size(filename));
	if (text_file_buffer)
	{
	    fp = fopen(filename, "rb");
	    if (fp)
	    {
		fread(text_file_buffer, 1, file_size(filename), fp);
		fclose(fp);

		text_file_dialog[2].dp = text_file_buffer;

		centre_dialog(text_file_dialog);
		set_dialog_color(text_file_dialog, GUI_FORE, GUI_BACK);
		do_dialog(text_file_dialog, 2);

		if (text_file_buffer)
		    free(text_file_buffer);
	    } else {
		alert("File access error!", "Could not load file:", 
		      filename,  
		      "Continue", NULL, 0, 0);
	    }
	} else {
	    alert("Memory allocation error!", "Could not load file:", 
	          filename,  
	          "Continue", NULL, 0, 0);
	}
    } else {
	alert("Could not find file:", filename, "",   
	      "Continue", NULL, 0, 0);
    }

}
static int
save_proc(void)
{
	char filename[1024];
	char buffer[256], *p;
	BITMAP *bmp = NULL;
	int quality = 0, flags = 0;

	if (file_select_ex("Save as JPG", last_path, "jpg", 1024, (SCREEN_W * 2) / 3, (SCREEN_H * 2) / 3)) {
		strcpy(filename, last_path);
		for (p = last_path + strlen(last_path); (p >= last_path) && (*p != '/') && (*p != '\\'); p--)
			;
		*(p + 1) = '\0';
		set_dialog_color(settings_dialog, gui_fg_color, gui_bg_color);
		centre_dialog(settings_dialog);
		if (popup_dialog(settings_dialog, -1) < 0)
			return 0;
		quality = settings_dialog[QUALITY_SLIDER].d2 + 1;
		if (settings_dialog[SS_444_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_444;
		if (settings_dialog[SS_422_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_422;
		if (settings_dialog[SS_411_RADIO].flags & D_SELECTED)
			flags = JPG_SAMPLING_411;
		if (settings_dialog[GREYSCALE_CHECK].flags & D_SELECTED)
			flags |= JPG_GREYSCALE;
		if (settings_dialog[OPTIMIZE_CHECK].flags & D_SELECTED)
			flags |= JPG_OPTIMIZE;
		bmp = settings_dialog[PREVIEW].dp;

		if (save_jpg_ex(filename, bmp, NULL, quality, flags, progress_cb)) {
			sprintf(buffer, "Error saving JPG image (error code %d)", jpgalleg_error);
			alert("", buffer, "", "Ok", NULL, 0, 0);
		}
	}
	return 0;
}
		void GUITextEntryDialog::InitDialog()
		{
			/*
				int (*proc)(int, DIALOG *, int); - dialog procedure (message handler)
				int x, y, w, h;       - position and size of the object
				int fg, bg;           - foreground and background colors
				int key;              - ASCII keyboard shortcut
				int flags;            - flags about the status of the object
				int d1, d2;           - whatever you want to use them for
				void *dp, *dp2, *dp3; - pointers to more object-specific data
			*/

			// list of controls on the dialog:
			// d_box_proc			-- the entire dialog is within this box
			// d_box_proc			-- the window caption is surrounded by a box
			// d_ctext_proc			-- the window caption is centered horizontally

			// d_ctext_proc			-- the prompt text is centered horizontally
			// d_ctext_proc			-- the prompt text is centered horizontally
			// d_ctext_proc			-- the prompt text is centered horizontally
			// d_ctext_proc			-- the prompt text is centered horizontally

			// d_box_proc			-- the text edit field is surrounded by a box
			// d_edit_proc			-- the text edit field that text is entered by the user into
			// d_button_proc		-- the "OK" button (caption can be changed)
			// d_yield_proc 		-- used to let the CPU rest while the user is not actively using the dialog


			enum ControlNames
			{
				FormMain,
				FrameCaption,
				StaticCaption,
				StaticPrompt1,
				StaticPrompt2,
				StaticPrompt3,
				StaticPrompt4,
				FrameEditField,
				TextEditField,
				ButtonOKButton,
				HiddenCPUYield,
				EndDialog
			};

			int controlCount = 1 + EndDialog;
			internalDialog_ = new DIALOG [controlCount];

			// zero out all controls
			for (int index = 0; index < controlCount; index++)
			{
				memset(&internalDialog_[index], 0, sizeof(DIALOG));
			}

			// clear the internal string
			memset(reinterpret_cast<void*>(internalTextBuffer_), 0, sizeof(internalTextBuffer_));


			// calculate the size of the form
			/*
				form height = the button height + the text entry height + 4 static texts + caption

				form width = longest line of prompt length * width of the current font

				each control should have 4 pixel padding
			*/


			int charWidth = text_length(font, "A");
			int charHeight = text_height(font);
			int controlPadding = 4;
			int formWidth = 0;
			int formHeight = 0;

			unsigned int longestLine = 0;
			for (unsigned int index = 0; index < prompts_.size(); index++)
			{
				if (prompts_.at(index).size() > longestLine)
				{
					longestLine = prompts_.at(index).size();
				}
			}

			formWidth = controlPadding + (charWidth * longestLine) + controlPadding;
			formHeight = (controlCount * (2*controlPadding)) +  (4 * charHeight);


			// init the main form -- a d_box_proc control
			internalDialog_[FormMain].proc				= d_box_proc;
			internalDialog_[FormMain].x					= 0;
			internalDialog_[FormMain].y					= 0;
			internalDialog_[FormMain].w					= formWidth;
			internalDialog_[FormMain].h					= formHeight;

			// init the frame for the window's caption text -- a d_box_proc control
			internalDialog_[FrameCaption].proc			= d_box_proc;
			internalDialog_[FrameCaption].x				= 0;
			internalDialog_[FrameCaption].y				= 0;
			internalDialog_[FrameCaption].w				= internalDialog_[FormMain].w;
			internalDialog_[FrameCaption].h				= controlPadding + charHeight + controlPadding;

			// init the window's caption text -- a d_ctext_proc control
			/*
			These draw text onto the screen.
			The dp field should point to the string to display.
			d_ctext_proc() centers the string horizontally, and d_rtext_proc() right aligns it.
			Any '&' characters in the string will be replaced with lines underneath the following character,
			for displaying keyboard shortcuts (as in MS Windows). To display a single ampersand,
			put "&&". To draw the text in something other than the default font, set the dp2 field to point to your custom font data.
			*/
			internalDialog_[StaticCaption].proc			= d_ctext_proc;
			internalDialog_[StaticCaption].x			= internalDialog_[FrameCaption].x + controlPadding;
			internalDialog_[StaticCaption].y			= controlPadding;
			internalDialog_[StaticCaption].w			= internalDialog_[FrameCaption].w - controlPadding;
			internalDialog_[StaticCaption].dp			= const_cast<void*>(reinterpret_cast<const void*>(windowCaption_.c_str()));

			// init the prompt texts -- four d_ctext_proc controls
			internalDialog_[StaticPrompt1].proc			= d_ctext_proc;
			internalDialog_[StaticPrompt1].x			= internalDialog_[FrameCaption].x + controlPadding;
			internalDialog_[StaticPrompt1].y			= internalDialog_[FrameCaption].y + internalDialog_[FrameCaption].h + controlPadding;
			internalDialog_[StaticPrompt1].w			= internalDialog_[FrameCaption].w - controlPadding;
			internalDialog_[StaticPrompt1].h			= controlPadding + charHeight + controlPadding;
			internalDialog_[StaticPrompt1].dp			= const_cast<void*>(reinterpret_cast<const void*>(prompts_.at(0).c_str()));

			internalDialog_[StaticPrompt2].proc			= d_ctext_proc;
			internalDialog_[StaticPrompt2].x			= internalDialog_[FrameCaption].x + controlPadding;
			internalDialog_[StaticPrompt2].y			= internalDialog_[StaticPrompt1].y + internalDialog_[StaticPrompt1].h;
			internalDialog_[StaticPrompt2].w			= internalDialog_[FrameCaption].w - controlPadding;
			internalDialog_[StaticPrompt2].h			= controlPadding + charHeight + controlPadding;
			internalDialog_[StaticPrompt2].dp			= const_cast<void*>(reinterpret_cast<const void*>(prompts_.at(1).c_str()));

			internalDialog_[StaticPrompt3].proc			= d_ctext_proc;
			internalDialog_[StaticPrompt3].x			= internalDialog_[FrameCaption].x + controlPadding;
			internalDialog_[StaticPrompt3].y			= internalDialog_[StaticPrompt2].y + internalDialog_[StaticPrompt2].h;
			internalDialog_[StaticPrompt3].w			= internalDialog_[FrameCaption].w - controlPadding;
			internalDialog_[StaticPrompt3].h			= controlPadding + charHeight + controlPadding;
			internalDialog_[StaticPrompt3].dp			= const_cast<void*>(reinterpret_cast<const void*>(prompts_.at(2).c_str()));

			internalDialog_[StaticPrompt4].proc			= d_ctext_proc;
			internalDialog_[StaticPrompt4].x			= internalDialog_[FrameCaption].x + controlPadding;
			internalDialog_[StaticPrompt4].y			= internalDialog_[StaticPrompt3].y + internalDialog_[StaticPrompt3].h;
			internalDialog_[StaticPrompt4].w			= internalDialog_[FrameCaption].w - controlPadding;
			internalDialog_[StaticPrompt4].h			= controlPadding + charHeight + controlPadding;
			internalDialog_[StaticPrompt4].dp			= const_cast<void*>(reinterpret_cast<const void*>(prompts_.at(3).c_str()));


			// init the frame that surrounds the edit field -- a d_box_proc control
			internalDialog_[FrameEditField].proc			= d_box_proc;
			internalDialog_[FrameEditField].x				= 0;
			internalDialog_[FrameEditField].y				= (internalDialog_[StaticPrompt4].y + internalDialog_[StaticPrompt4].h) - 1;
			internalDialog_[FrameEditField].w				= internalDialog_[FormMain].w;
			internalDialog_[FrameEditField].h				= charHeight + controlPadding;

			// init the text edit field -- a d_edit_proc control
			/*
			An editable text object (the dp field points to the string).
			When it has the input focus (obtained by clicking on it with the mouse),
			text can be typed into this object. The d1 field specifies the maximum number of
			characters that it will accept, and d2 is the text cursor position within the string.

			Note: dp must point to a buffer at least (d1 + 1) * 4 bytes long because,
			depending on the encoding format in use, a single character can occupy up to 4 bytes
			and room must be reserved for the terminating null character.
			*/

			internalDialog_[TextEditField].proc			= d_edit_proc;
			internalDialog_[TextEditField].x			= controlPadding;
			internalDialog_[TextEditField].y			= internalDialog_[StaticPrompt4].y + internalDialog_[StaticPrompt4].h;
			internalDialog_[TextEditField].w			= internalDialog_[FormMain].w - (2 * controlPadding);
			internalDialog_[TextEditField].h			= charHeight;
			internalDialog_[TextEditField].d1			= 0x400;
			internalDialog_[TextEditField].dp			= internalTextBuffer_;

			// init the OK button -- a d_button_proc control
			internalDialog_[ButtonOKButton].proc		= d_button_proc;
			internalDialog_[ButtonOKButton].x			= (internalDialog_[FormMain].w / 2) - ((text_length(font, buttonCaption_.c_str()) + (controlPadding*12)) / 2);;
			internalDialog_[ButtonOKButton].w			= text_length(font, buttonCaption_.c_str()) + (controlPadding * 12);
			internalDialog_[ButtonOKButton].h			= controlPadding + charHeight + controlPadding;
			internalDialog_[ButtonOKButton].y			= controlPadding + controlPadding + internalDialog_[FrameEditField].y + internalDialog_[FrameEditField].h;
			internalDialog_[ButtonOKButton].flags		= D_EXIT;
			internalDialog_[ButtonOKButton].dp			= const_cast<void*>(reinterpret_cast<const void*>(buttonCaption_.c_str()));

			// init the CPU yield -- a d_yield_proc control
			internalDialog_[HiddenCPUYield].proc		= d_yield_proc;


			// set the color of the dialog
			const int controlColorFG = makecol(255, 255, 255);
			const int controlColorBG = makecol(0, 0, 0);
			set_dialog_color(internalDialog_, controlColorFG, controlColorBG);

			// re- color the window caption
			internalDialog_[StaticCaption].bg			= -1;
			internalDialog_[FrameCaption].bg			= makecol(0, 0, 64);
			internalDialog_[FrameCaption].fg			= makecol(255, 255, 255);


			// center the dialog
			centre_dialog(internalDialog_);
		}
Exemple #6
0
void options_menu()
{

   show_mouse(screen);
   DIALOG options_dialog[] =
   {
   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */
      {d_bitmap_proc,     0,   0,SCREEN_W,SCREEN_H,0,255,     0,     0,      0,    0, title_back},
      {d_gamespeed_proc, 20,  10,    0,    0,    0,   0,      0,D_SELECTED,  0,    0, const_cast<char *>("gamespeed")},
      {d_slider_proc,   300,  20,   30,  440,    0, 255,      0,     0,    255,    get_config_int("MINER","BPS", 32) - 32, NULL,  (void *)speedslider_callback},
      {d_mapsize_proc,   20,  60,    0,    0,    0,   0,      0,     0,      0,    0, const_cast<char *>("mapsize")},
      {d_slider_proc,   300,  20,   30,  440,    0, 255,      0,D_HIDDEN,   80,    get_config_int("MINER","MAP_SIZE",20) - 20, NULL,  (void *)mapsizeslider_callback},
      {d_sound_proc,     20, 110,    0,    0,    0,   0,      0,     0,      0,    0, const_cast<char *>("sound")},
      {d_slider_proc,   300,  40,   30,  300,    0, 255,      0,D_HIDDEN,    6,  (int)log2(get_config_int("MINER","NR_OF_VOICES",0) + 1), NULL, (void *)soundslider_callback},
      {d_text_proc,     300,  10,  200,   30,    0, 255,      0,D_HIDDEN,    0,    0, const_cast<char *>("Nr of simultaneous sounds")},
      {d_number_proc,   330,  20,    0,    0,    0,   0,      0,     0,      3,   get_config_int("MINER","BPS", 32), NULL},
      {d_number_proc,   330,  20,    0,    0,    0,   0,      0,D_HIDDEN,    3,   get_config_int("MINER","MAP_SIZE",20) , NULL},
      {d_number_proc,   330,  40,    0,    0,    0,   0,      0,D_HIDDEN,    2,   get_config_int("MINER","NR_OF_VOICES",1), NULL},
      {d_back_proc,      20, 160,    0,    0,    0,   0,      0,     0,      0,    0, const_cast<char *>("exit menu")},
      {NULL,              0,   0,    0,    0,    0,   0,      0,     0,      0,    0,    0, NULL}
   };


   the_options_dialog = options_dialog; // ugly, but I found it easier to initialise the dialog
   // within the function, where all BITMAPS's are loaded etc.
   PALETTE options_palette;

   for (int i=0;i < 256;i++)
   {
      options_palette[i].r = game_palette[i].g;
      options_palette[i].g = game_palette[i].b;
      options_palette[i].b = game_palette[i].r;
   }
   set_dialog_color(options_dialog, bestfit_color(options_palette,0,0,0), bestfit_color(options_palette,63,63,63));


   DIALOG_PLAYER *p = init_dialog(options_dialog, 1);
   
   broadcast_dialog_message(MSG_DRAW, 0);
//   update_dialog(p);
   if (fade_speed)
   {
      fade_from(desktop_palette,options_palette,fade_speed);
   }
   else
   {
      set_palette(options_palette);
   }


   while(update_dialog(p));

   shutdown_dialog(p);

   set_config_int("MINER","BPS", options_dialog[SPEED_SLIDER].d2 + 32);
   set_config_int("MINER","MAP_SIZE", options_dialog[MAPSIZE_SLIDER].d2 + 20);
   set_config_int("MINER","NR_OF_VOICES", (1<<options_dialog[SOUND_SLIDER].d2));
   show_mouse(NULL);

   reinit();
   
   return;
}
Exemple #7
0
int main(int argc, char *argv[])
{
   char buf[256];
   int i;

   /* initialise everything */
   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_mouse();
   install_timer();

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 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;
      }
   }

   /* load the datafile */
   replace_filename(buf, argv[0], "example.dat", sizeof(buf));
   datafile = load_datafile(buf);
   if (!datafile) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", buf);
      return 1;
   }

   set_palette(datafile[THE_PALETTE].dat);

   /* set up colors */
   gui_fg_color = makecol(0, 0, 0);
   gui_mg_color = makecol(128, 128, 128);
   gui_bg_color = makecol(200, 240, 200);
   set_dialog_color(the_dialog, gui_fg_color, gui_bg_color);

   /* white color for d_clear_proc and the d_?text_procs */
   the_dialog[0].bg = makecol(255, 255, 255);
   for (i = 4; the_dialog[i].proc; i++) {
      if (the_dialog[i].proc == d_text_proc ||
          the_dialog[i].proc == d_ctext_proc ||
          the_dialog[i].proc == d_rtext_proc)
      {
         the_dialog[i].bg = the_dialog[0].bg;
      }
   }
   
   /* fill in bitmap pointers */
   the_dialog[BITMAP_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   the_dialog[ICON_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   
   /* shift the dialog 2 pixels away from the border */
   position_dialog(the_dialog, 2, 2);
   
   /* do the dialog */
   do_dialog(the_dialog, -1);

   unload_datafile(datafile);
   
   return 0;
}
Exemple #8
0
static int setup (void)
{
	#define RESOLUTION_LIST   4
	#define COLOUR_LIST       6
	#define ZBUFFER_LIST      8
	#define WINDOWED_BOX      9
	#define DOUBLEBUFFER_BOX 10
	#define BUTTON_OK        11
	
	DIALOG dlg[] = {
    /*	proc                 x    y    w    h  fg bg  key    flags d1 d2  dp */
    {	d_shadow_box_proc,   0,   0, 320, 200,  0, 0,   0,         0, 0, 0, NULL, NULL, NULL },
    {	d_ctext_proc,      160,  10,   0,   0,  0, 0,   0,         0, 0, 0, "____________", NULL, NULL },
    {	d_ctext_proc,      160,   8,   0,   0,  0, 0,   0,         0, 0, 0, "OpenGL Setup", NULL, NULL },
    {	d_text_proc,        10,  30,   0,   0,  0, 0,   0,         0, 0, 0, "Resolution", NULL, NULL },
    {	d_list_proc,        10,  40,  96,  52,  0, 0,   0,         0, 0, 0, resolution_lister, NULL, NULL },
    {	d_text_proc,       120,  30,   0,   0,  0, 0,   0,         0, 0, 0, "Colour depth", NULL, NULL },
    {	d_list_proc,       120,  40,  96,  48,  0, 0,   0,         0, 0, 0, colour_depth_lister, NULL, NULL },
    {	d_text_proc,        10, 104,  96,  48,  0, 0,   0,         0, 0, 0, "Z buffer", NULL, NULL },
    {	d_list_proc,        10, 114,  96,  48,  0, 0,   0,         0, 0, 0, zbuffer_depth_lister, NULL, NULL },
    {	d_check_proc,       10, 170,  96,   8,  0, 0,   0,         0, 1, 0, "Windowed", NULL, NULL },
    {	d_check_proc,       10, 180, 128,   8,  0, 0,   0,D_SELECTED, 1, 0, "Double Buffered", NULL, NULL },
    {	d_button_proc,     220, 150,  96,  18,  0, 0,   0,    D_EXIT, 0, 0, "Ok", NULL, NULL },
    {	d_button_proc,     220, 174,  96,  18,  0, 0,   0,    D_EXIT, 0, 0, "Exit", NULL, NULL },
    {	d_yield_proc,        0,   0,   0,   0,  0, 0,   0,         0, 0, 0, NULL, NULL, NULL },
    {	NULL,                0,   0,   0,   0,  0, 0,   0,         0, 0, 0, NULL, NULL, NULL }
	};

	int x;

	if (mode == AGL_WINDOWED)
		dlg[WINDOWED_BOX].flags |= D_SELECTED;

	centre_dialog (dlg);
	set_dialog_color (dlg, makecol(0, 0, 0), makecol(255, 255, 255));
		
	if (secs) {
		textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2 + 110,
		                  makecol(255, 255, 255), 0,
		                  "Frames: %i, Seconds: %i, FPS: %f",
		                  frames, secs, (float)frames / (float)secs);
	}
	
	x = do_dialog (dlg, 4);
	
	allegro_gl_clear_settings();
	allegro_gl_set(AGL_COLOR_DEPTH, colour_depths[dlg[COLOUR_LIST].d1].depth);
	allegro_gl_set(AGL_Z_DEPTH, zbuffer_depths[dlg[ZBUFFER_LIST].d1].depth);
	allegro_gl_set(AGL_DOUBLEBUFFER,
	              (dlg[DOUBLEBUFFER_BOX].flags & D_SELECTED) ? 1 : 0);
	allegro_gl_set(AGL_RENDERMETHOD, 1);
	
	mode = ((dlg[WINDOWED_BOX].flags & D_SELECTED)
	       ? AGL_WINDOWED : AGL_FULLSCREEN);
	
	allegro_gl_set(mode, TRUE);
	allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH
	                          | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | mode);
	
	width  = resolutions[dlg[RESOLUTION_LIST].d1].w;
	height = resolutions[dlg[RESOLUTION_LIST].d1].h;

	return (x == BUTTON_OK);
}
void initialize()
{
    char buf[1024];
    int i;

    // Do the libxml binary compatibility check
    initXML();

    // Initialise Allegro
    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();

    set_config_file("rpgedit.cfg");
    int grph_drv = (get_config_int("video", "fullscreen", 1)) ?
        GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED;
    int screen_w = get_config_int("video", "width", 800);
    int screen_h = get_config_int("video", "height", 600);

    if (get_config_int("tile_zoom", "grid", 1)) {
        showTileGrid = true;
    }

    set_color_conversion(
            (COLORCONV_TOTAL &
             ~(
                 COLORCONV_32A_TO_8  |
                 COLORCONV_32A_TO_15 |
                 COLORCONV_32A_TO_16 |
                 COLORCONV_32A_TO_24
              ))
            );

    int colordepth = 0;
    if (grph_drv == GFX_AUTODETECT_WINDOWED) {
        colordepth = desktop_color_depth();
    }
    if (colordepth == 0) {
        colordepth = 16;
    }
    set_color_depth(colordepth);

    if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
        set_color_depth(15);
        if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
            exit(1);
        }
    }

    buffer = create_bitmap(SCREEN_W, SCREEN_H);


    // Initialize GUI look and feel stuff
    agup_init(aphoton_theme);
    gui_fg_color = agup_fg_color;
    gui_bg_color = agup_bg_color;
    gui_shadow_box_proc = d_agup_shadow_box_proc;
    gui_button_proc = d_agup_button_proc;
    gui_edit_proc = d_agup_edit_proc;
    gui_text_list_proc = d_agup_text_list_proc;

    engine_data = load_datafile("gui.dat");

    DATAFILE* font_data = find_datafile_object(engine_data, "SmallFont");
    if (font_data) font = (FONT*)font_data->dat;

    engine_font = font;

    DATAFILE* mouse_pointer = find_datafile_object(engine_data, "_MS_STD_BMP");
    if (mouse_pointer) set_mouse_sprite((BITMAP*)mouse_pointer->dat);

    DATAFILE* logo = find_datafile_object(engine_data, "MoonlightLogo");
    if (logo) about_dlg[1].dp = (BITMAP*)logo->dat;
    else console.log(CON_QUIT, CON_ALWAYS, "Error loading MoonlightLogo");

    console.log(CON_LOG, CON_ALWAYS, "Loading module \"data\"...");
    module = new Module("data");

    // Lua initialisation
    console.log(CON_LOG, CON_ALWAYS, "Initialising scripting environment...");
    initScripting();

    D_AUTOTEXT_STATUS.dp2 = status_message;
    D_AUTOTEXT_MAPINFO.dp2 = status_mapinfo;

    set_dialog_color(main_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(newmap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(import_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(export_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(resizemap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(about_dlg, agup_fg_color, agup_bg_color);


    // Position the dialogs on the screen
    int margin = 6;
    int zoom_w = get_config_int("tile_zoom", "zoom_width", 120) - 1;
    int zoom_h = get_config_int("tile_zoom", "zoom_height", 120) - 1;
    int x, y, w, h;

    // Main (back + menu)
    set_dialog_size(&main_dlg[0],          -2,                -2,              SCREEN_W + 4,          SCREEN_H + 4);
    set_dialog_size(&main_dlg[1],          0,                 0,               SCREEN_W,              15);

    // Status bars
    set_dialog_size(&main_dlg[6],          0,                 SCREEN_H - 17,   SCREEN_W - 256,        17);
    set_dialog_size(&main_dlg[7],          SCREEN_W - 256,    SCREEN_H - 17,   256,                   17);
    set_dialog_size(&main_dlg[8],          3,                 SCREEN_H - 14,   SCREEN_W - 262,        11);
    set_dialog_size(&main_dlg[9],          SCREEN_W - 253,    SCREEN_H - 14,   250,                   11);

    // Edit tile area
    w = zoom_w + 4;
    h = zoom_h + 4;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_tile_layer[0],   x,                 y,               w,                     h);
    set_dialog_size(&edit_tile_layer[1],   x + 2,             y + 2,           w - 4,                 h - 4);
    set_dialog_size(&edit_tile_layer[2],   x + margin + w,    y + h - 14,      50,                    14);

    // Color sliders
    x += w + margin;
    w = 128;
    set_dialog_size(&edit_tile_layer[8],   x,                 y,               16,                    8);
    set_dialog_size(&edit_tile_layer[9],   x,                 y + 16,          16,                    8);
    set_dialog_size(&edit_tile_layer[10],  x,                 y + 32,          16,                    8);
    set_dialog_size(&edit_tile_layer[11],  x,                 y + 48 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[12],  x,                 y + 64 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[3],   x + 16,            y,               w,                     8);
    set_dialog_size(&edit_tile_layer[4],   x + 16,            y + 16,          w,                     8);
    set_dialog_size(&edit_tile_layer[5],   x + 16,            y + 32,          w,                     8);
    set_dialog_size(&edit_tile_layer[6],   x + 16,            y + 48 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[7],   x + 16,            y + 64 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[13],  x + 16 + w + 4,    y - 1,           11,                    10);
    set_dialog_size(&edit_tile_layer[14],  x + 16 + w + 4,    y + 16 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[15],  x + 16 + w + 4,    y + 32 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[20],  x + 16 + w + 18,   y + 4,           18,                    32);

    // Select tile area
    x = edit_tile_layer[20].x + edit_tile_layer[20].w + margin;
    w = SCREEN_W - x - margin;
    set_dialog_size(&edit_tile_layer[16],  x,                 y,               104,                   h);
    set_dialog_size(&edit_tile_layer[17],  x + 104,           y,               w - 104,               h);
    set_dialog_size(&edit_tile_layer[18],  x + 104 + 2,       y + 2,           w - 104 - 4 - 11,      h - 4);
    set_dialog_size(&edit_tile_layer[19],  x + w - 14,        y,               14,                    h);

    // Obstacle edit stuff
    w = 24;
    h = 24;
    x = margin;
    y = main_dlg[6].y - margin - h;
    for (i = 0; i < 5; i++) {
        set_dialog_size(&edit_obstacle_layer[i],   x + i*(w+margin),     y,     w,     h);
        set_dialog_size(&edit_obstacle_layer[i+5], x + i*(w+margin) + 2, y + 2, w - 4, h - 4);
    }

    // Edit map area
    x = margin;
    y = 16 + margin;
    w = SCREEN_W - 2 * margin;
    h = edit_obstacle_layer[0].y - margin - y;
    set_dialog_size(&main_dlg[2],          x,                 y,               w,                     h);
    set_dialog_size(&main_dlg[3],          x + 2,             y + 2,           w - 15,                h - 15);
    set_dialog_size(&main_dlg[4],          x + w - 14,        y,               14,                    h - 11);
    set_dialog_size(&main_dlg[5],          x,                 y + h - 14,      w - 11,                14);
    set_dialog_size(&main_dlg[10],         x + w - 12,        y + h - 12,      10,                    10);

    // Edit objects area
    w = 160;
    h = 120;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_objects_layer[0], x,                y,               w,                     h);
    set_dialog_size(&edit_objects_layer[1], w + margin * 2, main_dlg[6].y - margin - 14,  97,                    14);


    // Initialize map and tile stuff
    tileRepository = new TileRepository();

    // Import tilesets specified in rpgedit.cfg
    i = 1;
    while (i > 0) 
    {
        uszprintf(buf, sizeof buf, "tileset%d", i);

        const char* filename = get_config_string(buf, "filename", NULL);
        int tile_w = get_config_int(buf, "tile_w", 16);
        int tile_h = get_config_int(buf, "tile_h", 16);
        int tile_spacing = get_config_int(buf, "tile_spacing", 0);

        if (filename) {
            if (tile_w > 0 && tile_h > 0 && tile_spacing >= 0) {
                import_tile_bitmap(filename, tile_w, tile_h, tile_spacing);
            } else {
                allegro_message("Error, incorrect parameters for automatic tile import (%s)!", filename);
                // Print warning in log file
            }
            i++;
        } else  {
            i = -1;
        }
    }

    currentMap = new SquareMap(TILES_W, TILES_H);
    ustrcpy(map_filename, "untitled.tmx");

    // Load map specified in rpgedit.cfg
    const char* filename = get_config_string("startup", "load_map", NULL);
    if (filename) {
        if (!currentMap->loadMap(filename)) {
            ustrcpy(map_filename, filename);
            object_message(&D_MAP, MSG_NEW_MAP, 0);
            set_map_changed(false);
        } else {
            console.log(CON_LOG, CON_ALWAYS,
                    "Error while loading default map (%s)!\n", filename);
        }
    }

    update_window_title();

    map_edit_mode = EM_TILE;
    menu_item_edit_objects();
    //activate_mode(edit_objects_layer);
}
Exemple #10
0
/**
 * Shows unit-stats edit-dialog and allows to edit unit stats, 
 * change name, and armour (=skin)
 */
void Editor::edit_soldier()
{
    MouseRange temp_mouse_range(0, 0, SCREEN_W - 1, SCREEN_H - 1);
    DIALOG sol_dialog[] = {
        //(dialog proc)      (x)           (y)                   (w)      (h)  (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
        { d_agup_shadow_box_proc, DX,           DY,                   D_WIDTH,     D_HEIGHT, FG,  BG, 0, 0, 0, 0, NULL, NULL, NULL},
        { d_agup_button_proc,     DX + 130,     DY + SSY + SH*13 + 4, 100,     20,  FG,  BG, 0, D_EXIT, 0, 0, (void *)_("OK"), NULL, NULL},
        { d_agup_rtext_proc,      DX + STX,     DY + SSY - SH*1,      STW,     16,  FG,  BG, 0, 0, 0, 0, (void *)_("Name:"), NULL, NULL},
        { d_agup_edit_proc,       DX + SSX,     DY + SSY - SH*1 - 4, 23*8,     16,  FG,  BG, 0, 0, MAN_NAME_LEN, 0, NULL, NULL, NULL},
        { d_agup_text_proc,       DX + 100,     DY + SSY + SH*12 + 2,  100,     16,  FG,  BG, 0, 0, 0, 0, (void *)points_str, NULL, NULL},

        { d_agup_rtext_proc,      DX + STX,     DY + SSY + SH*0 + 1,  STW, 16 + 4,  FG,  BG, 0, 0, 0, 0, (void *)_("Race:"), NULL, NULL},
        { race_change_button_proc,DX + SSX,     DY + SSY + SH*0 - 6,    0, 16 + 4,  FG,  BG, 0, D_EXIT, 0, 0, NULL, NULL, NULL},

        { d_agup_rtext_proc,      DX + STX,     DY + SSY + SH*1 + 1,  STW, 16 + 4,  FG,  BG, 0, 0, 0, 0, (void *)_("Armour:"), NULL, NULL},
        { armour_change_button_proc,DX + SSX,     DY + SSY + SH*1 - 6,    0, 16 + 4,  FG,  BG, 0, D_EXIT, 0, 0, NULL, NULL, NULL},

        { d_agup_rtext_proc,      DX + STX,     DY + SSY + SH*2 + 1,  STW, 16 + 4,  FG,  BG, 0, 0, 0, 0, (void *)_("Appearance:"), NULL, NULL},
        { appearance_change_button_proc,DX + SSX,     DY + SSY + SH*2 - 6,    0, 16 + 4,  FG,  BG, 0, D_EXIT, 0, 0, NULL, NULL, NULL},

        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*3,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Time Units"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*3,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*4,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Stamina"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*4,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*5,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Health"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*5,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*6,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Bravery"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*6,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*7,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Reactions"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*7,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*8,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Firing"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*8,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*9,  STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Throwing"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*9,  SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_rtext_proc,  DX + STX, DY + STY + SH*10, STW, 16, FG, BG, 0, 0, 0, 0, (void *)_("Strength"), NULL, NULL},
        { d_agup_slider_pro2, DX + SSX, DY + SSY + SH*10, SSW, 16, FG, BG, 0, 0, 100, 33, NULL, NULL, NULL},
        { d_agup_ctext_proc,  DX, DY + SH/2, D_WIDTH, 16, FG, BG, 0, 0, 0, 0, (void *)_("Edit soldier attributes"), NULL, NULL},
        { d_yield_proc,           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL},
        { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL}
    };

    ::sol_dialog = sol_dialog;

    sol_dialog[D_BRAVERY].flags  |= D_DISABLED;

    sol_dialog[D_NAME].dp       = man->md.Name;
    sol_dialog[D_TIME].d2       = man->md.TimeUnits;
    sol_dialog[D_HEALTH].d2     = man->md.Health;
    sol_dialog[D_STAMINA].d2    = man->md.Stamina;
    sol_dialog[D_REACTION].d2   = man->md.Reactions;
    sol_dialog[D_STRENGTH].d2   = man->md.Strength;
    sol_dialog[D_FIRE_ACCUR].d2 = man->md.Firing;
    sol_dialog[D_THRU_ACCUR].d2 = man->md.Throwing;
    sol_dialog[D_BRAVERY].d2    = man->md.Bravery;

    points = sol_dialog[D_TIME].d2 + sol_dialog[D_HEALTH].d2 +
             sol_dialog[D_FIRE_ACCUR].d2 + sol_dialog[D_THRU_ACCUR].d2 +
             sol_dialog[D_STAMINA].d2 + (sol_dialog[D_STRENGTH].d2 * 2) +
             sol_dialog[D_REACTION].d2;
    sprintf(points_str, _("Points remain: %2d "), MAXPOINTS - points);

    sol_dialog[D_POINTS].fg = gui_fg_color;
    sol_dialog[D_POINTS].bg = gui_bg_color;

    while (mouse_b & 3) rest(1);

    if (man->md.SkinType == S_XCOM_0 || 
        man->md.SkinType == S_XCOM_1 || 
        man->md.SkinType == S_XCOM_2 || 
        man->md.SkinType == S_XCOM_3) {
        appearance_names = appearance_names_human;
        armour_names     = armour_names_human;
        if (man->md.Appearance >= 4) man->md.Appearance = 0;
        sol_dialog[D_RACE].d1 = 0;
    } else {
        appearance_names = appearance_names_alien;
        armour_names     = armour_names_alien;
        if (man->md.SkinType == S_SECTOID)
            sol_dialog[D_RACE].d1 = 1;
        else
        if (man->md.SkinType == S_MUTON)
            sol_dialog[D_RACE].d1 = 2;
        else
        if (man->md.SkinType == S_SNAKEMAN)
            sol_dialog[D_RACE].d1 = 3;
        else
        if (man->md.SkinType == S_ETHEREAL)
            sol_dialog[D_RACE].d1 = 4;
        else
        if (man->md.SkinType == S_FLOATER)
            sol_dialog[D_RACE].d1 = 5;
        else
        if (man->md.SkinType == S_CHRYS)
            sol_dialog[D_RACE].d1 = 6;
        else
			sol_dialog[D_RACE].d1 = 7;
        man->md.fFemale = 0;
        if (man->md.SkinType != S_CHAMELEON)
            man->md.Appearance = 0;
    }

    switch (man->md.SkinType) {
        case S_XCOM_0 : sol_dialog[D_ARMOUR].d1 = 0; break;
        case S_XCOM_1 : sol_dialog[D_ARMOUR].d1 = 1; break;
        case S_XCOM_2 : sol_dialog[D_ARMOUR].d1 = 2; break;
        case S_XCOM_3 : sol_dialog[D_ARMOUR].d1 = 3; break;
        case S_SECTOID: sol_dialog[D_ARMOUR].d1 = 0; break;
        case S_SNAKEMAN: sol_dialog[D_ARMOUR].d1 = 0; break; //LAWYER: Snakeman
        case S_ETHEREAL: sol_dialog[D_ARMOUR].d1 = 0; break; //LAWYER: Ethereal
        case S_FLOATER: sol_dialog[D_ARMOUR].d1 = 0; break; //LAWYER: Floater
        case S_CHRYS: sol_dialog[D_ARMOUR].d1 = 0; break; //Kratos: Chryssalid
        default:        sol_dialog[D_ARMOUR].d1 = 0; break;
    }

    sol_dialog[D_APPEARANCE].d1 = man->md.Appearance + (man->md.fFemale ? 4 : 0);

    fixup_unit_info();

    set_dialog_color(sol_dialog, gui_fg_color, gui_bg_color);
    centre_dialog(sol_dialog);
    popup_dialog(sol_dialog, -1);

    switch (sol_dialog[D_RACE].d1) {
        case  0: 
            man->md.fFemale = sol_dialog[D_APPEARANCE].d1 >= 4;
            man->md.Appearance = sol_dialog[D_APPEARANCE].d1 % 4;
            man->md.SkinType = sol_dialog[D_ARMOUR].d1 + 1; 
            break;
        case  1: 
            man->md.fFemale = 0;
            man->md.SkinType = S_SECTOID; 
            break;
        case  2: 
            man->md.fFemale = 0;
            man->md.SkinType = S_MUTON; 
            break;
        case  3: 
            man->md.fFemale = 0;
            man->md.SkinType = S_SNAKEMAN; //LAWYER:  Snakeman!!
            break;
        case  4: 
            man->md.fFemale = 0;
            man->md.SkinType = S_ETHEREAL; //LAWYER:  Ethereal!!
            break;
        case 5:
            man->md.fFemale = 0;
            man->md.SkinType = S_FLOATER; //LAWYER:  Floater!!
            break;      
        case 6:
            man->md.fFemale = 0;
            man->md.SkinType = S_CHRYS; //Kratos: Chryssalid
            break;
        default: 
            man->md.fFemale = 0; // Here too, even though it looks inconsistent
            man->md.SkinType = S_CHAMELEON; 
            man->md.Appearance = sol_dialog[D_APPEARANCE].d1;
            break;
    }

    man->md.TimeUnits  = sol_dialog[D_TIME].d2;
    man->md.Health     = sol_dialog[D_HEALTH].d2;
    man->md.Stamina    = sol_dialog[D_STAMINA].d2;
    man->md.Reactions  = sol_dialog[D_REACTION].d2;
    man->md.Strength   = sol_dialog[D_STRENGTH].d2;
    man->md.Firing     = sol_dialog[D_FIRE_ACCUR].d2;
    man->md.Throwing   = sol_dialog[D_THRU_ACCUR].d2;
    man->md.Bravery    = sol_dialog[D_BRAVERY].d2;

    man->process_MANDATA();

    ::sol_dialog = NULL;
}