32#include "player_fleet.h"
33#include "player_gui.h"
34#include "player_inventory.h"
37#include "tk/toolkit_priv.h"
40#define BUTTON_WIDTH 135
41#define BUTTON_HEIGHT 30
43#define SETGUI_WIDTH 400
44#define SETGUI_HEIGHT 300
46#define menu_Open(f) (menu_open |= (f))
47#define menu_Close(f) (menu_open &= ~(f))
51#define INFO_WIN_MAIN 0
52#define INFO_WIN_SHIP 1
53#define INFO_WIN_WEAP 2
54#define INFO_WIN_CARGO 3
55#define INFO_WIN_MISN 4
56#define INFO_WIN_STAND 5
57#define INFO_WIN_SHIPLOG 6
58static const char *info_names[INFO_WINDOWS] = {
71typedef struct InfoButton_s {
83static unsigned int info_wid = 0;
84static unsigned int *info_windows = NULL;
85static int info_lastTab;
89static int *info_factions;
91static int selectedMission = 0;
92static int selectedLog = 0;
93static int selectedLogType = 0;
94static char **logTypes=NULL;
97static char **logs=NULL;
98static int *logIDs=NULL;
99static int logWidgetsReady=0;
105static void info_close(
unsigned int wid,
const char *str );
106static void info_openMain(
unsigned int wid );
107static void info_setGui(
unsigned int wid,
const char *str );
108static void setgui_load(
unsigned int wdw,
const char *str );
109static void info_openShip(
unsigned int wid );
110static void info_openWeapons(
unsigned int wid );
111static void info_openCargo(
unsigned int wid );
112static void info_openMissions(
unsigned int wid );
113static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw );
114static void info_buttonClick(
unsigned int wid,
const char *str );
115static void standings_close(
unsigned int wid,
const char *str );
116static void ship_update(
unsigned int wid );
117static void weapons_genList(
unsigned int wid );
119static void weapons_autoweap(
unsigned int wid,
const char *str );
120static void weapons_fire(
unsigned int wid,
const char *str );
121static void weapons_inrange(
unsigned int wid,
const char *str );
122static void weapons_manual(
unsigned int wid,
const char *str );
123static void aim_lines(
unsigned int wid,
const char *str );
124static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
void* data );
125static void info_openStandings(
unsigned int wid );
126static void info_shiplogView(
unsigned int wid,
const char *str );
127static void standings_update(
unsigned int wid,
const char *str );
128static void cargo_genList(
unsigned int wid );
129static void cargo_update(
unsigned int wid,
const char *str );
130static void cargo_jettison(
unsigned int wid,
const char *str );
131static void mission_menu_abort(
unsigned int wid,
const char *str );
132static void mission_menu_genList(
unsigned int wid,
int first );
133static void mission_menu_update(
unsigned int wid,
const char *str );
134static void info_openShipLog(
unsigned int wid );
135static const char* info_getLogTypeFilter(
int lstPos );
136static void info_changeTab(
unsigned int wid,
const char *str,
int old,
int new );
138static int sort_buttons(
const void *p1,
const void *p2 )
153 luaL_unref( naevL, LUA_REGISTRYINDEX, btn->
func );
156static void info_buttonRegen (
void)
158 int wid, w, h, rows, cols;
162 wid = info_windows[ INFO_WIN_MAIN ];
165 rows = 1 + (
array_size(info_buttons) + 1) / cols;
167 for (
int i=0; i<
array_size(info_buttons); i++) {
169 int r = (i+2)/cols,
c = (i+2)%cols;
190 static int button_idgen = 0;
194 if (info_buttons == NULL)
198 btn->
id = ++button_idgen;
199 btn->
caption= strdup( caption );
202 btn->
env = __NLUA_CURENV;
203 btn->
func = luaL_ref( naevL, LUA_REGISTRYINDEX );
221 for (
int i=0; i<
array_size(info_buttons); i++) {
226 int wid = info_windows[ INFO_WIN_MAIN ];
230 info_buttonFree( btn );
243 for (
int i=0; i<
array_size(info_buttons); i++) {
246 int wid = info_windows[ INFO_WIN_MAIN ];
250 info_buttonFree( btn );
257static void info_buttonClick(
unsigned int wid,
const char *str )
260 for (
int i=0; i<
array_size(info_buttons); i++) {
262 if (strcmp( btn->
button, str )!=0)
265 lua_rawgeti( naevL, LUA_REGISTRYINDEX, btn->
func );
266 if (nlua_pcall( btn->
env, 0, 0 )) {
267 WARN( _(
"Failure to run info button with id '%d':\n%s"), btn->
id, lua_tostring( naevL, -1 ) );
270 land_needsTakeoff( 1 );
281 const char *names[INFO_WINDOWS];
284 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
291 info_close( 0, NULL );
300 info_wid =
window_create(
"wdwInfo", _(
"Info"), -1, -1, w, h );
304 for (
size_t i=0; i<INFO_WINDOWS; i++)
305 names[i] = _(info_names[i]);
306 info_windows = window_addTabbedWindow( info_wid, -1, -1, -1, -1,
"tabInfo",
307 INFO_WINDOWS, names, 0 );
310 info_openMain( info_windows[ INFO_WIN_MAIN ] );
311 info_openShip( info_windows[ INFO_WIN_SHIP ] );
312 info_openWeapons( info_windows[ INFO_WIN_WEAP ] );
313 info_openCargo( info_windows[ INFO_WIN_CARGO ] );
314 info_openMissions( info_windows[ INFO_WIN_MISN ] );
315 info_openStandings( info_windows[ INFO_WIN_STAND ] );
316 info_openShipLog( info_windows[ INFO_WIN_SHIPLOG ] );
324 window_tabWinOnChange( info_wid,
"tabInfo", info_changeTab );
326 window = info_lastTab;
327 window_tabWinSetActive( info_wid,
"tabInfo",
CLAMP( 0, 6, window ) );
333static void info_close(
unsigned int wid,
const char *str )
337 info_lastTab = window_tabWinGetActive( info_wid,
"tabInfo" );
355 if (info_windows != NULL)
356 weapons_genList( info_windows[ INFO_WIN_WEAP ] );
362static void info_openMain(
unsigned int wid )
365 char str[STRMAX_SHORT], creds[ECON_CRED_STRLEN];
368 int w, h, cargo_used, cargo_total, n;
369 unsigned int destroyed;
378 for (
int i=0; i<SHIP_CLASS_TOTAL; i++)
383 k +=
scnprintf( &str[k],
sizeof(str)-k,
"%s", _(
"Pilot:") );
384 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Date:") );
385 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n\n%s", _(
"Money:") );
386 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Current Ship:") );
387 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Fuel:") );
389 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n\n%s", _(
"Time played:") );
390 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times died:") );
391 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times jumped:") );
392 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Times landed:") );
393 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Damage done:") );
394 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Damage taken:") );
395 k +=
scnprintf( &str[k],
sizeof(str)-k,
"\n%s", _(
"Ships destroyed:") );
396 window_addText( wid, 20, 20, 120, h-80, 0,
"txtDPilot", &
gl_smallFont, &cFontGrey, str );
400 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%s", nt );
401 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n\n%s", creds );
403 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%.0f (%d %s)",
407 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%d / %d %s", cargo_used, cargo_total, n_(
"tonne",
"tonnes", cargo_total ) );
408 l +=
scnprintf( &str[l],
sizeof(str)-l,
"%s",
"\n\n" );
414 l +=
scnprintf( &str[l],
sizeof(str)-l,
"\n%s",
"" );
417 window_addText( wid, 160, 20,
418 w-80-160-40+20-180, h-80,
423 window_addButton( wid, -20, 20,
425 "btnClose", _(
"Close"), info_close );
428 "btnSetGUI", _(
"Set GUI"), info_setGui, SDLK_g );
444 for (
int i=0; i<nlic; i++)
447 for (
int i=0; i<ninv; i++) {
456 window_addText( wid, -20, -40, w-80-240-40-40, 20, 1,
"txtList",
457 NULL, NULL, _(
"Inventory") );
458 window_addList( wid, -20, -70, w-80-240-40-40, h-110-
BUTTON_HEIGHT,
459 "lstInventory",
inventory, n, 0, NULL, NULL );
471static void setgui_close(
unsigned int wdw,
const char *str )
483static void info_setGui(
unsigned int wid,
const char *str )
496 WARN(_(
"No GUI available."));
497 dialogue_alert( _(
"There are no GUI available, this means something went wrong somewhere. Inform the Naev maintainer.") );
502 wid =
window_create(
"wdwSetGUI", _(
"Select GUI"), -1, -1, SETGUI_WIDTH, SETGUI_HEIGHT );
506 gui_copy = malloc(
sizeof(
char*) * nguis );
507 for (
int i=0; i<nguis; i++)
508 gui_copy[i] = strdup( guis[i] );
511 window_addList( wid, 20, -50,
513 "lstGUI", gui_copy, nguis, 0, NULL, NULL );
514 toolkit_setList( wid,
"lstGUI",
gui_pick() );
518 "btnBack", _(
"Close"), setgui_close );
520 "btnLoad", _(
"Load"), setgui_load );
532static void setgui_load(
unsigned int wdw,
const char *str )
536 const char *gui = toolkit_getList( wid,
"lstGUI" );
538 if (strcmp(gui,_(
"None")) == 0)
546 setgui_close(wdw, NULL);
557static void info_openShip(
unsigned int wid )
567 window_addButton( wid, -20, 20,
569 "closeOutfits", _(
"Close"), info_close );
572 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", _(
"Name:") );
573 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Model:") );
574 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Class:") );
575 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Crew:") );
576 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
577 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Mass:") );
578 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Jump Time:") );
579 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Thrust:") );
580 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Speed:") );
581 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Turn:") );
582 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Time Constant:") );
583 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
584 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Absorption:") );
585 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Shield:") );
586 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Armour:") );
587 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Energy:") );
588 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Cargo Space:") );
589 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Fuel:") );
590 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
591 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Stats:") );
592 window_addText( wid, 20, -40, 100, h-60, 0,
"txtSDesc", &
gl_smallFont, &cFontGrey, buf );
593 window_addText( wid, 160, -40, w-20-20-20-160-180., h-60, 0,
"txtDDesc", &
gl_smallFont,
608static void ship_update(
unsigned int wid )
610 char buf[STRMAX_SHORT], *hyp_delay;
621 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
623 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
624 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s average"), hyp_delay );
625 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
627 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
628 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f m/s (max %.0f m/s)"),
630 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
634 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
636 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
638 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
640 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
643 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%.0f / %.0f %s (%d %s)",
646 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s",
"\n\n" );
649 window_modifyText( wid,
"txtDDesc", buf );
656static void info_openWeapons(
unsigned int wid )
658 int w, h, x, y, wlen;
671 window_addCust( wid, 220, y, w-200-60, 100,
"cstLegend", 0,
672 weapons_renderLegend, NULL, NULL, NULL, NULL );
678 window_addText( wid, x, y, wlen, 20, 0,
"txtLocal", NULL, NULL,
679 _(
"Current Weapon Set Settings"));
682 "chkFire", _(
"Enable instant Mode"), weapons_fire,
685 window_addText( wid, x+10, y, wlen, 20, 0,
"txtSInstant", NULL, NULL, _(
"(Weapons fire when this weapon set key is pressed)"));
688 "chkInrange", _(
"Only shoot weapons that are in range"), weapons_inrange,
692 "chkManual", _(
"Enable manual aiming mode."), weapons_manual,
695 window_addText( wid, x, y, wlen, 20, 0,
"txtGlobal", NULL, NULL,
696 _(
"Global Settings"));
699 "chkAutoweap", _(
"Automatically handle weapons"), weapons_autoweap,
player.
p->
autoweap );
702 "chkHelper", _(
"Dogfight aiming helper"), aim_lines,
player.
p->
aimLines );
705 weapons_genList( wid );
709 "closeCargo", _(
"Close"), info_close );
715static void weapons_genList(
unsigned int wid )
717 char **
buf, tbuf[STRMAX_SHORT];
726 n = toolkit_getListPos( wid,
"lstWeapSets" );
732 buf = malloc(
sizeof(
char*) * PILOT_WEAPON_SETS );
733 for (
int i=0; i<PILOT_WEAPON_SETS; i++) {
736 snprintf( tbuf,
sizeof(tbuf),
"%d - ??", (i+1)%10 );
738 snprintf( tbuf,
sizeof(tbuf),
"%d - %s", (i+1)%10, str );
739 buf[i] = strdup( tbuf );
741 window_addList( wid, 20+180+20, -40,
742 w - (20+180+20+20), 180,
743 "lstWeapSets", buf, PILOT_WEAPON_SETS,
749 toolkit_setListPos( wid,
"lstWeapSets", n );
761 pos = toolkit_getListPos( wid,
"lstWeapSets" );
767 window_checkboxSet( wid,
"chkFire",
771 window_checkboxSet( wid,
"chkInrange",
775 window_checkboxSet( wid,
"chkManual",
785static void weapons_autoweap(
unsigned int wid,
const char *str )
788 int state = window_checkboxState( wid, str );
793 _(
"Are you sure you want to enable automatic weapon groups for the "
794 "ship?\n\nThis will overwrite all manually-tweaked weapons groups.") );
796 window_checkboxSet( wid, str, 0 );
801 weapons_genList( wid );
810static void weapons_fire(
unsigned int wid,
const char *str )
815 state = window_checkboxState( wid, str );
819 if (t == WEAPSET_TYPE_ACTIVE)
823 c = WEAPSET_TYPE_WEAPON;
825 c = WEAPSET_TYPE_CHANGE;
829 for (i=0; i<PILOT_WEAPON_SETS; i++)
834 if (i >= PILOT_WEAPON_SETS) {
835 dialogue_alert( _(
"You can not set all your weapon sets to fire groups!") );
837 window_checkboxSet( wid, str, 0 );
844 weapons_genList( wid );
850static void weapons_inrange(
unsigned int wid,
const char *str )
852 int state = window_checkboxState( wid, str );
859static void weapons_manual(
unsigned int wid,
const char *str )
861 int state = window_checkboxState( wid, str );
868static void aim_lines(
unsigned int wid,
const char *str )
870 int state = window_checkboxState( wid, str );
877static void weapons_renderLegend(
double bx,
double by,
double bw,
double bh,
void* data )
905static void info_openCargo(
unsigned int wid )
914 "closeCargo", _(
"Close"), info_close );
918 window_disableButton( wid,
"btnJettisonCargo" );
921 window_addText( wid, 20, -40-200-20,
923 "txtCargoDesc", NULL, NULL, NULL );
926 cargo_genList( wid );
931static void cargo_genList(
unsigned int wid )
948 buf = malloc(
sizeof(
char*));
949 buf[0] = strdup(_(
"None"));
954 buf = malloc(
sizeof(
char*) *
array_size(pclist) );
957 int misn = (pc->
id != 0);
963 misn ? _(
" [#bMission#0]") :
"",
964 illegal ? _(
" (#rillegal#0)") :
"" );
969 window_addList( wid, 20, -40, w - 40, 200,
970 "lstCargo", buf, nbuf, 0, cargo_update, NULL );
977static void cargo_update(
unsigned int wid,
const char *str )
986 window_modifyText( wid,
"txtCargoDesc", NULL );
993 window_disableButton( wid,
"btnJettisonCargo" );
995 window_enableButton( wid,
"btnJettisonCargo" );
997 pos = toolkit_getListPos( wid,
"lstCargo" );
1007 l +=
scnprintf( &desc[l],
sizeof(desc)-l,
"\n\n%s", _(
"Carried by the following ships in your fleet:\n") );
1010 l +=
scnprintf( &desc[l],
sizeof(desc)-l, _(
"\n - %s (%d)"), plist[i].p->
name, plist[i].q );
1016 l +=
scnprintf( &desc[l],
sizeof(desc)-l,
"\n\n%s", _(
"Illegalized by the following factions:\n") );
1025 window_modifyText( wid,
"txtCargoDesc", desc );
1033static void cargo_jettison(
unsigned int wid,
const char *str )
1046 pos = toolkit_getListPos( wid,
"lstCargo" );
1049 if (pclist[pos].
id != 0) {
1053 _(
"Are you sure you want to abort this mission?") )) {
1071 WARN(_(
"Cargo '%d' does not belong to any active mission."),
1094 mission_menu_genList( info_windows[ INFO_WIN_MISN ], 0 );
1098 pfleet_cargoRm( pclist[pos].commodity, pclist[pos].quantity, 1 );
1101 ship_update( info_windows[ INFO_WIN_SHIP ] );
1102 cargo_genList( wid );
1103 cargo_update( wid, NULL );
1106 hparam[0].
type = HOOK_PARAM_STRING;
1108 hparam[1].
type = HOOK_PARAM_NUMBER;
1110 hparam[2].
type = HOOK_PARAM_SENTINEL;
1120static void info_getDim(
unsigned int wid,
int *w,
int *h,
int *lw )
1130static void standings_close(
unsigned int wid,
const char *str )
1135 info_factions = NULL;
1138static int factionsSort(
const void *p1,
const void *p2 )
1155static void info_openStandings(
unsigned int wid )
1161 info_getDim( wid, &w, &h, &lw );
1168 "closeMissions", _(
"Close"), info_close );
1171 window_addImage( wid, 0, 0, 0, 0,
"imgLogo", NULL, 0 );
1174 window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1,
"txtName",
1176 window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1,
"txtStanding",
1178 window_addText( wid, lw+40, 0, (w-(lw+60)), 300, 0,
"txtDescription",
1183 str = malloc(
sizeof(
char*) *
array_size(info_factions) );
1184 qsort( info_factions,
array_size(info_factions),
sizeof(
int), factionsSort );
1187 for (
int i=0; i<
array_size(info_factions); i++) {
1189 asprintf( &str[i],
"%s [ #%c%+d%%#0 ]",
1195 window_addList( wid, 20, -40, lw, h-60,
"lstStandings",
1196 str,
array_size(info_factions), 0, standings_update, NULL );
1203static void standings_update(
unsigned int wid,
const char *str )
1212 info_getDim( wid, &w, &h, &lw );
1215 p = toolkit_getListPos( wid,
"lstStandings" );
1220 int tw = t->
w * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1221 int th = t->
h * (double)FACTION_LOGO_SM /
MAX( t->
w, t->
h );
1222 window_modifyImage( wid,
"imgLogo", t, tw, th );
1224 window_moveWidget( wid,
"imgLogo", lw+40 + (w-(lw+60)-tw)/2, y - (FACTION_LOGO_SM-th)/2 );
1225 y -= FACTION_LOGO_SM;
1228 window_modifyImage( wid,
"imgLogo", NULL, 0, 0 );
1235 snprintf( buf,
sizeof(buf),
"#%c%+d%%#0 [ %s ]",
1241 window_modifyText( wid,
"txtStanding", buf );
1245 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"You can have a maximum reputation of %.0f%% with this faction."), round(
faction_reputationMax( info_factions[p] )) );
1246 window_modifyText( wid,
"txtDescription", buf );
1256static void info_openMissions(
unsigned int wid )
1265 "closeMissions", _(
"Close"), info_close );
1268 mission_menu_abort, SDLK_a );
1271 window_addText( wid, 300+40, -60,
1272 200, 40, 0,
"txtSReward",
1274 window_addText( wid, 300+40, -80,
1276 window_addText( wid, 300+40, -120,
1281 map_show( wid, 20, 20, 300, 260, 0.75, 0., 0. );
1284 mission_menu_genList(wid ,1);
1290static void mission_menu_genList(
unsigned int wid,
int first )
1304 selectedMission = -1;
1312 misn_names[j++] = strdup(_(
"No Missions"));
1313 window_modifyText( wid,
"txtReward", _(
"None") );
1314 window_modifyText( wid,
"txtDesc", _(
"You currently have no active missions.") );
1315 window_disableButton( wid,
"btnAbortMission" );
1316 selectedMission = 0;
1318 window_addList( wid, 20, -40,
1320 "lstMission", misn_names, j, selectedMission, mission_menu_update, NULL );
1327static void mission_menu_update(
unsigned int wid,
const char *str )
1331 const StarSystem *sys;
1332 int pos = toolkit_getListPos(wid,
"lstMission" );
1334 if (pos < 0 || pos == selectedMission)
1338 selectedMission = pos;
1340 window_modifyText( wid,
"txtReward", misn->
reward );
1341 window_modifyText( wid,
"txtDesc", misn->
desc );
1342 window_enableButton( wid,
"btnAbortMission" );
1347 map_center( wid, sys->name );
1353static void mission_menu_abort(
unsigned int wid,
const char *str )
1360 _(
"Are you sure you want to abort this mission?") ))
1364 pos = toolkit_getListPos(wid,
"lstMission" );
1383 mission_menu_genList(wid ,0);
1390#define LOGSPACING (h - 120 - BUTTON_HEIGHT )
1396static void shiplog_menu_update(
unsigned int wid,
const char *str )
1398 int regenerateEntries=0;
1404 if (!logWidgetsReady)
1410 if (strcmp(str,
"lstLogEntries" ) != 0) {
1415 logType = toolkit_getListPos( wid,
"lstLogType" );
1416 log = toolkit_getListPos( wid,
"lstLogs" );
1418 if (logType != selectedLogType) {
1420 selectedLogType = logType;
1424 if (selectedLog >= nlogs)
1426 window_addList( wid, 20, 60 +
BUTTON_HEIGHT + LOGSPACING / 2,
1427 w-40, LOGSPACING / 4,
1428 "lstLogs", logs, nlogs, 0, shiplog_menu_update, NULL );
1430 toolkit_setListPos( wid,
"lstLogs", selectedLog );
1431 regenerateEntries=1;
1433 if (regenerateEntries || selectedLog != log) {
1434 selectedLog =
CLAMP( 0, nlogs-1, log );
1437 shiplog_listLog( logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries, &logentries, 1 );
1439 w-40, LOGSPACING / 2-20,
1440 "lstLogEntries", logentries, nentries, 0, shiplog_menu_update, info_shiplogView );
1441 toolkit_setListPos( wid,
"lstLogEntries", 0 );
1451static const char* info_getLogTypeFilter(
int lstPos )
1455 return logTypes[lstPos];
1462static void shiplog_menu_genList(
unsigned int wid,
int first )
1483 shiplog_listTypes(&ntypes, &logTypes, 1);
1484 if ( selectedLogType >= ntypes )
1485 selectedLogType = 0;
1488 if ( selectedLog >= nlogs )
1491 shiplog_listLog(logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries, &logentries, 1);
1493 window_addList( wid, 20, 80 +
BUTTON_HEIGHT + 3*LOGSPACING/4 ,
1494 w-40, LOGSPACING / 4,
1495 "lstLogType", logTypes, ntypes, 0, shiplog_menu_update, NULL );
1496 window_addList( wid, 20, 60 +
BUTTON_HEIGHT + LOGSPACING / 2,
1497 w-40, LOGSPACING / 4,
1498 "lstLogs", logs, nlogs, 0, shiplog_menu_update, NULL );
1500 w-40, LOGSPACING / 2-20,
1501 "lstLogEntries", logentries, nentries, 0, shiplog_menu_update, info_shiplogView );
1506static void info_shiplogMenuDelete(
unsigned int wid,
const char *str )
1509 char buf[STRMAX_SHORT];
1512 if (logIDs[selectedLog] == LOG_ID_ALL) {
1513 dialogue_msg(
"", _(
"You are currently viewing all logs in the selected log type. Please select a log title to delete.") );
1517 snprintf( buf,
sizeof(buf),
1518 _(
"This will delete ALL \"%s\" log entries. This operation cannot be undone. Are you sure?"),
1525 logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter(selectedLogType), selectedLog-1 );
1529 selectedLogType = 0;
1530 shiplog_menu_genList(wid, 0);
1533static void info_shiplogView(
unsigned int wid,
const char *str )
1540 pos = toolkit_getListPos( wid,
"lstLogEntries" );
1544 logIDs[selectedLog], info_getLogTypeFilter(selectedLogType), &nentries,
1550 for (
int i=0; i<nentries; i++)
1551 free( logentries[i] );
1561static void info_shiplogAdd(
unsigned int wid,
const char *str )
1568 logType = toolkit_getListPos( wid,
"lstLogType" );
1569 log = toolkit_getListPos( wid,
"lstLogs" );
1570 if ( log < 0 || logIDs[log] == LOG_ID_ALL ) {
1571 tmp =
dialogue_inputRaw( _(
"Add a log entry"), 0, 4096, _(
"Add an entry to your diary:") );
1572 if ( ( tmp != NULL ) && ( strlen(tmp) > 0 ) ) {
1579 tmp =
dialogue_input( _(
"Add a log entry"), 0, 4096, _(
"Add an entry to the log titled '%s':"), logs[log] );
1580 if ( ( tmp != NULL ) && ( strlen(tmp) > 0 ) ) {
1581 logid = shiplog_getIdOfLogOfType( info_getLogTypeFilter(logType), log-1 );
1585 dialogue_msgRaw( _(
"Cannot add log"), _(
"Cannot find this log! Something went wrong here!") );
1589 shiplog_menu_genList( wid, 0 );
1598static void info_openShipLog(
unsigned int wid )
1603 selectedLogType = 0;
1609 "closeShipLog", _(
"Close"), info_close );
1612 info_shiplogMenuDelete );
1623 "logDesc1", &
gl_smallFont, NULL, _(
"Select log type:") );
1625 window_addText( wid, 20, 60 +
BUTTON_HEIGHT + 3* LOGSPACING / 4,
1627 "logDesc2", &
gl_smallFont, NULL, _(
"Select log title:") );
1629 window_addText( wid, 20, 25 +
BUTTON_HEIGHT + LOGSPACING / 2,
1635 shiplog_menu_genList(wid ,1);
1641static void info_changeTab(
unsigned int wid,
const char *str,
int old,
int new )
1646 const char *hookname;
1648 case INFO_WIN_MAIN: hookname =
"info_main";
break;
1649 case INFO_WIN_SHIP: hookname =
"info_ship";
break;
1650 case INFO_WIN_WEAP: hookname =
"info_weapons";
break;
1651 case INFO_WIN_CARGO: hookname =
"info_cargo";
break;
1652 case INFO_WIN_MISN: hookname =
"info_mission";
break;
1653 case INFO_WIN_STAND: hookname =
"info_standing";
break;
1654 case INFO_WIN_SHIPLOG:hookname=
"info_shiplog";
break;
1655 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.
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).
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_getKnown()
Gets all the known factions in an array (array.h).
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 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 gui_load(const char *name)
Attempts to load the actual GUI.
char * gui_pick(void)
Determines which GUI should be used.
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.
int info_buttonRegister(const char *caption, int priority, SDL_Keycode key)
Registers a button in the info menu.
void info_update(void)
Updates the info windows.
int info_buttonUnregister(int id)
Unregisters a button in the info menu.
void info_buttonClear(void)
Clears all the registered buttons.
void menu_info(int window)
Opens the information menu.
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.
static char buf[NEWS_MAX_LENGTH]
int misn_tryRun(Mission *misn, const char *func)
Tries to run a mission, but doesn't err if it fails.
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
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(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_weapSetManual(Pilot *p, int id, int manual)
Changes the weapon set manual 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.
void pilot_weapSetType(Pilot *p, int id, int type)
Changes the weapon sets mode.
void pilot_weaponSetDefault(Pilot *p)
Gives the pilot a default 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.
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.
char ** player_guiList(void)
Gets the list of GUIs.
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.
void weapons_update(const double dt)
Updates all the weapon layers.