Skip to content

Commit

Permalink
feat(port,UI): Allow Bionics to be hidden (#5855)
Browse files Browse the repository at this point in the history
* initial commit

port of CleverRaven/Cataclysm-DDA#65243

Co-Authored-By: Rewryte <129854247+rewryte@users.noreply.github.com>

* style(autofix.ci): automated formatting

---------

Co-authored-by: Rewryte <129854247+rewryte@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 31, 2024
1 parent a4dde2f commit 8dc9c31
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions data/raw/keybindings/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,13 @@
"name": "Toggle safe fuel mod",
"bindings": [ { "input_method": "keyboard", "key": "S" } ]
},
{
"type": "keybinding",
"id": "TOGGLE_SPRITE",
"category": "BIONICS",
"name": "Toggle sprite",
"bindings": [ { "input_method": "keyboard", "key": "H" } ]
},
{
"type": "keybinding",
"id": "TOGGLE_AUTO_START",
Expand Down
4 changes: 4 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,7 @@ void bionic::serialize( JsonOut &json ) const
if( energy_stored > 0_kJ ) {
json.member( "energy_stored", energy_stored );
}
json.member( "show_sprite", show_sprite );

json.end_object();
}
Expand All @@ -2955,6 +2956,9 @@ void bionic::deserialize( JsonIn &jsin )
if( jo.has_float( "auto_start_threshold" ) ) {
auto_start_threshold = jo.get_float( "auto_start_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 @@ -165,6 +165,7 @@ struct bionic {
int charge_timer = 0;
char invlet = 'a';
bool powered = false;
bool show_sprite = true;
/* Ammunition actually loaded in this bionic gun in deactivated state */
itype_id ammo_loaded = itype_id::NULL_ID();
/* Ammount of ammo actually held inside by this bionic gun in deactivated state */
Expand Down
13 changes: 13 additions & 0 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ static void draw_bionics_titlebar( const catacurses::window &window, Character *
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, "
"[<color_yellow>%s</color>] Toggle sprite visibility, "
"[<color_yellow>%s</color>] Toggle auto start mode." ),
ctxt.get_desc( "REASSIGN" ), ctxt.get_desc( "NEXT_TAB" ), ctxt.get_desc( "TOGGLE_SAFE_FUEL" ),
ctxt.get_desc( "TOGGLE_SPRITE" ),
ctxt.get_desc( "TOGGLE_AUTO_START" ) );
desc_append += string_format( _( " [<color_yellow>%s</color>] Sort: %s" ), ctxt.get_desc( "SORT" ),
sort_mode_str( uistate.bionic_sort_mode ) );
Expand Down Expand Up @@ -317,6 +319,9 @@ static std::string build_bionic_poweronly_string( const bionic &bio )
if( bio.incapacitated_time > 0_turns ) {
properties.emplace_back( _( "(incapacitated)" ) );
}
if( !bio.show_sprite ) {
properties.emplace_back( _( "(hidden)" ) );
}
if( !bio.has_flag( flag_SAFE_FUEL_OFF ) && ( !bio.info().fuel_opts.empty() ||
bio.info().is_remote_fueled ) ) {
properties.emplace_back( _( "(fuel saving ON)" ) );
Expand Down Expand Up @@ -630,6 +635,7 @@ void show_bionics_ui( Character &who )
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "TOGGLE_SAFE_FUEL" );
ctxt.register_action( "TOGGLE_SPRITE" );
ctxt.register_action( "TOGGLE_AUTO_START" );
ctxt.register_action( "SORT" );

Expand Down Expand Up @@ -840,6 +846,13 @@ void show_bionics_ui( Character &who )
popup( _( "You can't toggle auto start 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 @@ -3664,6 +3664,9 @@ std::vector<std::string> Character::get_overlay_ids() const

// 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.insert( std::pair<int, std::string>( order, overlay_id ) );
Expand Down

0 comments on commit 8dc9c31

Please sign in to comment.