Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use translation markers to optimize performance #31374

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions data/json/traps.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "temple_toggle"
"action": "temple_toggle",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -410,7 +411,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "glow"
"action": "glow",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -421,7 +423,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "hum"
"action": "hum",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -432,7 +435,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "shadow"
"action": "shadow",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -443,7 +447,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "drain"
"action": "drain",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -454,7 +459,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "snake"
"action": "snake",
"always_invisible": true
},
{
"type": "trap",
Expand Down
8 changes: 4 additions & 4 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ void construction_menu()
const inventory &total_inv = g->u.crafting_inventory();

input_context ctxt( "CONSTRUCTION" );
ctxt.register_action( "UP", _( "Move cursor up" ) );
ctxt.register_action( "DOWN", _( "Move cursor down" ) );
ctxt.register_action( "RIGHT", _( "Move tab right" ) );
ctxt.register_action( "LEFT", _( "Move tab left" ) );
ctxt.register_action( "UP", translate_marker( "Move cursor up" ) );
ctxt.register_action( "DOWN", translate_marker( "Move cursor down" ) );
ctxt.register_action( "RIGHT", translate_marker( "Move tab right" ) );
ctxt.register_action( "LEFT", translate_marker( "Move tab left" ) );
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "PAGE_DOWN" );
ctxt.register_action( "CONFIRM" );
Expand Down
10 changes: 5 additions & 5 deletions src/defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ void defense_game::setup()
refresh_setup( w, selection );

input_context ctxt( "DEFENSE_SETUP" );
ctxt.register_action( "UP", _( "Previous option" ) );
ctxt.register_action( "DOWN", _( "Next option" ) );
ctxt.register_action( "LEFT", _( "Cycle option value" ) );
ctxt.register_action( "RIGHT", _( "Cycle option value" ) );
ctxt.register_action( "CONFIRM", _( "Toggle option" ) );
ctxt.register_action( "UP", translate_marker( "Previous option" ) );
ctxt.register_action( "DOWN", translate_marker( "Next option" ) );
ctxt.register_action( "LEFT", translate_marker( "Cycle option value" ) );
ctxt.register_action( "RIGHT", translate_marker( "Cycle option value" ) );
ctxt.register_action( "CONFIRM", translate_marker( "Toggle option" ) );
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "PREV_TAB" );
ctxt.register_action( "START" );
Expand Down
33 changes: 17 additions & 16 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,17 +2199,18 @@ input_context get_default_mode_input_context()
input_context ctxt( "DEFAULTMODE" );
// Because those keys move the character, they don't pan, as their original name says
ctxt.set_iso( true );
ctxt.register_action( "UP", _( "Move North" ) );
ctxt.register_action( "RIGHTUP", _( "Move Northeast" ) );
ctxt.register_action( "RIGHT", _( "Move East" ) );
ctxt.register_action( "RIGHTDOWN", _( "Move Southeast" ) );
ctxt.register_action( "DOWN", _( "Move South" ) );
ctxt.register_action( "LEFTDOWN", _( "Move Southwest" ) );
ctxt.register_action( "LEFT", _( "Move West" ) );
ctxt.register_action( "LEFTUP", _( "Move Northwest" ) );
ctxt.register_action( "UP", translate_marker( "Move North" ) );
ctxt.register_action( "RIGHTUP", translate_marker( "Move Northeast" ) );
ctxt.register_action( "RIGHT", translate_marker( "Move East" ) );
ctxt.register_action( "RIGHTDOWN", translate_marker( "Move Southeast" ) );
ctxt.register_action( "DOWN", translate_marker( "Move South" ) );
ctxt.register_action( "LEFTDOWN", translate_marker( "Move Southwest" ) );
ctxt.register_action( "LEFTDOWN", translate_marker( "Move Southwest" ) );
ctxt.register_action( "LEFT", translate_marker( "Move West" ) );
ctxt.register_action( "LEFTUP", translate_marker( "Move Northwest" ) );
ctxt.register_action( "pause" );
ctxt.register_action( "LEVEL_DOWN", _( "Descend Stairs" ) );
ctxt.register_action( "LEVEL_UP", _( "Ascend Stairs" ) );
ctxt.register_action( "LEVEL_DOWN", translate_marker( "Descend Stairs" ) );
ctxt.register_action( "LEVEL_UP", translate_marker( "Ascend Stairs" ) );
ctxt.register_action( "toggle_map_memory" );
ctxt.register_action( "center" );
ctxt.register_action( "shift_n" );
Expand Down Expand Up @@ -7114,10 +7115,10 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )

