Skip to content

Commit

Permalink
feat(UI, port): Port hiding traits/mutations from DDA (#5754)
Browse files Browse the repository at this point in the history
* Port hiding of traits and mutations from DDA

Co-Authored-By: Fris0uman <41293484+Fris0uman@users.noreply.github.com>

* Second Switch

Oops, apparently we have two switches

* style(autofix.ci): automated formatting

* Apply suggestions from code review

---------

Co-authored-by: Fris0uman <41293484+Fris0uman@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Chaosvolt <chaosvolt@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 23, 2024
1 parent fffed7c commit ba05695
Show file tree
Hide file tree
Showing 5 changed files with 33 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 @@ -1890,6 +1890,13 @@
"id": "bionics",
"bindings": [ { "input_method": "keyboard", "key": "p" } ]
},
{
"type": "keybinding",
"id": "TOGGLE_SPRITE",
"category": "MUTATIONS",
"name": "Toggle sprite",
"bindings": [ { "input_method": "keyboard", "key": "," } ]
},
{
"type": "keybinding",
"name": "View/Activate Mutations",
Expand Down
3 changes: 3 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3662,6 +3662,9 @@ std::vector<std::string> Character::get_overlay_ids() const

// then get mutations
for( const std::pair<const trait_id, char_trait_data> &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<int, std::string>( order, overlay_id ) );
Expand Down
1 change: 1 addition & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ struct char_trait_data {
* is reset to @ref mutation_branch::cooldown.
*/
int charge = 0;
bool show_sprite = true;
void serialize( JsonOut &json ) const;
void deserialize( JsonIn &jsin );
};
Expand Down
20 changes: 20 additions & 0 deletions src/mutation_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class mutation_menu_mode {
activating,
examining,
reassigning,
hiding,
};
enum class mutation_tab_mode {
active,
Expand Down Expand Up @@ -78,9 +79,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::hiding ) {
desc += colorize( _( "Hiding" ), 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 );
Expand Down Expand Up @@ -234,6 +240,7 @@ detail::mutations_ui_result detail::show_mutations_ui_internal( Character &who )
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( "NEXT_TAB" );
ctxt.register_action( "PREV_TAB" );
Expand Down Expand Up @@ -285,6 +292,10 @@ detail::mutations_ui_result detail::show_mutations_ui_internal( Character &who )
}
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" ) );
}
}
}

Expand Down Expand Up @@ -440,6 +451,9 @@ detail::mutations_ui_result detail::show_mutations_ui_internal( Character &who )
// Describing mutations, not activating them!
examine_id = mut_id;
break;
case mutation_menu_mode::hiding:
who.my_mutations[*mut_id].show_sprite = !who.my_mutations[*mut_id].show_sprite;
break;
}
handled = true;
} else if( mutation_chars.valid( ch ) ) {
Expand Down Expand Up @@ -602,6 +616,9 @@ detail::mutations_ui_result detail::show_mutations_ui_internal( Character &who )
// Describing mutations, not activating them!
examine_id = mut_id;
break;
case mutation_menu_mode::hiding:
who.my_mutations[mut_id].show_sprite = !who.my_mutations[mut_id].show_sprite;
break;
}
}
} else if( action == "REASSIGN" ) {
Expand All @@ -612,6 +629,9 @@ detail::mutations_ui_result detail::show_mutations_ui_internal( Character &who )
menu_mode = menu_mode == mutation_menu_mode::activating ?
mutation_menu_mode::examining : mutation_menu_mode::activating;
examine_id = std::nullopt;
} else if( action == "TOGGLE_SPRITE" ) {
menu_mode = mutation_menu_mode::hiding;
examine_id = std::nullopt;
} else if( action == "QUIT" ) {
ret.cmd = mutations_ui_cmd::exit;
exit = true;
Expand Down
2 changes: 2 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ void char_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();
}

Expand All @@ -346,6 +347,7 @@ void char_trait_data::deserialize( JsonIn &jsin )
data.read( "key", key );
data.read( "charge", charge );
data.read( "powered", powered );
data.read( "show_sprite", show_sprite );
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit ba05695

Please sign in to comment.