33#include "player_fleet.h"
34#include "player_gui.h"
35#include "player_inventory.h"
38#include "tk/toolkit_priv.h"
41#define BUTTON_WIDTH 135
42#define BUTTON_HEIGHT 30
44#define menu_Open(f) (menu_open |= (f))
45#define menu_Close(f) (menu_open &= ~(f))
49#define INFO_WIN_MAIN 0
50#define INFO_WIN_SHIP 1
51#define INFO_WIN_WEAP 2
52#define INFO_WIN_CARGO 3
53#define INFO_WIN_MISN 4
54#define INFO_WIN_STAND 5
55#define INFO_WIN_SHIPLOG 6
56static const char *info_names[INFO_WINDOWS] = {
69typedef struct InfoButton_s {
81static unsigned int info_wid = 0;
82static unsigned int *info_windows = NULL;
83static int info_lastTab;
87static int *info_factions;
89static int selectedMission = 0;
90static int selectedLog = 0;
91static int selectedLogType = 0;
92static char **logTypes=NULL;
95static char **logs=NULL;
96static int *logIDs=NULL;
97static int logWidgetsReady=0;
103static void info_close(
unsigned int wid,
const char *str );
104static void info_openMain(
unsigned int wid );
105static void info_openShip(
unsigned int wid );
106static void info_openWeapons(
unsigned int wid );
107static void info_openCargo(
unsigned int wid );
108static void info_openMissions(
unsigned int wid );
109static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw );
110static void info_buttonClick(
unsigned int wid,
const char *str );
111static void standings_close(
unsigned int wid,
const char *str );
112static void ship_update(
unsigned int wid );
113static void weapons_genList(
unsigned int wid );
114static void weapons_updateList(
unsigned int wid,
const char *str );
115static void weapons_toggleList(
unsigned int wid,
const char *str );
116static void weapons_clear(
unsigned int wid,
const char *str );
117static void weapons_clearAll(
unsigned int wid,
const char *str );
118static void weapons_autoweap(
unsigned int wid,
const char *str );
119static void weapons_inrange(
unsigned int wid,
const char *str );
120static void weapons_manual(
unsigned int wid,
const char *str );
121static void weapons_volley(
unsigned int wid,
const char *str );
122static void aim_lines(
unsigned int wid,
const char *str );
123static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
void* data );
124static void info_openStandings(
unsigned int wid );
125static void info_shiplogView(
unsigned int wid,
const char *str );
126static void standings_update(
unsigned int wid,
const char *str );
127static void cargo_genList(
unsigned int wid );
128static void cargo_update(
unsigned int wid,
const char *str );
129static void cargo_jettison(
unsigned int wid,
const char *str );
130static void mission_menu_chk_hide(
unsigned int wid,
const char *str );
131static void mission_menu_chk_priority(
unsigned int wid,
const char *str );
132static void mission_menu_abort(
unsigned int wid,
const char *str );
133static void mission_menu_genList(
unsigned int wid,
int first );
134static void mission_menu_update(
unsigned int wid,
const char *str );
135static void info_openShipLog(
unsigned int wid );
136static const char* info_getLogTypeFilter(
int lstPos );
137static void info_changeTab(
unsigned int wid,
const char *str,
int old,
int new );
139static int sort_buttons(
const void *p1,
const void *p2 )
154 luaL_unref( naevL, LUA_REGISTRYINDEX, btn->
func );
157static void info_buttonRegen (
void)
159 int wid, w, h, rows, cols;
163 wid = info_windows[ INFO_WIN_MAIN ];
165 cols = (w-20) / (20+BUTTON_WIDTH);
168 for (
int i=0; i<
array_size(info_buttons); i++) {
170 int r = (i+1)/cols,
c = (i+1)%cols;
173 window_addButtonKey( wid, -20 -
c*(20+BUTTON_WIDTH), 20 + r*(20+BUTTON_HEIGHT),
174 BUTTON_WIDTH, BUTTON_HEIGHT,
177 window_resizeWidget( wid,
"lstInventory", w-80-300-40-40, h-90 - rows*(20+BUTTON_HEIGHT) );
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 );
203 btn->
env = __NLUA_CURENV;
204 btn->
func = luaL_ref( naevL, LUA_REGISTRYINDEX );
220int info_buttonUnregister(
int id )
222 for (
int i=0; i<
array_size(info_buttons); i++) {
227 int wid = info_windows[ INFO_WIN_MAIN ];
231 info_buttonFree( btn );
242void info_buttonClear (
void)
244 for (
int i=0; i<
array_size(info_buttons); i++) {
247 int wid = info_windows[ INFO_WIN_MAIN ];
251 info_buttonFree( btn );
258static void info_buttonClick(
unsigned int wid,
const char *str )
261 for (
int i=0; i<
array_size(info_buttons); i++) {
263 if (strcmp( btn->
button, str )!=0)
266 lua_rawgeti( naevL, LUA_REGISTRYINDEX, btn->
func );
267 if (nlua_pcall( btn->
env, 0, 0 )) {
268 WARN( _(
"Failure to run info button with id '%d':\n%s"), btn->
id, lua_tostring( naevL, -1 ) );
271 land_needsTakeoff( 1 );
279void menu_info(
int window )
282 const char *names[INFO_WINDOWS];
285 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
292 info_close( 0, NULL );
301 info_wid =
window_create(
"wdwInfo", _(
"Info"), -1, -1, w, h );
305 for (
size_t i=0; i<INFO_WINDOWS; i++)
306 names[i] = _(info_names[i]);
307 info_windows = window_addTabbedWindow( info_wid, -1, -1, -1, -1,
"tabInfo",
308 INFO_WINDOWS, names, 0 );
311 info_openMain( info_windows[ INFO_WIN_MAIN ] );
312 info_openShip( info_windows[ INFO_WIN_SHIP ] );
313 info_openWeapons( info_windows[ INFO_WIN_WEAP ] );
314 info_openCargo( info_windows[ INFO_WIN_CARGO ] );
315 info_openMissions( info_windows[ INFO_WIN_MISN ] );
316 info_openStandings( info_windows[ INFO_WIN_STAND ] );
317 info_openShipLog( info_windows[ INFO_WIN_SHIPLOG ] );
325 window_tabWinOnChange( info_wid,
"tabInfo", info_changeTab );
327 window = info_lastTab;
328 window_tabWinSetActive( info_wid,
"tabInfo",
CLAMP( 0, 6, window ) );
334static void info_close(
unsigned int wid,
const char *str )
338 info_lastTab = window_tabWinGetActive( info_wid,
"tabInfo" );
357void info_update (
void)
359 if (info_windows != NULL)
360 weapons_genList( info_windows[ INFO_WIN_WEAP ] );
366static void info_openMain(
unsigned int wid )
369 char str[STRMAX_SHORT], creds[ECON_CRED_STRLEN];
372 int w, h, cargo_used, cargo_total, n;
373 unsigned int destroyed;
382 for (
int i=0; i<SHIP_CLASS_TOTAL; i++)
387 k +=
scnprintf( &str[k],
sizeof(str)-k,
"%s", _(
"Pilot:") );
388 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Date:") );
389 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n\n%s", _(
"Money:") );
390 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Current Ship:") );
391 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Fuel:") );
393 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n\n%s", _(
"Time played:") );
394 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times died:") );
395 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times jumped:") );
396 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times landed:") );
397 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Damage done:") );
398 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Damage taken:") );
399 scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Ships destroyed:") );
400 window_addText( wid, 20, 20, 160, h-80, 0,
"txtDPilot", &
gl_smallFont, &cFontGrey, str );
404 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%s", nt );
405 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n\n%s", creds );
407 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%.0f %s (%d %s)",
411 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%d / %d %s", cargo_used, cargo_total, UNIT_MASS );
412 l +=
scnprintf( &str[l],
sizeof(str)-l,
"%s",
"\n\n" );
418 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n" );
421 window_addText( wid, 200, 20,
422 w-80-200-40+20-180, h-80,
427 window_addButton( wid, -20, 20,
428 BUTTON_WIDTH, BUTTON_HEIGHT,
429 "btnClose", _(
"Close"), info_close );
445 for (
int i=0; i<nlic; i++)
446 SDL_asprintf( &
inventory[i],
"#n%s#0%s", _(
"License: "), _(lic[i]) );
448 for (
int i=0; i<ninv; i++) {
457 window_addText( wid, -20, -40, w-80-300-40-40, 20, 1,
"txtList",
458 NULL, NULL, _(
"Inventory") );
459 window_addList( wid, -20, -70, w-80-300-40-40, h-110-BUTTON_HEIGHT,
460 "lstInventory",
inventory, n, 0, NULL, NULL );
471static void info_openShip(
unsigned int wid )
481 window_addButton( wid, -20, 20,
482 BUTTON_WIDTH, BUTTON_HEIGHT,
483 "closeOutfits", _(
"Close"), info_close );
486 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", _(
"Name:") );
487 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Model:") );
488 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Class:") );
489 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Crew:") );
490 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
491 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Mass:") );
492 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Jump Time:") );
493 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Accel:") );
494 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Speed:") );
495 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Turn:") );
496 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Time Constant:") );
497 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
498 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Absorption:") );
499 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Shield:") );
500 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Armour:") );
501 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Energy:") );
502 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Cargo Space:") );
503 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Fuel:") );
504 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
505 scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Stats:") );
506 window_addText( wid, 20, -40, 160, h-60, 0,
"txtSDesc", &
gl_smallFont, &cFontGrey, buf );
507 window_addText( wid, 200, -40, w-20-20-20-200-180., h-60, 0,
"txtDDesc", &
gl_smallFont,
522static void ship_update(
unsigned int wid )
524 char buf[STRMAX_SHORT], *hyp_delay;
525 char sshield[NUM2STRLEN], sarmour[NUM2STRLEN], senergy[NUM2STRLEN];
526 char scargo[NUM2STRLEN], sfuel[NUM2STRLEN];
544 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n" );
546 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
547 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s average"), hyp_delay );
548 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
550 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
551 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f %s (max %.0f %s)"),
553 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
554 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f %s"),
player.
p->
turn*180./M_PI, UNIT_ROTATION );
557 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
559 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
560 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s / %s %s"),
562 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
" (%s %s)"),
564 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
565 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s / %s %s"),
567 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
" (%s %s)"),
569 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
570 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s / %s %s"),
572 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
" (%s %s)"),
574 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
575 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s / %s %s"), scargo,
num2strU(cargo,0), UNIT_MASS );
576 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
577 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s / %s %s (%d %s)"),
580 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s",
"\n\n" );
583 window_modifyText( wid,
"txtDDesc", buf );
590static void info_openWeapons(
unsigned int wid )
592 int w, h, x, y, wlen;
605 window_addCust( wid, 220, y, w-200-60, 100,
"cstLegend", 0,
606 weapons_renderLegend, NULL, NULL, NULL, NULL );
612 window_addButton( wid, x+10, y, BUTTON_WIDTH, BUTTON_HEIGHT,
613 "btnCycle", _(
"Cycle Mode"), weapons_toggleList );
614 window_addButton( wid, x+10+(BUTTON_WIDTH+10), y, BUTTON_WIDTH, BUTTON_HEIGHT,
615 "btnClear", _(
"Clear"), weapons_clear );
616 window_addButton( wid, x+10+(BUTTON_WIDTH+10)*2, y, BUTTON_WIDTH, BUTTON_HEIGHT,
617 "btnClearAll", _(
"Clear All"), weapons_clearAll );
619 window_addText( wid, x+10, y, wlen, 100, 0,
"txtSMode", NULL, NULL,
620 _(
"Cycles through the following modes:\n"
621 "- Switch: sets the selected weapons as primary and secondary weapons.\n"
622 "- Hold: turns on the selected outfits as long as key is held\n"
623 "- Toggle: toggles the selected outfits to on or off state"
625 y -= 8+window_getTextHeight( wid,
"txtSMode" );
626 window_addCheckbox( wid, x+10, y, wlen, BUTTON_HEIGHT,
627 "chkManual", _(
"Enable manual aiming mode"), weapons_manual,
630 window_addCheckbox( wid, x+10, y, wlen, BUTTON_HEIGHT,
631 "chkVolley", _(
"Enable volley mode (weapons fire jointly)"), weapons_volley,
634 window_addCheckbox( wid, x+10, y, wlen, BUTTON_HEIGHT,
635 "chkInrange", _(
"Only shoot weapons that are in range"), weapons_inrange,
638 window_addCheckbox( wid, x+10, y, wlen, BUTTON_HEIGHT,
639 "chkHelper", _(
"Dogfight visual aiming helper (all sets)"), aim_lines,
player.
p->
aimLines );
641 window_addCheckbox( wid, x+10, y, wlen, BUTTON_HEIGHT,
642 "chkAutoweap", _(
"Automatically handle all weapons sets"), weapons_autoweap,
player.
p->
autoweap );
645 weapons_genList( wid );
648 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
649 "closeCargo", _(
"Close"), info_close );
655static void weapons_genList(
unsigned int wid )
657 char **buf, tbuf[STRMAX_SHORT];
666 n = toolkit_getListPos( wid,
"lstWeapSets" );
672 buf = malloc(
sizeof(
char*) * PILOT_WEAPON_SETS );
673 for (
int i=0; i<PILOT_WEAPON_SETS; i++) {
676 snprintf( tbuf,
sizeof(tbuf),
"%d - ??", (i+1)%10 );
678 snprintf( tbuf,
sizeof(tbuf),
"%d - %s", (i+1)%10, str );
679 buf[i] = strdup( tbuf );
681 window_addList( wid, 20+180+20, -40,
682 w - (20+180+20+20), 200,
683 "lstWeapSets", buf, PILOT_WEAPON_SETS,
684 0, weapons_updateList, weapons_toggleList );
689 toolkit_setListPos( wid,
"lstWeapSets", n );
695static void weapons_updateList(
unsigned int wid,
const char *str )
701 pos = toolkit_getListPos( wid,
"lstWeapSets" );
707 window_checkboxSet( wid,
"chkInrange",
711 window_checkboxSet( wid,
"chkManual",
718static void weapons_toggleList(
unsigned int wid,
const char *str )
726 case WEAPSET_TYPE_SWITCH:
727 c = WEAPSET_TYPE_HOLD;
729 case WEAPSET_TYPE_HOLD:
730 c = WEAPSET_TYPE_TOGGLE;
732 case WEAPSET_TYPE_TOGGLE:
733 c = WEAPSET_TYPE_SWITCH;
737 c = WEAPSET_TYPE_SWITCH;
743 for (i=0; i<PILOT_WEAPON_SETS; i++)
748 if (i >= PILOT_WEAPON_SETS) {
757 weapons_genList( wid );
763static void weapons_clear(
unsigned int wid,
const char *str )
769 weapons_genList( wid );
775static void weapons_clearAll(
unsigned int wid,
const char *str )
779 _(
"Are you sure you want to clear all your current weapon sets?") );
784 for (
int i=0; i<PILOT_WEAPON_SETS; i++)
788 weapons_genList( wid );
794static void weapons_autoweap(
unsigned int wid,
const char *str )
797 int state = window_checkboxState( wid, str );
802 _(
"Are you sure you want to enable automatic weapon groups for the "
803 "ship?\n\nThis will overwrite all manually-tweaked weapons groups.") );
805 window_checkboxSet( wid, str, 0 );
810 weapons_genList( wid );
819static void weapons_inrange(
unsigned int wid,
const char *str )
821 int state = window_checkboxState( wid, str );
828static void weapons_manual(
unsigned int wid,
const char *str )
830 int state = window_checkboxState( wid, str );
837static void weapons_volley(
unsigned int wid,
const char *str )
839 int state = window_checkboxState( wid, str );
846static void aim_lines(
unsigned int wid,
const char *str )
848 int state = window_checkboxState( wid, str );
855static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
void* data )
883static void info_openCargo(
unsigned int wid )
891 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
892 "closeCargo", _(
"Close"), info_close );
893 window_addButton( wid, -20-BUTTON_WIDTH-10, 20,
894 BUTTON_WIDTH, BUTTON_HEIGHT,
"btnJettisonCargo", _(
"Jettison"),
896 window_disableButton( wid,
"btnJettisonCargo" );
899 window_addText( wid, 20, -40-200-20,
900 w - 40, h - BUTTON_HEIGHT - 260, 0,
901 "txtCargoDesc", NULL, NULL, NULL );
904 cargo_genList( wid );
909static void cargo_genList(
unsigned int wid )
926 buf = malloc(
sizeof(
char*));
927 buf[0] = strdup(_(
"None"));
932 buf = malloc(
sizeof(
char*) *
array_size(pclist) );
935 int misn = (pc->
id != 0);
938 SDL_asprintf(&buf[i],
"%s %d%s%s",
941 misn ? _(
" [#bMission#0]") :
"",
942 illegal ? _(
" (#rillegal#0)") :
"" );
947 window_addList( wid, 20, -40, w - 40, 200,
948 "lstCargo", buf, nbuf, 0, cargo_update, NULL );
955static void cargo_update(
unsigned int wid,
const char *str )
964 window_modifyText( wid,
"txtCargoDesc", NULL );
971 window_disableButton( wid,
"btnJettisonCargo" );
973 window_enableButton( wid,
"btnJettisonCargo" );
975 pos = toolkit_getListPos( wid,
"lstCargo" );
985 l +=
scnprintf( &desc[l],
sizeof(desc)-l,
"\n\n%s", _(
"Carried by the following ships in your fleet:\n") );
988 l +=
scnprintf( &desc[l],
sizeof(desc)-l, _(
"\n - %s (%d)"), plist[i].p->name, plist[i].q );
994 l +=
scnprintf( &desc[l],
sizeof(desc)-l,
"\n\n%s", _(
"Illegalized by the following factions:\n") );
1003 window_modifyText( wid,
"txtCargoDesc", desc );
1011static void cargo_jettison(
unsigned int wid,
const char *str )
1023 pos = toolkit_getListPos( wid,
"lstCargo" );
1026 if (pclist[pos].
id != 0) {
1031 _(
"Are you sure you want to abort this mission?") )) {
1049 WARN(_(
"Cargo '%d' does not belong to any active mission."),
1057 ret = misn_tryRun( misn,
"abort" );
1072 mission_menu_genList( info_windows[ INFO_WIN_MISN ], 0 );
1076 pfleet_cargoRm( pclist[pos].commodity, pclist[pos].quantity, 1 );
1079 ship_update( info_windows[ INFO_WIN_SHIP ] );
1080 cargo_genList( wid );
1081 cargo_update( wid, NULL );
1084 hparam[0].
type = HOOK_PARAM_COMMODITY;
1086 hparam[1].
type = HOOK_PARAM_NUMBER;
1088 hparam[2].
type = HOOK_PARAM_SENTINEL;
1098static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw )
1108static void standings_close(
unsigned int wid,
const char *str )
1113 info_factions = NULL;
1116static int factionsSort(
const void *p1,
const void *p2 )
1133static void info_openStandings(
unsigned int wid )
1139 info_getDim( wid, &w, &h, &lw );
1145 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1146 "closeMissions", _(
"Close"), info_close );
1149 window_addImage( wid, 0, 0, 0, 0,
"imgLogo", NULL, 0 );
1152 window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 0,
"txtName",
1154 window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 0,
"txtStanding",
1156 window_addText( wid, lw+40, 0, (w-(lw+60)), h-80, 0,
"txtDescription",
1161 str = malloc(
sizeof(
char*) *
array_size(info_factions) );
1162 qsort( info_factions,
array_size(info_factions),
sizeof(
int), factionsSort );
1165 for (
int i=0; i<
array_size(info_factions); i++) {
1167 SDL_asprintf( &str[i],
"%s [ #%c%+d%%#0 ]",
1173 window_addList( wid, 20, -40, lw, h-60,
"lstStandings",
1174 str,
array_size(info_factions), 0, standings_update, NULL );
1181static void standings_update(
unsigned int wid,
const char *str )
1191 info_getDim( wid, &w, &h, &lw );
1194 p = toolkit_getListPos( wid,
"lstStandings" );
1201 int tw = t->
w * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1202 int th = t->
h * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1203 window_modifyImage( wid,
"imgLogo", t, tw, th );
1204 window_moveWidget( wid,
"imgLogo", x + (FACTION_LOGO_SM-tw), y - (FACTION_LOGO_SM-th)/2 );
1205 x += FACTION_LOGO_SM+20;
1209 window_modifyImage( wid,
"imgLogo", NULL, 0, 0 );
1214 snprintf( buf,
sizeof(buf), p_(
"standings",
"#%c%+d%%#0 [ %s ]"),
1220 window_modifyText( wid,
"txtStanding", buf );
1224 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"You can have a maximum reputation of %.0f%% with this faction."), round(
faction_reputationMax( info_factions[p] )) );
1235 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s", _(
"Ally Factions:") );
1250 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n\n%s", _(
"Enemy Factions:") );
1257 window_modifyText( wid,
"txtDescription", buf );
1267static void info_openMissions(
unsigned int wid )
1275 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1276 "closeMissions", _(
"Close"), info_close );
1277 window_addButtonKey( wid, -20-BUTTON_WIDTH-10, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1278 "btnAbortMission", _(
"Abort"), mission_menu_abort, SDLK_a );
1281 window_addCheckbox( wid, 300+40, 20+BUTTON_HEIGHT+10,
1282 w-300-60, BUTTON_HEIGHT,
1283 "chkHide", _(
"Hide mission on-screen display"),
1284 mission_menu_chk_hide, 0 );
1286 window_addCheckbox( wid, 300+40, 20+BUTTON_HEIGHT+10+
gl_defFont.
h+10,
1287 w-300-60, BUTTON_HEIGHT,
1288 "chkPrefer", _(
"Prioritize the mission"),
1289 mission_menu_chk_priority, 0 );
1292 window_addText( wid, 300+40, -40,
1293 w-300-60, h - BUTTON_HEIGHT - 120, 0,
"txtDesc",
1297 map_show( wid, 20, 20, 300, 260, 0.75, 0., 0. );
1300 mission_menu_genList(wid ,1);
1306static void mission_menu_genList(
unsigned int wid,
int first )
1320 selectedMission = -1;
1328 misn_names[j++] = strdup(_(
"No Missions"));
1329 window_modifyText( wid,
"txtDesc", _(
"You currently have no active missions.") );
1330 window_disableButton( wid,
"btnAbortMission" );
1331 window_disableCheckbox( wid,
"chkHide" );
1332 window_disableCheckbox( wid,
"chkPrefer" );
1333 selectedMission = 0;
1335 window_addList( wid, 20, -40,
1337 "lstMission", misn_names, j, selectedMission, mission_menu_update, NULL );
1344static void mission_menu_update(
unsigned int wid,
const char *str )
1349 const StarSystem *sys;
1350 int pos = toolkit_getListPos(wid,
"lstMission" );
1352 if (pos < 0 || pos == selectedMission)
1356 selectedMission = pos;
1358 snprintf( buf,
sizeof(buf),_(
"%s\n#nReward:#0 %s\n\n%s"), misn->
title, misn->
reward, misn->
desc );
1359 window_modifyText( wid,
"txtDesc", buf );
1360 window_enableButton( wid,
"btnAbortMission" );
1361 window_enableCheckbox( wid,
"chkHide" );
1362 window_enableCheckbox( wid,
"chkPrefer" );
1363 if (misn->
osd == 0) {
1364 window_checkboxSet( wid,
"chkHide", 0 );
1365 window_checkboxSet( wid,
"chkPrefer", 0 );
1368 window_checkboxSet( wid,
"chkHide", osd_getHide( misn->
osd ) );
1369 window_checkboxSet( wid,
"chkPrefer", osd_getPriority( misn->
osd ) != misn->
data->
avail.
priority );
1375 map_center( wid, sys->name );
1377static void mission_menu_chk_hide(
unsigned int wid,
const char *str )
1380 int pos = toolkit_getListPos(wid,
"lstMission" );
1387 osd_setHide( misn->
osd, window_checkboxState(wid,str) );
1389static void mission_menu_chk_priority(
unsigned int wid,
const char *str )
1392 int pos = toolkit_getListPos(wid,
"lstMission" );
1405static void mission_menu_abort(
unsigned int wid,
const char *str )
1412 _(
"Are you sure you want to abort this mission?") ))
1416 pos = toolkit_getListPos(wid,
"lstMission" );
1420 ret = misn_tryRun( misn,
"abort" );
1435 mission_menu_genList(wid ,0);
1442#define LOGSPACING (h - 120 - BUTTON_HEIGHT )
1448static void shiplog_menu_update(
unsigned int wid,
const char *str )
1454 if (!logWidgetsReady)
1460 if (strcmp(str,
"lstLogEntries" ) != 0) {
1461 int regenerateEntries=0;
1468 logType = toolkit_getListPos( wid,
"lstLogType" );
1469 log = toolkit_getListPos( wid,
"lstLogs" );
1471 if (logType != selectedLogType) {
1473 selectedLogType = logType;
1477 if (selectedLog >= nlogs)
1479 window_addList( wid, 20, 60 + BUTTON_HEIGHT + LOGSPACING / 2,
1480 w-40, LOGSPACING / 4,
1481 "lstLogs", logs, nlogs, 0, shiplog_menu_update, NULL );
1483 toolkit_setListPos( wid,
"lstLogs", selectedLog );
1484 regenerateEntries=1;
1486 if (regenerateEntries || selectedLog != log) {
1487 selectedLog =
CLAMP( 0, nlogs-1, log );
1490 shiplog_listLog( logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries, &logentries, 1 );
1491 window_addList( wid, 20, 40 + BUTTON_HEIGHT,
1492 w-40, LOGSPACING / 2-20,
1493 "lstLogEntries", logentries, nentries, 0, shiplog_menu_update, info_shiplogView );
1494 toolkit_setListPos( wid,
"lstLogEntries", 0 );
1504static const char* info_getLogTypeFilter(
int lstPos )
1508 return logTypes[lstPos];
1515static void shiplog_menu_genList(
unsigned int wid,
int first )
1536 shiplog_listTypes(&ntypes, &logTypes, 1);
1537 if ( selectedLogType >= ntypes )
1538 selectedLogType = 0;
1541 if ( selectedLog >= nlogs )
1544 shiplog_listLog(logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries, &logentries, 1);
1546 window_addList( wid, 20, 80 + BUTTON_HEIGHT + 3*LOGSPACING/4 ,
1547 w-40, LOGSPACING / 4,
1548 "lstLogType", logTypes, ntypes, 0, shiplog_menu_update, NULL );
1549 window_addList( wid, 20, 60 + BUTTON_HEIGHT + LOGSPACING / 2,
1550 w-40, LOGSPACING / 4,
1551 "lstLogs", logs, nlogs, 0, shiplog_menu_update, NULL );
1552 window_addList( wid, 20, 40 + BUTTON_HEIGHT,
1553 w-40, LOGSPACING / 2-20,
1554 "lstLogEntries", logentries, nentries, 0, shiplog_menu_update, info_shiplogView );
1559static void info_shiplogMenuDelete(
unsigned int wid,
const char *str )
1562 char buf[STRMAX_SHORT];
1565 if (logIDs[selectedLog] == LOG_ID_ALL) {
1566 dialogue_msg(
"", _(
"You are currently viewing all logs in the selected log type. Please select a log title to delete.") );
1570 snprintf( buf,
sizeof(buf),
1571 _(
"This will delete ALL \"%s\" log entries. This operation cannot be undone. Are you sure?"),
1578 logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter(selectedLogType), selectedLog-1 );
1582 selectedLogType = 0;
1583 shiplog_menu_genList(wid, 0);
1586static void info_shiplogView(
unsigned int wid,
const char *str )
1593 pos = toolkit_getListPos( wid,
"lstLogEntries" );
1597 logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries,
1603 for (
int i=0; i<nentries; i++)
1604 free( logentries[i] );
1614static void info_shiplogAdd(
unsigned int wid,
const char *str )
1620 logType = toolkit_getListPos( wid,
"lstLogType" );
1621 log = toolkit_getListPos( wid,
"lstLogs" );
1622 if ( log < 0 || logIDs[log] == LOG_ID_ALL ) {
1623 tmp =
dialogue_inputRaw( _(
"Add a log entry"), 0, 4096, _(
"Add an entry to your diary:") );
1624 if ( ( tmp != NULL ) && ( strlen(tmp) > 0 ) ) {
1631 tmp =
dialogue_input( _(
"Add a log entry"), 0, 4096, _(
"Add an entry to the log titled '%s':"), logs[log] );
1632 if ( ( tmp != NULL ) && ( strlen(tmp) > 0 ) ) {
1633 int logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter(logType), log-1 );
1637 dialogue_msgRaw( _(
"Cannot add log"), _(
"Cannot find this log! Something went wrong here!") );
1641 shiplog_menu_genList( wid, 0 );
1650static void info_openShipLog(
unsigned int wid )
1655 selectedLogType = 0;
1660 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1661 "closeShipLog", _(
"Close"), info_close );
1662 window_addButton( wid, -20 - 1*(20+BUTTON_WIDTH), 20,
1663 BUTTON_WIDTH, BUTTON_HEIGHT,
"btnDeleteLog", _(
"Delete"),
1664 info_shiplogMenuDelete );
1665 window_addButton( wid, -20 - 2*(20+BUTTON_WIDTH), 20, BUTTON_WIDTH,
1666 BUTTON_HEIGHT,
"btnViewLog", _(
"View Entry"),
1668 window_addButton( wid, -20 - 3*(20+BUTTON_WIDTH), 20, BUTTON_WIDTH,
1669 BUTTON_HEIGHT,
"btnAddLog", _(
"Add Entry"),
1673 window_addText( wid, 20, 80 + BUTTON_HEIGHT + LOGSPACING,
1675 "logDesc1", &
gl_smallFont, NULL, _(
"Select log type:") );
1677 window_addText( wid, 20, 60 + BUTTON_HEIGHT + 3* LOGSPACING / 4,
1679 "logDesc2", &
gl_smallFont, NULL, _(
"Select log title:") );
1681 window_addText( wid, 20, 25 + BUTTON_HEIGHT + LOGSPACING / 2,
1687 shiplog_menu_genList(wid ,1);
1693static void info_changeTab(
unsigned int wid,
const char *str,
int old,
int new )
1698 const char *hookname;
1700 case INFO_WIN_MAIN: hookname =
"info_main";
break;
1701 case INFO_WIN_SHIP: hookname =
"info_ship";
break;
1702 case INFO_WIN_WEAP: hookname =
"info_weapons";
break;
1703 case INFO_WIN_CARGO: hookname =
"info_cargo";
break;
1704 case INFO_WIN_MISN: hookname =
"info_mission";
break;
1705 case INFO_WIN_STAND: hookname =
"info_standing";
break;
1706 case INFO_WIN_SHIPLOG:hookname=
"info_shiplog";
break;
1707 default: ERR( _(
"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.
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and 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?
char faction_getColourChar(int f)
Gets the faction character associated to its standing with the player.
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.
double faction_getPlayer(int f)
Gets the player's standing with a faction.
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?
double faction_reputationMax(int f)
Gets the maximum reputation of 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 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.
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_weaponSetDefault(Pilot *p)
Gives the pilot a default weapon set.
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.
The actual hook parameter.
Represents an active mission.
Stores a pilot commodity.
const Commodity * commodity
PilotWeaponSet weapon_sets[PILOT_WEAPON_SETS]
Represents an item in the player inventory.
PilotWeaponSet weapon_sets[PILOT_WEAPON_SETS]
unsigned int jumped_times
unsigned int ships_destroyed[SHIP_CLASS_TOTAL]
unsigned int death_counter
unsigned int landed_times
Abstraction for rendering sprite sheets.