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

Craft Gui show amounts #43393

Merged
merged 6 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -481,7 +481,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 @@ -910,6 +910,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 @@ -229,6 +229,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