Skip to content

Commit

Permalink
Craft Gui show amounts (#43393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Watt authored Sep 7, 2020
1 parent 61e0d40 commit e306138
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "crafting.h"
#include "cursesdef.h"
#include "input.h"
#include "inventory.h"
#include "item.h"
#include "itype.h"
#include "json.h"
Expand Down Expand Up @@ -533,12 +534,34 @@ const recipe *select_crafting_recipe( int &batch_size )
_( "Batch time savings: <color_cyan>%s</color>" ),
current[line]->batch_savings_string() );

const int makes = current[line]->makes_amount();
if( makes > 1 ) {
ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col,
_( "Recipe makes: <color_cyan>%d</color>" ),
makes );
}

print_colored_text(
w_data, point( xpos, ypos++ ), col, col,
string_format( _( "Dark craftable? <color_cyan>%s</color>" ),
current[line]->has_flag( flag_BLIND_EASY ) ? _( "Easy" ) :
current[line]->has_flag( flag_BLIND_HARD ) ? _( "Hard" ) :
_( "Impossible" ) ) );

std::string nearby_string;
const int nearby_amount = crafting_inv.count_item( current[line]->result() );

if( nearby_amount == 0 ) {
nearby_string = "<color_light_gray>0</color>";
} else if( nearby_amount > 9000 ) {
// at some point you get too many to count at a glance and just know you have a lot
nearby_string = _( "<color_red>It's Over 9000!!!</color>" );
} else {
nearby_string = string_format( "<color_yellow>%d</color>", nearby_amount );
}
ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col,
_( "Nearby: %s" ), nearby_string );

const bool can_craft_this = available[line].can_craft;
if( can_craft_this && !available[line].can_craft_non_rotten ) {
ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col,
Expand Down
14 changes: 14 additions & 0 deletions src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,20 @@ enchantment inventory::get_active_enchantment_cache( const Character &owner ) co
return temp_cache;
}

int inventory::count_item( const itype_id &item_type ) const
{
int num = 0;
const itype_bin bin = get_binned_items();
if( bin.find( item_type ) == bin.end() ) {
return num;
}
const std::list<const item *> items = get_binned_items().find( item_type )->second;
for( const item *it : items ) {
num += it->count();
}
return num;
}

void inventory::assign_empty_invlet( item &it, const Character &p, const bool force )
{
const std::string auto_setting = get_option<std::string>( "AUTO_INV_ASSIGN" );
Expand Down
2 changes: 2 additions & 0 deletions src/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class inventory : public visitable<inventory>
// gets a singular enchantment that is an amalgamation of all items that have active enchantments
enchantment get_active_enchantment_cache( const Character &owner ) const;

int count_item( const itype_id &item_type ) const;

private:
invlet_favorites invlet_cache;
char find_usable_cached_invlet( const itype_id &item_type );
Expand Down
14 changes: 13 additions & 1 deletion src/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ item recipe::create_result() const
if( !newit.craft_has_charges() ) {
newit.charges = 0;
} else if( result_mult != 1 ) {
// TODO: Make it work for charge-less items
// TODO: Make it work for charge-less items (update makes amount)
newit.charges *= result_mult;
}

Expand Down Expand Up @@ -934,6 +934,18 @@ bool recipe::hot_result() const
return false;
}

int recipe::makes_amount() const
{
int makes;
if( charges.has_value() ) {
makes = charges.value();
} else {
makes = item::find_type( result_ )->charges_default();
}
// return either charges * mult or 1
return makes ? makes * result_mult : 1 ;
}

void recipe::incorporate_build_reqs()
{
if( !blueprint_reqs ) {
Expand Down
3 changes: 3 additions & 0 deletions src/recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class recipe

bool hot_result() const;

// Returns the ammount or charges recipe will produce.
int makes_amount() const;

private:
void incorporate_build_reqs();
void add_requirements( const std::vector<std::pair<requirement_id, int>> &reqs );
Expand Down

0 comments on commit e306138

Please sign in to comment.