From 960f9484cafdd440becbd94f2d75efc3f861aa21 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 3 Oct 2021 01:09:45 +0200 Subject: [PATCH] Add option to toggle display of trait/mutation on player sprite --- data/raw/keybindings.json | 7 +++++++ src/character.cpp | 3 +++ src/character.h | 3 +++ src/mutation_ui.cpp | 17 +++++++++++++++++ src/savegame_json.cpp | 2 ++ 5 files changed, 32 insertions(+) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index bef6f1a69ce5e..775e8e3e6a08f 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -2737,6 +2737,13 @@ "name": "Reassign invlet", "bindings": [ { "input_method": "keyboard_any", "key": "=" } ] }, + { + "type": "keybinding", + "id": "TOGGLE_SPRITE", + "category": "MUTATIONS", + "name": "Toggle sprite", + "bindings": [ { "input_method": "keyboard_any", "key": "," } ] + }, { "type": "keybinding", "id": "UP", diff --git a/src/character.cpp b/src/character.cpp index e5aaa8378f41f..41e38c2fa833d 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -2705,6 +2705,9 @@ std::vector> Character::get_overlay_ids() co // then get mutations for( const std::pair &mut : my_mutations ) { + if( !mut.second.show_sprite ) { + continue; + } overlay_id = ( mut.second.powered ? "active_" : "" ) + mut.first.str(); order = get_overlay_order_of_mutation( overlay_id ); mutation_sorting.insert( std::pair( order, overlay_id ) ); diff --git a/src/character.h b/src/character.h index 8256f7b2f4a63..7117d8349af50 100644 --- a/src/character.h +++ b/src/character.h @@ -3127,6 +3127,9 @@ class Character : public Creature, public visitable * is reset to @ref mutation_branch::cooldown. */ int charge = 0; + + bool show_sprite = true; + void serialize( JsonOut &json ) const; void deserialize( const JsonObject &data ); }; diff --git a/src/mutation_ui.cpp b/src/mutation_ui.cpp index d04d4397e19d2..61c10ae7dfe58 100644 --- a/src/mutation_ui.cpp +++ b/src/mutation_ui.cpp @@ -41,6 +41,7 @@ enum class mutation_menu_mode : int { activating, examining, reassigning, + hidding, }; static void show_mutations_titlebar( const catacurses::window &window, @@ -62,9 +63,14 @@ static void show_mutations_titlebar( const catacurses::window &window, c_light_blue ) + " " + shortcut_desc( _( "%s to activate mutation, " ), ctxt.get_desc( "TOGGLE_EXAMINE" ) ); } + if( menu_mode == mutation_menu_mode::hidding ) { + desc += colorize( _( "Hidding" ), c_cyan ) + " " + shortcut_desc( _( "%s to activate mutation, " ), + ctxt.get_desc( "TOGGLE_EXAMINE" ) ); + } if( menu_mode != mutation_menu_mode::reassigning ) { desc += shortcut_desc( _( "%s to reassign invlet, " ), ctxt.get_desc( "REASSIGN" ) ); } + desc += shortcut_desc( _( "%s to toggle sprite visibility, " ), ctxt.get_desc( "TOGGLE_SPRITE" ) ); desc += shortcut_desc( _( "%s to change keybindings." ), ctxt.get_desc( "HELP_KEYBINDINGS" ) ); // NOLINTNEXTLINE(cata-use-named-point-constants) fold_and_print( window, point( 1, 0 ), getmaxx( window ) - 1, c_white, desc ); @@ -172,6 +178,7 @@ void avatar::power_mutations() ctxt.register_updown(); ctxt.register_action( "ANY_INPUT" ); ctxt.register_action( "TOGGLE_EXAMINE" ); + ctxt.register_action( "TOGGLE_SPRITE" ); ctxt.register_action( "REASSIGN" ); ctxt.register_action( "HELP_KEYBINDINGS" ); ctxt.register_action( "QUIT" ); @@ -215,6 +222,10 @@ void avatar::power_mutations() type = has_base_trait( passive[i] ) ? c_cyan : c_light_cyan; mvwprintz( wBio, point( 2, list_start_y + i - scroll_position ), type, "%c %s", td.key, md.name() ); + if( !td.show_sprite ) { + //~ Hint: Letter to show which mutation is Hidden in the mutation menu + wprintz( wBio, c_cyan, _( " H" ) ); + } } } @@ -352,6 +363,9 @@ void avatar::power_mutations() // Describing mutations, not activating them! examine_id = mut_id; break; + case mutation_menu_mode::hidding: + my_mutations[mut_id].show_sprite = !my_mutations[mut_id].show_sprite; + break; } handled = true; } else if( mutation_chars.valid( ch ) ) { @@ -375,6 +389,9 @@ void avatar::power_mutations() menu_mode = menu_mode == mutation_menu_mode::activating ? mutation_menu_mode::examining : mutation_menu_mode::activating; examine_id = cata::nullopt; + } else if( action == "TOGGLE_SPRITE" ) { + menu_mode = mutation_menu_mode::hidding; + examine_id = cata::nullopt; } else if( action == "QUIT" ) { exit = true; } diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 833073ebbc3db..89a99f6433720 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -485,6 +485,7 @@ void Character::trait_data::serialize( JsonOut &json ) const json.member( "key", key ); json.member( "charge", charge ); json.member( "powered", powered ); + json.member( "show_sprite", show_sprite ); json.end_object(); } @@ -494,6 +495,7 @@ void Character::trait_data::deserialize( const JsonObject &data ) data.read( "key", key ); data.read( "charge", charge ); data.read( "powered", powered ); + data.read( "show_sprite", show_sprite ); } void consumption_event::serialize( JsonOut &json ) const