Skip to content

Commit

Permalink
Added system_name to get the name of a system and let systems have
Browse files Browse the repository at this point in the history
different display names.
  • Loading branch information
bobbens committed Apr 26, 2024
1 parent d3d0a13 commit cebf763
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/dev_uniedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ static void uniedit_renderOverlay( double bx, double by, double bw, double bh,
l = scnprintf(
buf, sizeof( buf ), "#%c%.0f#0 = #%c%.0f#0 + #%c%.0f#0 [%s - %s]",
getValCol( value ), value, getValCol( base ), base, getValCol( bonus ),
bonus, _( sys->name ), faction_name( f ) );
bonus, system_name( sys ), faction_name( f ) );

/* Local presence sources. */
for ( int j = 0; j < array_size( sys->spobs ); j++ ) {
Expand Down Expand Up @@ -1494,9 +1494,9 @@ static void uniedit_renameSys( void )
}

/* Get name. */
name =
dialogue_input( _( "Rename Star System" ), 1, 32,
_( "What do you want to rename #r%s#0?" ), sys->name );
name = dialogue_input( _( "Rename Star System" ), 1, 32,
_( "What do you want to rename #r%s#0?" ),
system_name( sys ) );

/* Keep current name. */
if ( name == NULL ) {
Expand Down Expand Up @@ -1915,7 +1915,7 @@ static void uniedit_findSearch( unsigned int wid, const char *str )

/* Set fancy name. */
snprintf( found[n].display, sizeof( found[n].display ),
_( "%s (%s system)" ), spobs[i], sys->name );
_( "%s (%s system)" ), spobs[i], system_name( sys ) );
n++;
}
free( spobs );
Expand Down
14 changes: 7 additions & 7 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void map_open( void )

/* System Name */
window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont,
NULL, _( cur->name ) );
NULL, system_name( cur ) );
y -= 10;

