Skip to content

Commit

Permalink
Rework repair menu (#59827)
Browse files Browse the repository at this point in the history
* Reworked repair menu

* Remove unused parameters
  • Loading branch information
Anton Burmistrov authored Sep 30, 2022
1 parent a4b97ec commit 07a9641
Showing 1 changed file with 71 additions and 3 deletions.
74 changes: 71 additions & 3 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,65 @@ item_location game_menus::inv::salvage( Character &you, const salvage_actor *act
class repair_inventory_preset: public inventory_selector_preset
{
public:
repair_inventory_preset( const repair_item_actor *actor, const item *main_tool ) :
repair_inventory_preset( const repair_item_actor *actor, const item *main_tool,
const Character &you ) :
actor( actor ), main_tool( main_tool ) {

_indent_entries = false;

append_cell( [actor, &you]( const item_location & loc ) {
const int comp_needed = std::max<int>( 1,
std::ceil( loc->base_volume() / 250_ml * actor->cost_scaling ) );
std::set<itype_id> valid_entries = actor->get_valid_repair_materials( *loc );
const inventory &crafting_inv = you.crafting_inventory();
std::function<bool( const item & )> filter;
if( loc->is_filthy() ) {
filter = []( const item & component ) {
return component.allow_crafting_component();
};
} else {
filter = is_crafting_component;
}
std::vector<std::string> material_list;
for( const auto &component_id : valid_entries ) {
if( item::count_by_charges( component_id ) ) {
if( crafting_inv.has_charges( component_id, 1 ) ) {
const int num_comp = crafting_inv.charges_of( component_id );
material_list.push_back( colorize( string_format( _( "%s (%d)" ), item::nname( component_id ),
num_comp ), num_comp < comp_needed ? c_red : c_unset ) );
}
} else if( crafting_inv.has_amount( component_id, 1, false, filter ) ) {
const int num_comp = crafting_inv.amount_of( component_id, false );
material_list.push_back( colorize( string_format( _( "%s (%d)" ), item::nname( component_id ),
num_comp ), num_comp < comp_needed ? c_red : c_unset ) );
}
}
std::string ret = join( material_list, ", " );
if( ret.empty() ) {
ret = _( "<color_red>NONE</color>" );
}
return ret;
},
_( "MATERIALS AVAILABLE" ) );

append_cell( [actor, &you]( const item_location & loc ) {
const int level = you.get_skill_level( actor->used_skill );
const repair_item_actor::repair_type action_type = actor->default_action( *loc, level );
const std::pair<float, float> chance = actor->repair_chance( you, *loc, action_type );
return colorize( string_format( "%0.1f%%", 100.0f * chance.first ),
chance.first == 0 ? c_yellow : ( chance.second == 0 ? c_light_green : c_unset ) );
},
_( "SUCCESS CHANCE" ) );

append_cell( [actor, &you]( const item_location & loc ) {
const int level = you.get_skill_level( actor->used_skill );
const repair_item_actor::repair_type action_type = actor->default_action( *loc, level );
const std::pair<float, float> chance = actor->repair_chance( you, *loc, action_type );
return colorize( string_format( "%0.1f%%", 100.0f * chance.second ),
chance.second > chance.first ? c_yellow : ( chance.second == 0 &&
chance.first > 0 ? c_light_green : c_unset ) );
},
_( "DAMAGE CHANCE" ) );
}

bool is_shown( const item_location &loc ) const override {
Expand All @@ -1761,13 +1818,24 @@ class repair_inventory_preset: public inventory_selector_preset
const item *main_tool;
};

static std::string get_repair_hint( const Character &you, const repair_item_actor *actor,
const item *main_tool )
{
auto hint = std::string();
hint.append( string_format( _( "Tool: <color_cyan>%s</color>" ), main_tool->display_name() ) );
hint.append( string_format( " | " ) );
hint.append( string_format( _( "Skill used: <color_cyan>%s (%d)</color>" ),
actor->used_skill.obj().name(), you.get_skill_level( actor->used_skill ) ) );
return hint;
}

item_location game_menus::inv::repair( Character &you, const repair_item_actor *actor,
const item *main_tool )
{
return inv_internal( you, repair_inventory_preset( actor, main_tool ),
return inv_internal( you, repair_inventory_preset( actor, main_tool, you ),
_( "Repair what?" ), 1,
string_format( _( "You have no items that could be repaired with a %s." ),
main_tool->type_name( 1 ) ) );
main_tool->type_name( 1 ) ), get_repair_hint( you, actor, main_tool ) );
}

item_location game_menus::inv::saw_barrel( Character &you, item &tool )
Expand Down

0 comments on commit 07a9641

Please sign in to comment.