/** * @brief Updates the mission menu mission information based on what's selected. * @param str Unused. */ static void mission_menu_update( unsigned int wid, char* str ) { (void)str; char *active_misn; Mission* misn; active_misn = toolkit_getList( wid, "lstMission" ); if ((active_misn==NULL) || (strcmp(active_misn,"No Missions")==0)) { window_modifyText( wid, "txtReward", "None" ); window_modifyText( wid, "txtDesc", "You currently have no active missions." ); window_disableButton( wid, "btnAbortMission" ); return; } /* Modify the text. */ misn = &player_missions[ toolkit_getListPos(wid, "lstMission" ) ]; window_modifyText( wid, "txtReward", misn->reward ); window_modifyText( wid, "txtDesc", misn->desc ); window_enableButton( wid, "btnAbortMission" ); /* Select the system. */ if (misn->markers != NULL) map_center( system_getIndex( misn->markers[0].sys )->name ); }
/** * @brief Updates the missions in the spaceport bar. * @param wid Window to update the outfits in. * @param str Unused. */ static void bar_update( unsigned int wid, char* str ) { (void) str; int pos; int w, h, iw, ih, bw, bh, dh; /* Get dimensions. */ bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh ); dh = gl_printHeightRaw( &gl_smallFont, w - iw - 60, land_planet->bar_description ); /* Get array. */ pos = toolkit_getImageArrayPos( wid, "iarMissions" ); /* See if is news. */ if (pos==0) { /* News selected. */ if (!widget_exists(wid, "cstNews")) { /* Destroy portrait. */ if (widget_exists(wid, "imgPortrait")) { window_destroyWidget(wid, "imgPortrait"); } /* Disable button. */ window_disableButton( wid, "btnApproach" ); /* Clear text. */ window_modifyText( wid, "txtPortrait", NULL ); window_modifyText( wid, "txtMission", NULL ); /* Create news. */ news_widget( wid, iw + 60, -40 - (40 + dh), w - iw - 100, h - 40 - (dh+20) - 40 - bh - 20 ); } return; } /* Shift to ignore news now. */ pos--; /* Destroy news widget if needed. */ if (widget_exists(wid, "cstNews")) { window_destroyWidget( wid, "cstNews" ); } /* Create widgets if needed. */ if (!widget_exists(wid, "imgPortrait")) { window_addImage( wid, iw + 40 + (w-iw-60-PORTRAIT_WIDTH)/2, -(40 + dh + 40 + gl_defFont.h + 20 + PORTRAIT_HEIGHT), 0, 0, "imgPortrait", NULL, 1 ); } /* Enable button. */ window_enableButton( wid, "btnApproach" ); /* Set portrait. */ window_modifyText( wid, "txtPortrait", npc_getName( pos ) ); window_modifyImage( wid, "imgPortrait", npc_getTexture( pos ), 0, 0 ); /* Set mission description. */ window_modifyText( wid, "txtMission", npc_getDesc( pos )); }
/** * @brief Adds a system to the selection. */ static void uniedit_selectAdd( StarSystem *sys ) { /* Allocate if needed. */ if (uniedit_msys < uniedit_nsys+1) { if (uniedit_msys == 0) uniedit_msys = 1; uniedit_msys *= 2; uniedit_sys = realloc( uniedit_sys, sizeof(StarSystem*) * uniedit_msys ); } /* Add system. */ uniedit_sys[ uniedit_nsys ] = sys; uniedit_nsys++; /* Set text again. */ uniedit_selectText(); /* Enable buttons again. */ window_enableButton( uniedit_wid, "btnJump" ); window_enableButton( uniedit_wid, "btnRename" ); window_enableButton( uniedit_wid, "btnEdit" ); if (uniedit_nsys == 1) window_enableButton( uniedit_wid, "btnOpen" ); else window_disableButton( uniedit_wid, "btnOpen" ); }
/** * @brief Deselects selected targets. */ static void uniedit_deselect (void) { if (uniedit_nsys > 0) free( uniedit_sys ); uniedit_sys = NULL; uniedit_nsys = 0; uniedit_msys = 0; /* Change window stuff. */ window_disableButton( uniedit_wid, "btnJump" ); window_disableButton( uniedit_wid, "btnRename" ); window_disableButton( uniedit_wid, "btnEdit" ); window_disableButton( uniedit_wid, "btnOpen" ); window_modifyText( uniedit_wid, "txtSelected", "No selection" ); window_modifyText( uniedit_wid, "txtPresence", "N/A" ); }
/** * @brief Checks if should add the refuel button and does if needed. */ void land_checkAddRefuel (void) { char buf[ECON_CRED_STRLEN], cred[ECON_CRED_STRLEN]; unsigned int w; /* Check to see if fuel conditions are met. */ if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL)) { if (!widget_exists( land_windows[0], "txtRefuel" )) window_addText( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20) + 20, 200, gl_defFont.h, 1, "txtRefuel", &gl_defFont, &cBlack, "No refueling services." ); return; } /* Full fuel. */ if (player.p->fuel >= player.p->fuel_max) { if (widget_exists( land_windows[0], "btnRefuel" )) window_destroyWidget( land_windows[0], "btnRefuel" ); if (widget_exists( land_windows[0], "txtRefuel" )) window_destroyWidget( land_windows[0], "txtRefuel" ); return; } /* Autorefuel. */ if (conf.autorefuel) { spaceport_refuel( land_windows[0], "btnRefuel" ); w = land_getWid( LAND_WINDOW_EQUIPMENT ); if (w > 0) equipment_updateShips( w, NULL ); /* Must update counter. */ if (player.p->fuel >= player.p->fuel_max) return; } /* Just enable button if it exists. */ if (widget_exists( land_windows[0], "btnRefuel" )) { window_enableButton( land_windows[0], "btnRefuel"); credits2str( cred, player.p->credits, 2 ); snprintf( buf, sizeof(buf), "Credits: %s", cred ); window_modifyText( land_windows[0], "txtRefuel", buf ); } /* Else create it. */ else { /* Refuel button. */ credits2str( cred, refuel_price(), 2 ); snprintf( buf, sizeof(buf), "Refuel %s", cred ); window_addButton( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20), LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnRefuel", buf, spaceport_refuel ); /* Player credits. */ credits2str( cred, player.p->credits, 2 ); snprintf( buf, sizeof(buf), "Credits: %s", cred ); window_addText( land_windows[0], -20, 20 + 2*(LAND_BUTTON_HEIGHT + 20), LAND_BUTTON_WIDTH, gl_smallFont.h, 1, "txtRefuel", &gl_smallFont, &cBlack, buf ); } /* Make sure player can click it. */ if (!player_hasCredits( refuel_price() )) window_disableButton( land_windows[0], "btnRefuel" ); }
/** * @brief Updates the mission list. * @param wid Window of the mission computer. * @param str Unused. */ static void misn_update( unsigned int wid, char* str ) { (void) str; char *active_misn; Mission* misn; char txt[256], *buf; /* Clear computer markers. */ space_clearComputerMarkers(); /* Update date stuff. */ buf = ntime_pretty( 0, 2 ); snprintf( txt, sizeof(txt), "%s\n%d Tons", buf, player.p->cargo_free ); free(buf); window_modifyText( wid, "txtDate", txt ); active_misn = toolkit_getList( wid, "lstMission" ); if (strcmp(active_misn,"No Missions")==0) { window_modifyText( wid, "txtReward", "None" ); window_modifyText( wid, "txtDesc", "There are no missions available here." ); window_disableButton( wid, "btnAcceptMission" ); return; } misn = &mission_computer[ toolkit_getListPos( wid, "lstMission" ) ]; mission_sysComputerMark( misn ); if (misn->markers != NULL) map_center( system_getIndex( misn->markers[0].sys )->name ); window_modifyText( wid, "txtReward", misn->reward ); window_modifyText( wid, "txtDesc", misn->desc ); window_enableButton( wid, "btnAcceptMission" ); }
/** * @brief Updates the commodity window. * @param wid Window to update. * @param str Unused. */ static void commodity_update( unsigned int wid, char* str ) { (void)str; char buf[PATH_MAX]; char *comname; Commodity *com; comname = toolkit_getList( wid, "lstGoods" ); if ((comname==NULL) || (strcmp( comname, "None" )==0)) { nsnprintf( buf, PATH_MAX, "NA Tons\n" "NA Credits/Ton\n" "\n" "NA Tons\n" ); window_modifyText( wid, "txtDInfo", buf ); window_modifyText( wid, "txtDesc", "No outfits available." ); window_disableButton( wid, "btnCommodityBuy" ); window_disableButton( wid, "btnCommoditySell" ); return; } com = commodity_get( comname ); /* modify text */ nsnprintf( buf, PATH_MAX, "%d Tons\n" "%"CREDITS_PRI" Credits/Ton\n" "\n" "%d Tons\n", pilot_cargoOwned( player.p, comname ), planet_commodityPrice( land_planet, com ), pilot_cargoFree(player.p)); window_modifyText( wid, "txtDInfo", buf ); window_modifyText( wid, "txtDesc", com->description ); /* Button enabling/disabling */ if (commodity_canBuy( comname )) window_enableButton( wid, "btnCommodityBuy" ); else window_disableButtonSoft( wid, "btnCommodityBuy" ); if (commodity_canSell( comname )) window_enableButton( wid, "btnCommoditySell" ); else window_disableButtonSoft( wid, "btnCommoditySell" ); }
/** * @brief Disables a button, while still running the button's function. * * @param wid ID of the window to get widget from. * @param name Name of the button to disable. */ void window_disableButtonSoft( const unsigned int wid, char *name ) { Widget *wgt; /* Get the widget. */ wgt = btn_get( wid, name ); if (wgt == NULL) return; wgt->dat.btn.softdisable = 1; window_disableButton( wid, name ); }
/** * @brief Updates the player's cargo in the cargo menu. * @param str Unused. */ static void cargo_update( unsigned int wid, char* str ) { (void)str; if (player.p->ncommodities==0) return; /* No cargo */ /* Can jettison all but mission cargo when not landed*/ if (landed) window_disableButton( wid, "btnJettisonCargo" ); else window_enableButton( wid, "btnJettisonCargo" ); }
/** * @brief Updates the player's cargo in the cargo menu. * @param str Unused. */ static void cargo_update( unsigned int wid, char* str ) { (void)str; int pos; if (player->ncommodities==0) return; /* No cargo */ pos = toolkit_getListPos( wid, "lstCargo" ); /* Can jettison all but mission cargo when not landed*/ if (landed || (player->commodities[pos].id != 0)) window_disableButton( wid, "btnJettisonCargo" ); else window_enableButton( wid, "btnJettisonCargo" ); }
/** * @brief Removes a system from the selection. */ static void uniedit_selectRm( StarSystem *sys ) { int i; for (i=0; i<uniedit_nsys; i++) { if (uniedit_sys[i] == sys) { uniedit_nsys--; memmove( &uniedit_sys[i], &uniedit_sys[i+1], sizeof(StarSystem*) * (uniedit_nsys - i) ); uniedit_selectText(); if (uniedit_nsys == 1) window_enableButton( uniedit_wid, "btnOpen" ); else window_disableButton( uniedit_wid, "btnOpen" ); return; } } WARN("Trying to remove system '%s' from selection when not selected.", sys->name); }
/** * @brief Shows the player his cargo. * * @param str Unused. */ static void info_cargo_menu( unsigned int parent, char* str ) { (void) str; unsigned int wid; char **buf; int nbuf; int i; /* Create the window */ wid = window_create( "Cargo", -1, -1, CARGO_WIDTH, CARGO_HEIGHT ); window_setParent( wid, parent ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeCargo", "Back", window_close ); window_addButton( wid, -40 - BUTTON_WIDTH, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnJettisonCargo", "Jettison", cargo_jettison ); window_disableButton( wid, "btnJettisonCargo" ); /* List */ if (player->ncommodities==0) { /* No cargo */ buf = malloc(sizeof(char*)); buf[0] = strdup("None"); nbuf = 1; } else { /* List the player's cargo */ buf = malloc(sizeof(char*)*player->ncommodities); for (i=0; i<player->ncommodities; i++) { buf[i] = malloc(sizeof(char)*128); snprintf(buf[i],128, "%s%s %d", player->commodities[i].commodity->name, (player->commodities[i].id != 0) ? "*" : "", player->commodities[i].quantity); } nbuf = player->ncommodities; } window_addList( wid, 20, -40, CARGO_WIDTH - 40, CARGO_HEIGHT - BUTTON_HEIGHT - 80, "lstCargo", buf, nbuf, 0, cargo_update ); cargo_update(wid, NULL); }
/** * @brief Shows the player his cargo. * * @param str Unused. */ static void info_openCargo( unsigned int wid ) { int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeCargo", "Close", info_close ); window_addButton( wid, -40 - BUTTON_WIDTH, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnJettisonCargo", "Jettison", cargo_jettison ); window_disableButton( wid, "btnJettisonCargo" ); /* Generate the list. */ cargo_genList( wid ); }
/** * @brief Updates the outfits in the outfit window. * @param wid Window to update the outfits in. * @param str Unused. */ void outfits_update( unsigned int wid, char* str ) { (void)str; char *outfitname; Outfit* outfit; char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN]; double th; int iw, ih; int w, h; /* Get dimensions. */ outfits_getSize( wid, &w, &h, &iw, &ih, NULL, NULL ); /* Get and set parameters. */ outfitname = toolkit_getImageArray( wid, "iarOutfits" ); if (strcmp(outfitname,"None")==0) { /* No outfits */ window_modifyImage( wid, "imgOutfit", NULL, 0, 0 ); window_disableButton( wid, "btnBuyOutfit" ); window_disableButton( wid, "btnSellOutfit" ); snprintf( buf, PATH_MAX, "NA\n" "\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" ); window_modifyText( wid, "txtDDesc", buf ); window_modifyText( wid, "txtOutfitName", "None" ); window_modifyText( wid, "txtDescShort", NULL ); /* Reposition. */ window_moveWidget( wid, "txtSDesc", 20+iw+20, -60 ); window_moveWidget( wid, "txtDDesc", 20+iw+20+60, -60 ); window_moveWidget( wid, "txtDescription", 20+iw+40, -240 ); return; } outfit = outfit_get( outfitname ); /* new image */ window_modifyImage( wid, "imgOutfit", outfit->gfx_store, 0, 0 ); if (outfit_canBuy(outfit,1,0) > 0) window_enableButton( wid, "btnBuyOutfit" ); else window_disableButton( wid, "btnBuyOutfit" ); /* gray out sell button */ if (outfit_canSell(outfit,1,0) > 0) window_enableButton( wid, "btnSellOutfit" ); else window_disableButton( wid, "btnSellOutfit" ); /* new text */ window_modifyText( wid, "txtDescription", outfit->description ); credits2str( buf2, outfit->price, 2 ); credits2str( buf3, player.p->credits, 2 ); snprintf( buf, PATH_MAX, "%d\n" "\n" "%s\n" "%s\n" "%.0f tons\n" "\n" "%s credits\n" "%s credits\n" "%s\n", player_outfitOwned(outfit), outfit_slotName(outfit), outfit_slotSize(outfit), outfit->mass, buf2, buf3, (outfit->license != NULL) ? outfit->license : "None" ); window_modifyText( wid, "txtDDesc", buf ); window_modifyText( wid, "txtOutfitName", outfit->name ); window_modifyText( wid, "txtDescShort", outfit->desc_short ); th = MAX( 128, gl_printHeightRaw( &gl_smallFont, 320, outfit->desc_short ) ); window_moveWidget( wid, "txtSDesc", 40+iw+20, -60-th-20 ); window_moveWidget( wid, "txtDDesc", 40+iw+20+60, -60-th-20 ); th += gl_printHeightRaw( &gl_smallFont, 250, buf ); window_moveWidget( wid, "txtDescription", 20+iw+40, -60-th-20 ); }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w, h, x, y, rw; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); window_handleKeys( wid, map_keyHandler ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * [Autonav] * [ Find ] * [ Close ] */ x = -70; /* Right column X offset. */ y = -20; rw = ABS(x) + 60; /* Right column indented width maximum. */ /* System Name */ window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); y -= 10; /* Faction image */ window_addImage( wid, -90 + 32, y - 32, 0, 0, "imgFaction", NULL, 0 ); y -= 64 + 10; /* Faction */ window_addText( wid, x, y, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_addText( wid, x, y, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_addText( wid, x, y, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtPresence", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_addText( wid, x, y, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 150, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_addText( wid, x, y, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Find button */ window_addButton( wid, -20 - (BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnFind", "Find", map_inputFind ); /* Autonav button */ window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAutonav", "Autonav", player_autonavStartWindow ); /* * Bottom stuff * * [+] [-] Nebula, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-200, h-100, 1. ); /* Reset zoom. */ map_update( wid ); /* * Disable Autonav button if player lacks fuel. */ if ((player.p->fuel < HYPERSPACE_FUEL) || pilot_isFlag( player.p, PILOT_NOJUMP)) window_disableButton( wid, "btnAutonav" ); }
/** * @brief Opens the main menu (titlescreen). */ void menu_main (void) { int offset_logo, offset_wdw, freespace; unsigned int bwid, wid; glTexture *tex; int h, y; if (menu_isOpen(MENU_MAIN)) { WARN( _("Menu main is already open.") ); return; } /* Clean up GUI - must be done before using SCREEN_W or SCREEN_H. */ gui_cleanup(); player_soundStop(); /* Stop sound. */ /* Play load music. */ music_choose("load"); /* Load background and friends. */ tex = gl_newImage( GFX_PATH"Naev.png", 0 ); main_naevLogo = tex; menu_main_bkg_system(); /* Set dimensions */ y = 20 + (BUTTON_HEIGHT+20)*5; h = y + 80; if (conf.devmode) { h += BUTTON_HEIGHT + 20; y += BUTTON_HEIGHT + 20; } /* Calculate Logo and window offset. */ freespace = SCREEN_H - tex->sh - h; if (freespace < 0) { /* Not enough freespace, this can get ugly. */ offset_logo = SCREEN_W - tex->sh; offset_wdw = 0; } /* Otherwise space evenly. */ else { offset_logo = -freespace/4; offset_wdw = freespace/2; } /* create background image window */ bwid = window_create( "BG", -1, -1, -1, -1 ); window_onClose( bwid, menu_main_cleanBG ); window_setBorder( bwid, 0 ); window_addImage( bwid, (SCREEN_W-tex->sw)/2., offset_logo, 0, 0, "imgLogo", tex, 0 ); window_addText( bwid, 0, 10, SCREEN_W, 30., 1, "txtBG", NULL, &cWhite, naev_version(1) ); /* create menu window */ wid = window_create( "Main Menu", -1, offset_wdw, MAIN_WIDTH, h ); window_setCancel( wid, main_menu_promptClose ); /* Buttons. */ window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnLoad", _("Load Game"), menu_main_load, SDLK_l ); y -= BUTTON_HEIGHT+20; window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnNew", _("New Game"), menu_main_new, SDLK_n ); y -= BUTTON_HEIGHT+20; window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnTutorial", _("Tutorial"), menu_main_tutorial, SDLK_t ); y -= BUTTON_HEIGHT+20; if (conf.devmode) { window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnEditor", _("Editors"), menu_editors_open, SDLK_e ); y -= BUTTON_HEIGHT+20; } window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnOptions", _("Options"), menu_options_button, SDLK_o ); y -= BUTTON_HEIGHT+20; window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnCredits", _("Credits"), menu_main_credits, SDLK_c ); y -= BUTTON_HEIGHT+20; window_addButtonKey( wid, 20, y, BUTTON_WIDTH, BUTTON_HEIGHT, "btnExit", _("Exit"), menu_exit, SDLK_x ); /* Disable load button if there are no saves. */ if (!save_hasSave()) window_disableButton( wid, "btnLoad" ); /* Make the background window a child of the menu. */ window_setParent( bwid, wid ); unpause_game(); menu_Open(MENU_MAIN); }
/** * @brief Updates the ships in the shipyard window. * @param wid Window to update the ships in. * @param str Unused. */ void shipyard_update( unsigned int wid, char* str ) { (void)str; char *shipname; Ship* ship; char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN]; shipname = toolkit_getImageArray( wid, "iarShipyard" ); /* No ships */ if (strcmp(shipname,"None")==0) { window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_disableButton( wid, "btnBuyShip"); window_disableButton( wid, "btnTradeShip"); snprintf( buf, PATH_MAX, "None\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" ); window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_modifyText( wid, "txtStats", NULL ); window_modifyText( wid, "txtDescription", NULL ); window_modifyText( wid, "txtDDesc", buf ); return; } ship = ship_get( shipname ); shipyard_selected = ship; /* update image */ window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 ); /* update text */ window_modifyText( wid, "txtStats", ship->desc_stats ); window_modifyText( wid, "txtDescription", ship->description ); credits2str( buf2, ship->price, 2 ); credits2str( buf3, player.p->credits, 2 ); snprintf( buf, PATH_MAX, "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tons\n" "%.1f STU average\n" "%.0f kN/ton\n" "%.0f m/s\n" "%.0f deg/s\n" "\n" "%.0f%% damage\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f tons\n" "%d units\n" "%s credits\n" "%s credits\n" "%s\n", ship->name, ship_class(ship), ship->fabricator, ship->crew, /* Weapons & Manoeuvrability */ ship->cpu, ship->mass, pow( ship->mass, 1./2.5 ) / 5. * (ship->stats_array.jump_delay/100.+1.), /**< @todo make this more portable. */ ship->thrust / ship->mass, ship->speed, ship->turn*180/M_PI, /* Misc */ ship->dmg_absorb*100., ship->shield, ship->shield_regen, ship->armour, ship->armour_regen, ship->energy, ship->energy_regen, ship->cap_cargo, ship->fuel, buf2, buf3, (ship->license != NULL) ? ship->license : "None" ); window_modifyText( wid, "txtDDesc", buf ); if (!shipyard_canBuy( shipname )) window_disableButton( wid, "btnBuyShip"); else window_enableButton( wid, "btnBuyShip"); if (!shipyard_canTrade( shipname )) window_disableButton( wid, "btnTradeShip"); else window_enableButton( wid, "btnTradeShip"); }
/** * @brief Updates the ships in the shipyard window. * @param wid Window to update the ships in. * @param str Unused. */ void shipyard_update( unsigned int wid, char* str ) { (void)str; char *shipname, *license_text; Ship* ship; char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN]; size_t len; shipname = toolkit_getImageArray( wid, "iarShipyard" ); /* No ships */ if (strcmp(shipname,"None")==0) { window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_disableButton( wid, "btnBuyShip"); window_disableButton( wid, "btnTradeShip"); nsnprintf( buf, PATH_MAX, "None\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" ); window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_modifyText( wid, "txtStats", NULL ); window_modifyText( wid, "txtDescription", NULL ); window_modifyText( wid, "txtDDesc", buf ); return; } ship = ship_get( shipname ); shipyard_selected = ship; /* update image */ window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 ); /* update text */ window_modifyText( wid, "txtStats", ship->desc_stats ); window_modifyText( wid, "txtDescription", ship->description ); price2str( buf2, ship_buyPrice(ship), player.p->credits, 2 ); credits2str( buf3, player.p->credits, 2 ); /* Remove the word " License". It's redundant and makes the text overflow into another text box */ license_text = ship->license; if (license_text) { len = strlen(ship->license); if (strcmp(" License", ship->license + len - 8) == 0) { license_text = malloc(len - 7); assert(license_text); memcpy(license_text, ship->license, len - 8); license_text[len - 8] = '\0'; } } nsnprintf( buf, PATH_MAX, "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tons\n" "%.0f kN/ton\n" "%.0f m/s\n" "%.0f deg/s\n" "\n" "%.0f%% damage\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f tons\n" "%d units\n" "%.0f units\n" "%s credits\n" "%s credits\n" "%s\n", ship->name, ship_class(ship), ship->fabricator, ship->crew, /* Weapons & Manoeuvrability */ ship->cpu, ship->mass, ship->thrust, ship->speed, ship->turn*180/M_PI, /* Misc */ ship->dmg_absorb*100., ship->shield, ship->shield_regen, ship->armour, ship->armour_regen, ship->energy, ship->energy_regen, ship->cap_cargo, ship->fuel, ship->fuel_consumption, buf2, buf3, (license_text != NULL) ? license_text : "None" ); window_modifyText( wid, "txtDDesc", buf ); if (license_text != ship->license) free(license_text); if (!shipyard_canBuy( shipname, land_planet )) window_disableButtonSoft( wid, "btnBuyShip"); else window_enableButton( wid, "btnBuyShip"); if (!shipyard_canTrade( shipname )) window_disableButtonSoft( wid, "btnTradeShip"); else window_enableButton( wid, "btnTradeShip"); }
/** * @brief Opens the main menu (titlescreen). */ void menu_main (void) { int offset_logo, offset_wdw, freespace; unsigned int bwid, wid; glTexture *tex; /* Play load music. */ music_choose("load"); /* Load background and friends. */ tex = gl_newImage( "gfx/NAEV.png", 0 ); main_naevLogo = tex; nebu_prep( 300., 0. ); /* Needed for nebula to not spaz out */ /* Calculate Logo and window offset. */ freespace = SCREEN_H - tex->sh - MAIN_HEIGHT; if (freespace < 0) { /* Not enough freespace, this can get ugly. */ offset_logo = SCREEN_W - tex->sh; offset_wdw = 0; } else { /* We'll want a maximum seperation of 30 between logo and text. */ if (freespace/3 > 25) { freespace -= 25; offset_logo = -25; offset_wdw = -25 - tex->sh - 25; } /* Otherwise space evenly. */ else { offset_logo = -freespace/3; offset_wdw = freespace/3; } } /* create background image window */ bwid = window_create( "BG", -1, -1, SCREEN_W, SCREEN_H ); window_onClose( bwid, menu_main_cleanBG ); window_addRect( bwid, 0, 0, SCREEN_W, SCREEN_H, "rctBG", &cBlack, 0 ); window_addCust( bwid, 0, 0, SCREEN_W, SCREEN_H, "cstBG", 0, menu_main_nebu, NULL, &menu_main_lasttick ); window_addImage( bwid, (SCREEN_W-tex->sw)/2., offset_logo, "imgLogo", tex, 0 ); window_addText( bwid, 0., 10, SCREEN_W, 30., 1, "txtBG", NULL, &cWhite, naev_version(1) ); /* create menu window */ wid = window_create( "Main Menu", -1, offset_wdw, MAIN_WIDTH, MAIN_HEIGHT ); window_setCancel( wid, main_menu_promptClose ); /* Buttons. */ window_addButton( wid, 20, 20 + (BUTTON_HEIGHT+20)*4, BUTTON_WIDTH, BUTTON_HEIGHT, "btnLoad", "Load Game", menu_main_load ); window_addButton( wid, 20, 20 + (BUTTON_HEIGHT+20)*3, BUTTON_WIDTH, BUTTON_HEIGHT, "btnNew", "New Game", menu_main_new ); window_addButton( wid, 20, 20 + (BUTTON_HEIGHT+20)*2, BUTTON_WIDTH, BUTTON_HEIGHT, "btnOptions", "Options", menu_options_button ); window_addButton( wid, 20, 20 + (BUTTON_HEIGHT+20), BUTTON_WIDTH, BUTTON_HEIGHT, "btnCredits", "Credits", menu_main_credits ); window_addButton( wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnExit", "Exit", menu_exit ); /* Disable load button if there are no saves. */ if (!save_hasSave()) window_disableButton( wid, "btnLoad" ); /* Make the background window a parent of the menu. */ window_setParent( bwid, wid ); /* Reset timer. */ menu_main_lasttick = SDL_GetTicks(); menu_Open(MENU_MAIN); }