void OptionMenu::set_active() { active_flag = 1; // load palette and bitmap so no need to load every time if( !color_remap_table ) { color_remap_table = (short *)mem_add( sizeof(*color_remap_table)*0x100 ); ColorTable colorTable; { File palFile; { // save stack space for str and palBuf String str(DIR_IMAGE); str += "CHOOSE2.COL"; palFile.file_open(str); } { 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( color_remap_table, colorTable.get_table(0), sizeof(*color_remap_table)*0x100 ); } if( !background_bitmap ) { File imageFile; String str(DIR_IMAGE); str += "CHOOSE2.ICN"; imageFile.file_open(str); background_bitmap = (char *)mem_add( imageFile.file_size() ); imageFile.file_read( background_bitmap, imageFile.file_size() ); } }
//-------- Begin of function GameFileArray::menu --------// // // <int> actionMode = -2 - save screen to back buffer // -1 - restore screen to back buffer // 1 - save game // 2 - load game // 3 - load game from main menu // // <int *> recno = if overwritting save game or load game acion // is succcessful, return the recno of GameFile // // return : <int> 1 - game loaded/saved // 0 - user cancel loading/saving // -1 - loading/saving error // int GameFileArray::menu(int actionMode, int *recno) { enum { PAGE_WIDTH = 800, PAGE_HEIGHT = 600 }; int bx = (VGA_WIDTH - PAGE_WIDTH) / 2; int by = (VGA_HEIGHT - PAGE_HEIGHT) / 2; if( actionMode == -2 || actionMode == -1) { // copy or restore screen to back buffer int scrnX1, scrnY1, scrnX2, scrnY2; scrnX1 = bx; scrnY1 = by; scrnX2 = scrnX1 + PAGE_WIDTH - 1; scrnY2 = scrnY1 + PAGE_HEIGHT - 1; return 1; } action_mode = actionMode; pre_game = 0; if( actionMode == 3 ) // actionMode = 3 means load game from main menu, so action_mode is still two { action_mode = 2; pre_game = 1; } if( action_mode==2 && size()==0 ) { box.msg( text_game_menu.str_none_save_game() ); // "You haven't saved any games yet." ); return 0; } // load race icon char deinitGameSet=0; char deinitUnitRes=0; char deinitRaceRes=0; char deinitMonsterRes=0; if( !game_set.set_opened_flag ) { game_set.open_set(1); deinitGameSet = 1; } if( !unit_res.init_flag ) { unit_res.init(); deinitUnitRes = 1; } if( !race_res.init_flag ) { race_res.init(); deinitRaceRes = 1; } if( !monster_res.init_flag ) { monster_res.init(); // ##### begin Gilbert 30/10 ######// // deinitRaceRes = 1; deinitMonsterRes = 1; // ##### end Gilbert 30/10 ######// } //-------------------------------------// mouse_cursor.set_icon(CURSOR_NORMAL); mouse_cursor.set_frame(0); power.win_opened = 1; int minRecno = 1; //------ set current record no. -------// // ####### begin Gilbert 3/5 ########// int i; if( size() == 0 ) { browse_recno = 0; } else { browse_recno = 1; for( i=1 ; i<=size() ; i++ ) { if( strcasecmp(last_file_name, game_file_array[i]->file_name)==0 ) { browse_recno = i; break; } } } // ####### end Gilbert 3/5 ########// //---------------------------------// browse_top_recno = minRecno; // in save game mode, browse_recno = 0 means selecting empty slot // in load game mode, browse_recno = 0 means nonthing is selected // browse_top_recno = browse_recno ? browse_recno : minRecno; // -------- generate palette ------// short colorRemapTable[0x100]; { String str(DIR_IMAGE); if( pre_game ) str += "CHOOSE.COL"; else str += "CHOOSE2.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) ); } int retFlag = 0; #define SLOT_Y_SPACING 80 #define SLOT_X1(n) (bx + 119) #define SLOT_Y1(n) (by + SLOT_Y_SPACING * (n) + 110) #define SLOT_X2(n) (bx + 119 + SLOT_WIDTH - 1) #define SLOT_Y2(n) (by + SLOT_Y_SPACING * (n) + 110 + SLOT_HEIGHT - 1) char *arrowBitmap = image_button.read("TRI-R"); int pageUpX1 = bx + (LSCROLL_X2 + LSCROLL_X1 - ((Bitmap *)arrowBitmap)->get_width()) / 2; int pageUpY1 = by + (LSCROLL_Y2 + LSCROLL_Y1 - ((Bitmap *)arrowBitmap)->get_height()) / 2; int pageUpX2 = pageUpX1 + ((Bitmap *)arrowBitmap)->get_width() - 1; int pageUpY2 = pageUpY1 + ((Bitmap *)arrowBitmap)->get_height() - 1; int pageDownX1 = bx + (RSCROLL_X2 + RSCROLL_X1 - ((Bitmap *)arrowBitmap)->get_width()) / 2; int pageDownY1 = by + (RSCROLL_Y2 + RSCROLL_Y1 - ((Bitmap *)arrowBitmap)->get_height()) / 2; int pageDownX2 = pageDownX1 + ((Bitmap *)arrowBitmap)->get_width() - 1; int pageDownY2 = pageDownY1 + ((Bitmap *)arrowBitmap)->get_height() - 1; int pageNoX1 = bx + 556; int pageNoY1 = by + 87; int pageNoX2 = bx + 675; int pageNoY2 = by + 107; // ------- define save buffer area ----------// Blob2DW browseArea[MAX_BROWSE_DISP_REC]; // save bitmap of save game slot areas Blob2DW pageUpArea, pageDownArea; Blob2DW pageNoArea; // ------- define button object ----------// Button startButton, cancelButton, delButton; Button saveNewButton; if( !pre_game ) { startButton.create_text( bx+BUTTON2_X1, by+BUTTON2_Y1, bx+BUTTON2_X2, by+BUTTON2_Y2, action_mode == 1 ? text_game_menu.str_save() : text_game_menu.str_load() ); if( action_mode == 1 ) saveNewButton.create_text( bx+BUTTON3_X1, by+BUTTON3_Y1, bx+BUTTON3_X2, by+BUTTON3_Y2, text_game_menu.str_save_new() ); delButton.create_text( bx+BUTTON7_X1, by+BUTTON7_Y1, bx+BUTTON7_X2, by+BUTTON7_Y2, text_game_menu.str_delete_save() ); cancelButton.create_text( bx+BUTTON4_X1, by+BUTTON4_Y1, bx+BUTTON4_X2, by+BUTTON4_Y2, text_game_menu.str_cancel() ); } // int i; int page, maxPage; maxPage = (size()-minRecno+1 + MAX_BROWSE_DISP_REC-1) / MAX_BROWSE_DISP_REC; // divide but round up page = (browse_recno - minRecno) / MAX_BROWSE_DISP_REC; while(1) { //---------- yield --------// sys.yield(); mouse.get_event(); // --------- display ----------// // ------- display image --------// File imageFile; String str(DIR_IMAGE); if( pre_game ) { str += "CHOOSE.ICN"; imageFile.file_open(str); vga.active_buf->put_large_bitmap(bx, by, &imageFile, colorRemapTable); } else { str += "CHOOSE2.ICN"; imageFile.file_open(str); vga.active_buf->put_large_bitmap_trans(bx, by, &imageFile, colorRemapTable); } // ------- display title -------// if( action_mode == 1 ) font_bold_black.center_put( bx+SCROLL_SHEET_X1, by+SCROLL_SHEET_Y1, bx+SCROLL_SHEET_X2, SLOT_Y1(0), text_game_menu.str_save_game() ); // "Save Game" ); else if( action_mode == 2 ) font_bold_black.center_put( bx+SCROLL_SHEET_X1, by+SCROLL_SHEET_Y1, bx+SCROLL_SHEET_X2, SLOT_Y1(0), text_game_menu.str_load_game() ); // "Load Game" ); // display save, save new/ load, delete cancel button if( pre_game ) { if( action_mode == 1 ) { font_thin_black.center_put( bx+BUTTON2_X1, by+BUTTON2_Y1, bx+BUTTON2_X2, by+BUTTON2_Y2, text_game_menu.str_save() ); // "Save" ); font_thin_black.center_put( bx+BUTTON3_X1, by+BUTTON3_Y1, bx+BUTTON3_X2, by+BUTTON3_Y2, text_game_menu.str_save_new() ); // "Save New" ); } else if( action_mode == 2 ) { font_thin_black.center_put( bx+BUTTON2_X1, by+BUTTON2_Y1, bx+BUTTON2_X2, by+BUTTON2_Y2, text_game_menu.str_load() ); // "Load" ); } font_thin_black.center_put( bx+BUTTON4_X1, by+BUTTON4_Y1, bx+BUTTON4_X2, by+BUTTON4_Y2, text_game_menu.str_cancel() ); // "Cancel" ); font_thin_black.center_put( bx+BUTTON7_X1, by+BUTTON7_Y1, bx+BUTTON7_X2, by+BUTTON7_Y2, text_game_menu.str_delete_save() ); // "Delete" ); } else { startButton.paint(); if( action_mode == 1 ) saveNewButton.paint(); cancelButton.paint(); delButton.paint(); } // capture area for( i = 0; i < MAX_BROWSE_DISP_REC; ++i ) { browseArea[i].clear(); browseArea[i].resize(SLOT_X1(i), SLOT_Y1(i), SLOT_WIDTH, SLOT_HEIGHT ); vga.active_buf->read_bitmapW( SLOT_X1(i), SLOT_Y1(i), SLOT_X2(i), SLOT_Y2(i), browseArea[i].bitmap_ptr() ); } // capture page up area pageUpArea.clear(); pageUpArea.resize( pageUpX1, pageUpY1, ((Bitmap *)arrowBitmap)->get_width(), ((Bitmap *)arrowBitmap)->get_height() ); vga.active_buf->read_bitmapW( pageUpX1, pageUpY1, pageUpX2, pageUpY2, pageUpArea.bitmap_ptr() ); pageDownArea.clear(); pageDownArea.resize( pageDownX1, pageDownY1, ((Bitmap *)arrowBitmap)->get_width(), ((Bitmap *)arrowBitmap)->get_height() ); vga.active_buf->read_bitmapW( pageDownX1, pageDownY1, pageDownX2, pageDownY2, pageDownArea.bitmap_ptr() ); // capture page no area pageNoArea.clear(); pageNoArea.resize( pageNoX1, pageNoY1, pageNoX2-pageNoX1+1, pageNoY2-pageNoY1+1 ); vga.active_buf->read_bitmapW( pageNoX1, pageNoY1, pageNoX2, pageNoY2, pageNoArea.bitmap_ptr() ); for( i = 0; i < MAX_BROWSE_DISP_REC; ++i ) { int browseSlotX1 = SLOT_X1(i); int browseSlotY1 = SLOT_Y1(i); int browseSlotX2 = SLOT_X2(i); int browseSlotY2 = SLOT_Y2(i); // draw save bitmap area vga_buffer.put_bitmapW( browseSlotX1, browseSlotY1, browseArea[i].bitmap_ptr() ); // draw slot content int rec = page * MAX_BROWSE_DISP_REC + i + minRecno; if( rec == 0 ) { font_bold_black.center_put( browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2, text_game_menu.str_empty_game_slot() ); // "Empty Game Slot" ); } else if( rec >= 1 && rec <= size() ) { // remain game_file_array[rec]->disp_info() for file find operator[](rec)->disp_info( browseSlotX1, browseSlotY1 ); } // draw selected frame if( rec == browse_recno ) { // draw black frame vga_buffer.rect( browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2, 2, V_BLACK ); } } // String str; // str = "page "; // str += page+1; // str += "/"; // str += maxPage; vga.active_buf->put_bitmapW( pageNoX1, pageNoY1, pageNoArea.bitmap_ptr() ); font_snds.center_put( pageNoX1, pageNoY1, pageNoX2, pageNoY2, text_game_menu.str_page_str(page+1, maxPage) ); if( page > 0 ) vga.active_buf->put_bitmap(pageUpX1, pageUpY1, arrowBitmap, 0, 2, true); else vga.active_buf->put_bitmapW( pageUpX1, pageUpY1, pageUpArea.bitmap_ptr() ); if( page < maxPage-1 ) vga.active_buf->put_bitmap(pageDownX1, pageDownY1, arrowBitmap, 0, 2); else vga.active_buf->put_bitmapW( pageDownX1, pageDownY1, pageDownArea.bitmap_ptr() ); // ------ detect slots -------// int breakWhileFlag = 0; for( i = 0; i < MAX_BROWSE_DISP_REC; ++i ) { int rec = page * MAX_BROWSE_DISP_REC + i + minRecno; int browseSlotX1 = SLOT_X1(i); int browseSlotY1 = SLOT_Y1(i); int browseSlotX2 = SLOT_X2(i); int browseSlotY2 = SLOT_Y2(i); if( rec < minRecno || rec > size() ) continue; if( mouse.double_click(browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2) ) { // double click on game slot if( browse_recno == rec ) { browse_recno = rec; if( recno ) *recno = browse_recno; breakWhileFlag = 1; // signal to break while(1) loop retFlag = process_action(0); // if( retFlag < 0 ) // box.msg("Error"); break; // BUGHERE : how to break while loop } } else if( mouse.single_click(browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2) ) { // click on game slot if( browse_recno != rec ) { // refresh old slot int oldSlot = browse_recno - page * MAX_BROWSE_DISP_REC - minRecno; // refresh new slot browse_recno = rec; break; } } } // ------- detect scroll button -------// if( page > 0 && mouse.any_click( bx+LSCROLL_X1, by+LSCROLL_Y1, bx+LSCROLL_X2, by+LSCROLL_Y2 ) ) { page--; } if( page < maxPage-1 && mouse.any_click( bx+RSCROLL_X1, by+RSCROLL_Y1, bx+RSCROLL_X2, by+RSCROLL_Y2 ) ) { page++; } // -------- detect button at bottom -------// if( (pre_game ? mouse.single_click( bx+BUTTON4_X1, by+BUTTON4_Y1, bx+BUTTON4_X2, by+BUTTON4_Y2) : cancelButton.detect()) || mouse.key_code == KEY_ESC || mouse.any_click(RIGHT_BUTTON) > 0) // also when ESC key is pressed or right button { // cancel button or escape key retFlag = 0; breakWhileFlag = 1; break; // break while(1) } else if( (action_mode == 1 || (action_mode == 2 && browse_recno)) && (pre_game ? mouse.single_click(bx+BUTTON2_X1, by+BUTTON2_Y1, bx+BUTTON2_X2, by+BUTTON2_Y2) : startButton.detect()) ) { // save / load button if( recno ) *recno = browse_recno; retFlag = process_action(0); if( retFlag != 0 ) { // if( retFlag < 0 ) // box.msg("Error"); breakWhileFlag = 1; break; } } else if( action_mode == 1 && (pre_game ? mouse.single_click( bx+BUTTON3_X1, by+BUTTON3_Y1, bx+BUTTON3_X2, by+BUTTON3_Y2) : saveNewButton.detect()) ) { // save new button retFlag = process_action(1); if( retFlag != 0 ) { // if( retFlag < 0 ) // box.msg("Error"); breakWhileFlag = 1; break; } } else if( browse_recno && (pre_game ? mouse.single_click( bx+BUTTON7_X1, by+BUTTON7_Y1, bx+BUTTON7_X2, by+BUTTON7_Y2) : delButton.detect()) ) { // delete save game button if( browse_recno != 0 ) // cannot del save game slot { del_game(); if( browse_recno > size() ) { browse_recno = size(); } // if( browse_top_recno > size()-MAX_BROWSE_DISP_REC+1) // browse_top_recno = size()-MAX_BROWSE_DISP_REC+1; // if( browse_top_recno < minRecno ) // browse_top_recno = minRecno; // scrollBar.set_view_recno(browse_top_recno); // recalculate page maxPage = (size()-minRecno+1 + MAX_BROWSE_DISP_REC-1) / MAX_BROWSE_DISP_REC; // divide but round up if( page >= maxPage ) { page = maxPage - 1; if( page < 0 ) page = 0; } if( action_mode == 2 && size()==0 ) { box.msg( text_game_menu.str_none_save_game()); // "You haven't saved any games yet." ); return 0; } } else { box.msg( text_game_menu.str_cannot_delete_slot()); // "Cannot delete this slot"); } } vga.flip(); if( breakWhileFlag ) break; } power.win_opened = 0; if( retFlag <= 0 ) { // if load game is successful, no need to deinit resource if( deinitGameSet ) game_set.close_set(); if( deinitUnitRes ) unit_res.deinit(); if( deinitRaceRes ) race_res.deinit(); if( deinitMonsterRes ) monster_res.deinit(); } mouse.reset_click(); return retFlag; #undef SLOT_X1 #undef SLOT_Y1 #undef SLOT_X2 #undef SLOT_y2 }
//--------- Begin of function Game::disp_gen_game_status ---------// // // <int> addStep - the steps to be added to the current gen game // progress. // (pass 0 for starting the generating game process. // void Game::disp_gen_game_status(int addStep) { // #### begin Gilbert 14/12 ######// { VgaFrontLock vgaLock; int res = ProcessNextEvent(); if (res == 0) { sys.signal_exit_flag = 1; return; } } // #### end Gilbert 14/12 ######// int POPUP_WINDOW_WIDTH; int POPUP_WINDOW_HEIGHT; if (game.is_campaign_mode()) { POPUP_WINDOW_WIDTH = 444; POPUP_WINDOW_HEIGHT = 275; } else { POPUP_WINDOW_WIDTH = 535; POPUP_WINDOW_HEIGHT = 386; } const int POPUP_WINDOW_X1 = (vga_buffer.buf_width() - POPUP_WINDOW_WIDTH) / 2; const int POPUP_WINDOW_Y1 = (vga_buffer.buf_height() - POPUP_WINDOW_HEIGHT) / 2; const int BAR_X1 = POPUP_WINDOW_X1 + 105; const int BAR_Y1 = POPUP_WINDOW_Y1 + 198; static int genGameProgress=0; VgaFrontReLock vgaReLock; // ------- draw status background ------ // if (game.is_campaign_mode()) image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, "NEWWORLD"); //---- if addStep == 0, start the game generation process ----// if( addStep == 0 ) { genGameProgress = 0; if (game.is_campaign_mode()) image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, "NEWWORLD"); return; } //------------------------------------------// genGameProgress += addStep; int hasLocked=0; if( vga_buffer.vptr_dd_buf ) { if (game.is_campaign_mode()) { short* progressBitmap =NULL; int size = genGameProgress *237 / 100; if (size > 237) size = 237; progressBitmap = (short *)mem_add( BitmapW::size(size, 16) ); vga.active_buf->put_bitmap( BAR_X1, BAR_Y1, image_menu.read("PROGRESS") ); vga.active_buf->read_bitmapW( BAR_X1, BAR_Y1, BAR_X1 +size -1, BAR_Y1 +16-1, progressBitmap ); short* colorRemapTable = NULL; char* backgroundBitmap = NULL; colorRemapTable = (short *)mem_add( sizeof(*colorRemapTable)*0x100 ); ColorTable colorTable; { File palFile; { String str(DIR_IMAGE); str += "NEWWORLD.COL"; palFile.file_open(str); } { 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)*0x100 ); } File imageFile; String str(DIR_IMAGE); str += "NEWWORLD.ICN"; imageFile.file_open(str); backgroundBitmap = (char *)mem_add( imageFile.file_size() ); imageFile.file_read( backgroundBitmap, imageFile.file_size() ); vga.active_buf->put_bitmap_trans_remap(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, backgroundBitmap, colorRemapTable ); vga.active_buf->put_bitmapW(BAR_X1, BAR_Y1, progressBitmap, true); mem_del( backgroundBitmap ); mem_del( colorRemapTable ); mem_del( progressBitmap ); } else { char fileName[] = "NW_00"; fileName[3] = '0' + (char) ((((genGameProgress) /5) +1) /10); fileName[4] = '0' + (char) ((((genGameProgress) /5) +1) %10); image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, fileName); } } // ####### end Gilbert 10/3 #########// }
static void demo_screen() { //------- display screen -----------// int dataSize; File* filePtr = image_interface.get_file("DEMOSCR", dataSize); if (filePtr->file_get_short() != -1 ) { // use common color palette filePtr->file_seek(filePtr->file_pos() - sizeof(short)); vga_back.put_large_bitmap(0, 0, filePtr); } else { // use own color palette unsigned char palette[256 * 3]; short *remapTable; filePtr->file_read(palette, 256 * 3); PalDesc palDesc(palette, 3, 256, 6); ColorTable colorTable; colorTable.generate_table_fast(MAX_BRIGHTNESS_ADJUST_DEGREE, palDesc, ColorTable::bright_func); remapTable = (short *) colorTable.get_table(0); vga_back.put_large_bitmap(0, 0, filePtr, remapTable); } vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1); sys.blt_virtual_buf(); //-------- detect button --------// int highlightButton=0; while(1) { MSG msg; if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage( &msg, NULL, 0, 0)) { return; } TranslateMessage(&msg); DispatchMessage(&msg); continue; } else if( sys.paused_flag || !sys.active_flag ) { WaitMessage(); continue; } //---------- detect menu option buttons -----------// sys.yield(); mouse.get_event(); DemoButton* buttonPtr = demo_button_array; for( int i=0 ; i<DEMO_BUTTON_COUNT ; i++, buttonPtr++ ) { //----- has clicked on a button -------// if( mouse.single_click( buttonPtr->x1, buttonPtr->y1, buttonPtr->x1+buttonPtr->width-1, buttonPtr->y1+buttonPtr->height-1, 0 ) ) { audio.play_wav("BEEPS-1",audio.int_to_DsVolume(config.sound_effect_volume)); switch(i) { case 0: open_http( "anker.url", "http://www.ankerpub.com" ); return; case 1: open_http( "vu.url", "http://www.virtual-u.org" ); return; case 2: return; } } //---- if the mouse cursor is in the area ----// if( mouse.in_area( buttonPtr->x1, buttonPtr->y1, buttonPtr->x1+buttonPtr->width-1, buttonPtr->y1+buttonPtr->height-1 ) ) { if( highlightButton != i+1 ) { highlightButton = i+1; // restore original image first vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1); mouse.hide_area(buttonPtr->x1, buttonPtr->y1, buttonPtr->x1+buttonPtr->width-1, buttonPtr->y1+buttonPtr->height-1); image_interface.put_front( buttonPtr->x1, buttonPtr->y1, buttonPtr->file_name ); mouse.show_area(); sys.blt_virtual_buf(); } break; } } //------- the mouse cursor is not on any of the buttons ------// if( i==DEMO_BUTTON_COUNT ) { if( highlightButton != 0 ) { vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1);// restore original image highlightButton = 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; }
//--------- Begin of function Game::disp_gen_game_status ---------// // // <int> addStep - the steps to be added to the current gen game // progress. // (pass 0 for starting the generating game process. // void Game::disp_gen_game_status(int addStep) { // #### begin Gilbert 14/12 ######// { VgaFrontLock vgaLock; #if 0 // FIXME MSG msg; while (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE) > 0) { // do not get WM_QUIT if (!GetMessage( &msg, NULL, 0, 0)) { sys.signal_exit_flag = 1; // BUGHERE : vga_front is unlocked return; } TranslateMessage(&msg); DispatchMessage(&msg); } #endif } // #### end Gilbert 14/12 ######// int POPUP_WINDOW_WIDTH; int POPUP_WINDOW_HEIGHT; if (game.is_campaign_mode()) { POPUP_WINDOW_WIDTH = 444; POPUP_WINDOW_HEIGHT = 275; } else { #if(!defined(GERMAN) && !defined(FRENCH) && !defined(SPANISH) && !defined(ITALIAN)) // US POPUP_WINDOW_WIDTH = 535; POPUP_WINDOW_HEIGHT = 386; #else POPUP_WINDOW_WIDTH = 444; POPUP_WINDOW_HEIGHT = 275; #endif } // const POPUP_WINDOW_WIDTH = 266; // const POPUP_WINDOW_HEIGHT = 149; // const POPUP_WINDOW_WIDTH = 535; // const POPUP_WINDOW_HEIGHT = 386; const int POPUP_WINDOW_X1 = (vga_front.buf_width() - POPUP_WINDOW_WIDTH) / 2; const int POPUP_WINDOW_Y1 = (vga_front.buf_height() - POPUP_WINDOW_HEIGHT) / 2; const int BAR_X1 = POPUP_WINDOW_X1 + 105; const int BAR_Y1 = POPUP_WINDOW_Y1 + 198; static int genGameProgress=0; // int hasLocked=0; // if( !vga_front.buf_locked ) // lock buffer // { // vga_front.temp_lock(); // hasLocked = 1; // } VgaFrontReLock vgaReLock; // ------- draw status background ------ // if( addStep == 0 || sys.need_redraw_flag ) { if (game.is_campaign_mode()) image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, "NEWWORLD"); sys.need_redraw_flag = 0; } //---- if addStep == 0, start the game generation process ----// if( addStep == 0 ) { genGameProgress = 0; if (game.is_campaign_mode()) image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, "NEWWORLD"); return; } //------------------------------------------// genGameProgress += addStep; int hasLocked=0; if( vga_front.is_inited() ) { if (game.is_campaign_mode()) { short* progressBitmap =NULL; int size = genGameProgress *237 / 100; if (size > 237) size = 237; progressBitmap = (short *)mem_add( BitmapW::size(size, 16) ); vga.active_buf->put_bitmap( BAR_X1, BAR_Y1, image_menu.read("PROGRESS") ); vga.active_buf->read_bitmapW( BAR_X1, BAR_Y1, BAR_X1 +size -1, BAR_Y1 +16-1, progressBitmap ); short* colorRemapTable = NULL; char* backgroundBitmap = NULL; colorRemapTable = (short *)mem_add( sizeof(*colorRemapTable)*0x100 ); ColorTable colorTable; { File palFile; { String str(DIR_IMAGE); str += "NEWWORLD.COL"; palFile.file_open(str); } { 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)*0x100 ); } File imageFile; String str(DIR_IMAGE); str += "NEWWORLD.ICN"; imageFile.file_open(str); backgroundBitmap = (char *)mem_add( imageFile.file_size() ); imageFile.file_read( backgroundBitmap, imageFile.file_size() ); vga.active_buf->put_bitmap_trans_remap(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, backgroundBitmap, colorRemapTable ); vga.active_buf->put_bitmapW_trans( BAR_X1, BAR_Y1, progressBitmap ); mem_del( backgroundBitmap ); mem_del( colorRemapTable ); mem_del( progressBitmap ); } else { #if(defined(GERMAN) || defined(FRENCH) || defined(SPANISH) || defined(ITALIAN)) // prepare palette ColorTable colorTable; { String str = DIR_IMAGE; str += "NW.COL"; PalDescFile palBufDesc( str, 8, 3, 0x100, 8 ); // 8 byte header colorTable.generate_table_fast( 0, palBufDesc, ColorTable::bright_func ); } short* colorRemapTable = (short *)colorTable.get_table(0); // put background bitmap { File imageFile; String str = DIR_IMAGE; str += "NW.ICN"; imageFile.file_open(str); vga.active_buf->put_large_bitmap_trans( POPUP_WINDOW_X1, POPUP_WINDOW_Y1, &imageFile, colorRemapTable ); } // put bar int size = genGameProgress *237 / 100; if (size > 237) size = 237; if( size > 0 ) { vga.active_buf->put_bitmap_area_trans( BAR_X1, BAR_Y1, image_menu.read("PROGRESS"), 0, 0, size -1, 16-1 ); } #else char fileName[] = "NW_00"; fileName[3] = '0' + (char) ((((genGameProgress) /5) +1) /10); fileName[4] = '0' + (char) ((((genGameProgress) /5) +1) %10); image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, fileName); #endif } sys.blt_virtual_buf(); } // ####### end Gilbert 10/3 #########// }