/** * @brief Opens the small ingame menu. */ void menu_small (void) { unsigned int wid; /* Check if menu should be openable. */ if ((player == NULL) || player_isFlag(PLAYER_DESTROYED) || pilot_isFlag(player,PILOT_DEAD) || comm_isOpen() || dialogue_isOpen() || /* Shouldn't open over dialogues. */ (menu_isOpen(MENU_MAIN) || menu_isOpen(MENU_SMALL) || menu_isOpen(MENU_DEATH) )) return; wid = window_create( "Menu", -1, -1, MENU_WIDTH, MENU_HEIGHT ); window_setCancel( wid, menu_small_close ); window_addButton( wid, 20, 20 + BUTTON_HEIGHT*2 + 20*2, BUTTON_WIDTH, BUTTON_HEIGHT, "btnResume", "Resume", menu_small_close ); window_addButton( wid, 20, 20 + BUTTON_HEIGHT + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnOptions", "Options", menu_options_button ); window_addButton( wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnExit", "Exit", menu_small_exit ); menu_Open(MENU_SMALL); }
/** * @brief Opens the information menu. */ void menu_info (void) { char str[128]; char *nt; unsigned int wid; /* Can't open menu twice. */ if (menu_isOpen(MENU_INFO) || dialogue_isOpen()) return; /* Pauses the player's sounds. */ player_soundPause(); wid = window_create( "Info", -1, -1, INFO_WIDTH, INFO_HEIGHT ); /* pilot generics */ nt = ntime_pretty( ntime_get() ); window_addText( wid, 20, 20, 120, INFO_HEIGHT-60, 0, "txtDPilot", &gl_smallFont, &cDConsole, "Pilot:\n" "Date:\n" "Combat\n" " Rating:\n" "\n" "Ship:\n" "Fuel:\n" ); snprintf( str, 128, "%s\n" "%s\n" "\n" "%s\n" "\n" "%s\n" "%d (%d jumps)" , player_name, nt, player_rating(), player->name, (int)player->fuel, pilot_getJumps(player) ); window_addText( wid, 80, 20, INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60, 0, "txtPilot", &gl_smallFont, &cBlack, str ); free(nt); /* menu */ window_addButton( wid, -20, (20 + BUTTON_HEIGHT)*4 + 20, BUTTON_WIDTH, BUTTON_HEIGHT, player->ship->name, "Ship", ship_view ); window_addButton( wid, -20, (20 + BUTTON_HEIGHT)*3 + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits", "Outfts", info_outfits_menu ); window_addButton( wid, -20, (20 + BUTTON_HEIGHT)*2 + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnCargo", "Cargo", info_cargo_menu ); window_addButton( wid, -20, 20 + BUTTON_HEIGHT + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnMissions", "Missions", info_missions_menu ); window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", menu_info_close ); menu_Open(MENU_INFO); }
/** * @brief Opens the information menu. */ void menu_info( int window ) { int w, h; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Open closes when previously opened. */ if (menu_isOpen(MENU_INFO) || dialogue_isOpen()) { info_close( 0, NULL ); return; } /* Dimensions. */ w = 600; h = 500; /* Create the window. */ info_wid = window_create( "Info", -1, -1, w, h ); window_setCancel( info_wid, info_close ); /* Create tabbed window. */ info_windows = window_addTabbedWindow( info_wid, -1, -1, -1, -1, "tabInfo", INFO_WINDOWS, info_names ); /* Open the subwindows. */ info_openMain( info_windows[ INFO_WIN_MAIN ] ); info_openShip( info_windows[ INFO_WIN_SHIP ] ); info_openWeapons( info_windows[ INFO_WIN_WEAP ] ); info_openCargo( info_windows[ INFO_WIN_CARGO ] ); info_openMissions( info_windows[ INFO_WIN_MISN ] ); info_openStandings( info_windows[ INFO_WIN_STAND ] ); menu_Open(MENU_INFO); /* Set active window. */ window_tabWinSetActive( info_wid, "tabInfo", CLAMP( 0, 5, window ) ); }
/** * @brief Toolkit window input is handled here. */ int toolkit_inputWindow( Window *wdw, SDL_Event *event, int purge ) { int ret; ret = 0; /* Event handler. */ if (wdw->eventevent != NULL) wdw->eventevent( wdw->id, event ); /* Hack in case window got destroyed in eventevent. */ if (!window_isFlag(wdw, WINDOW_KILL)) { /* Pass it on. */ switch (event->type) { case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: toolkit_mouseEvent(wdw, event); ret = 1; break; case SDL_KEYDOWN: case SDL_KEYUP: ret = toolkit_keyEvent(wdw, event); break; } } /* Clean up the dead if needed. */ if (purge && !dialogue_isOpen()) { /* Hack, since dialogues use secondary loop. */ if (toolkit_delayCounter > 0) toolkit_delayCounter--; else toolkit_purgeDead(); } return ret; /* don't block input */ }
/** * @brief Updates the toolkit input for repeating keys. */ void toolkit_update (void) { unsigned int t; Window *wdw; Widget *wgt; char buf[2]; SDL_Event event; int ret; /* Clean up the dead if needed. */ if (!dialogue_isOpen()) { /* Hack, since dialogues use secondary loop. */ if (toolkit_delayCounter > 0) toolkit_delayCounter--; else toolkit_purgeDead(); } /* Killed all the windows. */ if (windows == NULL) { SDL_ShowCursor(SDL_DISABLE); toolkit_open = 0; /* disable toolkit */ if (paused) unpause_game(); } /* Must have a key pressed. */ if (input_key == 0) return; t = SDL_GetTicks(); /* Should be repeating. */ if (input_keyTime + INPUT_DELAY + input_keyCounter*INPUT_FREQ > t) return; /* Increment counter. */ input_keyCounter++; /* Check to see what it affects. */ if (windows != NULL) { /* Get the window. */ wdw = toolkit_getActiveWindow(); if (wdw == NULL) return; /* See if widget needs event. */ for (wgt=wdw->widgets; wgt!=NULL; wgt=wgt->next) { if (wgt_isFlag( wgt, WGT_FLAG_RAWINPUT )) { if (wgt->rawevent != NULL) { event.type = SDL_KEYDOWN; event.key.state = SDL_PRESSED; event.key.keysym.sym = input_key; event.key.keysym.mod = 0; ret = wgt->rawevent( wgt, &event ); if (ret != 0) return; } } } /* Handle the focused widget. */ wgt = toolkit_getFocus( wdw ); if ((wgt != NULL) && (wgt->keyevent != NULL)) { wgt->keyevent( wgt, input_key, 0 ); } if ((input_text != 0) && (wgt != NULL) && (wgt->textevent != NULL)) { buf[0] = input_text; buf[1] = '\0'; wgt->textevent( wgt, buf ); } } }