std::string action;
input_context ctxt( "LIST_ITEMS" );
ctxt.register_action( "UP", _( "Move cursor up" ) );
ctxt.register_action( "DOWN", _( "Move cursor down" ) );
ctxt.register_action( "LEFT", _( "Previous item" ) );
ctxt.register_action( "RIGHT", _( "Next item" ) );
ctxt.register_action( "UP", translate_marker( "Move cursor up" ) );
ctxt.register_action( "DOWN", translate_marker( "Move cursor down" ) );
ctxt.register_action( "LEFT", translate_marker( "Previous item" ) );
ctxt.register_action( "RIGHT", translate_marker( "Next item" ) );
ctxt.register_action( "PAGE_DOWN" );
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "NEXT_TAB" );
Expand Down Expand Up @@ -7474,8 +7475,8 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list

std::string action;
input_context ctxt( "LIST_MONSTERS" );
ctxt.register_action( "UP", _( "Move cursor up" ) );
ctxt.register_action( "DOWN", _( "Move cursor down" ) );
ctxt.register_action( "UP", translate_marker( "Move cursor up" ) );
ctxt.register_action( "DOWN", translate_marker( "Move cursor down" ) );
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "PREV_TAB" );
ctxt.register_action( "SAFEMODE_BLACKLIST_ADD" );
Expand Down
6 changes: 3 additions & 3 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@ void input_context::display_menu()
// Shamelessly stolen from help.cpp

input_context ctxt( "HELP_KEYBINDINGS" );
ctxt.register_action( "UP", _( "Scroll up" ) );
ctxt.register_action( "DOWN", _( "Scroll down" ) );
ctxt.register_action( "UP", translate_marker( "Scroll up" ) );
ctxt.register_action( "DOWN", translate_marker( "Scroll down" ) );
ctxt.register_action( "PAGE_DOWN" );
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "REMOVE" );
Expand Down Expand Up @@ -1293,7 +1293,7 @@ const std::string input_context::get_action_name( const std::string &action_id )
const input_manager::t_string_string_map::const_iterator action_name_override =
action_name_overrides.find( action_id );
if( action_name_override != action_name_overrides.end() ) {
return action_name_override->second;
return _( action_name_override->second );
}

