Skip to content

Commit

Permalink
Add option to hide bionics (#65243)
Browse files Browse the repository at this point in the history
* add toggle

* astyle

* tidy up

* tidy up more
  • Loading branch information
Rewryte authored Apr 22, 2023
1 parent 8adf00c commit 34b078d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,13 @@
"name": "Toggle safe fuel mod",
"bindings": [ { "input_method": "keyboard_char", "key": "S" }, { "input_method": "keyboard_code", "key": "s", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "TOGGLE_SPRITE",
"category": "BIONICS",
"name": "Toggle sprite",
"bindings": [ { "input_method": "keyboard_char", "key": "H" }, { "input_method": "keyboard_code", "key": "h", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "REFUEL",
Expand Down
4 changes: 4 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,7 @@ void bionic::serialize( JsonOut &json ) const
if( is_safe_fuel_on() ) {
json.member( "safe_fuel_threshold", safe_fuel_threshold );
}
json.member( "show_sprite", show_sprite );

if( has_weapon() ) {
json.member( "weapon", weapon );
Expand Down Expand Up @@ -3162,6 +3163,9 @@ void bionic::deserialize( const JsonObject &jo )
if( jo.has_float( "safe_fuel_threshold" ) ) {
safe_fuel_threshold = jo.get_float( "safe_fuel_threshold" );
}
if( jo.has_bool( "show_sprite" ) ) {
show_sprite = jo.get_bool( "show_sprite" );
}
if( jo.has_array( "bionic_tags" ) ) {
for( const std::string line : jo.get_array( "bionic_tags" ) ) {
bionic_tags.insert( line );
Expand Down
1 change: 1 addition & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct bionic {
time_duration charge_timer = 0_turns;
char invlet = 'a';
bool powered = false;
bool show_sprite = true;
/* An amount of time during which this bionic has been rendered inoperative. */
time_duration incapacitated_time;

Expand Down
15 changes: 13 additions & 2 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ static void draw_bionics_titlebar( const catacurses::window &window, avatar *p,

std::string desc_append = string_format(
_( "[<color_yellow>%s</color>] Reassign, [<color_yellow>%s</color>] Switch tabs, "
"[<color_yellow>%s</color>] Toggle fuel saving mode, " ),
ctxt.get_desc( "REASSIGN" ), ctxt.get_desc( "NEXT_TAB" ), ctxt.get_desc( "TOGGLE_SAFE_FUEL" ) );
"[<color_yellow>%s</color>] Toggle fuel saving mode, [<color_yellow>%s</color>] Toggle sprite visibility, " ),
ctxt.get_desc( "REASSIGN" ), ctxt.get_desc( "NEXT_TAB" ), ctxt.get_desc( "TOGGLE_SAFE_FUEL" ),
ctxt.get_desc( "TOGGLE_SPRITE" ) );
desc_append += string_format( _( " [<color_yellow>%s</color>] Sort: %s" ), ctxt.get_desc( "SORT" ),
sort_mode_str( uistate.bionic_sort_mode ) );
std::string desc;
Expand Down Expand Up @@ -330,6 +331,9 @@ static std::string build_bionic_poweronly_string( const bionic &bio, avatar *p )
if( bio.incapacitated_time > 0_turns ) {
properties.emplace_back( _( "(incapacitated)" ) );
}
if( !bio.show_sprite ) {
properties.emplace_back( _( "(hidden)" ) );
}

if( bio.is_safe_fuel_on() ) {
const std::string label = string_format( _( "(fuel saving ON > %d %%)" ),
Expand Down Expand Up @@ -647,6 +651,7 @@ void avatar::power_bionics()
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "TOGGLE_SAFE_FUEL" );
ctxt.register_action( "TOGGLE_SPRITE" );
ctxt.register_action( "SORT" );

ui.on_redraw( [&]( const ui_adaptor & ) {
Expand Down Expand Up @@ -846,6 +851,12 @@ void avatar::power_bionics()
popup( _( "You can't toggle fuel saving mode on a non-fueled CBM." ) );
}
}
} else if( action == "TOGGLE_SPRITE" ) {
auto &bio_list = tab_mode == TAB_ACTIVE ? active : passive;
if( !current_bionic_list->empty() ) {
tmp = bio_list[cursor];
tmp->show_sprite = !tmp->show_sprite;
}
} else if( action == "SORT" ) {
uistate.bionic_sort_mode = pick_sort_mode();
// FIXME: is there a better way to resort?
Expand Down
3 changes: 3 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,9 @@ std::vector<std::pair<std::string, std::string>> Character::get_overlay_ids() co

// then get bionics
for( const bionic &bio : *my_bionics ) {
if( !bio.show_sprite ) {
continue;
}
overlay_id = ( bio.powered ? "active_" : "" ) + bio.id.str();
order = get_overlay_order_of_mutation( overlay_id );
mutation_sorting.emplace( order, std::pair<std::string, std::string> { overlay_id, "" } );
Expand Down

0 comments on commit 34b078d

Please sign in to comment.