/* Faction image */
Expand Down Expand Up @@ -608,7 +608,7 @@ static void map_update( unsigned int wid )
_( "Showing %s prices relative to %s:\n"
"Positive/blue indicate profit while negative/orange values "
"indicate loss when sold at the corresponding system." ),
_( c->name ), _( sys->name ) );
_( c->name ), system_name( sys ) );
map_update_status( wid, buf );
} else {
snprintf( buf, sizeof( buf ),
Expand All @@ -632,7 +632,7 @@ static void map_update( unsigned int wid )
* Right Text
*/
if ( sys_isFlag( sys, SYSTEM_MARKED | SYSTEM_CMARKED ) )
window_modifyText( wid, "txtSysname", _( sys->name ) );
window_modifyText( wid, "txtSysname", system_name( sys ) );
else
window_modifyText( wid, "txtSysname", _( "Unknown" ) );

Expand Down Expand Up @@ -677,7 +677,7 @@ static void map_update( unsigned int wid )
}

/* System is known */
window_modifyText( wid, "txtSysname", _( sys->name ) );
window_modifyText( wid, "txtSysname", system_name( sys ) );

f = -1;
multiple = 0;
Expand Down Expand Up @@ -1608,7 +1608,7 @@ void map_renderNames( double bx, double by, double x, double y, double zoom,

font = ( zoom >= 1.5 ) ? &gl_defFont : &gl_smallFont;

textw = gl_printWidthRaw( font, _( sys->name ) );
textw = gl_printWidthRaw( font, system_name( sys ) );
tx = x + ( sys->pos.x + 12. ) * zoom;
ty = y + ( sys->pos.y ) * zoom - font->h * 0.5;

Expand All @@ -1618,7 +1618,7 @@ void map_renderNames( double bx, double by, double x, double y, double zoom,

col = cWhite;
col.a = alpha;
gl_printRaw( font, tx, ty, &col, -1, _( sys->name ) );
gl_printRaw( font, tx, ty, &col, -1, system_name( sys ) );
}

/* Raw hidden values if we're in the editor. */
Expand Down Expand Up @@ -2337,7 +2337,7 @@ static void map_buttonMarkSystem( unsigned int wid, const char *str )
sys->note = dialogue_input(
_( "Add System Note" ), 0, 60,
_( "Write a note about the #o%s#0 system:" ),
sys_isKnown( sys ) ? _( sys->name ) : _( "Unknown" ) );
sys_isKnown( sys ) ? system_name( sys ) : _( "Unknown" ) );
if ( sys->note != NULL )
sys_setFlag( sys, SYSTEM_PMARKED );
}
Expand Down
6 changes: 3 additions & 3 deletions src/map_find.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ static void map_findAccumulateResult( map_find_t *found, int n, StarSystem *sys,
/* Set fancy name. */
if ( spob == NULL )
snprintf( found[n].display, sizeof( found[n].display ), _( "%s (%s)" ),
_( sys->name ), route_info );
system_name( sys ), route_info );
else
snprintf( found[n].display, sizeof( found[n].display ),
_( "#%c%s%s (%s, %s)" ), map_getSpobColourChar( spob ),
map_getSpobSymbol( spob ), spob_name( spob ), _( sys->name ),
route_info );
map_getSpobSymbol( spob ), spob_name( spob ),
system_name( sys ), route_info );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/map_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void ovr_refresh( void )
continue;
/* Initialize the map overlay stuff. */
snprintf( buf, sizeof( buf ), "%s%s", jump_getSymbol( jp ),
sys_isKnown( jp->target ) ? _( jp->target->name )
sys_isKnown( jp->target ) ? system_name( jp->target )
: _( "Unknown" ) );
pos[items] = &jp->pos;
mo[items] = &jp->mo;
Expand Down
15 changes: 8 additions & 7 deletions src/map_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void map_system_open( int sys_selected )
window_onClose( wid, map_system_cleanup );
window_handleKeys( wid, map_system_keyHandler );
window_addText( wid, 40, h - 30, 160, 20, 1, "txtSysname", &gl_defFont,
&cFontGreen, _( cur_sys_sel->name ) );
&cFontGreen, system_name( cur_sys_sel ) );
window_addImage( wid, -90 + 32, h - 30, 0, 0, "imgFaction", NULL, 0 );
/* Close button */
window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose",
Expand Down Expand Up @@ -363,9 +363,10 @@ static void map_system_render( double bx, double by, double w, double h,
( by + ( nshow - 0.5 ) * pitch + offset ), 0, &cFontRed,
-1., _( "Obscured by the nebula" ) );
}
gl_printRaw(
&gl_smallFont, bx + 5 + pitch, by + ( nshow - 0.5 ) * pitch + offset,
( cur_spob_sel == 0 ? &cFontGreen : &cFontWhite ), -1., _( sys->name ) );
gl_printRaw( &gl_smallFont, bx + 5 + pitch,
by + ( nshow - 0.5 ) * pitch + offset,
( cur_spob_sel == 0 ? &cFontGreen : &cFontWhite ), -1.,
system_name( sys ) );
if ( ( cur_spob_sel == 0 ) && bgImage != NULL ) {
double imgw, imgh, s;
iw = w - 50 - pitch - nameWidth;
Expand Down Expand Up @@ -411,7 +412,7 @@ static void map_system_render( double bx, double by, double w, double h,
int infopos = 0;
int stars = MAX( array_size( starImages ), 0 );
cnt += scnprintf( &buf[cnt], sizeof( buf ) - cnt, _( "#nSystem:#0 %s\n" ),
_( sys->name ) );
system_name( sys ) );
/* display sun information */
cnt += scnprintf( &buf[cnt], sizeof( buf ) - cnt,
n_( "%d-star system\n", "%d-star system\n", stars ),
Expand Down Expand Up @@ -551,7 +552,7 @@ static void map_system_render( double bx, double by, double w, double h,
if ( sys_isKnown( sys->jumps[i].target ) )
infopos +=
scnprintf( &infobuf[infopos], sizeof( infobuf ) - infopos,
" %s\n", _( sys->jumps[i].target->name ) );
" %s\n", system_name( sys->jumps[i].target ) );
else
infopos +=
scnprintf( &infobuf[infopos], sizeof( infobuf ) - infopos,
Expand Down Expand Up @@ -917,7 +918,7 @@ void map_system_updateSelected( unsigned int wid )
}
}
/* get width of star name text */
textw = gl_printWidthRaw( &gl_smallFont, _( sys->name ) );
textw = gl_printWidthRaw( &gl_smallFont, system_name( sys ) );
if ( textw > nameWidth )
nameWidth = textw;

Expand Down
2 changes: 1 addition & 1 deletion src/nlua_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static int systemL_eq( lua_State *L )
static int systemL_name( lua_State *L )
{
const StarSystem *sys = luaL_validsystem( L, 1 );
lua_pushstring( L, _( sys->name ) );
lua_pushstring( L, system_name( sys ) );
return 1;
}

Expand Down
11 changes: 10 additions & 1 deletion src/space.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ char **system_searchFuzzyCase( const char *sysname, int *n )
len = 0;
for ( int i = 0; i < array_size( systems_stack ); i++ ) {
StarSystem *sys = &systems_stack[i];
if ( SDL_strcasestr( _( sys->name ), sysname ) != NULL ) {
if ( SDL_strcasestr( system_name( sys ), sysname ) != NULL ) {
names[len] = sys->name;
len++;
} else if ( ( sys->features != NULL ) &&
Expand Down Expand Up @@ -2868,6 +2868,13 @@ StarSystem *system_new( void )
return sys;
}

const char *system_name( const StarSystem *sys )
{
if ( sys->display != NULL )
return _( sys->display );
return _( sys->name );
}

/**
* @brief Reconstructs the jumps for a single system.
*/
Expand Down Expand Up @@ -3113,6 +3120,7 @@ static int system_parse( StarSystem *sys, const char *filename )
/* Only handle nodes. */
xml_onlyNodes( node );

xmlr_strd( node, "display", sys->display );
if ( xml_isNode( node, "pos" ) ) {
flags |= FLAG_POSSET;
xmlr_attr_float( node, "x", sys->pos.x );
Expand Down Expand Up @@ -3866,6 +3874,7 @@ void space_exit( void )

free( sys->filename );
free( sys->name );
free( sys->display );
free( sys->background );
free( sys->map_shader );
free( sys->features );
Expand Down
4 changes: 3 additions & 1 deletion src/space.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ struct StarSystem_ {
char *filename; /** Name of the file loaded from. */

/* General. */
char *name; /**< star system name */
char *name; /**< Star system name */
char *display; /**< Star system display name. */
vec2 pos; /**< Position */
int spacedust; /**< Amount of "space dust" it has. */
double
Expand Down Expand Up @@ -420,6 +421,7 @@ void system_reconstructJumps( StarSystem *sys );
void systems_reconstructJumps( void );
void systems_reconstructSpobs( void );
StarSystem *system_new( void );
const char *system_name( const StarSystem *sys );
int system_addSpob( StarSystem *sys, const char *spobname );
int system_rmSpob( StarSystem *sys, const char *spobname );
int system_addVirtualSpob( StarSystem *sys, const char *spobname );
Expand Down

0 comments on commit cebf763

Please sign in to comment.