// 2) Check if the hotkey has a name
Expand Down
28 changes: 14 additions & 14 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,18 +1566,18 @@ inventory_selector::inventory_selector( const player &u, const inventory_selecto
, own_gear_column( preset )
, map_column( preset )
{
ctxt.register_action( "DOWN", _( "Next item" ) );
ctxt.register_action( "UP", _( "Previous item" ) );
ctxt.register_action( "RIGHT", _( "Next column" ) );
ctxt.register_action( "LEFT", _( "Previous column" ) );
ctxt.register_action( "CONFIRM", _( "Confirm your selection" ) );
ctxt.register_action( "QUIT", _( "Cancel" ) );
ctxt.register_action( "CATEGORY_SELECTION", _( "Switch selection mode" ) );
ctxt.register_action( "TOGGLE_FAVORITE", _( "Toggle favorite" ) );
ctxt.register_action( "NEXT_TAB", _( "Page down" ) );
ctxt.register_action( "PREV_TAB", _( "Page up" ) );
ctxt.register_action( "HOME", _( "Home" ) );
ctxt.register_action( "END", _( "End" ) );
ctxt.register_action( "DOWN", translate_marker( "Next item" ) );
ctxt.register_action( "UP", translate_marker( "Previous item" ) );
ctxt.register_action( "RIGHT", translate_marker( "Next column" ) );
ctxt.register_action( "LEFT", translate_marker( "Previous column" ) );
ctxt.register_action( "CONFIRM", translate_marker( "Confirm your selection" ) );
ctxt.register_action( "QUIT", translate_marker( "Cancel" ) );
ctxt.register_action( "CATEGORY_SELECTION", translate_marker( "Switch selection mode" ) );
ctxt.register_action( "TOGGLE_FAVORITE", translate_marker( "Toggle favorite" ) );
ctxt.register_action( "NEXT_TAB", translate_marker( "Page down" ) );
ctxt.register_action( "PREV_TAB", translate_marker( "Page up" ) );
ctxt.register_action( "HOME", translate_marker( "Home" ) );
ctxt.register_action( "END", translate_marker( "End" ) );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "ANY_INPUT" ); // For invlets
ctxt.register_action( "INVENTORY_FILTER" );
Expand Down Expand Up @@ -1789,8 +1789,8 @@ inventory_multiselector::inventory_multiselector( const player &p,
inventory_selector( p, preset ),
selection_col( new selection_column( "SELECTION_COLUMN", selection_column_title ) )
{
ctxt.register_action( "RIGHT", _( "Mark/unmark selected item" ) );
ctxt.register_action( "DROP_NON_FAVORITE", _( "Mark/unmark non-favorite items" ) );
ctxt.register_action( "RIGHT", translate_marker( "Mark/unmark selected item" ) );
ctxt.register_action( "DROP_NON_FAVORITE", translate_marker( "Mark/unmark non-favorite items" ) );

for( auto &elem : get_all_columns() ) {
elem->set_multiselect( true );
Expand Down
6 changes: 3 additions & 3 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3174,9 +3174,9 @@ void map::bash_ter_furn( const tripoint &p, bash_params &params )
sound_volume = sound_fail_vol;
}

sound = bash->sound_fail.empty() ? _( "Thnk!" ) : _( bash->sound_fail );
params.did_bash = true;
if( !params.silent ) {
sound = bash->sound_fail.empty() ? _( "Thnk!" ) : _( bash->sound_fail );
sounds::sound( p, sound_volume, sounds::sound_t::combat, sound, false,
"smash_fail", soundfxvariant );
}
Expand Down Expand Up @@ -3205,7 +3205,7 @@ void map::bash_ter_furn( const tripoint &p, bash_params &params )
}

soundfxid = "smash_success";
sound = _( bash->sound );
sound = bash->sound;
// Set this now in case the ter_set below changes this
const bool collapses = smash_ter && has_flag( "COLLAPSES", p );
const bool supports = smash_ter && has_flag( "SUPPORTS_ROOF", p );
Expand Down Expand Up @@ -3337,7 +3337,7 @@ void map::bash_ter_furn( const tripoint &p, bash_params &params )
params.success |= success; // Not always true, so that we can tell when to stop destroying
params.bashed_solid = true;
if( !sound.empty() && !params.silent ) {
sounds::sound( p, sound_volume, sounds::sound_t::combat, sound, false,
sounds::sound( p, sound_volume, sounds::sound_t::combat, _( sound ), false,
soundfxid, soundfxvariant );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ void Messages::dialog::init()
w = catacurses::newwin( w_height, w_width, w_y, w_x );

ctxt = input_context( "MESSAGE_LOG" );
ctxt.register_action( "UP", _( "Scroll up" ) );
ctxt.register_action( "DOWN", _( "Scroll down" ) );
ctxt.register_action( "UP", translate_marker( "Scroll up" ) );
ctxt.register_action( "DOWN", translate_marker( "Scroll down" ) );
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "PAGE_DOWN" );
ctxt.register_action( "FILTER" );
Expand Down
4 changes: 2 additions & 2 deletions src/mission_companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr
part_y + TITLE_TAB_HEIGHT + 1, part_x + MAX_FAC_NAME_SIZE );

input_context ctxt( "FACTIONS" );
ctxt.register_action( "UP", _( "Move cursor up" ) );
ctxt.register_action( "DOWN", _( "Move cursor down" ) );
ctxt.register_action( "UP", translate_marker( "Move cursor up" ) );
ctxt.register_action( "DOWN", translate_marker( "Move cursor down" ) );
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "PREV_TAB" );
ctxt.register_action( "PAGE_UP" );
Expand Down
14 changes: 8 additions & 6 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,18 +917,20 @@ void monster::footsteps( const tripoint &p )
if( volume == 0 ) {
return;
}
std::string footstep = _( "footsteps." );
std::string footstep;
if( type->in_species( BLOB ) ) {
footstep = _( "plop." );
footstep = translate_marker( "plop." );
} else if( type->in_species( ZOMBIE ) ) {
footstep = _( "shuffling." );
footstep = translate_marker( "shuffling." );
} else if( type->in_species( ROBOT ) ) {
footstep = _( "mechanical whirring." );
footstep = translate_marker( "mechanical whirring." );
} else if( type->in_species( WORM ) ) {
footstep = _( "rustle." );
footstep = translate_marker( "rustle." );
} else {
footstep = translate_marker( "footsteps" );
}
int dist = rl_dist( p, g->u.pos() );
sounds::add_footstep( p, volume, dist, this, footstep );
sounds::add_footstep( p, volume, dist, this, _( footstep ) );
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,8 @@ static bool search( tripoint &curs, const tripoint &orig, const bool show_explor

input_context ctxt( "OVERMAP_SEARCH" );
ctxt.register_leftright();
ctxt.register_action( "NEXT_TAB", _( "Next target" ) );
ctxt.register_action( "PREV_TAB", _( "Previous target" ) );
ctxt.register_action( "NEXT_TAB", translate_marker( "Next target" ) );
ctxt.register_action( "PREV_TAB", translate_marker( "Previous target" ) );
ctxt.register_action( "QUIT" );
ctxt.register_action( "CONFIRM" );
ctxt.register_action( "HELP_KEYBINDINGS" );
Expand Down
6 changes: 3 additions & 3 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,13 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
ctxt.register_action( "DOWN" );
ctxt.register_action( "RIGHT" );
ctxt.register_action( "LEFT" );
ctxt.register_action( "NEXT_TAB", _( "Next page" ) );
ctxt.register_action( "PREV_TAB", _( "Previous page" ) );
ctxt.register_action( "NEXT_TAB", translate_marker( "Next page" ) );
ctxt.register_action( "PREV_TAB", translate_marker( "Previous page" ) );
ctxt.register_action( "SCROLL_UP" );
ctxt.register_action( "SCROLL_DOWN" );
ctxt.register_action( "CONFIRM" );
ctxt.register_action( "SELECT_ALL" );
ctxt.register_action( "QUIT", _( "Cancel" ) );
ctxt.register_action( "QUIT", translate_marker( "Cancel" ) );
ctxt.register_action( "ANY_INPUT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "FILTER" );
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2932,8 +2932,8 @@ void player::search_surroundings()
if( !sees( tp ) ) {
continue;
}
if( tr.name().empty() || tr.can_see( tp, *this ) ) {
// Already seen, or has no name -> can never be seen
if( tr.is_always_invisible() || tr.can_see( tp, *this ) ) {
// Already seen, or can never be seen
continue;
}
// Chance to detect traps we haven't yet seen.
Expand Down
6 changes: 3 additions & 3 deletions src/player_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,10 @@ Strength - 4; Dexterity - 4; Intelligence - 4; Perception - 4" ) );

input_context ctxt( "PLAYER_INFO" );
ctxt.register_updown();
ctxt.register_action( "NEXT_TAB", _( "Cycle to next category" ) );
ctxt.register_action( "PREV_TAB", _( "Cycle to previous category" ) );
ctxt.register_action( "NEXT_TAB", translate_marker( "Cycle to next category" ) );
ctxt.register_action( "PREV_TAB", translate_marker( "Cycle to previous category" ) );
ctxt.register_action( "QUIT" );
ctxt.register_action( "CONFIRM", _( "Toggle skill training" ) );
ctxt.register_action( "CONFIRM", translate_marker( "Toggle skill training" ) );
ctxt.register_action( "HELP_KEYBINDINGS" );
std::string action;

Expand Down
4 changes: 2 additions & 2 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ void trap::load( JsonObject &jo, const std::string & )
act = trap_function_from_string( jo.get_string( "action" ) );

optional( jo, was_loaded, "benign", benign, false );
optional( jo, was_loaded, "always_invisible", always_invisible, false );
optional( jo, was_loaded, "funnel_radius", funnel_radius_mm, 0 );
assign( jo, "trigger_weight", trigger_weight );
optional( jo, was_loaded, "drops", components );
}

std::string trap::name() const
{
// trap names can be empty, those are special always invisible traps. See player::search_surroundings
return name_.empty() ? name_ : _( name_ );
return _( name_ );
}

void trap::reset()
Expand Down
7 changes: 7 additions & 0 deletions src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct trap {
int avoidance; // 0 to ??, affects avoidance
int difficulty; // 0 to ??, difficulty of assembly & disassembly
bool benign = false;
bool always_invisible = false;
trap_function act;
std::string name_;
/**
Expand All @@ -86,6 +87,12 @@ struct trap {
std::vector<itype_id> components; // For disassembly?
public:
std::string name() const;
/**
* There are special always invisible traps. See player::search_surroundings
*/
bool is_always_invisible() const {
return always_invisible;
}
/**
* How easy it is to spot the trap. Smaller values means it's easier to spot.
*/
Expand Down
Loading