Example #1
0
//---------- Begin of function Game::multi_player_menu ----------//
//
void Game::multi_player_menu(char *cmdLine)
{
	mouse_cursor.set_icon(CURSOR_NORMAL);

	if( cmdLine != NULL && mp_obj.init_flag && mp_obj.is_lobbied() )
	{
		// find player profile
		char* lobbiedName = mp_obj.get_lobbied_name();
		// find profile with the same login name

		if( lobbiedName && player_profile.load_by_login_name(lobbiedName) )
		{
			if( player_profile.mp_new_game_flag == 1 )		// new game
			{
				player_profile.mp_new_game_flag = 0;
				player_profile.save();

				game_file_array.init( player_profile.save_game_path(NULL), "*.svm" );	// necessary to set the path and extension
				multi_player_game(cmdLine);

				return;
			}
			else if ( player_profile.mp_new_game_flag == 2 )		// load game
			{
				player_profile.mp_new_game_flag = 0;

				// if load file is specified in the profile
				game_file_array.init( player_profile.save_game_path(NULL), "*.svm" );	// necessary to set the path and extension

				char loadFileName[16];
				if( player_profile.mp_load_file_name[0] )
				{
					strcpy(loadFileName, player_profile.mp_load_file_name);
					strcat( loadFileName, ".svm" ),		// append extension
					player_profile.mp_load_file_name[0] = '\0';
				}
				else
				{
					loadFileName[0] = '\0';
				}

				player_profile.save();

				if( loadFileName[0]
					&& game_file.load_game(player_profile.save_game_path(NULL), loadFileName) )
				{
					load_mp_game( loadFileName, cmdLine );
				}
				else
				{
					// conventional choose load game
					int loadedRecno;
					if( game_file_array.menu(3, &loadedRecno) == 1 )
					{
						err_when( !loadedRecno );
						load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
					}
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();		// game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;
				}
				return;
			}
			else
			{
				return;	// quit

				// player_profile.mp_new_game_flag not specified
				// continue to interface
			}
		}	// end if load by login name
#ifdef DEBUG
		else
		{
			if( lobbiedName )
				err.msg( "Cannot find profile" );
		}
#endif
	}	// end if launchMode

//	char optionFlag[5] = { 1, 1, 1, 1, 1, };

	bool launchMode = (cmdLine != NULL);

	{
		VgaFrontLock vgaLock;

		while(1)
		{
			if (!process_messages()) return;

			VgaFrontReLock vgaReLock;

			// -------- display ----------//

			vga.disp_image_file("M_main");

			// ------ display button ------//

			if( player_profile.is_registered() )
			{
				font_thin_black.center_put_paragraph(
					BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2, 
					text_game_menu.str_new_game(), 0 );
				font_thin_black.center_put_paragraph(
					BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2, 
					text_game_menu.str_load_game(), 0 );
			}

			if( launchMode )
			{
				font_thin_black.center_put_paragraph(
					BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2, 
					text_game_menu.str_player_register(), 0);
			}

			// display quit in launch mode,
			// display cancel otherwise
			font_thin_black.center_put_paragraph(
				BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2, 
				!launchMode ? text_game_menu.str_cancel() : text_game_menu.str_quit(),
				0 );

                        vga.flip();

			sys.yield();
			mouse.get_event();
			if( config.music_flag )
			{
				if( !music.is_playing(3) )
					music.play(3, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
			}
			else
			{
				music.stop();
			}

			// --------- detect -------//

			// detect player register

			if( launchMode
				&& mouse.single_click( BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2) )
			{
				player_profile.register_menu();
			}

			// detect new game
			else if( player_profile.is_registered()
				&& mouse.single_click( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2) )
			{
				game_file_array.init( player_profile.save_game_path(NULL), "*.svm" );	// necessary to set the path and extension

				multi_player_game(cmdLine);

				if (launchMode && !sys.signal_exit_flag )
				{
					// if exit from main game, signal_exit_flag is non-zero
					// signal_exit_flag is zero usually means exit from multiplayer setup menu
					continue;
				}
				break;
			}

			// detect load game
			else if( player_profile.is_registered()
				&& mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2) )
			{
				int loadedRecno = 0;

				game_file_array.init( player_profile.save_game_path(NULL), "*.svm" );	// necessary to set the path and extension

				// ##### begin Gilbert 20/1 #######//
				// if( game_file_array.menu(2, &loadedRecno) == 1 )
				if( game_file_array.menu(3, &loadedRecno) == 1 )
				// ##### begin Gilbert 20/1 #######//
				{
					err_when( !loadedRecno );
					load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();		// game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;

					if (launchMode && !sys.signal_exit_flag )
					{
						// if exit from main game, signal_exit_flag is non-zero
						// signal_exit_flag is zero usually means exit from multiplayer setup menu
						continue;
					}
				}
				break;
			}
			// cancel
			else if( mouse.single_click(BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2) )
			{
				break;
			}

		}	// end while
	}	// end scope of vgaLock
}
Example #2
0
//---------- Begin of function Game::multi_player_menu ----------//
//
// ####### begin Gilbert 13/2 ########//
void Game::multi_player_menu(char *cmdLine)
// ####### end Gilbert 13/2 ########//
{
	enum { MULTI_PLAYER_OPTION_COUNT = 5 };

	static OptionInfo multi_player_option_array[MULTI_PLAYER_OPTION_COUNT] =
	{
		{ 5+SWORD1_X,  10+SWORD1_Y, 282+SWORD1_X,  62+SWORD1_Y },
		{ 5+SWORD1_X,  67+SWORD1_Y, 282+SWORD1_X, 112+SWORD1_Y },
		{ 5+SWORD1_X, 120+SWORD1_Y, 282+SWORD1_X, 175+SWORD1_Y },
		{ 5+SWORD1_X, 182+SWORD1_Y, 282+SWORD1_X, 223+SWORD1_Y },
		{40+SWORD1_X, 238+SWORD1_Y, 254+SWORD1_X, 280+SWORD1_Y },
	};

	static char multi_player_option_flag[MULTI_PLAYER_OPTION_COUNT] =
	{
		-1, 1, 1, -1, 1,
	};

	game_mode = GAME_MULTI_PLAYER;

	//------ display the multi player menu options ------//

	int refreshFlag = 1, i;
	mouse_cursor.set_icon(CURSOR_NORMAL);
	char *menuBitmap = NULL;
	char *brightBitmap = NULL;
	char *darkBitmap = NULL;
	int pointingOption = -1;


	//---------- detect buttons -----------//

	while(1)
	{
		sys.yield();
		mouse.get_event();

		if( refreshFlag )
		{
			image_interface.put_to_buf( &vga_back, "M_MAIN" );

			vga_util.blt_buf(0,0,VGA_WIDTH-1, VGA_HEIGHT-1);

			if(!menuBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-2", resSize);
				menuBitmap = mem_add(resSize);
				resFile->file_read(menuBitmap, resSize);
			}
			if(!brightBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-2B", resSize);
				brightBitmap = mem_add(resSize);
				resFile->file_read(brightBitmap, resSize);
			}
			if(!darkBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-2C", resSize);
				darkBitmap = mem_add(resSize);
				resFile->file_read(darkBitmap, resSize);
			}

			for( i = 0; i < MULTI_PLAYER_OPTION_COUNT; ++i )
			{
				if( multi_player_option_flag[i] >= 0 )
				{
					mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
						multi_player_option_array[i].x2, multi_player_option_array[i].y2);
					vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, 
						multi_player_option_flag[i] ? menuBitmap : darkBitmap,
						multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
						multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
					mouse.show_area();
				}
			}

			pointingOption = -1;
			refreshFlag=0;
		}

		// ###### begin Gilbert 18/9 ########//
		if( config.music_flag )
		{
			if( !music.is_playing(1) )
				music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
		}
		else
			music.stop();
		// ###### end Gilbert 18/9 ########//

		// display main menu
		int newPointingOption = -1;
		for(i = 0; i < MULTI_PLAYER_OPTION_COUNT; ++i)
		{
			if( multi_player_option_flag[i] > 0 &&
				mouse.in_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
				multi_player_option_array[i].x2, multi_player_option_array[i].y2) )
			{
				newPointingOption = i;
				break;
			}
		}

		if( pointingOption != newPointingOption)
		{
			err_when( !menuBitmap );
			err_when( !brightBitmap );
			err_when( !darkBitmap );

			// put un-highlighted option back
			i = pointingOption;
			if( i >= 0 && i < MULTI_PLAYER_OPTION_COUNT )
			{
				mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
					multi_player_option_array[i].x2, multi_player_option_array[i].y2);
				vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, menuBitmap,
					multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
					multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
				mouse.show_area();
			}

			// put new hightlighted option
			i = newPointingOption;
			if( i >= 0 && i < MULTI_PLAYER_OPTION_COUNT )
			{
				mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
					multi_player_option_array[i].x2, multi_player_option_array[i].y2);
				vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, brightBitmap,
					multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
					multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
				mouse.show_area();
			}
			pointingOption = newPointingOption;
		}

		sys.blt_virtual_buf();		// blt the virtual front buffer to the screen

		OptionInfo* optionInfo = multi_player_option_array;

		for( int i=0 ; i<MULTI_PLAYER_OPTION_COUNT ; i++, optionInfo++ )
		{
			if( multi_player_option_flag[i] > 0 &&
				mouse.single_click( optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2 ) )
			{
				// free some resource
				if( menuBitmap )
				{
					mem_del(menuBitmap);
					menuBitmap = NULL;
				}
				if( brightBitmap )
				{
					mem_del(brightBitmap);
					brightBitmap = NULL;
				}
				if( darkBitmap )
				{
					mem_del(darkBitmap);
					darkBitmap = NULL;
				}
				refreshFlag = 1;

				switch(i+1)
				{
					case 2:
						// ####### begin Gilbert 13/2 #######//
						multi_player_game(cmdLine);
						// ####### end Gilbert 13/2 #######//
						break;

					case 3:
						// ##### begin Gilbert 26/8 ######//
						{
							int loadedRecno = 0;
							game_file_array.init("*.SVM");
							if( game_file_array.menu(2, &loadedRecno) == 1 )
							{
								err_when( !loadedRecno );
								// ####### begin Gilbert 13/2 #######//
								load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
								// ####### begin Gilbert 13/2 #######//
							}
							{
								char signalExitFlagBackup = sys.signal_exit_flag;
								sys.signal_exit_flag = 2;
								game.deinit();		// game.deinit() is needed if game_file_array.menu fails
								sys.signal_exit_flag = signalExitFlagBackup;
							}
						// ##### end Gilbert 26/8 ######//
						}
						break;

					case 5:
						break;
				}

				return;
			}
		}
	}

	if( menuBitmap )
		mem_del(menuBitmap);
	if( brightBitmap )
		mem_del(brightBitmap);
	if( darkBitmap )
		mem_del(darkBitmap);
}
Example #3
0
//#ifndef DISABLE_MULTI_PLAYER
//---------- Begin of function Game::multi_player_menu ----------//
//
void Game::multi_player_menu(char *cmdLine)
{
	mouse_cursor.set_icon(CURSOR_NORMAL);

	if( cmdLine != NULL && mp_obj.init_flag && mp_obj.is_lobbied() )
	{
		// find player profile
		char* lobbiedName = mp_obj.get_lobbied_name();
		// find profile with the same login name

		if( lobbiedName && player_profile.load_by_login_name(lobbiedName) )
		{
			if( player_profile.mp_new_game_flag == 1 )		// new game
			{
				player_profile.mp_new_game_flag = 0;
				player_profile.save();

				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension
				multi_player_game(cmdLine);

				return;
			}
			else if ( player_profile.mp_new_game_flag == 2 )		// load game
			{
				player_profile.mp_new_game_flag = 0;

				// if load file is specified in the profile
				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension

				char loadFileName[16];
				if( player_profile.mp_load_file_name[0] )
				{
					strcpy(loadFileName, player_profile.mp_load_file_name);
					strcat( loadFileName, ".SVM" ),		// append extension
					player_profile.mp_load_file_name[0] = '\0';
				}
				else
				{
					loadFileName[0] = '\0';
				}

				player_profile.save();

				if( loadFileName[0]
					&& game_file.load_game(player_profile.save_game_path(NULL), loadFileName) )
				{
					load_mp_game( loadFileName, cmdLine );
				}
				else
				{
					// conventional choose load game
					int loadedRecno;
					if( game_file_array.menu(3, &loadedRecno) == 1 )
					{
						err_when( !loadedRecno );
						load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
					}
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();		// game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;
				}
				return;
			}
			else
			{
				return;	// quit

				// player_profile.mp_new_game_flag not specified
				// continue to interface
			}
		}	// end if load by login name
#ifdef DEBUG
		else
		{
			if( lobbiedName )
				err.msg( "Cannot find profile" );
		}
#endif
	}	// end if launchMode

//	char optionFlag[5] = { 1, 1, 1, 1, 1, };

	int refreshFlag = SPOPTION_ALL;
	bool launchMode = (cmdLine != NULL);

	{
		VgaFrontLock vgaLock;

		while(1)
		{
#if 0  // FIXME
			MSG msg;
			if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
			{
				if (!GetMessage( &msg, NULL, 0, 0))
				{
					sys.signal_exit_flag = 1;
					// BUGHERE : vga_front is unlocked
					return;
				}
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
			else if( sys.paused_flag || !sys.active_flag )
			{
				WaitMessage();
				continue;
			}
#endif
			if( sys.need_redraw_flag )
			{
				refreshFlag = SPOPTION_ALL;
				sys.need_redraw_flag = 0;
			}

			VgaFrontReLock vgaReLock;

			// -------- display ----------//

			if( refreshFlag )
			{
				if( refreshFlag & SPOPTION_PAGE )
				{
					vga.use_back();
					vga_util.disp_image_file("M_MAIN");

					// ------ display button ------//

					if( player_profile.is_registered() )
					{
						font_thin_black.center_put_paragraph(
							BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2, 
							text_game_menu.str_new_game(), 0 );
						font_thin_black.center_put_paragraph(
							BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2, 
							text_game_menu.str_load_game(), 0 );
					}

					if( launchMode )
					{
						font_thin_black.center_put_paragraph(
							BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2, 
							text_game_menu.str_player_register(), 0);
					}

					// display quit in launch mode,
					// display cancel otherwise
					font_thin_black.center_put_paragraph(
						BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2, 
						!launchMode ? text_game_menu.str_cancel() : text_game_menu.str_quit(),
						0 );

					vga_util.blt_buf( 0, 0, VGA_WIDTH-1, VGA_HEIGHT-1, 0 );
					vga.use_front();
				}

				refreshFlag = 0;
			}

			sys.blt_virtual_buf();		// blt the virtual front buffer to the screen
			sys.yield();
			mouse.get_event();
			if( config.music_flag )
			{
				if( !music.is_playing(3) )
					music.play(3, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
			}
			else
			{
				music.stop();
			}

			// --------- detect -------//

			// detect player register

			if( launchMode
				&& mouse.single_click( BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2) )
			{
				player_profile.register_menu();
				if( player_profile.is_registered() )
				{
					refreshFlag = SPOPTION_ALL;		// to display new/load game button
				}
			}

			// detect new game
			else if( player_profile.is_registered()
				&& mouse.single_click( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2) )
			{
				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension

				multi_player_game(cmdLine);

				if (launchMode && !sys.signal_exit_flag )
				{
					// if exit from main game, signal_exit_flag is non-zero
					// signal_exit_flag is zero usually means exit from multiplayer setup menu
					refreshFlag = SPOPTION_ALL;
					continue;
				}
				break;
			}

			// detect load game
			else if( player_profile.is_registered()
				&& mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2) )
			{
				int loadedRecno = 0;

				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension

				// ##### begin Gilbert 20/1 #######//
				// if( game_file_array.menu(2, &loadedRecno) == 1 )
				if( game_file_array.menu(3, &loadedRecno) == 1 )
				// ##### begin Gilbert 20/1 #######//
				{
					err_when( !loadedRecno );
					load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();		// game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;

					if (launchMode && !sys.signal_exit_flag )
					{
						// if exit from main game, signal_exit_flag is non-zero
						// signal_exit_flag is zero usually means exit from multiplayer setup menu
						refreshFlag = SPOPTION_ALL;
						continue;
					}
				}
				break;
			}
			// cancel
			else if( mouse.single_click(BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2) )
			{
				break;
			}

		}	// end while
	}	// end scope of vgaLock
}