30#include "player_fleet.h"
31#include "player_inventory.h"
33#include "tk/toolkit_priv.h"
36#define BUTTON_WIDTH 135
37#define BUTTON_HEIGHT 30
39#define menu_Open( f ) ( menu_open |= ( f ) )
40#define menu_Close( f ) \
41 ( menu_open &= ~( f ) )
46#define INFO_WIN_MAIN 0
47#define INFO_WIN_SHIP 1
48#define INFO_WIN_WEAP 2
49#define INFO_WIN_CARGO 3
50#define INFO_WIN_MISN 4
51#define INFO_WIN_STAND 5
52#define INFO_WIN_SHIPLOG 6
53static const char *info_names[INFO_WINDOWS] = {
54 N_(
"Main" ), N_(
"Ship" ), N_(
"Weapons" ), N_(
"Cargo" ),
55 N_(
"Missions" ), N_(
"Standings" ), N_(
"Ship log" ),
61typedef struct InfoButton_s {
73static unsigned int info_wid = 0;
74static unsigned int *info_windows = NULL;
75static int info_lastTab;
79static int *info_factions;
81static int selectedMission = 0;
82static int selectedLog = 0;
83static int selectedLogType = 0;
84static char **logTypes = NULL;
87static char **logs = NULL;
88static int *logIDs = NULL;
89static int logWidgetsReady = 0;
95static void info_close(
unsigned int wid,
const char *str );
96static void info_cleanup(
unsigned int wid,
const char *str );
97static void info_openMain(
unsigned int wid );
98static void info_openShip(
unsigned int wid );
99static void info_openWeapons(
unsigned int wid );
100static void info_openCargo(
unsigned int wid );
101static void info_openMissions(
unsigned int wid );
102static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw );
103static void info_buttonClick(
unsigned int wid,
const char *str );
104static void standings_close(
unsigned int wid,
const char *str );
105static void ship_update(
unsigned int wid );
106static void weapons_genList(
unsigned int wid );
107static void weapons_updateList(
unsigned int wid,
const char *str );
108static void weapons_toggleList(
unsigned int wid,
const char *str );
109static void weapons_clear(
unsigned int wid,
const char *str );
110static void weapons_clearAll(
unsigned int wid,
const char *str );
111static void weapons_autoweap(
unsigned int wid,
const char *str );
112static void weapons_inrange(
unsigned int wid,
const char *str );
113static void weapons_manual(
unsigned int wid,
const char *str );
114static void weapons_volley(
unsigned int wid,
const char *str );
115static void aim_lines(
unsigned int wid,
const char *str );
116static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
118static void weapons_help(
unsigned int wid,
const char *str );
119static void weapons_advanced(
unsigned int wid,
const char *str );
120static void info_openStandings(
unsigned int wid );
121static void info_shiplogView(
unsigned int wid,
const char *str );
122static void standings_update(
unsigned int wid,
const char *str );
123static void cargo_genList(
unsigned int wid );
124static void cargo_update(
unsigned int wid,
const char *str );
125static void cargo_jettison(
unsigned int wid,
const char *str );
126static void mission_menu_chk_hide(
unsigned int wid,
const char *str );
127static void mission_menu_chk_priority(
unsigned int wid,
const char *str );
128static void mission_menu_abort(
unsigned int wid,
const char *str );
129static void mission_menu_genList(
unsigned int wid,
int first );
130static void mission_menu_update(
unsigned int wid,
const char *str );
131static void info_openShipLog(
unsigned int wid );
132static const char *info_getLogTypeFilter(
int lstPos );
133static void info_changeTab(
unsigned int wid,
const char *str,
int old,
136static int sort_buttons(
const void *p1,
const void *p2 )
151 luaL_unref(
naevL, LUA_REGISTRYINDEX, btn->
func );
154static void info_buttonRegen(
void )
156 int wid, w, h, rows, cols;
160 wid = info_windows[INFO_WIN_MAIN];
163 rows = 1 + (
array_size( info_buttons ) ) / cols;
165 for (
int i = 0; i <
array_size( info_buttons ); i++ ) {
167 int r = ( i + 1 ) / cols,
c = ( i + 1 ) % cols;
173 info_buttonClick, btn->
key );
189int info_buttonRegister(
const char *caption,
int priority, SDL_Keycode key )
191 static int button_idgen = 0;
195 if ( info_buttons == NULL )
199 btn->
id = ++button_idgen;
200 btn->
caption = strdup( caption );
201 SDL_asprintf( &btn->
button,
"btnExtra::%s", caption );
204 btn->
func = luaL_ref(
naevL, LUA_REGISTRYINDEX );
222int info_buttonUnregister(
int id )
224 for (
int i = 0; i <
array_size( info_buttons ); i++ ) {
229 int wid = info_windows[INFO_WIN_MAIN];
233 info_buttonFree( btn );
246 for (
int i = 0; i <
array_size( info_buttons ); i++ ) {
249 int wid = info_windows[INFO_WIN_MAIN];
253 info_buttonFree( btn );
260static void info_buttonClick(
unsigned int wid,
const char *str )
263 for (
int i = 0; i <
array_size( info_buttons ); i++ ) {
265 if ( strcmp( btn->
button, str ) != 0 )
268 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, btn->
func );
269 if ( nlua_pcall( btn->
env, 0, 0 ) ) {
270 WARN( _(
"Failure to run info button with id '%d':\n%s" ), btn->
id,
271 lua_tostring(
naevL, -1 ) );
274 land_needsTakeoff( 1 );
282void menu_info(
int window )
285 const char *names[INFO_WINDOWS];
288 if ( pilot_isFlag(
player.p, PILOT_MANUAL_CONTROL ) )
295 info_close( 0, NULL );
304 info_wid =
window_create(
"wdwInfo", _(
"Info" ), -1, -1, w, h );
309 for (
size_t i = 0; i < INFO_WINDOWS; i++ )
310 names[i] = _( info_names[i] );
311 info_windows = window_addTabbedWindow( info_wid, -1, -1, -1, -1,
"tabInfo",
312 INFO_WINDOWS, names, 0 );
315 info_openMain( info_windows[INFO_WIN_MAIN] );
316 info_openShip( info_windows[INFO_WIN_SHIP] );
317 info_openWeapons( info_windows[INFO_WIN_WEAP] );
318 info_openCargo( info_windows[INFO_WIN_CARGO] );
319 info_openMissions( info_windows[INFO_WIN_MISN] );
320 info_openStandings( info_windows[INFO_WIN_STAND] );
321 info_openShipLog( info_windows[INFO_WIN_SHIPLOG] );
329 window_tabWinOnChange( info_wid,
"tabInfo", info_changeTab );
331 window = info_lastTab;
332 window_tabWinSetActive( info_wid,
"tabInfo",
CLAMP( 0, 6, window ) );
338static void info_close(
unsigned int wid,
const char *str )
341 info_lastTab = window_tabWinGetActive( info_wid,
"tabInfo" );
345static void info_cleanup(
unsigned int wid,
const char *str )
369 if ( info_windows != NULL )
370 weapons_genList( info_windows[INFO_WIN_WEAP] );
376static void info_openMain(
unsigned int wid )
379 char str[STRMAX_SHORT], creds[ECON_CRED_STRLEN];
382 int w, h, cargo_used, cargo_total, n;
383 unsigned int destroyed;
392 for (
int i = 0; i < SHIP_CLASS_TOTAL; i++ )
393 destroyed +=
player.ships_destroyed[i];
397 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"%s", _(
"Pilot:" ) );
398 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Date:" ) );
399 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n\n%s", _(
"Money:" ) );
400 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Current Ship:" ) );
401 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Fuel:" ) );
402 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s",
403 (
player.fleet_capacity > 0 ) ? _(
"Cargo (fleet):" )
405 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n\n%s", _(
"Time played:" ) );
406 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Times died:" ) );
407 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Times jumped:" ) );
408 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Times landed:" ) );
409 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Damage done:" ) );
410 k +=
scnprintf( &str[k],
sizeof( str ) - k,
"\n%s", _(
"Damage taken:" ) );
411 scnprintf( &str[k],
sizeof( str ) - k,
"\n%s",
412 _(
"Ships destroyed:" ) );
413 window_addText( wid, 20, 20, 160, h - 80, 0,
"txtDPilot", &
gl_smallFont,
418 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%s", nt );
419 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n\n%s", creds );
421 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%.0f %s (%d %s)",
426 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%d / %d %s", cargo_used,
427 cargo_total, UNIT_MASS );
428 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"%s",
"\n\n" );
429 l +=
scnprintf( &str[l],
sizeof( str ) - l, _(
"%.1f hours" ),
430 player.time_played / 3600. );
431 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%s",
433 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%s",
435 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n%s\n",
438 scnprintf( &str[l],
sizeof( str ) - l, _(
"%s %s" ),
441 l +=
scnprintf( &str[l],
sizeof( str ) - l,
"\n" );
443 &str[l],
sizeof( str ) - l, _(
"%s %s" ),
446 scnprintf( &str[l],
sizeof( str ) - l,
"\n%s",
448 window_addText( wid, 200, 20, w - 80 - 200 - 40 + 20 - 180, h - 80, 0,
454 _(
"Close" ), info_close, SDLK_c );
468 inventory = malloc(
sizeof(
char * ) * n );
469 for (
int i = 0; i < nlic; i++ )
470 SDL_asprintf( &
inventory[i],
"#n%s#0%s", _(
"License: " ),
473 for (
int i = 0; i < ninv; i++ ) {
478 SDL_asprintf( &
inventory[nlic + i], _(
"%s (%s)" ), _( pi->
name ),
483 window_addText( wid, -20, -40, w - 80 - 300 - 40 - 40, 20, 1,
"txtList",
484 NULL, NULL, _(
"Inventory" ) );
485 window_addList( wid, -20, -70, w - 80 - 300 - 40 - 40,
498static void info_openShip(
unsigned int wid )
509 "closeOutfits", _(
"Close" ), info_close, SDLK_c );
512 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s", _(
"Name:" ) );
513 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Model:" ) );
514 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Class:" ) );
515 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Crew:" ) );
516 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
517 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Mass:" ) );
518 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Jump Time:" ) );
519 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Accel:" ) );
520 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Speed:" ) );
521 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Turn:" ) );
522 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Time Constant:" ) );
523 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
524 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Absorption:" ) );
525 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Shield:" ) );
526 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Armour:" ) );
527 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Energy:" ) );
528 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Cargo Space:" ) );
529 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Fuel:" ) );
530 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
531 scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s", _(
"Stats:" ) );
532 window_addText( wid, 20, -40, 160, h - 60, 0,
"txtSDesc", &
gl_smallFont,
534 window_addText( wid, 200, -40, w - 20 - 20 - 20 - 200 - 180., h - 60, 0,
539 equipment_slotSelect( &info_eq, &
player.ps );
540 info_eq.canmodify = 0;
549static void ship_update(
unsigned int wid )
551 char buf[STRMAX_SHORT], *hyp_delay;
552 char sshield[NUM2STRLEN], sarmour[NUM2STRLEN], senergy[NUM2STRLEN];
553 char scargo[NUM2STRLEN], sfuel[NUM2STRLEN];
567 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s",
568 _(
player.p->ship->name ) );
569 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%s",
571 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%d",
572 (
int)floor(
player.p->crew ) );
574 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n\n" );
575 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s %s" ),
577 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
578 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s average" ), hyp_delay );
579 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
580 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%.0f %s" ),
player.p->accel,
582 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
584 &buf[l],
sizeof( buf ) - l, _(
"%.0f %s (max %.0f %s)" ),
player.p->speed,
588 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
589 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%.0f %s" ),
590 player.p->turn * 180. / M_PI, UNIT_ROTATION );
592 scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%.0f%%",
593 player.p->stats.time_mod *
player.p->ship->dt_default * 100. );
595 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
596 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n%.0f%%",
597 player.p->dmg_absorb * 100. );
598 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
599 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s / %s %s" ), sshield,
601 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
" (%s %s)" ),
603 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
604 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s / %s %s" ), sarmour,
606 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
" (%s %s)" ),
608 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
609 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s / %s %s" ), senergy,
611 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
" (%s %s)" ),
613 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
614 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s / %s %s" ), scargo,
616 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n" );
617 l +=
scnprintf( &buf[l],
sizeof( buf ) - l, _(
"%s / %s %s (%d %s)" ), sfuel,
621 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s",
"\n\n" );
624 window_modifyText( wid,
"txtDDesc", buf );
631static void info_openWeapons(
unsigned int wid )
633 int w, h, x, y, wlen;
634 const int advanced =
player.p->advweap;
641 equipment_slotSelect( &info_eq_weaps, &
player.ps );
642 info_eq_weaps.weapons = 0;
643 info_eq_weaps.canmodify = 0;
647 window_addCust( wid, 220, y, w - 200 - 60, 100,
"cstLegend", 0,
648 weapons_renderLegend, NULL, NULL, NULL, NULL );
656 "btnCycle", _(
"Cycle Mode" ), weapons_toggleList,
660 window_addButtonKey( wid, x + 10 + (
BUTTON_WIDTH + 10 ) * 0, y,
662 weapons_clear, SDLK_l );
663 window_addButtonKey( wid, x + 10 + (
BUTTON_WIDTH + 10 ) * 1, y,
665 _(
"Clear All" ), weapons_clearAll, SDLK_a );
670 wid, x + 10, y, wlen, 100, 0,
"txtSMode", NULL, NULL,
671 _(
"Cycles through the following modes:\n"
672 "- Default: tap to toggle, hold to hold\n"
673 "- Hold: turns on the selected outfits as long as key is held\n"
674 "- Toggle: toggles the selected outfits to on or off state" ) );
675 y -= 8 + window_getTextHeight( wid,
"txtSMode" );
679 _(
"Enable manual aiming mode" ), weapons_manual,
684 _(
"Enable volley mode (weapons fire jointly)" ), weapons_volley,
689 _(
"Only shoot weapons that are in range" ), weapons_inrange,
692 window_addCheckbox( wid, x + 10, y, wlen,
BUTTON_HEIGHT,
"chkHelper",
693 _(
"Dogfight visual aiming helper (all sets)" ),
694 aim_lines,
player.p->aimLines );
697 window_addCheckbox( wid, x + 10, y, wlen,
BUTTON_HEIGHT,
"chkAutoweap",
698 _(
"Automatically handle all weapons sets" ),
699 weapons_autoweap,
player.p->autoweap );
702 weapons_genList( wid );
706 "closeWeapons", _(
"Close" ), info_close, SDLK_c );
709 weapons_help, SDLK_h );
712 weapons_advanced, SDLK_e );
714 window_buttonCaption( wid,
"btnAdvanced", p_(
"UI",
"Simple" ) );
720static void weapons_genList(
unsigned int wid )
722 char **buf, tbuf[STRMAX_SHORT];
731 n = toolkit_getListPos( wid,
"lstWeapSets" );
736 buf = malloc(
sizeof(
char * ) * PILOT_WEAPON_SETS );
737 for (
int i = 0; i < PILOT_WEAPON_SETS; i++ ) {
740 snprintf( tbuf,
sizeof( tbuf ),
"#%c%s#0 - %s", ( i == 0 ) ?
'r' :
'y',
741 ( i == 0 ) ? _(
"Primary" ) : _(
"Secondary" ), str );
743 snprintf( tbuf,
sizeof( tbuf ), _(
"Weapset %d - %s" ),
744 ( i - 2 + 1 ) % 10, str );
745 buf[i] = strdup( tbuf );
747 window_addList( wid, 20 + 180 + 20, -40, w - ( 20 + 180 + 20 + 20 ), 250,
748 "lstWeapSets", buf, PILOT_WEAPON_SETS, 0, weapons_updateList,
749 weapons_toggleList );
754 toolkit_setListPos( wid,
"lstWeapSets", n );
760static void weapons_updateList(
unsigned int wid,
const char *str )
766 pos = toolkit_getListPos( wid,
"lstWeapSets" );
769 info_eq_weaps.weapons = pos;
772 window_checkboxSet( wid,
"chkInrange",
776 window_checkboxSet( wid,
"chkVolley",
780 window_checkboxSet( wid,
"chkManual",
785 window_checkboxSet( wid,
"chkAutoweap",
player.p->autoweap );
788static void weapons_toggleList(
unsigned int wid,
const char *str )
796 case WEAPSET_TYPE_DEFAULT:
797 c = WEAPSET_TYPE_HOLD;
799 case WEAPSET_TYPE_HOLD:
800 c = WEAPSET_TYPE_TOGGLE;
802 case WEAPSET_TYPE_TOGGLE:
803 c = WEAPSET_TYPE_DEFAULT;
807 c = WEAPSET_TYPE_HOLD;
813 weapons_genList( wid );
819static void weapons_clear(
unsigned int wid,
const char *str )
825 weapons_genList( wid );
831static void weapons_clearAll(
unsigned int wid,
const char *str )
835 _(
"Clear All Weapon Sets?" ),
836 _(
"Are you sure you want to clear all your current weapon sets?" ) );
841 for (
int i = 0; i < PILOT_WEAPON_SETS; i++ )
845 weapons_genList( wid );
851static void weapons_autoweap(
unsigned int wid,
const char *str )
854 int state = window_checkboxState( wid, str );
859 _(
"Enable autoweapons?" ),
860 _(
"Are you sure you want to enable automatic weapon groups for the "
861 "ship?\n\nThis will overwrite all manually-tweaked weapons "
864 window_checkboxSet( wid, str, 0 );
869 weapons_genList( wid );
877static void weapons_inrange(
unsigned int wid,
const char *str )
879 int state = window_checkboxState( wid, str );
883 window_checkboxSet( wid,
"chkAutoweap",
player.p->autoweap );
889static void weapons_manual(
unsigned int wid,
const char *str )
891 int state = window_checkboxState( wid, str );
895 window_checkboxSet( wid,
"chkAutoweap",
player.p->autoweap );
901static void weapons_volley(
unsigned int wid,
const char *str )
903 int state = window_checkboxState( wid, str );
907 window_checkboxSet( wid,
"chkAutoweap",
player.p->autoweap );
913static void aim_lines(
unsigned int wid,
const char *str )
915 int state = window_checkboxState( wid, str );
916 player.p->aimLines = state;
922static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
936 _(
"Outfit that can be activated" ) );
941 _(
"Outfit that is enabled for the weapon set" ) );
947static void weapons_help(
unsigned int wid,
const char *str )
951 naevpedia_open(
"mechanics/weaponsets" );
957static void weapons_advanced(
unsigned int wid,
const char *str )
962 int n = toolkit_getListPos( wid,
"lstWeapSets" );
963 window_clearWidgets( wid );
964 info_openWeapons( wid );
965 toolkit_setListPos( wid,
"lstWeapSets", n );
973static void info_openCargo(
unsigned int wid )
982 _(
"Close" ), info_close, SDLK_c );
985 cargo_jettison, SDLK_j );
986 window_disableButton( wid,
"btnJettisonCargo" );
989 window_addText( wid, 20, -40 - 200 - 20, w - 40, h -
BUTTON_HEIGHT - 260, 0,
990 "txtCargoDesc", NULL, NULL, NULL );
993 cargo_genList( wid );
998static void cargo_genList(
unsigned int wid )
1015 buf = malloc(
sizeof(
char *) );
1016 buf[0] = strdup( _(
"None" ) );
1020 buf = malloc(
sizeof(
char * ) *
array_size( pclist ) );
1021 for (
int i = 0; i <
array_size( pclist ); i++ ) {
1023 int misn = ( pc->
id != 0 );
1026 SDL_asprintf( &buf[i],
"%s %d%s%s", _( pc->
commodity->
name ),
1027 pc->
quantity, misn ? _(
" [#bMission#0]" ) :
"",
1028 illegal ? _(
" (#rillegal#0)" ) :
"" );
1033 window_addList( wid, 20, -40, w - 40, 200,
"lstCargo", buf, nbuf, 0,
1034 cargo_update, NULL );
1041static void cargo_update(
unsigned int wid,
const char *str )
1050 window_modifyText( wid,
"txtCargoDesc", NULL );
1056 if (
landed || pilot_isFlag(
player.p, PILOT_LANDING ) )
1057 window_disableButton( wid,
"btnJettisonCargo" );
1059 window_enableButton( wid,
"btnJettisonCargo" );
1061 pos = toolkit_getListPos( wid,
"lstCargo" );
1065 l =
scnprintf( desc,
sizeof( desc ),
"%s", _( com->
name ) );
1067 l =
scnprintf( desc,
sizeof( desc ),
"%s\n\n%s", _( com->
name ),
1071 if ( pclist[pos].
id > 0 ) {
1072 l +=
scnprintf( &desc[l],
sizeof( desc ) - l,
"\n\n%s",
1073 _(
"This is cargo related to a mission and can only be "
1074 "carried by your main ship." ) );
1075 }
else if ( (
player.fleet_capacity > 0 ) && ( pclist[pos].quantity > 0 ) ) {
1076 l +=
scnprintf( &desc[l],
sizeof( desc ) - l,
"\n\n%s",
1077 _(
"Carried by the following ships in your fleet:\n" ) );
1079 for (
int i = 0; i <
array_size( plist ); i++ )
1080 l +=
scnprintf( &desc[l],
sizeof( desc ) - l, _(
"\n - %s (%d)" ),
1081 plist[i].p->name, plist[i].q );
1087 l +=
scnprintf( &desc[l],
sizeof( desc ) - l,
"\n\n%s",
1088 _(
"Illegalized by the following factions:\n" ) );
1094 l +=
scnprintf( &desc[l],
sizeof( desc ) - l, _(
"\n - %s" ),
1098 window_modifyText( wid,
"txtCargoDesc", desc );
1106static void cargo_jettison(
unsigned int wid,
const char *str )
1118 pos = toolkit_getListPos( wid,
"lstCargo" );
1121 if ( pclist[pos].
id != 0 ) {
1126 _(
"Abort Mission" ),
1127 _(
"Are you sure you want to abort this mission?" ) ) ) {
1145 WARN( _(
"Cargo '%d' does not belong to any active mission." ),
1153 ret = misn_tryRun( misn,
"abort" );
1168 mission_menu_genList( info_windows[INFO_WIN_MISN], 0 );
1171 pfleet_cargoRm( pclist[pos].commodity, pclist[pos].quantity, 1 );
1174 ship_update( info_windows[INFO_WIN_SHIP] );
1175 cargo_genList( wid );
1176 cargo_update( wid, NULL );
1179 hparam[0].
type = HOOK_PARAM_COMMODITY;
1182 hparam[1].
type = HOOK_PARAM_NUMBER;
1184 hparam[2].
type = HOOK_PARAM_SENTINEL;
1194static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw )
1204static void standings_close(
unsigned int wid,
const char *str )
1209 info_factions = NULL;
1212static int factionsSort(
const void *p1,
const void *p2 )
1229static void info_openStandings(
unsigned int wid )
1238 info_getDim( wid, &w, &h, &lw );
1245 "closeMissions", _(
"Close" ), info_close, SDLK_c );
1248 window_addImage( wid, 0, 0, 0, 0,
"imgLogo", NULL, 0 );
1251 window_addText( wid, lw + 40, 0, ( w - ( lw + 60 ) ), 20, 0,
"txtName",
1253 window_addText( wid, lw + 40, 0, ( w - ( lw + 60 ) ), 40, 0,
"txtStanding",
1255 window_addText( wid, lw + 40, 0, ( w - ( lw + 60 ) ), h - 80, 0,
1260 str = malloc(
sizeof(
char *) *
array_size( info_factions ) );
1261 qsort( info_factions,
array_size( info_factions ),
sizeof(
int ),
1265 for (
int i = 0; i <
array_size( info_factions ); i++ ) {
1267 SDL_asprintf( &str[i], p_(
"standings",
"%s [ #%c%+.0f%%#0 ]" ),
1273 window_addList( wid, 20, -40, lw, h - 60,
"lstStandings", str,
1274 array_size( info_factions ), 0, standings_update, NULL );
1281static void standings_update(
unsigned int wid,
const char *str )
1292 info_getDim( wid, &w, &h, &lw );
1295 p = toolkit_getListPos( wid,
"lstStandings" );
1302 int tw = t->
w * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1303 int th = t->
h * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1304 window_modifyImage( wid,
"imgLogo", t, tw, th );
1306 y - ( FACTION_LOGO_SM - th ) / 2 );
1307 x += FACTION_LOGO_SM + 20;
1310 window_modifyImage( wid,
"imgLogo", NULL, 0, 0 );
1315 l = snprintf( buf,
sizeof( buf ), p_(
"standings",
"#%c%+.0f%%#0 [ %s ]" ),
1319 if (
ABS( ml - m ) > 1e-1 )
1321 &buf[l],
sizeof( buf ) - l,
1322 p_(
"standings",
"\n#%c%+.0f%%#0 #nin %s#0" ),
1323 faction_reputationColourCharSystem( info_factions[p],
cur_system ), ml,
1328 window_modifyText( wid,
"txtStanding", buf );
1331 l =
scnprintf( buf,
sizeof( buf ),
"%s\n\n",
1334 &buf[l],
sizeof( buf ) - l,
1335 _(
"You can have a maximum reputation of %.0f%% with this faction." ),
1341 for (
int i = 0; i <
array_size( flist ); i++ ) {
1348 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n\n%s",
1349 _(
"Ally Factions:" ) );
1352 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n- %s",
1359 for (
int i = 0; i <
array_size( flist ); i++ ) {
1366 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n\n%s",
1367 _(
"Enemy Factions:" ) );
1370 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"\n- %s",
1375 window_modifyText( wid,
"txtDescription", buf );
1385static void info_openMissions(
unsigned int wid )
1394 "closeMissions", _(
"Close" ), info_close, SDLK_c );
1397 mission_menu_abort, SDLK_a );
1400 window_addCheckbox( wid, 300 + 40, 20 +
BUTTON_HEIGHT + 10, w - 300 - 60,
1402 _(
"Hide mission on-screen display" ),
1403 mission_menu_chk_hide, 0 );
1408 mission_menu_chk_priority, 0 );
1411 window_addText( wid, 300 + 40, -40, w - 300 - 60, h -
BUTTON_HEIGHT - 120, 0,
1412 "txtDesc", NULL, NULL, NULL );
1415 map_show( wid, 20, 20, 300, 260, 0.75, 0., 0. );
1418 mission_menu_genList( wid, 1 );
1424static void mission_menu_genList(
unsigned int wid,
int first )
1439 selectedMission = -1;
1448 misn_names[j++] = strdup( _(
"No Missions" ) );
1449 window_modifyText( wid,
"txtDesc",
1450 _(
"You currently have no active missions." ) );
1451 window_disableButton( wid,
"btnAbortMission" );
1452 window_disableCheckbox( wid,
"chkHide" );
1453 window_disableCheckbox( wid,
"chkPrefer" );
1454 selectedMission = 0;
1456 window_addList( wid, 20, -40, 300, h - 340,
"lstMission", misn_names, j,
1457 selectedMission, mission_menu_update, NULL );
1464static void mission_menu_update(
unsigned int wid,
const char *str )
1469 const StarSystem *sys;
1470 int pos = toolkit_getListPos( wid,
"lstMission" );
1472 if ( pos < 0 || pos == selectedMission )
1476 selectedMission = pos;
1478 snprintf( buf,
sizeof( buf ), _(
"%s\n#nReward:#0 %s\n\n%s" ), misn->
title,
1480 window_modifyText( wid,
"txtDesc", buf );
1481 if ( pilot_isFlag(
player.p, PILOT_LANDING ) )
1482 window_disableButton( wid,
"btnAbortMission" );
1484 window_enableButton( wid,
"btnAbortMission" );
1485 window_enableCheckbox( wid,
"chkHide" );
1486 window_enableCheckbox( wid,
"chkPrefer" );
1487 window_checkboxSet( wid,
"chkHide", misn_osdGetHide( misn ) );
1488 window_checkboxSet( wid,
"chkPrefer",
1489 misn_osdGetPriority( misn ) !=
1495 map_center( wid, sys->name );
1497static void mission_menu_chk_hide(
unsigned int wid,
const char *str )
1500 int pos = toolkit_getListPos( wid,
"lstMission" );
1505 if ( misn->
osd == 0 )
1509static void mission_menu_chk_priority(
unsigned int wid,
const char *str )
1512 int pos = toolkit_getListPos( wid,
"lstMission" );
1517 if ( misn->
osd == 0 )
1520 100 * window_checkboxState( wid, str ) );
1526static void mission_menu_abort(
unsigned int wid,
const char *str )
1533 _(
"Are you sure you want to abort this mission?" ) ) )
1537 pos = toolkit_getListPos( wid,
"lstMission" );
1541 ret = misn_tryRun( misn,
"abort" );
1556 mission_menu_genList( wid, 0 );
1564#define LOGSPACING ( h - 120 - BUTTON_HEIGHT )
1570static void shiplog_menu_update(
unsigned int wid,
const char *str )
1576 if ( !logWidgetsReady )
1582 if ( strcmp( str,
"lstLogEntries" ) != 0 ) {
1583 int regenerateEntries = 0;
1588 logWidgetsReady = 0;
1590 logType = toolkit_getListPos( wid,
"lstLogType" );
1591 log = toolkit_getListPos( wid,
"lstLogs" );
1593 if ( logType != selectedLogType ) {
1595 selectedLogType = logType;
1599 &nlogs, &logs, &logIDs, 1 );
1600 if ( selectedLog >= nlogs )
1602 window_addList( wid, 20, 60 +
BUTTON_HEIGHT + LOGSPACING / 2, w - 40,
1603 LOGSPACING / 4,
"lstLogs", logs, nlogs, 0,
1604 shiplog_menu_update, NULL );
1606 toolkit_setListPos( wid,
"lstLogs", selectedLog );
1607 regenerateEntries = 1;
1609 if ( regenerateEntries || selectedLog != log ) {
1610 selectedLog =
CLAMP( 0, nlogs - 1, log );
1614 info_getLogTypeFilter( selectedLogType ), &nentries,
1617 LOGSPACING / 2 - 20,
"lstLogEntries", logentries,
1618 nentries, 0, shiplog_menu_update, info_shiplogView );
1619 toolkit_setListPos( wid,
"lstLogEntries", 0 );
1622 logWidgetsReady = 1;
1629static const char *info_getLogTypeFilter(
int lstPos )
1633 return logTypes[lstPos];
1640static void shiplog_menu_genList(
unsigned int wid,
int first )
1661 shiplog_listTypes( &ntypes, &logTypes, 1 );
1662 if ( selectedLogType >= ntypes )
1663 selectedLogType = 0;
1666 &logs, &logIDs, 1 );
1667 if ( selectedLog >= nlogs )
1671 info_getLogTypeFilter( selectedLogType ), &nentries,
1673 logWidgetsReady = 0;
1674 window_addList( wid, 20, 80 +
BUTTON_HEIGHT + 3 * LOGSPACING / 4, w - 40,
1675 LOGSPACING / 4,
"lstLogType", logTypes, ntypes, 0,
1676 shiplog_menu_update, NULL );
1677 window_addList( wid, 20, 60 +
BUTTON_HEIGHT + LOGSPACING / 2, w - 40,
1678 LOGSPACING / 4,
"lstLogs", logs, nlogs, 0,
1679 shiplog_menu_update, NULL );
1680 window_addList( wid, 20, 40 +
BUTTON_HEIGHT, w - 40, LOGSPACING / 2 - 20,
1681 "lstLogEntries", logentries, nentries, 0,
1682 shiplog_menu_update, info_shiplogView );
1684 logWidgetsReady = 1;
1687static void info_shiplogMenuDelete(
unsigned int wid,
const char *str )
1690 char buf[STRMAX_SHORT];
1693 if ( logIDs[selectedLog] == LOG_ID_ALL ) {
1694 dialogue_msg(
"", _(
"You are currently viewing all logs in the selected "
1695 "log type. Please select a log title to delete." ) );
1699 snprintf( buf,
sizeof( buf ),
1700 _(
"This will delete ALL \"%s\" log entries. This operation "
1701 "cannot be undone. Are you sure?" ),
1702 logs[selectedLog] );
1709 logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter( selectedLogType ),
1714 selectedLogType = 0;
1715 shiplog_menu_genList( wid, 0 );
1718static void info_shiplogView(
unsigned int wid,
const char *str )
1725 pos = toolkit_getListPos( wid,
"lstLogEntries" );
1729 info_getLogTypeFilter( selectedLogType ), &nentries,
1732 if ( pos < nentries )
1735 for (
int i = 0; i < nentries; i++ )
1736 free( logentries[i] );
1746static void info_shiplogAdd(
unsigned int wid,
const char *str )
1752 logType = toolkit_getListPos( wid,
"lstLogType" );
1753 log = toolkit_getListPos( wid,
"lstLogs" );
1754 if ( log < 0 || logIDs[log] == LOG_ID_ALL ) {
1756 _(
"Add an entry to your diary:" ) );
1757 if ( ( tmp != NULL ) && ( strlen( tmp ) > 0 ) ) {
1765 _(
"Add an entry to the log titled '%s':" ),
1767 if ( ( tmp != NULL ) && ( strlen( tmp ) > 0 ) ) {
1768 int logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter( logType ),
1774 _(
"Cannot add log" ),
1775 _(
"Cannot find this log! Something went wrong here!" ) );
1779 shiplog_menu_genList( wid, 0 );
1787static void info_openShipLog(
unsigned int wid )
1792 selectedLogType = 0;
1798 "closeShipLog", _(
"Close" ), info_close, SDLK_c );
1801 info_shiplogMenuDelete, SDLK_d );
1804 info_shiplogView, SDLK_v );
1807 info_shiplogAdd, SDLK_a );
1810 window_addText( wid, 20, 80 +
BUTTON_HEIGHT + LOGSPACING, w - 40, texth, 0,
1811 "logDesc1", &
gl_smallFont, NULL, _(
"Select log type:" ) );
1813 window_addText( wid, 20, 60 +
BUTTON_HEIGHT + 3 * LOGSPACING / 4, w - 40,
1815 _(
"Select log title:" ) );
1817 window_addText( wid, 20, 25 +
BUTTON_HEIGHT + LOGSPACING / 2, w - 40, texth,
1818 0,
"logDesc3", &
gl_smallFont, NULL, _(
"Log entries:" ) );
1822 shiplog_menu_genList( wid, 1 );
1828static void info_changeTab(
unsigned int wid,
const char *str,
int old,
1834 const char *hookname;
1837 hookname =
"info_main";
1840 hookname =
"info_ship";
1843 hookname =
"info_weapons";
1845 case INFO_WIN_CARGO:
1846 hookname =
"info_cargo";
1849 hookname =
"info_mission";
1851 case INFO_WIN_STAND:
1852 hookname =
"info_standing";
1854 case INFO_WIN_SHIPLOG:
1855 hookname =
"info_shiplog";
1858 WARN( _(
"Invalid info tab ID: %d" ),
new );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void claim_activateAll(void)
Activates all the claims.
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
char * dialogue_inputRaw(const char *title, int min, int max, const char *msg)
Creates a dialogue that allows the player to write a message.
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
int dialogue_YesNoRaw(const char *caption, const char *msg)
Runs a dialogue with both yes and no options.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
int dialogue_isOpen(void)
Checks to see if a dialogue is open.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
void equipment_slotWidget(unsigned int wid, double x, double y, double w, double h, CstSlotWidget *data)
Creates the slot widget and initializes it.
int equipment_shipStats(char *buf, int max_len, const Pilot *s, int dpseps, int name)
Creates and allocates a string containing the ship stats.
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
const int * faction_getEnemies(int f)
Gets the list of enemies of a faction.
int faction_isKnown(int id)
Is the faction known?
void faction_updateGlobal(void)
Computes the global faction standing for each of the factions.
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
const char * faction_name(int f)
Gets a factions "real" (internal) name.
const char * faction_getStandingText(int f)
Gets the player's standing in human readable form.
int faction_isDynamic(int id)
Is faction dynamic.
const int * faction_getAllies(int f)
Gets the list of allies of a faction.
int * faction_getKnown()
Gets all the known factions in an array (array.h).
int faction_isInvisible(int id)
Is the faction invisible?
char faction_reputationColourChar(int f)
Gets the faction character associated to its standing with the player.
double faction_reputationMax(int f)
Gets the maximum reputation of a faction.
double faction_reputation(int f)
Gets the player's standing with a faction.
const char * faction_description(int f)
Gets the faction's description (translated).
int faction_isStatic(int id)
Is the faction static?
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
int hooks_run(const char *stack)
Runs all the hooks of stack.
void info_update(void)
Updates the info windows.
void info_buttonClear(void)
Clears all the registered buttons.
void bar_regen(void)
Regenerates the bar list.
Mission ** player_missions
const StarSystem * mission_getSystemMarker(const Mission *misn)
Gets the first system that has been marked by a mission.
void mission_cleanup(Mission *misn)
Cleans up a mission.
void mission_sysMark(void)
Marks all active systems that need marking.
void mission_shift(int pos)
Puts the specified mission at the end of the player_missions array.
void misn_osdSetHide(Mission *misn, int hide)
Sets the hide state of the mission OSD.
Header file with generic functions and naev-specifics.
int num2str(char dest[NUM2STRLEN], double n, int decimals)
Converts a numeric value to a string.
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
const char * num2strU(double n, int decimals)
Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
ntime_t ntime_get(void)
Gets the current time.
char * ntime_pretty(ntime_t t, int d)
Gets the time in a pretty human readable format.
ntime_t pilot_hyperspaceDelay(const Pilot *p)
Calculates the hyperspace delay for a pilot.
int pilot_getJumps(const Pilot *p)
Gets the amount of jumps the pilot has left.
int pilot_cargoFree(const Pilot *p)
Gets the pilot's free cargo space.
int pilot_cargoUsed(const Pilot *p)
Gets how much cargo ship has on board.
int pilot_weapSetTypeCheck(Pilot *p, int id)
Checks the current weapon set type.
void pilot_weapSetInrange(Pilot *p, int id, int inrange)
Changes the weapon set inrange property.
void pilot_weaponSafe(Pilot *p)
Sets the weapon set as safe.
void pilot_weapSetManual(Pilot *p, int id, int manual)
Changes the weapon set manual property.
void pilot_weapSetVolley(Pilot *p, int id, int volley)
Changes the weapon set volley property.
int pilot_weapSetManualCheck(Pilot *p, int id)
Checks the current weapon set manual property.
void ws_copy(PilotWeaponSet dest[PILOT_WEAPON_SETS], const PilotWeaponSet src[PILOT_WEAPON_SETS])
Copies a weapon set over.
int pilot_weapSetVolleyCheck(Pilot *p, int id)
Checks the current weapon set volley property.
void pilot_weapSetClear(Pilot *p, int id)
Clears a weapon set.
void pilot_weaponAuto(Pilot *p)
Tries to automatically set and create the pilot's weapon set.
int pilot_weapSetInrangeCheck(Pilot *p, int id)
Checks the current weapon set inrange property.
const char * pilot_weapSetName(Pilot *p, int id)
Gets the name of a weapon set.
void pilot_weapSetType(Pilot *p, int id, WeaponSetType type)
Changes the weapon sets mode.
const char ** player_getLicenses()
Gets the array (array.h) of license names in the player's inventory.
PilotCommodity * pfleet_cargoList(void)
Gets a list of all the cargo in the fleet.
PFleetCargo * pfleet_cargoListShips(const Commodity *com)
Gets the list of ships that are carry a certain commodity in the player fleet and the amount they are...
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
int pfleet_cargoRm(const Commodity *com, int q, int jet)
Removes some cargo from the player's fleet.
int pfleet_cargoUsed(void)
Gets the total cargo space used by the player's fleet.
static PlayerItem * inventory
const PlayerItem * player_inventory(void)
Gets the whole player inventory.
const char * ship_class(const Ship *s)
Gets the ship's class name in human readable form.
int shiplog_appendByID(int logid, const char *msg)
Adds to the log file.
void shiplog_listLog(int logid, const char *type, int *nentries, char ***logentries, int incempty)
Get all log entries matching logid, or if logid==LOG_ID_ALL, matching type, or if type==NULL,...
void shiplog_listLogsOfType(const char *type, int *nlogs, char ***logsOut, int **logIDs, int includeAll)
Lists matching logs (which haven't expired via "removeAfter") into the provided arrays.
void shiplog_delete(int logid)
Deletes a log (e.g. a cancelled mission may wish to do this, or the user might).
int shiplog_append(const char *idstr, const char *msg)
Appends to the log file.
int shiplog_create(const char *idstr, const char *logname, const char *type, int overwrite, int maxLen)
Creates a new log with given title of given type.
int shiplog_getID(const char *idstr)
Checks to see if the log family exists.
double system_getReputationOrGlobal(const StarSystem *sys, int faction)
Gets the local reputation of the player in a system or returns the global standing.
The actual hook parameter.
union HookParam::@325330313164266255110350307176363262300250041145 u
Represents an active mission.
Stores a pilot commodity.
const Commodity * commodity
Represents an item in the player inventory.
Abstraction for rendering sprite sheets.