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 3 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
27 changes: 27 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,38 @@ 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 );
}
}
Theundyingcode marked this conversation as resolved.
Show resolved Hide resolved
ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col,
_( "Nearby: <color_cyan>%s</color>" ), nearby_string );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just "Nearby" is a little ambiguous, and there's certainly space in the UI to clarify a little more. I'm not sure how best to tweak it; maybe "Already present nearby: %s" or "There are already %s nearby"?

Also, it seems like the color_cyan tag is redundant here; there's always another colour inside it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cyan tag is a result of me not paying attention to copy and paste when I rewrote it.

I struggled with what the label should be but ended up deciding to be as general as possible because I didn't want to get caught up with amount/charges/portions discrepancies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to at least make it clear that it's the recipe output that's being counted here, otherwise it's just an arbitrary number without context.


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely we already have a function that can do this? Can't you use the code already used to look for crafting ingredients, asking for 9000 of whatever item. Since there's feedback in the UI about how many items you have when you're short, it must be returning that partial count.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time looking around and while there were a couple I could theoretically use, they all seemed to be either threshold driven (has_components) or, charges vs amounts specific (visitable amount_of, charges_of). Since I would have to write a wrapper to use those anyways, I figured it would be better to just write a function that did what I wanted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a threshold-driven one might be a good option. As you already pointed out, you don't need to count all when there are many.

{
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
15 changes: 14 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,19 @@ 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