Пример #1
0
//--------- Begin of static function disp_nation_chat ---------//
//
static void disp_nation_chat(int refreshFlag)
{
	int nationRecno = nation_filter(info.browse_nation_recno);

	//----- if the selected nation is the viewing nation ----//

	if( !(sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
		 info.viewing_nation_recno == nation_array.player_recno ) )
	{
		return;
	}

	//-------- display the chat get control -------//

	vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_TALK_Y2 );

	font_san.put( REPORT_DET_X1+10, REPORT_DET_Y1+10,
					  "Please enter your chat message and press <Enter> to send." );

	// ###### begin Gilbert 15/10 #######//
	if( !init_get_chat )
	{
		get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
			info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
		get_chat.clear();
		init_get_chat = 1;
	}
	// ###### end Gilbert 15/10 #######//

	int vgaUseBack = vga.use_back_buf;

	vga.use_back();
	get_chat.paint(1);			// 1-paint cursor

	if( !vgaUseBack )
		vga.use_front();

	//-------- display receiver type buttons ---------//

	int y=REPORT_TALK_Y2-70;

	for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
	{
		if( info.chat_receiver_type == i )
			vga.d3_panel_down( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );
		else
			vga.d3_panel_up( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );

		font_san.center_put( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20, chat_receiver_str_array[i-1] );
	}
}
Пример #2
0
int GetAGroup::detect()
{
	if( !enable_flag )
		return 0;

	err_when( focused_geta < 0 || focused_geta > geta_num);

	GetA *getPtr = &geta_array[focused_geta];
	err_when( !getPtr->enable_flag );

	unsigned keyCode = getPtr->detect_key();
	if( keyCode )
	{
		getPtr->paint(1);
		// detect change field focus button
		if( keyCode == KEY_RETURN || keyCode == KEY_DOWN || keyCode == KEY_TAB )
		{
			set_focus(-1);
		}
		else if( keyCode == KEY_UP )
		{
			set_focus(-2);
		}
		return 1;
	}

	// detect clicking on the area
	for( int i = 0; i < geta_num; ++i )
	{
		getPtr = &geta_array[i];
		if( getPtr->detect_click() )
		{
			set_focus(i);
			return 1;
		}
	}
	return 0;
}
Пример #3
0
// ----- begin of function GameFile::ask_desc -------//
//
// ask description
//
// return 1 if accept and set the GameFile::game_desc
//
int GameFile::ask_desc()
{
	char gameDesc[SAVE_GAME_DESC_LEN+1];
	strcpy( gameDesc, game_desc );

	Blob2DW keyFieldArea;

	int boxWidth = 700;
	int boxHeight = 150;
	int boxX1 = (VGA_WIDTH - boxWidth) / 2;
	int boxX2 = boxX1 + boxWidth - 1;
	int boxY1 = (VGA_HEIGHT - boxHeight) / 2;
	int boxY2 = boxY1 + boxHeight - 1;

	// ------ init get field -------//

	GetA descTextBox;
	descTextBox.init( boxX1+16, boxY1+50, boxX2-12, gameDesc, SAVE_GAME_DESC_LEN, &font_san, 0, 0 );

	keyFieldArea.resize( descTextBox.x, descTextBox.y, 
		descTextBox.x_limit-descTextBox.x+1, descTextBox.font_ptr->max_font_height );

	// ------ ok cancel button --------//

	const int buttonWidth = 100;
	const int buttonHeight = 24;
	Button button_ok, button_cancel;

	int x = (2*boxX1 + boxX2) / 3 - buttonWidth / 2;
	int y = boxY2 - buttonHeight - 10;
	button_ok.create_text( x, y, x+buttonWidth-1, y+buttonHeight-1, text_basic.str_box_ok() );
	x = (boxX1 + 2*boxX2) / 3 - buttonWidth / 2;
	button_cancel.create_text( x, y, x+buttonWidth-1, y+buttonHeight-1, text_basic.str_box_cancel() );

	// --------------------------------//

	int retFlag = 0;

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

		if( 1 )
		{
			// ------ display message Box ------//

			vga_buffer.d3_panel_up( boxX1, boxY1, boxX2, boxY2 );
			vga_buffer.d3_panel_down( boxX1+4, boxY1+4, boxX2-4, boxY2-4 );

			// ------ display box title ------//

			font_bold_black.put( boxX1+16, boxY1+20, text_game_menu.str_ask_desc_save() ); // "Description of save game");

			// ------ set get field background -------//

			vga_buffer.read_bitmapW( keyFieldArea.left_edge, keyFieldArea.top_edge, 
				keyFieldArea.left_edge+keyFieldArea.width-1, keyFieldArea.top_edge+keyFieldArea.height-1,
				keyFieldArea.bitmap_ptr() );
			descTextBox.set_background( keyFieldArea.ptr );

			descTextBox.paint(1);

			// ------- paint button --------//

			button_ok.paint();
			button_cancel.paint();

			// --------------------------------//
		}

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

		if( descTextBox.detect() )
		{
			descTextBox.paint(1);
		}

		if( button_ok.detect(KEY_RETURN) )
		{
			retFlag = 1;
			break;
		}

		if( button_cancel.detect(KEY_ESC) )
		{
			retFlag = 0;
			break;
		}
                vga.flip();
	}

	// ------ update game_desc ----------//

	if( retFlag )
	{
		strcpy( game_desc, gameDesc );
	}

	return retFlag;
}
Пример #4
0
//---------- Begin of function Game::select_scenario ----------//
//
// Select a scenario. 
//
// <int>    scenCount		   - no. of available scenarios. 
// <char**> scenFileNameArray - an array of <char*> pointing to the file name of the
//										  available scenarios. 
//
// return : <int> >0 - id. of the scenario selected. 
//                 0 - cancel
//
int Game::select_scenario(int scenCount, ScenInfo* scenInfoArray)
{
	char* scenFileName;
	char	pictName[20];
	char	textName[20];
	char* pathName;

	if( scenCount==0 )
	{
		box.msg( "Scenario files not found." );
		return 0;
	}

	//-------------------------------------//

	// ##### begin Gilbert 4/11 ########//
	// stop any music
	music.stop();
	// ##### end Gilbert 4/11 ########//

	int menuX1 = TUTOR_MENU_X1;
	int menuY1 = TUTOR_MENU_Y1;

	mouse_cursor.set_icon(CURSOR_NORMAL);

	power.win_opened = 1;

	int minRecno = 1;
	int browseRecno = minRecno;

	//--------------------------------------//
	Button3D scrollUp, scrollDown, startButton, cancelButton;
	int retFlag = 0;
	int refreshFlag = TUOPTION_ALL;

	scrollUp.create(menuX1+SCROLL_X1,menuY1+SCROLL_Y1-17, "SV-UP-U", "SV-UP-D", 1, 0);
	scrollDown.create(menuX1+SCROLL_X1,menuY1+SCROLL_Y2+1, "SV-DW-U", "SV-DW-D", 1, 0);
	// ###### begin Gilbert 1/11 ########//
//	startButton.create(menuX1+170, menuY1+529, "START-U", "START-D",1, 0);
//	cancelButton.create(menuX1+465, menuY1+529, "CANCEL-U", "CANCEL-D", 1, 0);
	startButton.create(menuX1+373, menuY1+529, "START-U", "START-D",1, 0);
	cancelButton.create(menuX1+548, menuY1+529, "CANCEL-U", "CANCEL-D", 1, 0);
	// ###### end Gilbert 1/11 ########//

	SlideVBar scrollBar;
	scrollBar.init_scroll(menuX1+SCROLL_X1, menuY1+SCROLL_Y1, menuX1+SCROLL_X2, menuY1+SCROLL_Y2,
		MAX_BROWSE_DISP_REC, disp_scroll_bar_func);
	scrollBar.set(minRecno, scenCount, minRecno);

	scrollBar.set_view_recno(browseRecno - MAX_BROWSE_DISP_REC/2);
	Button3D textScrollUp, textScrollDown;
	textScrollUp.create(menuX1+TEXT_SCROLL_X1, menuY1+TEXT_SCROLL_Y1-17,
		"SV-UP-U", "SV-UP-D", 1, 0);
	textScrollDown.create(menuX1+TEXT_SCROLL_X1,menuY1+TEXT_SCROLL_Y2+1, 
		"SV-DW-U", "SV-DW-D", 1, 0);
	VLenQueue textBuffer;
	*(textBuffer.reserve(1)) = '\0';

	Font &textFont = font_std;
	const int TEXT_LINE_SPACE = 4;
	const int ESTIMATED_LINE_IN_TEXT_AREA = 
		(TEXT_AREA_Y2 - TEXT_AREA_Y1 + 1) / (textFont.font_height + TEXT_LINE_SPACE);

	SlideVBar textScrollBar;
	textScrollBar.init_scroll(menuX1+TEXT_SCROLL_X1, menuY1+TEXT_SCROLL_Y1, 
		menuX1+TEXT_SCROLL_X2, menuY1+TEXT_SCROLL_Y2,
		ESTIMATED_LINE_IN_TEXT_AREA, disp_scroll_bar_func);

	// ###### begin Gilbert 1/11 ########//
	GetA playerNameField;
	playerNameField.init( menuX1+NAME_FIELD_X1, menuY1+NAME_FIELD_Y1, menuX1+NAME_FIELD_X2, 
		config.player_name, config.PLAYER_NAME_LEN, &font_san, 0, 1);
	// ###### end Gilbert 1/11 ########//

#ifdef TU_USE_BACKUP_SURFACE
	// create temporary surface
	Blob browseArea[MAX_BROWSE_DISP_REC];
	Blob scrollArea;
	Blob textArea;
	Blob textScrollArea;
	// ##### begin Gilbert 1/11 #######//
	Blob nameFieldArea;
	// ##### end Gilbert 1/11 #######//
#endif

	while(1)
	{
		//---------- yield --------//

		sys.yield();

		mouse.get_event();

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

		if( refreshFlag )
		{
#ifndef TU_USE_BACKUP_SURFACE
			refreshFlag = TUOPTION_ALL;
#endif
			scenFileName = scenInfoArray[browseRecno-1].file_name;
			m.change_file_ext( pictName, scenFileName, "SCP" );
			m.change_file_ext( textName, scenFileName, "SCT" );
			pathName = DIR_SCENARIO_PATH(scenInfoArray[browseRecno-1].dir_id);
			err_when( ! *pathName );
			if( refreshFlag & TUOPTION_PAGE )
			{
				mouse.hide_area(menuX1, menuY1, menuX1+TUTOR_MENU_WIDTH, menuY1+TUTOR_MENU_HEIGHT);

				image_interface.put_front( menuX1, menuY1, "SCENARIO" );
#ifdef TU_USE_BACKUP_SURFACE
				// capture into browseArea, scrollArea, textArea
				for( int j = 0; j < MAX_BROWSE_DISP_REC; ++j)
				{
					browseArea[j].resize(2*sizeof(short) + BROWSE_REC_WIDTH*BROWSE_REC_HEIGHT);
					vga_front.read_bitmap(
						menuX1+BROWSE_X1, menuY1+BROWSE_Y1 + j*BROWSE_REC_HEIGHT,
						menuX1+BROWSE_X2, menuY1+BROWSE_Y1 + j*BROWSE_REC_HEIGHT+BROWSE_REC_HEIGHT-1,
						browseArea[j].ptr);
				}

				scrollArea.resize(2*sizeof(short)+(SCROLL_X2-SCROLL_X1+1)*(SCROLL_Y2-SCROLL_Y1+1));
				vga_front.read_bitmap(menuX1+SCROLL_X1,menuY1+SCROLL_Y1,menuX1+SCROLL_X2,menuY1+SCROLL_Y2, scrollArea.ptr);

				textArea.resize(2*sizeof(short)+TEXT_AREA_WIDTH*TEXT_AREA_HEIGHT);
				vga_front.read_bitmap(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1,
					menuX1+TEXT_AREA_X2, menuY1+TEXT_AREA_Y2, textArea.ptr);

				textScrollArea.resize( 2*sizeof(short)+
					(TEXT_SCROLL_X2-TEXT_SCROLL_X1+1)*(TEXT_SCROLL_Y2-TEXT_SCROLL_Y1+1));
				vga_front.read_bitmap(menuX1+TEXT_SCROLL_X1, menuY1+TEXT_SCROLL_Y1,
					menuX1+TEXT_SCROLL_X2, menuY1+TEXT_SCROLL_Y2, textScrollArea.ptr);

				// ###### begin Gilbert 1/11 ########//
				nameFieldArea.resize( 2*sizeof(short) + 
					(playerNameField.x_limit-playerNameField.x+1)*playerNameField.height());
				vga_front.read_bitmap(playerNameField.x, playerNameField.y,
					playerNameField.x_limit, playerNameField.y+playerNameField.height()-1,
					nameFieldArea.ptr);
				playerNameField.back_ground_bitmap = nameFieldArea.ptr;
				// ###### end Gilbert 1/11 ########//
#endif
				scrollUp.paint();
				scrollDown.paint();
				startButton.paint();
				cancelButton.paint();

				textScrollUp.paint();
				textScrollDown.paint();

				mouse.show_area();
			}

			if( refreshFlag & TUOPTION_PIC_AREA )
			{
				String str;

				str = pathName;
				str += pictName;

				if( browseRecno && m.is_file_exist(str) )
				{
					File pictFile;
					pictFile.file_open(str);
					vga_front.put_large_bitmap(menuX1+21,menuY1+19, &pictFile);
					pictFile.file_close();
				}
				else
				{
					// draw the background
#ifdef TU_USE_BACKUP_SURFACE
					// copy from ?
#endif
				}
			}

			if( refreshFlag & TUOPTION_TEXT_BUFFER )
			{
				// load text buffer
				String str;

				str = pathName;
				str += textName;

				if( browseRecno && m.is_file_exist(str) )
				{
					File textFile;
					int dataSize;
					textFile.file_open(str);
					// ##### patch begin Gilbert 2/2 ####//
					dataSize = textFile.file_size();

					FileTxt fileTxt( &textFile, dataSize );  // initialize fileTxt with an existing file stream

					fileTxt.next_line();		// skip the title lines
					fileTxt.next_line();
					fileTxt.next_line();
					fileTxt.next_line();

					textBuffer.clear();
					fileTxt.read_paragraph(textBuffer.reserve(dataSize+8), dataSize);
					// ##### end begin Gilbert 2/2 ####//

			      int dispLines;    // no. of lines can be displayed on the area
			      int totalLines;   // total no. of lines of the text

					textFont.count_line( menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1,
						menuX1+TEXT_AREA_X2, menuY1+TEXT_AREA_Y2,
						textBuffer.queue_buf, TEXT_LINE_SPACE, dispLines, totalLines );

					// textScrollBar.view_size = dispLines;
					textScrollBar.set(1, totalLines ,1);
					refreshFlag |= TUOPTION_TEXT_SCROLL;
				}
			}

			if( refreshFlag & TUOPTION_TEXT_AREA )
			{
#ifdef TU_USE_BACKUP_SURFACE
				// copy from back buffer
				vga_front.put_bitmap(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1, 
					textArea.ptr);
#endif
					textFont.put_paragraph(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1, menuX1+TEXT_AREA_X2, menuY1+TEXT_AREA_Y2,
						textBuffer.queue_buf, TEXT_LINE_SPACE, textScrollBar.view_recno );		// 4 - space between lines
			}

			if( refreshFlag & TUOPTION_TEXT_SCROLL )
			{
#ifdef TU_USE_BACKUP_SURFACE
				vga_front.put_bitmap(menuX1+TEXT_SCROLL_X1, menuY1+TEXT_SCROLL_Y1, 
					textScrollArea.ptr);
#endif
				// display scroll bar
				textScrollBar.paint();
			}

			if( refreshFlag & TUOPTION_SCROLL )
			{
#ifdef TU_USE_BACKUP_SURFACE
				// copy from back buffer
				vga_front.put_bitmap(menuX1+SCROLL_X1, menuY1+SCROLL_Y1, 
					scrollArea.ptr);
#endif
				// display scroll bar
				scrollBar.paint();
			}

			if( refreshFlag & TUOPTION_ALL_BROWSE )
			{
				int rec, slot;
				for( slot = 0; slot < scrollBar.view_size; ++slot)
				{
					int browseSlotX1 = menuX1+BROWSE_X1;
					int browseSlotY1 = menuY1+BROWSE_Y1+slot*BROWSE_REC_HEIGHT;
					int browseSlotX2 = menuX1+BROWSE_X2;
					int browseSlotY2 = menuY1+BROWSE_Y1+(slot+1)*BROWSE_REC_HEIGHT-1;

					rec = scrollBar.view_recno + slot;
					if( refreshFlag & TUOPTION_BROWSE(slot) )
					{
#ifdef TU_USE_BACKUP_SURFACE
						vga_front.put_bitmap(browseSlotX1, browseSlotY1,
							browseArea[rec%MAX_BROWSE_DISP_REC].ptr);
#endif
						if( rec >= 1 && rec <= scenCount )
						{
							int textX = font_bible.put(browseSlotX1+TEXT_OFFSET_X,
								browseSlotY1+TEXT_OFFSET_Y, m.format(rec), 0, browseSlotX2 );

							//----- display the scenario name -----//

							textX = font_bible.put(textX, browseSlotY1+TEXT_OFFSET_Y,
								". ", 0, browseSlotX2 );

							textX = font_bible.put(textX, browseSlotY1+TEXT_OFFSET_Y,
								scenInfoArray[rec-1].scen_name, 0, browseSlotX2 );

							//---- display the scenario difficulty and bonus points ----//

							String str(translate.process("Difficulty: "));
							str += scenInfoArray[rec-1].goal_difficulty;

							font_bible.put(browseSlotX1+TEXT_OFFSET_X+400, browseSlotY1+TEXT_OFFSET_Y,
												str, 0, browseSlotX2 );

							str  = translate.process("Score Bonus: ");
							str += scenInfoArray[rec-1].goal_score_bonus;

							font_bible.put(browseSlotX1+TEXT_OFFSET_X+530, browseSlotY1+TEXT_OFFSET_Y,
												str, 0, browseSlotX2 );

							//--------------------------------------//

							if( rec == browseRecno )
							{
								vga_front.adjust_brightness(browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2, -2);

								//vga_front.put_bitmap_trans_decompress( menuX1+BROWSE_X1, menuY1+BROWSE_Y1+slot*BROWSE_REC_HEIGHT,
								//	image_button.read("LS-DWN"));
							}
						}
					}
				}
			}

			// ###### begin Gilbert 1/11 #######//
			if( refreshFlag & TUOPTION_NAME_FIELD )
				playerNameField.paint();
			// ###### end Gilbert 1/11 #######//

			refreshFlag = 0;
		}

		sys.blt_virtual_buf();

		if( scrollBar.detect() == 1)
		{
			refreshFlag |= TUOPTION_SCROLL | TUOPTION_ALL_BROWSE;
		}
		else if( scrollUp.detect() )
		{
			// click on scroll up
			int oldValue = scrollBar.view_recno;
			if( oldValue != scrollBar.set_view_recno(oldValue-1) )
				refreshFlag |= TUOPTION_ALL_BROWSE | TUOPTION_SCROLL;
		}
		else if( scrollDown.detect() )
		{
			// click on scroll down
			int oldValue = scrollBar.view_recno;
			if( oldValue != scrollBar.set_view_recno(oldValue+1) )
				refreshFlag |= TUOPTION_ALL_BROWSE | TUOPTION_SCROLL;
		}
		else if( textScrollBar.detect() == 1 )
		{
			refreshFlag |= TUOPTION_TEXT_SCROLL | TUOPTION_TEXT_AREA;
		}
		else if( textScrollUp.detect() )
		{
			// click on scroll up
			int oldValue = textScrollBar.view_recno;
			if( oldValue != textScrollBar.set_view_recno(oldValue-1) )
				refreshFlag |= TUOPTION_TEXT_SCROLL | TUOPTION_TEXT_AREA;
		}
		else if( textScrollDown.detect() )
		{
			// click on scroll down
			int oldValue = textScrollBar.view_recno;
			if( oldValue != textScrollBar.set_view_recno(oldValue+1) )
				refreshFlag |= TUOPTION_TEXT_SCROLL | TUOPTION_TEXT_AREA;
		}
		else if( mouse.double_click( menuX1+BROWSE_X1, menuY1+BROWSE_Y1, 
			menuX1+BROWSE_X1+BROWSE_REC_WIDTH-1, 
			menuY1+BROWSE_Y1+ BROWSE_REC_HEIGHT*MAX_BROWSE_DISP_REC -1) )
		{
			// double click on game slot
			int oldValue = browseRecno;
			int newValue = scrollBar.view_recno + (mouse.click_y(0) - BROWSE_Y1 - menuY1) / BROWSE_REC_HEIGHT;
			if( newValue <= scenCount && newValue == oldValue )
			{
				browseRecno = newValue;
				retFlag = newValue;
				break;
			}
		}
		else if( mouse.single_click( menuX1+BROWSE_X1, menuY1+BROWSE_Y1, 
			menuX1+BROWSE_X1+BROWSE_REC_WIDTH-1, 
			menuY1+BROWSE_Y1+ BROWSE_REC_HEIGHT*MAX_BROWSE_DISP_REC -1) )
		{
			// click on game slot
			int oldValue = browseRecno;
			int newValue = scrollBar.view_recno + (mouse.click_y(0) - BROWSE_Y1 - menuY1) / BROWSE_REC_HEIGHT;
			if( newValue <= scenCount )
			{
				if( oldValue != newValue )
				{
					browseRecno = newValue;
					refreshFlag |= TUOPTION_BROWSE(newValue-scrollBar.view_recno)
						| TUOPTION_TEXT_BUFFER
						| TUOPTION_TEXT_AREA | TUOPTION_PIC_AREA;
					if( oldValue-scrollBar.view_recno >= 0 && oldValue-scrollBar.view_recno < MAX_BROWSE_DISP_REC)
						refreshFlag |= TUOPTION_BROWSE(oldValue-scrollBar.view_recno);
				}
			}
		}
		// ######## begin Gilbert 1/11 #########//
		else if( playerNameField.detect() )
		{
			// load button
			refreshFlag = TUOPTION_NAME_FIELD;
		}
		// ######## end Gilbert 1/11 #########//
		else if( cancelButton.detect(KEY_ESC) || mouse.any_click(RIGHT_BUTTON) > 0)		// also when ESC key is pressed or right button
		{
			// cancel button or escape key
			refreshFlag = TUOPTION_ALL;
			retFlag = 0;
			break;		// break while(1)
		}
		else if( startButton.detect() )
		{
			// load button
			refreshFlag = TUOPTION_ALL;
			retFlag = browseRecno;
			break;
		}
	}

	power.win_opened = 0;

	return retFlag;
}
Пример #5
0
//--------- Begin of static function detect_nation_chat ---------//
//
static void detect_nation_chat()
{
	int nationRecno = nation_filter(info.browse_nation_recno);

	//----- if the selected nation is the viewing nation ----//

	if( sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
		 info.viewing_nation_recno == nation_array.player_recno )
	{
		// ###### begin Gilbert 15/10 #######//
		if( !init_get_chat )
		{
			get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
				info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
			get_chat.clear();
			init_get_chat = 1;
		}
		// ###### end Gilbert 15/10 #######//

		for( int i=0 ; i<5 ; i++ )
		{
			int keyCode = get_chat.detect();

			if( !keyCode )
				break;

			//---- press <Enter> to send the chat message ----//

			if( keyCode == KEY_RETURN && info.player_chat_str[0] != '\0')
			{
				if( remote.is_enable() )
				{
					// packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
					short *shortPtr = (short *)remote.new_send_queue_msg(MSG_CHAT, 2*sizeof(short) + strlen(info.player_chat_str)+1 );

					switch( info.chat_receiver_type )
					{
					case 1:		// selected
						shortPtr[0] = nationRecno;
						break;
					case 2:		// all allies
						shortPtr[0] = -1;
						break;
					case 3:		// all human
						shortPtr[0] = 0;
						break;
					}
					shortPtr[1] = info.viewing_nation_recno;

					strcpy(2*sizeof(short)+(char *)shortPtr, info.player_chat_str);
				}

				get_chat.clear();
				break;
			}

			mouse.get_event();
		}
	}

	//-------- detect receiver type buttons ---------//

	int y=REPORT_TALK_Y2-70;

	for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
	{
		if( mouse.single_click( REPORT_DET_X1+10, y, REPORT_DET_X2-50, y+20 ) )
		{
			info.chat_receiver_type = i;
			return;
		}
	}
}
Пример #6
0
// ------- Begin of function Game::select_campaign_menu -----//
//
// select which campaign to play, set config as well
//
// return 0=cancel, >0 for campaign selected
//
int Game::select_campaign_menu()
{
	// static char *campaignList[] = { "Occidental Heroes" };	//, "Human Learning Campaign", "Fryhtan Campaign", "Fryhtan Learning Campaign", };
	static const char *campaignList[] = 
	{
		text_campaign.str_campaign_name(CAMPAIGN_EAST_WEST),
	};
	int campaignCount = sizeof(campaignList) / sizeof(campaignList[0]);

	Config tempConfig = config;

	// ------ adjust config ------//

	tempConfig.default_campaign_setting();

	if( tempConfig.race_id < 0 )		// human race only
		tempConfig.race_id = 1;

	// ----------------------------//

	int optionMode;
	if (campaignCount == 1)
		optionMode = OPTION_BASIC;
	else
		optionMode = OPTION_CAMPAIGN;

	TempGameSet tempGameSet(1);		// game_set.open_set
	TempUnitRes tempUnitRes;			// unit_res.init
	TempRaceRes tempRaceRes;			// race_res.init

	// take name from profile

	if( player_profile.is_registered() )
	{
		strcpy( tempConfig.player_name, player_profile.player_name );
	}

	//--------- initialize variable ---------//

	int i;
	int w, h;
	int cx, cy;
	String str;
	long refreshFlag = SGOPTION_ALL;
	int retFlag = 0;

	// -------- generate palette ------//

	short colorRemapTable[0x100];
	{
		str = DIR_IMAGE;
		str += "CHOOSE.COL";

		File palFile;
		palFile.file_open(str);
		ColorTable colorTable;

		BYTE palBuf[0x100][3];
		palFile.file_seek(8);     				// bypass the header info
		palFile.file_read(palBuf, sizeof(palBuf));
		palFile.file_close();

		// ------- palette description -------------//

		PalDesc palBufDesc( palBuf, 3, 0x100, 8 );

		//-------- create color remap table ---------//

		colorTable.generate_table_fast( 0, palBufDesc, ColorTable::bright_func );
		memcpy( colorRemapTable, colorTable.get_table(0), sizeof(colorRemapTable) );
	}

	// ------ initialize human / fryhtan button ------//

	ButtonCustomGroup campaignGroup(campaignCount);

	for( i = 0; i < campaignCount; ++i )
	{
		// divide 125, 680 into campaignCount partitions
		// cx is the center of each parition
		// campaignCount = 1 , (1:1)
		// campaignCount = 2 , (3:1), (1:3)
		// campaignCount = 3 , (5:1), (3:3), (1:5)
		//cx = ( 125*((campaignCount-i)*2-1) + 680*(i*2+1)) / (campaignCount*2);
		//cy = 136;
		cx = 390;
		cy = ( 136 * ((campaignCount-i)*2-1) + 280*(i*2+1)) / (campaignCount*2);

		w = font_thin_black.text_width( campaignList[i] );
		h = font_thin_black.text_height();
		campaignGroup[i].create( cx-w/2-10, cy-h/2-5, cx+w/2+10, cy+h/2+5,
		i_disp_text_button, ButtonCustomPara( campaignList[i], 0 ), 0 );
	}

	// -------- initialize player name field ------//

	GetA playerNameField;
	playerNameField.init( 364, 89, 688, tempConfig.player_name,
		tempConfig.PLAYER_NAME_LEN, &font_bold_black, 0, 1 );

	// -------- initialize human group ---------//

	ButtonCustomGroup raceGroup(MAX_RACE);

	err_when( !race_res.init_flag );
	cx = 210;
	cy = 160;
	const int raceGroupYSpacing = 22;
	for( i = 0; i < MAX_RACE; ++i, (cy += raceGroupYSpacing) )
	{
		w = font_thin_black.text_width( race_res[i+1]->name );
		h = raceGroupYSpacing;
		raceGroup[i].create( cx-w/2-5, cy-h/2, cx+w/2+5, cy+h/2,
			i_disp_race_button, ButtonCustomPara( NULL, i+1 ), 0 );
	}

	// ------- create color group --------//

	ButtonCustomGroup colorGroup(MAX_COLOR_SCHEME);
	const int colorButtonFrameX = 382;
	const int colorButtonFrameY = 155;
	cx = 391;
	cy = 162;
	const int colorButtonWidth = 29;
	const int colorButtonHeight = 30;
	for(i = 0; i < MAX_COLOR_SCHEME; ++i, (cx+=colorButtonWidth) )
	{
		colorGroup[i].create( cx, cy, cx+colorButtonWidth-1, cy+colorButtonHeight-1, 
			i_disp_color_button, ButtonCustomPara(NULL, i+1), 0 );
	}

	// ---------- initialize campaign difficulty_level button group -------//

	ButtonCustomGroup campDiffGroup(5);
	char campDiffButtonStr[5][10];
	cx = 410;
	cy = 331;
	for( i = 0; i < 5; ++i )
	{
		strcpy( campDiffButtonStr[i], misc.roman_number(i+1) );

		w = font_thin_black.text_width(campDiffButtonStr[i]);
		h = font_thin_black.text_height();
		campDiffGroup[i].create( cx, cy, cx+w+10, cy+h+10,
			i_disp_text_button, ButtonCustomPara(campDiffButtonStr[i], i+1), 0);
		cx += w + 20;
	}

	// --------- initialize building size --------//

	ButtonCustomGroup buildingSizeGroup(2);
	const char *buildingSizeButtonStr[2] =
	{
		text_game_menu.str_building_set(1),
		text_game_menu.str_building_set(2),
	};
	cx = 370+63;
	cy = 386;
	for( i = 0; i < buildingSizeGroup.button_num; ++i )
	{
		w = font_thin_black.text_width(buildingSizeButtonStr[i]);
		h = font_thin_black.text_height();
		buildingSizeGroup[i].create( cx, cy, cx+w+10, cy+h+10, 
			i_disp_text_button, ButtonCustomPara(buildingSizeButtonStr[i], i+1), 0 );
		cx += w + 12;
	}

	// ------ initialize fog of war ------//

	const int option3X = 320;
	ButtonCustomGroup fogGroup(2);
	cx = option3X;
	cy = 173; // cy = 143;
	w = font_thin_black.text_width( text_game_menu.str_off_on(0) );	// Off
	h = font_thin_black.text_height();
	fogGroup[0].create( cx, cy, cx+w+10, cy+h+10,
		i_disp_text_button, ButtonCustomPara( text_game_menu.str_off_on(0), 0), 0 );		// Off
	cx += w+20;
	w = font_thin_black.text_width( text_game_menu.str_off_on(1) );	// On
	fogGroup[1].create( cx, cy, cx+w+10, cy+h+10,
		i_disp_text_button, ButtonCustomPara( text_game_menu.str_off_on(1), 1), 0 );	// On

/*
	// --------- initialize spy methodology-------//

	char *spyMethodStr[2] = { "Must  Research", "All  Available" };

	ButtonCustomGroup spyMethodGroup(2);
	cx = option3X-10;
	cy = 348;
	for( i = 0; i < 2; ++i )
	{
		w = font_thin_black.text_width( spyMethodStr[i] );
		h = font_thin_black.text_height();
		spyMethodGroup[i].create( cx, cy, cx+w+10, cy+h+10,
			i_disp_text_button, ButtonCustomPara( spyMethodStr[i], i), 0 );
		cx += w+20;
	}
*/
	// --------- initialize random_event_frequency button group --------//

	const char *randomEventStr[4] =
	{
		text_game_menu.str_never_to_frequent(OPTION_NONE),
		text_game_menu.str_never_to_frequent(OPTION_LOW),
		text_game_menu.str_never_to_frequent(OPTION_MODERATE),
		text_game_menu.str_never_to_frequent(OPTION_HIGH),
	};

	ButtonCustomGroup randomEventGroup(4);
	cx = option3X;
	cy = 314; // cy = 384;
	for( i = 0; i < 4; ++i )
	{
		w = font_thin_black.text_width( randomEventStr[i] );
		h = font_thin_black.text_height();
		randomEventGroup[i].create(cx, cy, cx+w+10, cy+h+6,
			i_disp_text_button, ButtonCustomPara(randomEventStr[i], i), 0);
		if( (i+1) % 2 == 0 )
		{
			// line feed
			cx = option3X;
			cy += 26;
		}
		else
		{
			cx += 144;
		}
	}


	// ------- loop ---------//

	{
		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 0;
				}
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
			else if( sys.paused_flag || !sys.active_flag )
			{
				WaitMessage();
				continue;
			}
#endif

			if( sys.need_redraw_flag )
			{
				refreshFlag = SGOPTION_ALL;
				sys.need_redraw_flag = 0;
			}

			VgaFrontReLock vgaReLock;

			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();
			}

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

			if( refreshFlag )
			{
				if( optionMode == OPTION_CAMPAIGN )
				{
					if( refreshFlag & SGOPTION_PAGE )
					{
						vga.use_back();
						vga_util.disp_image_file("CHOOSE");

						// ------- display option Mode ------//

						for( i = OPTION_CAMPAIGN; i <= OPTION_ADVANCED; ++i )
						{
							// red font for selected
							Font *fontPtr = (i == optionMode ? &font_bold_red : &font_bold_black );

							fontPtr->center_put(OPTION_SWITCH_X1, OPTION_SWITCH_Y1+OPTION_SWITCH_Y_SPACING*i,
								OPTION_SWITCH_X2, OPTION_SWITCH_Y2+OPTION_SWITCH_Y_SPACING*i, 
								misc.roman_number(i+1) );
						}

						// ----- display start, cancel button ------//

						font_thin_black.center_put( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2,
							text_game_menu.str_start() );
						font_thin_black.center_put( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2,
							text_game_menu.str_cancel() );

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

					if( refreshFlag & SGOPTION_CAMPAIGN )
						campaignGroup.paint();
				}

				// ------- display basic option ---------//

				if( optionMode == OPTION_BASIC )
				{
					if( refreshFlag & SGOPTION_PAGE )
					{
						vga.use_back();
						vga_util.disp_image_file("CHOOSE");
						// BUGHERE : option menu column and finger

						font_bold_black.right_put( playerNameField.x, playerNameField.y,
							text_game_menu.str_king_name() );
						font_bold_black.center_put( 116, 126, 303, 146,	text_game_menu.str_nationality() );
						font_bold_black.center_put( 382, 129, 600, 149, text_game_menu.str_color() );
						font_bold_black.center_put( 341, 305, 654, 324, text_game_menu.str_difficulty_level() );
						font_bold_black.center_put( 341, 365, 660, 384, text_game_menu.str_building_set() );
						
						// ------- display option Mode ------//

						for( i = OPTION_CAMPAIGN; i <= OPTION_ADVANCED; ++i )
						{
							// red font for selected
							Font *fontPtr = (i == optionMode ? &font_bold_red : &font_bold_black );

							fontPtr->center_put(OPTION_SWITCH_X1, OPTION_SWITCH_Y1+OPTION_SWITCH_Y_SPACING*i,
								OPTION_SWITCH_X2, OPTION_SWITCH_Y2+OPTION_SWITCH_Y_SPACING*i, 
								misc.roman_number(i+1) );
						}

						// ----- display start, cancel button ------//

						font_thin_black.center_put( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2,
							text_game_menu.str_start() );
						font_thin_black.center_put( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2,
							text_game_menu.str_cancel() );

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

					if( refreshFlag & SGOPTION_RACE )
						raceGroup.paint( tempConfig.race_id-1 );
					if( refreshFlag & SGOPTION_COLOR )
					{
						vga.use_back();		// to avoid flickering

						// ------ put color box ------ //
						char *bitmapPtr = image_button.read("F-COLOR");
						vga.active_buf->put_bitmap_trans_remap_decompress(
							colorButtonFrameX, colorButtonFrameY, bitmapPtr,
							game.color_remap_array[tempConfig.player_nation_color].color_table );
						colorGroup.paint(tempConfig.player_nation_color-1);

						vga.use_front();

						vga_util.blt_buf( colorButtonFrameX, colorButtonFrameY,
							colorButtonFrameX + ((Bitmap *)bitmapPtr)->get_width() - 1,
							colorButtonFrameY + ((Bitmap *)bitmapPtr)->get_height() - 1, 0 );
					}
					if( refreshFlag & SGOPTION_DIFFICULTY )
						campDiffGroup.paint(tempConfig.campaign_difficulty-1);
					if( refreshFlag & SGOPTION_BUILDING_SIZE )
						buildingSizeGroup.paint(tempConfig.building_size-1);
					if( refreshFlag & SGOPTION_NAME_FIELD )
						playerNameField.paint();
				}

				// ------- display advanced option ---------//
				if( optionMode == OPTION_ADVANCED )
				{
					if( refreshFlag & SGOPTION_PAGE )
					{
						vga.use_back();
						vga_util.disp_image_file("CHOOSE");

						font_bold_black.put_paragraph( 126, 173, option3X-10, 213-1,
							text_game_menu.str_fog_of_war() );

//						font_bold_black.put_paragraph( 126, 339, option3X-10, 389-1,
//							text_game_menu.str_spy_methodology() );

						font_bold_black.put_paragraph( 126, 314, option3X-10, 364-1,
							text_game_menu.str_random_events() );

						// ------- display option Mode ------//

						for( i = OPTION_CAMPAIGN; i <= OPTION_ADVANCED; ++i )
						{
							// red font for selected
							Font *fontPtr = (i == optionMode ? &font_bold_red : &font_bold_black );

							fontPtr->center_put(OPTION_SWITCH_X1, OPTION_SWITCH_Y1+OPTION_SWITCH_Y_SPACING*i,
								OPTION_SWITCH_X2, OPTION_SWITCH_Y2+OPTION_SWITCH_Y_SPACING*i,
								misc.roman_number(i+1) );
						}

						// ----- display start, cancel button ------//

						font_thin_black.center_put( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2,
							text_game_menu.str_start() );
						font_thin_black.center_put( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2,
							text_game_menu.str_cancel() );

						vga.use_front();
						vga_util.blt_buf( 0, 0, VGA_WIDTH-1, VGA_HEIGHT-1, 0 );
					}
					if( refreshFlag & SGOPTION_FOG )
						fogGroup.paint(tempConfig.fog_of_war);

//					if( refreshFlag & SGOPTION_SPY_METHOD )
//						spyMethodGroup.paint(tempConfig.spy_methodology);

					if( refreshFlag & SGOPTION_RANDOM_EVENT )
						randomEventGroup.paint(tempConfig.random_event_frequency);
				}

				refreshFlag = 0;
			}

			sys.blt_virtual_buf();

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

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

			if( optionMode == OPTION_CAMPAIGN )
			{
				if( campaignGroup.detect() >= 0 
					|| campaignGroup[campaignGroup()].detect(0,0,0,1) )	// detect pushed button, but suspend pop
				{
					optionMode = OPTION_BASIC;		// auto change to basic mode
					refreshFlag = SGOPTION_ALL;
				}
			}

			else if( optionMode == OPTION_BASIC )
			{
				if( raceGroup.detect() >= 0)
				{
					tempConfig.race_id = raceGroup[raceGroup()].custom_para.value;
					//refreshFlag |= SGOPTION_RACE;
				}
				else if( colorGroup.detect() >= 0)
				{
					tempConfig.player_nation_color = colorGroup[colorGroup()].custom_para.value;
					refreshFlag |= SGOPTION_COLOR;
				}
				else if( campDiffGroup.detect() >= 0)
				{
					tempConfig.campaign_difficulty = campDiffGroup[campDiffGroup()].custom_para.value;
					refreshFlag |= SGOPTION_DIFFICULTY;
				}
				else if( buildingSizeGroup.detect() >= 0)
				{
					tempConfig.building_size = buildingSizeGroup[buildingSizeGroup()].custom_para.value;
					//refreshFlag |= SGOPTION_BUILDING_SIZE;
				}
				else if( playerNameField.detect() )
				{
					refreshFlag |= SGOPTION_NAME_FIELD;
				}
			}

			else if( optionMode == OPTION_ADVANCED )
			{
				if( fogGroup.detect() >= 0 )
				{
					tempConfig.fog_of_war = fogGroup[fogGroup()].custom_para.value;
					// refreshFlag |= SGOPTION_FOG;
				}
/*
				else if( spyMethodGroup.detect() >= 0 )
				{
					tempConfig.spy_methodology = spyMethodGroup[spyMethodGroup()].custom_para.value;
					// refreshFlag |= SGOPTION_SPY_METHOD;
				}
*/
				else if( randomEventGroup.detect() >= 0)
				{
					tempConfig.random_event_frequency = randomEventGroup[randomEventGroup()].custom_para.value;
					refreshFlag |= SGOPTION_RANDOM_EVENT;
				}
			}

			// -------- detect switch option button ---------//

			for( i = OPTION_CAMPAIGN; i <= OPTION_ADVANCED; ++i )
			{
				if( mouse.single_click( OPTION_SWITCH_X1, OPTION_SWITCH_Y1+OPTION_SWITCH_Y_SPACING*i,
					OPTION_SWITCH_X2, OPTION_SWITCH_Y2+OPTION_SWITCH_Y_SPACING*i) )
				{
					optionMode = i;
					refreshFlag = SGOPTION_ALL;
				}
			}

			// -------- detect start button --------//

			if( mouse.single_click( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2 ) )
			{
				retFlag = campaignGroup() + 1;
				break;			// break  while(1)
			}

			// -------- detect cancel button --------//

			if( mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2 ) )
			{
				retFlag = 0;
				break;			// break  while(1)
			}

		}	// end while
	} // end of scope of VgaLock

	if( retFlag )
	{
		tempConfig.human_difficulty_rating = tempConfig.single_player_difficulty(1);
		tempConfig.monster_difficulty_rating = tempConfig.single_player_difficulty(-1);
		config = tempConfig;
	}

	return retFlag;
}
Пример #7
0
//--------- Begin of static function detect_nation_chat ---------//
//
static void detect_nation_chat()
{
/*	int nationRecno = info.nation_filter(info.browse_nation_recno);

	//----- if the selected nation is the viewing nation ----//

	if( sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
		 info.viewing_nation_recno == nation_array.player_recno )
	{
		// ###### begin Gilbert 22/2 #######//
		if( !init_get_chat || get_chat.x != REPORT_DET_X1+10 || get_chat.y != REPORT_DET_Y1+30 )		// re-init after resolution change
		{
			get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
				info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
			get_chat.clear();
			init_get_chat = 1;
		}
		// ###### end Gilbert 22/2 #######//

		for( int i=0 ; i<5 ; i++ )
		{
			int keyCode = get_chat.detect();

			if( !keyCode )
				break;

			//---- press <Enter> to send the chat message ----//

			if( keyCode == KEY_RETURN && info.player_chat_str[0] != '\0')
			{
				if( remote.is_enable() )
				{
					// packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
					short *shortPtr = (short *)remote.new_send_queue_msg(MSG_CHAT, 2*sizeof(short) + strlen(info.player_chat_str)+1 );

					switch( info.chat_receiver_type )
					{
					case 1:		// selected
						shortPtr[0] = nationRecno;
						break;
					case 2:		// all allies
						shortPtr[0] = -1;
						break;
					case 3:		// all human
						shortPtr[0] = 0;
						break;
					}
					shortPtr[1] = info.viewing_nation_recno;

					strcpy(2*sizeof(short)+(char *)shortPtr, info.player_chat_str);
				}

				get_chat.clear();
				break;
			}

			mouse.get_event();
		}
	}

	//-------- detect receiver type buttons ---------//

	int y=REPORT_TALK_Y2-70;

	for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
	{
		if( mouse.single_click( REPORT_DET_X1+10, y, REPORT_DET_X2-50, y+20 ) )
		{
			info.chat_receiver_type = i;
			return;
		}
	}
*/

	// init button

	if( !init_get_chat || get_chat.x != REPORT_DET_X1+10 || get_chat.y != REPORT_TALK_Y2 - 26 )		// re-init after resolution change
	{
		get_chat.init( REPORT_DET_X1 + 10, REPORT_TALK_Y2 - 26, REPORT_DET_X2-10,
			info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
		get_chat.clear();

		init_get_chat = 1;
	}

	// detect receiver button 

	int x = RECIPIENT_BUTTON_X1;
	int y1 = RECIPIENT_BUTTON_Y1;
	int y2 = RECIPIENT_BUTTON_Y2;
	int i;

	if( mouse.single_click( x, y1, x+68, y2 ) )
		info.chat_receiver_type = CHAT_RECEIVER_ALL_HUMAN;
	x += 70;

	if( mouse.single_click( x, y1, x+68, y2 ) )
		info.chat_receiver_type = CHAT_RECEIVER_ALL_ALLY;
	x += 70;

	// draw nation color button
	int nc = info.nation_filter();
	int nationRecno;
	if( info.chat_receiver_type == CHAT_RECEIVER_CURRENT
		&& info.browse_nation_recno >= 1 && info.browse_nation_recno <= nc )
		nationRecno = info.nation_filter(info.browse_nation_recno);
	else
		nationRecno = 0;
	for( i = 1; i <= nc; ++i )
	{
		int n = info.nation_filter(i);
		if( nation_array[n]->is_remote() )
		{
			if( mouse.single_click( x, y1, x+24, y2 ) )
			{
				info.browse_nation_recno = i;
				info.chat_receiver_type = CHAT_RECEIVER_CURRENT;
			}
			x += 26;
		}
	}

	// draw hide nation button

	x = REPORT_DET_X2 - 200 - 8 ;
	if( mouse.single_click( x, y1, x+200-1, y2 ) )
		hide_nation_browse = !hide_nation_browse;

	// detect get, detect max 5 times

	for( i=0 ; i<5 ; i++ )
	{
		int keyCode = get_chat.detect();

		if( !keyCode )
			break;

		//---- press <Enter> to send the chat message ----//

		if( keyCode == KEY_RETURN && info.player_chat_str[0] != '\0')
		{
			if( remote.is_enable() )
			{
				// use new_msg instead of new_send_queue_msg, so chat message can send immediately
				// packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
				// short *shortPtr = (short *)remote.new_send_queue_msg(MSG_CHAT, 2*sizeof(short) + strlen(info.player_chat_str)+1 );

				RemoteMsg *remoteMsg = remote.new_msg(MSG_CHAT, 2*sizeof(short) + strlen(info.player_chat_str)+1 );
				short *shortPtr = (short *)remoteMsg->data_buf;

				switch( info.chat_receiver_type )
				{
				case CHAT_RECEIVER_CURRENT:
					shortPtr[0] = nationRecno;
					break;
				case CHAT_RECEIVER_ALL_ALLY:
					shortPtr[0] = -1;
					break;
				case CHAT_RECEIVER_ALL_HUMAN:
					shortPtr[0] = 0;
					break;
				}
				shortPtr[1] = info.viewing_nation_recno;

				strcpy(2*sizeof(short)+(char *)shortPtr, info.player_chat_str);
		      remote.send_free_msg( remoteMsg );     // send out the message and free it after finishing sending
			}

			{
				// add a copy to sender
				int chatIndex = info.append_chat( NULL );
				if( chatIndex )
				{
					ChatInfo *chatInfo = &info.remote_chat_array[chatIndex-1];
					chatInfo->received_date = info.game_date;
					chatInfo->from_nation_recno = (char)info.viewing_nation_recno;
					strcpy( chatInfo->chat_str, info.player_chat_str );
				}
			}

			get_chat.clear();
			break;
		}

		mouse.get_event();
	}
}
Пример #8
0
//--------- Begin of static function disp_nation_chat ---------//
//
static void disp_nation_chat(int refreshFlag)
{
/*
	int nationRecno = info.nation_filter(info.browse_nation_recno);

	//----- if the selected nation is the viewing nation ----//

	if( !(sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
		 info.viewing_nation_recno == nation_array.player_recno ) )
	{
		return;
	}

	//-------- display the chat get control -------//

	vga_util.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_TALK_Y2 );

	font_bld.put( REPORT_DET_X1+10, REPORT_DET_Y1+10,
					  // "Please enter your chat message and press <Enter> to send." );
		text_reports.str_chat_inst() );

	// ###### begin Gilbert 22/2 #######//
	if( !init_get_chat || get_chat.x != REPORT_DET_X1+10 || get_chat.y != REPORT_DET_Y1+30 )		// re-init after resolution change
	// ###### end Gilbert 22/2 #######//
	{
		get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
			info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
		get_chat.clear();

		button_hide_nation_browse.create_text( REPORT_DET_X2-100, REPORT_TALK_Y2-24,
			REPORT_DET_X2-8, REPORT_TALK_Y2-8, "Hide Kingdoms' Detail" );

		init_get_chat = 1;
	}

	int vgaUseBack = vga.use_back_buf;

	vga.use_back();
	get_chat.paint(1);			// 1-paint cursor

	if( !vgaUseBack )
		vga.use_front();

	//-------- display receiver type buttons ---------//

	int y=REPORT_TALK_Y2-70;

	for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
	{
		if( info.chat_receiver_type == i )
			vga_util.d3_panel_down( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );
		else
			vga_util.d3_panel_up( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );

		// font_bld.center_put( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20, chat_receiver_str_array[i-1] );
		font_bld.center_put( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20, 
			text_reports.str_chat_recipient(i) );
	}
*/

	int vgaUseBack = vga.use_back_buf;
	vga.use_back();

	// init button

	if( !init_get_chat || get_chat.x != REPORT_DET_X1+10 || get_chat.y != REPORT_TALK_Y2 - 26 )		// re-init after resolution change
	{
		get_chat.init( REPORT_DET_X1 + 10, REPORT_TALK_Y2 - 26, REPORT_DET_X2-10,
			info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
		get_chat.clear();

		init_get_chat = 1;
	}

	// disp frame
	vga_util.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_TALK_Y2 );

	font_bld.put( REPORT_DET_X1+10, REPORT_TALK_Y2 - 66,
					  // "Please enter your chat message and press <Enter> to send." );
		text_reports.str_chat_inst() );

	// display receiver button 

	int x = RECIPIENT_BUTTON_X1;
	int y1 = RECIPIENT_BUTTON_Y1;
	int y2 = RECIPIENT_BUTTON_Y2;
	int i;

	if( info.chat_receiver_type == CHAT_RECEIVER_ALL_HUMAN )
	{
		vga_util.d3_panel_down( x, y1, x+68, y2 );
		font_bld.center_put( x, y1+2, x+68, y2-1, text_reports.str_chat_recipient(CHAT_RECEIVER_ALL_HUMAN) );
	}
	else
	{
		vga_util.d3_panel_up( x, y1, x+68, y2, 0, 1 );
		font_bld.center_put( x, y1+1, x+68, y2-2, text_reports.str_chat_recipient(CHAT_RECEIVER_ALL_HUMAN) );
	}
	x += 70;

	if( info.chat_receiver_type == CHAT_RECEIVER_ALL_ALLY )
	{
		vga_util.d3_panel_down( x, y1, x+68, y2 );
		font_bld.center_put( x, y1+2, x+68, y2-1, text_reports.str_chat_recipient(CHAT_RECEIVER_ALL_ALLY) );
	}
	else
	{
		vga_util.d3_panel_up( x, y1, x+68, y2, 0, 1 );
		font_bld.center_put( x, y1+1, x+68, y2-2, text_reports.str_chat_recipient(CHAT_RECEIVER_ALL_ALLY) );
	}
	x += 70;

	// draw nation color button
	int nc = info.nation_filter();
	int nationRecno;
	if( info.chat_receiver_type == CHAT_RECEIVER_CURRENT
		&& info.browse_nation_recno >= 1 && info.browse_nation_recno <= nc )
		nationRecno = info.nation_filter(info.browse_nation_recno);
	else
		nationRecno = 0;
	for( i = 1; i <= nc; ++i )
	{
		int n = info.nation_filter(i);
		if( nation_array[n]->is_remote() )
		{
			if( nationRecno == n )
			{
				vga_util.d3_panel_down( x, y1, x+24, y2 );
				vga.active_buf->bar( x+7, y1+7, x+18, y2-5, nation_array[n]->nation_color );
			}
			else
			{
				vga_util.d3_panel_up( x, y1, x+24, y2, 0 ,1 );
				vga.active_buf->bar( x+6, y1+6, x+17, y2-6, nation_array[n]->nation_color );
			}
			x += 26;
		}
	}

	// draw hide nation button

	x = REPORT_DET_X2 - 200 - 8 ;
	if( hide_nation_browse )
	{
		vga_util.d3_panel_down( x, y1, x+200-1, y2 );
		font_bld.center_put( x, y1+2, x+200-1, y2-1, text_reports.str_hide_nation_detail() );
	}
	else
	{
		vga_util.d3_panel_up( x, y1, x+200-1, y2, 0, 1 );
		font_bld.center_put( x, y1+1, x+200-1, y2-2, text_reports.str_hide_nation_detail() );
	}

	// draw get field

	get_chat.paint(1);			// 1-paint cursor

	// display message log, display news in reversed order, from down to up

	int chatMsgCount = info.chat_msg_filter();
	int msgY = REPORT_TALK_Y2 - 80;
	for( i = -1; i >= -chatMsgCount && msgY >= REPORT_DET_Y1+4 ; --i )
	{
		ChatInfo *chatInfo = &info.remote_chat_array[info.chat_msg_filter(i)-1];
		if( !nation_array.is_deleted( chatInfo->from_nation_recno ) )
		{
			nation_array[chatInfo->from_nation_recno]->disp_nation_color( REPORT_DET_X1+10, msgY+2 );
			font_cara_w.put( REPORT_DET_X1+25, msgY, chatInfo->chat_str, 0, REPORT_DET_X2-6 );
			msgY -= font_cara_w.max_font_height;
		}
	}

	if( !vgaUseBack )
		vga.use_front();
}