/** * @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 main info window. */ static void info_openMain( unsigned int wid ) { char str[128], **buf, creds[ECON_CRED_STRLEN]; char **licenses; int nlicenses; int i; char *nt; int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* pilot generics */ nt = ntime_pretty( ntime_get(), 2 ); window_addText( wid, 40, 20, 120, h-80, 0, "txtDPilot", &gl_smallFont, &cDConsole, "Pilot:\n" "Date:\n" "Combat Rating:\n" "\n" "Money:\n" "Ship:\n" "Fuel:" ); credits2str( creds, player.p->credits, 2 ); snprintf( str, 128, "%s\n" "%s\n" "%s\n" "\n" "%s Credits\n" "%s\n" "%.0f (%d Jumps)", player.name, nt, player_rating(), creds, player.p->name, player.p->fuel, pilot_getJumps(player.p) ); window_addText( wid, 140, 20, 200, h-80, 0, "txtPilot", &gl_smallFont, &cBlack, str ); free(nt); /* menu */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", info_close ); /* List. */ buf = player_getLicenses( &nlicenses ); licenses = malloc(sizeof(char*)*nlicenses); for (i=0; i<nlicenses; i++) licenses[i] = strdup(buf[i]); window_addText( wid, -20, -40, w-80-200-40, 20, 1, "txtList", NULL, &cDConsole, "Licenses" ); window_addList( wid, -20, -70, w-80-200-40, h-110-BUTTON_HEIGHT, "lstLicenses", licenses, nlicenses, 0, NULL ); }
/** * @brief Converts the time to a pretty human readable format. * * @usage strt = time.str() -- Gets current time * @uasge strt = time.str( nil, 5 ) -- Gets current time with full decimals * @usage strt = time.str( time.get() + time.create(0,5,0) ) -- Gets time in 5 STP * @usage strt = t:str() -- Gets the string of t * * @luatparam Time t Time to convert to pretty format. If omitted, current time is used. * @luatparam[opt=2] number d Decimals to use for displaying STU (should be between 0 and 5). * @luatreturn string The time in human readable format. * @luafunc str( t, d ) */ static int time_str( lua_State *L ) { int top; ntime_t t; char nt[64]; int d; /* Defaults. */ d = 2; /* Parse parameters. */ top = lua_gettop(L); if ((top > 0) && !lua_isnil(L,1)) t = luaL_validtime(L,1); else t = ntime_get(); if (top > 1) d = luaL_checkint(L,2); /* Push string. */ ntime_prettyBuf( nt, sizeof(nt), t, d ); lua_pushstring(L, nt); return 1; }
/** * @brief Gets the current time in internal representation time. * * @usage t = time.get() * * @luatreturn Time Time in internal representation time. * @luafunc get() */ static int time_get( lua_State *L ) { lua_pushtime( L, ntime_get() ); return 1; }
/** * @brief Adds an article. * @usage news.add(faction,title,body,[date_to_rm, [date]]) * * @usage s = news.add( "Empire", "Hello world!", "The Empire wishes to say hello!", 0 ) -- Adds an Empire specific article, with date 0. * * @luaparam faction faction of the article, "Generic" for non-factional * @luaparam title Title of the article * @luaparam content What's in the article * @luaparam date_to_rm date to remove the article * @luaparam date What time to put, defaults to current date, use 0 to not use a date * @luareturn The article matching name or nil if error. * @luafunc add( s ) */ int newsL_add( lua_State *L ) { news_t *n_article; char *title, *content, *faction; ntime_t date, date_to_rm; title = NULL; content = NULL; faction = NULL; date = ntime_get(); date_to_rm = 50000000000000; /* If a table is passed in. ugly hack */ if (lua_istable(L, 1)) { lua_pushnil(L); /* traverse table */ while (lua_next(L, -2)) { /* traverse sub table */ if (lua_istable(L, -1)) { lua_pushnil(L); while (lua_next(L, -2)) { if (lua_isnumber(L, -1)) { if (date_to_rm) date_to_rm = lua_tonumber(L, -1); else date = lua_tonumber(L, -1); } else if (lua_istime(L, -1)) { if (date_to_rm) date_to_rm = luaL_validtime(L, -1); else date = luaL_validtime(L, -1); } else if (lua_isstring(L, -1)) { if (!faction) faction = strdup(lua_tostring(L, -1)); else if (!title) title = strdup(lua_tostring(L, -1)); else if (!content) content = strdup(lua_tostring(L, -1)); } lua_pop(L, 1); } if (title && content && faction) new_article(title, content, faction, date, date_to_rm); else WARN("Bad arguments"); free(faction); free(title); free(content); faction = NULL; title = NULL; content = NULL; date = ntime_get(); date_to_rm = 50000000000000; } lua_pop(L, 1); } lua_pop(L, 1); /* If we're landed, we should regenerate the news buffer. */ if (landed) { generate_news(faction_name(land_planet->faction)); if (land_loaded) bar_regen(); } return 0; } if (!(lua_isstring(L, 1) && lua_isstring(L, 2) && lua_isstring(L, 3))) { WARN("\nBad arguments, use " "addArticle(\"Faction\",\"Title\",\"Content\",[date,[date_to_rm]])"); return 0; } faction = strdup(lua_tostring(L, 1)); title = strdup(lua_tostring(L, 2)); content = strdup(lua_tostring(L, 3)); /* get date and date to remove, or leave at defaults*/ if (lua_isnumber(L, 4) || lua_istime(L, 4)) { if (lua_istime(L, 4)) date_to_rm = luaL_validtime(L, 4); else date_to_rm = lua_tonumber(L, 4); } if (lua_isnumber(L, 5) || lua_istime(L, 5)) { if (lua_istime(L, 5)) date = luaL_validtime(L, 5); else date = lua_tonumber(L, 5); } if (title && content && faction) n_article = new_article(title, content, faction, date, date_to_rm); else WARN("Bad arguments"); lua_pusharticle(L, n_article->id); free(title); free(content); free(faction); /* If we're landed, we should regenerate the news buffer. */ if (landed) { generate_news(faction_name(land_planet->faction)); if (land_loaded) bar_regen(); } return 1; }