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

In-game Armor sprite change #66931

Merged
merged 17 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@
"name": "Toggle armor visibility on character sprite",
"bindings": [ { "input_method": "keyboard_any", "key": "H" } ]
},
{
"type": "keybinding",
"id": "CHANGE_SPRITE",
"category": "SORT_ARMOR",
"name": "Change sprite of armor.",
"bindings": [ { "input_method": "keyboard_any", "key": "C" } ]
lispcoc marked this conversation as resolved.
Show resolved Hide resolved
},
{
"type": "keybinding",
"id": "ASSIGN_INVLETS",
Expand Down
35 changes: 35 additions & 0 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ void outfit::sort_armor( Character &guy )
ctxt.register_action( "MOVE_ARMOR" );
ctxt.register_action( "CHANGE_SIDE" );
ctxt.register_action( "TOGGLE_CLOTH" );
ctxt.register_action( "CHANGE_SPRITE" );
ctxt.register_action( "ASSIGN_INVLETS" );
ctxt.register_action( "SORT_ARMOR" );
ctxt.register_action( "EQUIP_ARMOR" );
Expand Down Expand Up @@ -731,10 +732,12 @@ void outfit::sort_armor( Character &guy )
right_print( w_sort_cat, 0, 0, c_white, string_format(
_( "[<color_yellow>%s</color>] Hide sprite. "
"[<color_yellow>%s</color>] Change side. "
"[<color_yellow>%s</color>] Change sprite. "
"Press [<color_yellow>%s</color>] for help. "
"Press [<color_yellow>%s</color>] to change keybindings." ),
ctxt.get_desc( "TOGGLE_CLOTH" ),
ctxt.get_desc( "CHANGE_SIDE" ),
ctxt.get_desc( "CHANGE_SPRITE" ),
ctxt.get_desc( "USAGE_HELP" ),
ctxt.get_desc( "HELP_KEYBINDINGS" ) ) );

Expand Down Expand Up @@ -1031,6 +1034,36 @@ void outfit::sort_armor( Character &guy )
tmp_worn[leftListIndex]->unset_flag( json_flag_HIDDEN );
}
}
} else if( action == "CHANGE_SPRITE" && leftListIndex < leftListSize ) {
uilist menu;
menu.title = _( "Change sprite" );
menu.addentry( 0, true, MENU_AUTOASSIGN, _( "Select sprite from items" ) );
menu.addentry( 1, true, MENU_AUTOASSIGN, _( "Restore default sprite" ) );
menu.addentry( 2, true, MENU_AUTOASSIGN, _( "Cancel" ) );
menu.query();
if( menu.ret == 0 ) {
item_location loc;
avatar *you = player_character.as_avatar();
auto armor_filter = [&]( const item & i ) {
return i.is_armor();
};
if( you != nullptr ) {
loc = game_menus::inv::titled_filter_menu( armor_filter,
*you,
_( "Select appearance of this armor:" ),
-1,
_( "You have nothing to wear." ) );
}
if( loc && loc.get_item() ) {
const item *i = loc.get_item();
const std::string variant = i->has_itype_variant() ? i->itype_variant().id : "";
tmp_worn[leftListIndex]->set_var( "sprite_override", i->typeId().str() );
tmp_worn[leftListIndex]->set_var( "sprite_override_variant", variant );
}
} else if( menu.ret == 1 ) {
tmp_worn[leftListIndex]->erase_var( "sprite_override" );
tmp_worn[leftListIndex]->erase_var( "sprite_override_variant" );
}
lispcoc marked this conversation as resolved.
Show resolved Hide resolved
} else if( action == "SORT_ARMOR" ) {
mid_pane.offset = 0;
// Copy to a vector because stable_sort requires random-access
Expand Down Expand Up @@ -1183,6 +1216,8 @@ void outfit::sort_armor( Character &guy )
ctxt.get_desc( "CHANGE_SIDE" ) ),
string_format( _( "[<color_yellow>%s</color>] to toggle item visibility on character sprite.\n" ),
ctxt.get_desc( "TOGGLE_CLOTH" ) ),
string_format( _( "[<color_yellow>%s</color>] to change sprite of item.\n" ),
ctxt.get_desc( "CHANGE_SPRITE" ) ),
string_format( _( "[<color_yellow>%s</color>] to sort worn items into natural layer order.\n" ),
ctxt.get_desc( "SORT_ARMOR" ) ),
string_format( _( "[<color_yellow>%s</color>] to equip a new item.\n" ),
Expand Down
9 changes: 7 additions & 2 deletions src/character_attire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,8 +1791,13 @@ void outfit::get_overlay_ids( std::vector<std::pair<std::string, std::string>> &
if( worn_item.has_flag( json_flag_HIDDEN ) ) {
continue;
}
const std::string variant = worn_item.has_itype_variant() ? worn_item.itype_variant().id : "";
overlay_ids.emplace_back( "worn_" + worn_item.typeId().str(), variant );
if( worn_item.has_var( "sprite_override" ) ) {
overlay_ids.emplace_back( "worn_" + worn_item.get_var( "sprite_override" ),
worn_item.get_var( "sprite_override_variant", "" ) );
} else {
const std::string variant = worn_item.has_itype_variant() ? worn_item.itype_variant().id : "";
overlay_ids.emplace_back( "worn_" + worn_item.typeId().str(), variant );
}
}
}

Expand Down