From e231a0c037447c7428df42da89bf65b5d4b22f64 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 15:03:33 -0800 Subject: [PATCH 01/13] Inventory view update - Show new color for food in sealed container + Show # stacks of item inside container and color if food/rotting --- src/item.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index bd840f055466b..0f9cd06fdf6f9 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4231,6 +4231,48 @@ nc_color item::color_in_inventory() const // Show perishables as a separate color else if( food->goes_bad() ) { ret = c_light_cyan; + + map_cursor nearby[9] = { player_character.pos() - tripoint( -1, -1, 0 ), + player_character.pos() - tripoint( -1, 0, 0 ), + player_character.pos() - tripoint( -1, 1, 0 ), + player_character.pos() - tripoint( 0, -1, 0 ), + player_character.pos() - tripoint( 0, 0, 0 ), + player_character.pos() - tripoint( 0, 1, 0 ), + player_character.pos() - tripoint( 1, -1, 0 ), + player_character.pos() - tripoint( 1, 0, 0 ), + player_character.pos() - tripoint( 1, 1, 0 ), + }; + + player_character.visit_items( [&]( const item * node, const item * parent ) { + if( node == food ) { + if( parent ) { + const item_pocket *const parent_pocket = parent->contained_where( *node ); + if( parent_pocket ) { + if( parent_pocket->spoil_multiplier() == 0 ) { + ret = c_blue; // Blue = Not currently spoiling due to being sealed + return VisitResponse::ABORT; + } + } + } + } + return VisitResponse::NEXT; + } ); + for( const map_cursor &checkp : nearby ) { + checkp.visit_items( [&]( const item * node, const item * parent ) { + if( node == food ) { + if( parent ) { + const item_pocket *const parent_pocket = parent->contained_where( *node ); + if( parent_pocket ) { + if( parent_pocket->spoil_multiplier() == 0 ) { + ret = c_blue; //Blue in any surrounding square + return VisitResponse::ABORT; + } + } + } + } + return VisitResponse::NEXT; + } ); + } } break; @@ -4588,6 +4630,8 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t std::string maintext; std::string contents_suffix_text; + std::string colorprefix = ""; + std::string colorsuffix = ""; if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) { maintext = type_name( quantity ); @@ -4621,16 +4665,56 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t contents_item.charges > 1 ) ? contents_item.charges : 1; + + // Color second half of container contents depending on perishability (highest perishability of all contents) + if( contents_item.is_food() && contents_item.goes_bad() ) { + // For perishables + colorprefix = "<" + string_from_color( contents_item.color_in_inventory() ) + ">"; + colorprefix.replace( 1, 1, "color" ); // changes to + if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { + colorprefix = ""; + } + colorsuffix = ""; + } + contents_suffix_text = string_format( pgettext( "item name", //~ [container item name] " > [inner item name]" - " > %1$s" ), + " > %1$s%2$s" ), /* with_contents=false for nested items to prevent excessively long names */ - contents_item.tname( contents_count, true, 0, false ) ); + colorprefix, contents_item.tname( contents_count, true, 0, false ) + /* with_contents=false for nested items to prevent excessively long names */ + ) + string_format( " (%d)%s", contents_count, colorsuffix ); + } else if( !contents.empty() ) { - contents_suffix_text = string_format( npgettext( "item name", + + int worstrot = 0; + if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { + colorprefix = ""; + worstrot = 1; + } else { + // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. + // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) + for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { + if( worstrot < 4 && it->rotten() ) { + worstrot = 4; + colorprefix = ""; + } else if( worstrot < 3 && it->is_going_bad() ) { + worstrot = 3; + colorprefix = ""; + } else if( worstrot < 2 && it->goes_bad() ) { + worstrot = 2; + colorprefix = ""; + } else if( worstrot < 1 && it->is_food() ) { + worstrot = 1; + colorprefix = ""; + } + } + } + colorsuffix = ( worstrot > 0 ) ? "" : ""; + contents_suffix_text = string_format( pgettext( "item name", //~ [container item name] " > [count] item" - " > %1$zd item", " > %1$zd items", - contents.num_item_stacks() ), contents.num_item_stacks() ); + " > %1$s%2$zd items%3$s" ), + colorprefix, contents.num_item_stacks(), colorsuffix ); } } From 666f9edb1a161a8e623110c563437695360e60f0 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 15:18:27 -0800 Subject: [PATCH 02/13] Changing Blue to Light Blue for readability --- src/item.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 0f9cd06fdf6f9..446a79df027f0 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4249,7 +4249,7 @@ nc_color item::color_in_inventory() const const item_pocket *const parent_pocket = parent->contained_where( *node ); if( parent_pocket ) { if( parent_pocket->spoil_multiplier() == 0 ) { - ret = c_blue; // Blue = Not currently spoiling due to being sealed + ret = c_light_blue; // Blue = Not currently spoiling due to being sealed return VisitResponse::ABORT; } } @@ -4264,7 +4264,7 @@ nc_color item::color_in_inventory() const const item_pocket *const parent_pocket = parent->contained_where( *node ); if( parent_pocket ) { if( parent_pocket->spoil_multiplier() == 0 ) { - ret = c_blue; //Blue in any surrounding square + ret = c_light_blue; //Blue in any surrounding square return VisitResponse::ABORT; } } @@ -4672,7 +4672,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t colorprefix = "<" + string_from_color( contents_item.color_in_inventory() ) + ">"; colorprefix.replace( 1, 1, "color" ); // changes to if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { - colorprefix = ""; + colorprefix = ""; } colorsuffix = ""; } @@ -4689,7 +4689,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t int worstrot = 0; if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { - colorprefix = ""; + colorprefix = ""; worstrot = 1; } else { // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. From 173b085ca43e9149213526693bee16b9823f951d Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 15:47:03 -0800 Subject: [PATCH 03/13] Allowed nonperishable comestibles in container to show their color correctly --- src/item.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 446a79df027f0..960f7278a7aa9 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4667,8 +4667,8 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t : 1; // Color second half of container contents depending on perishability (highest perishability of all contents) - if( contents_item.is_food() && contents_item.goes_bad() ) { - // For perishables + if( contents_item.is_food() ) { + // For comestibles colorprefix = "<" + string_from_color( contents_item.color_in_inventory() ) + ">"; colorprefix.replace( 1, 1, "color" ); // changes to if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { From 7349ec6b044e6bccf02687768836632c9f125ebc Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 16:22:40 -0800 Subject: [PATCH 04/13] Removed contents_count due to clash with ammo display --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index 960f7278a7aa9..709f06a371e02 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4683,7 +4683,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t /* with_contents=false for nested items to prevent excessively long names */ colorprefix, contents_item.tname( contents_count, true, 0, false ) /* with_contents=false for nested items to prevent excessively long names */ - ) + string_format( " (%d)%s", contents_count, colorsuffix ); + ) + string_format( " %s", colorsuffix ); } else if( !contents.empty() ) { From 86c0b3a3bc1df5170ee0a2caaafa431bf89848c3 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 17:05:07 -0800 Subject: [PATCH 05/13] Removed sealed item coloration - pending backlink reference to parent item implementation for item class! --- src/item.cpp | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 709f06a371e02..969ea14ed922e 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4231,48 +4231,6 @@ nc_color item::color_in_inventory() const // Show perishables as a separate color else if( food->goes_bad() ) { ret = c_light_cyan; - - map_cursor nearby[9] = { player_character.pos() - tripoint( -1, -1, 0 ), - player_character.pos() - tripoint( -1, 0, 0 ), - player_character.pos() - tripoint( -1, 1, 0 ), - player_character.pos() - tripoint( 0, -1, 0 ), - player_character.pos() - tripoint( 0, 0, 0 ), - player_character.pos() - tripoint( 0, 1, 0 ), - player_character.pos() - tripoint( 1, -1, 0 ), - player_character.pos() - tripoint( 1, 0, 0 ), - player_character.pos() - tripoint( 1, 1, 0 ), - }; - - player_character.visit_items( [&]( const item * node, const item * parent ) { - if( node == food ) { - if( parent ) { - const item_pocket *const parent_pocket = parent->contained_where( *node ); - if( parent_pocket ) { - if( parent_pocket->spoil_multiplier() == 0 ) { - ret = c_light_blue; // Blue = Not currently spoiling due to being sealed - return VisitResponse::ABORT; - } - } - } - } - return VisitResponse::NEXT; - } ); - for( const map_cursor &checkp : nearby ) { - checkp.visit_items( [&]( const item * node, const item * parent ) { - if( node == food ) { - if( parent ) { - const item_pocket *const parent_pocket = parent->contained_where( *node ); - if( parent_pocket ) { - if( parent_pocket->spoil_multiplier() == 0 ) { - ret = c_light_blue; //Blue in any surrounding square - return VisitResponse::ABORT; - } - } - } - } - return VisitResponse::NEXT; - } ); - } } break; From 1990ea5b52dc53dbfeef7daf2fabd96b49ade221 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 23:19:25 -0800 Subject: [PATCH 06/13] Fixed trailing space / singular+plural ngettext implementation --- src/item.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 969ea14ed922e..61f7c36b888f6 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4641,7 +4641,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t /* with_contents=false for nested items to prevent excessively long names */ colorprefix, contents_item.tname( contents_count, true, 0, false ) /* with_contents=false for nested items to prevent excessively long names */ - ) + string_format( " %s", colorsuffix ); + ) + string_format( "%s", colorsuffix ); } else if( !contents.empty() ) { @@ -4671,8 +4671,10 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t colorsuffix = ( worstrot > 0 ) ? "" : ""; contents_suffix_text = string_format( pgettext( "item name", //~ [container item name] " > [count] item" - " > %1$s%2$zd items%3$s" ), - colorprefix, contents.num_item_stacks(), colorsuffix ); + " > %1$s" ), colorprefix ) + + string_format( ngettext( "%1$zd item", "%1$zd items", contents.num_item_stacks() ), + contents.num_item_stacks() ) + + string_format( pgettext( "color suffix", "%3$s" ), colorsuffix ); } } From 76959367756caab5b612b8b559c17ef57873402b Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Fri, 25 Dec 2020 23:22:11 -0800 Subject: [PATCH 07/13] pgettext reference fix --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index 61f7c36b888f6..a1c207f2d5ba4 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4674,7 +4674,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t " > %1$s" ), colorprefix ) + string_format( ngettext( "%1$zd item", "%1$zd items", contents.num_item_stacks() ), contents.num_item_stacks() ) + - string_format( pgettext( "color suffix", "%3$s" ), colorsuffix ); + string_format( pgettext( "color suffix", "%1$s" ), colorsuffix ); } } From 22fd22840190f5eb38e0958eb30b003a5d3b7a96 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Sat, 26 Dec 2020 13:05:22 -0800 Subject: [PATCH 08/13] Get spoil_multiplier and ensure equal to zero for sealed / nonperishing indicator. Removed sealed indicator for multiple items. --- src/item.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index a1c207f2d5ba4..2d43f14a51f69 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4588,8 +4588,8 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t std::string maintext; std::string contents_suffix_text; - std::string colorprefix = ""; - std::string colorsuffix = ""; + std::string colorprefix; + std::string colorsuffix; if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) { maintext = type_name( quantity ); @@ -4627,9 +4627,10 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t // Color second half of container contents depending on perishability (highest perishability of all contents) if( contents_item.is_food() ) { // For comestibles + const item_pocket* const parent_pocket = contained_where(contents_item); colorprefix = "<" + string_from_color( contents_item.color_in_inventory() ) + ">"; colorprefix.replace( 1, 1, "color" ); // changes to - if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { + if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed && parent_pocket->spoil_multiplier() == 0 ) { colorprefix = ""; } colorsuffix = ""; @@ -4646,10 +4647,6 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t } else if( !contents.empty() ) { int worstrot = 0; - if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed ) { - colorprefix = ""; - worstrot = 1; - } else { // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { @@ -4667,7 +4664,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t colorprefix = ""; } } - } + colorsuffix = ( worstrot > 0 ) ? "" : ""; contents_suffix_text = string_format( pgettext( "item name", //~ [container item name] " > [count] item" From 8152d404e15f48fb9572c8688a89566aa94ea0f2 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Sat, 26 Dec 2020 18:47:14 -0800 Subject: [PATCH 09/13] Implemented colorize() function + removed sealed definition redundancy --- src/item.cpp | 68 +++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 2d43f14a51f69..dc68417f28b31 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4588,8 +4588,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t std::string maintext; std::string contents_suffix_text; - std::string colorprefix; - std::string colorsuffix; + nc_color colorprefix; if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) { maintext = type_name( quantity ); @@ -4627,51 +4626,48 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t // Color second half of container contents depending on perishability (highest perishability of all contents) if( contents_item.is_food() ) { // For comestibles - const item_pocket* const parent_pocket = contained_where(contents_item); - colorprefix = "<" + string_from_color( contents_item.color_in_inventory() ) + ">"; - colorprefix.replace( 1, 1, "color" ); // changes to - if( contents.get_sealed_summary() == item_contents::sealed_summary::all_sealed && parent_pocket->spoil_multiplier() == 0 ) { - colorprefix = ""; + const item_pocket *const parent_pocket = contained_where( contents_item ); + + colorprefix = contents_item.color_in_inventory(); + if( parent_pocket->spoil_multiplier() == 0 ) { + colorprefix = c_light_blue; } - colorsuffix = ""; } contents_suffix_text = string_format( pgettext( "item name", //~ [container item name] " > [inner item name]" - " > %1$s%2$s" ), - /* with_contents=false for nested items to prevent excessively long names */ - colorprefix, contents_item.tname( contents_count, true, 0, false ) + " > %1$s" ), /* with_contents=false for nested items to prevent excessively long names */ - ) + string_format( "%s", colorsuffix ); + contents_item.tname( contents_count, true, 0, false ) ); + } else if( !contents.empty() ) { int worstrot = 0; - // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. - // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) - for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { - if( worstrot < 4 && it->rotten() ) { - worstrot = 4; - colorprefix = ""; - } else if( worstrot < 3 && it->is_going_bad() ) { - worstrot = 3; - colorprefix = ""; - } else if( worstrot < 2 && it->goes_bad() ) { - worstrot = 2; - colorprefix = ""; - } else if( worstrot < 1 && it->is_food() ) { - worstrot = 1; - colorprefix = ""; - } + + // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. + // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) + for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { + if( worstrot < 4 && it->rotten() ) { + worstrot = 4; + colorprefix = c_brown; + } else if( worstrot < 3 && it->is_going_bad() ) { + worstrot = 3; + colorprefix = c_yellow; + } else if( worstrot < 2 && it->goes_bad() ) { + worstrot = 2; + colorprefix = c_light_cyan; + } else if( worstrot < 1 && it->is_food() ) { + worstrot = 1; + colorprefix = c_cyan; } - - colorsuffix = ( worstrot > 0 ) ? "" : ""; - contents_suffix_text = string_format( pgettext( "item name", - //~ [container item name] " > [count] item" - " > %1$s" ), colorprefix ) + - string_format( ngettext( "%1$zd item", "%1$zd items", contents.num_item_stacks() ), - contents.num_item_stacks() ) + - string_format( pgettext( "color suffix", "%1$s" ), colorsuffix ); + + } + contents_suffix_text = string_format( ngettext( " > %1$zd item", " > %1$zd items", + contents.num_item_stacks() ), contents.num_item_stacks() ); + } + if( colorprefix ) { + contents_suffix_text = colorize( contents_suffix_text, colorprefix ); } } From d18b376c8127cc93ce7ddcb317791fd434ff2c1e Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Wed, 30 Dec 2020 00:16:49 -0800 Subject: [PATCH 10/13] Fixed Advanced Inventory display - Selected + Inactive Pane --- src/advanced_inv.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 1e466034567d4..dec799af2e19c 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -334,20 +334,10 @@ void advanced_inventory::print_items( const advanced_inventory_pane &pane, bool const item &it = *sitem.items.front(); const bool selected = active && index == static_cast( i ); - nc_color thiscolor = active ? it.color_in_inventory() : norm; + nc_color thiscolor; nc_color thiscolordark = c_dark_gray; nc_color print_color; - if( selected ) { - thiscolor = inCategoryMode && pane.sortby == SORTBY_CATEGORY ? c_white_red : hilite( c_white ); - thiscolordark = hilite( thiscolordark ); - if( compact ) { - mvwprintz( window, point( 1, 6 + item_line ), thiscolor, " %s", spaces ); - } else { - mvwprintz( window, point( 1, 6 + item_line ), thiscolor, ">>%s", spaces ); - } - } - std::string item_name; std::string stolen_string; bool stolen = false; @@ -379,6 +369,26 @@ void advanced_inventory::print_items( const advanced_inventory_pane &pane, bool item_name = string_format( "%s %s", it.symbol(), item_name ); } + if (active) { + thiscolor = it.color_in_inventory(); + } + else { + item_name = remove_color_tags(item_name); + thiscolor = norm; + } + + if (selected) { + thiscolor = inCategoryMode && pane.sortby == SORTBY_CATEGORY ? c_white_red : hilite(c_white); + thiscolordark = hilite(thiscolordark); + item_name = remove_color_tags(item_name); + if (compact) { + mvwprintz(window, point(1, 6 + item_line), thiscolor, " %s", spaces); + } + else { + mvwprintz(window, point(1, 6 + item_line), thiscolor, ">>%s", spaces); + } + } + //print item name trim_and_print( window, point( compact ? 1 : 4, 6 + item_line ), max_name_length, thiscolor, item_name ); From e372737118f44a80d3ec1fb63dd694d761098517 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Wed, 30 Dec 2020 00:19:25 -0800 Subject: [PATCH 11/13] Astyle fixes --- src/advanced_inv.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index dec799af2e19c..3e154fa0e0cf6 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -369,23 +369,21 @@ void advanced_inventory::print_items( const advanced_inventory_pane &pane, bool item_name = string_format( "%s %s", it.symbol(), item_name ); } - if (active) { + if( active ) { thiscolor = it.color_in_inventory(); - } - else { - item_name = remove_color_tags(item_name); + } else { + item_name = remove_color_tags( item_name ); thiscolor = norm; } - if (selected) { - thiscolor = inCategoryMode && pane.sortby == SORTBY_CATEGORY ? c_white_red : hilite(c_white); - thiscolordark = hilite(thiscolordark); - item_name = remove_color_tags(item_name); - if (compact) { - mvwprintz(window, point(1, 6 + item_line), thiscolor, " %s", spaces); - } - else { - mvwprintz(window, point(1, 6 + item_line), thiscolor, ">>%s", spaces); + if( selected ) { + thiscolor = inCategoryMode && pane.sortby == SORTBY_CATEGORY ? c_white_red : hilite( c_white ); + thiscolordark = hilite( thiscolordark ); + item_name = remove_color_tags( item_name ); + if( compact ) { + mvwprintz( window, point( 1, 6 + item_line ), thiscolor, " %s", spaces ); + } else { + mvwprintz( window, point( 1, 6 + item_line ), thiscolor, ">>%s", spaces ); } } From 1ff921ead9b2ab8b34f3ed32f8fe0cd189b392e8 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Thu, 31 Dec 2020 19:31:29 -0800 Subject: [PATCH 12/13] Search all items instead of 1 layer deep for any spoiling / old / rotten items in containers with multiple items --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index dc68417f28b31..2bb56dcee1a86 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4647,7 +4647,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) - for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { + for( const item *it : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { if( worstrot < 4 && it->rotten() ) { worstrot = 4; colorprefix = c_brown; From 750d7452f083d93ae0e60136877fe52d9f1d9e71 Mon Sep 17 00:00:00 2001 From: NorseFTX <55260779+NorseFTX@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:20:37 -0800 Subject: [PATCH 13/13] Updated handling of sealed items in containers with multiple items, handles multiple pockets --- src/item.cpp | 99 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 22 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 2bb56dcee1a86..5d787ca10cef6 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4589,6 +4589,8 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t std::string maintext; std::string contents_suffix_text; nc_color colorprefix; + bool hasfood = false; + bool colorstrip = false; if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) { maintext = type_name( quantity ); @@ -4624,13 +4626,26 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t : 1; // Color second half of container contents depending on perishability (highest perishability of all contents) - if( contents_item.is_food() ) { - // For comestibles - const item_pocket *const parent_pocket = contained_where( contents_item ); - - colorprefix = contents_item.color_in_inventory(); - if( parent_pocket->spoil_multiplier() == 0 ) { - colorprefix = c_light_blue; + // Search anywhere within contents for food. + for( const item *it : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { + // Check if the item is also a container, and has food inside + if( !it->is_container_empty() ) { + for( const item *itsub : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { + if( itsub->is_food() ) { + hasfood = true; + } + } + } + // Use the sealed color or get item's default color rules if the item is food or has food inside + if( it->is_food() || hasfood ) { + // For comestibles + const item_pocket *const parent_pocket = contained_where( contents_item ); + + colorprefix = contents_item.color_in_inventory(); + if( parent_pocket->spoil_multiplier() == 0 ) { + colorprefix = c_light_blue; + colorstrip = true; + } } } @@ -4640,28 +4655,68 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t /* with_contents=false for nested items to prevent excessively long names */ contents_item.tname( contents_count, true, 0, false ) ); + // This color strip is necessary to make sure the nested item doesn't retain its "spoiling" color + contents_suffix_text = colorstrip ? remove_color_tags( contents_suffix_text ) : + contents_suffix_text; + } else if( !contents.empty() ) { int worstrot = 0; + bool sealed = false; - // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. - // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) - for( const item *it : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { - if( worstrot < 4 && it->rotten() ) { - worstrot = 4; - colorprefix = c_brown; - } else if( worstrot < 3 && it->is_going_bad() ) { - worstrot = 3; - colorprefix = c_yellow; - } else if( worstrot < 2 && it->goes_bad() ) { - worstrot = 2; - colorprefix = c_light_cyan; - } else if( worstrot < 1 && it->is_food() ) { - worstrot = 1; - colorprefix = c_cyan; + // - If all the container's top level items are in pockets with spoil multiplier of 0, + // set color to light_blue and skip searching through all items for perishable coloring. + + for( const item *it : contents.all_items_top( item_pocket::pocket_type::CONTAINER ) ) { + // Check if the item is also a container, and has food inside + if( !it->is_container_empty() ) { + for( const item *itsub : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { + if( itsub->is_food() ) { + hasfood = true; + } + } } + // If this item has food or is food, then check if it's sealed in a non-spoiling pocket + if( it->is_food() || hasfood ) { + const item_pocket *const parent_pocket = contained_where( *it ); + if( parent_pocket->spoil_multiplier() == 0 ) { + sealed = true; + } else { + sealed = false; + break; // Prioritizes food found in any spoiling pocket, and will color suffix accordingly + } + } + } + if( sealed ) { + colorprefix = c_light_blue; + } else { + // If at least one item wasn't in a sealed + spoil modifier == 0 pocket: + // If container has multiple food items, take the worst rot state and use that as the color for the "# items" text. + // 0 = No food; 1 = Non-perishable (cyan); 2 = Perishable (light cyan); 3 = Old (yellow); 4 = Rotten (brown) + // - If the item isn't food, skip. + + for( const item *it : contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) { + const item_pocket *const parent_pocket = contained_where( *it ); + if( parent_pocket->spoil_multiplier() != 0 ) { + if( it->is_food() ) { + if( worstrot < 4 && it->rotten() ) { + worstrot = 4; + colorprefix = c_brown; + } else if( worstrot < 3 && it->is_going_bad() ) { + worstrot = 3; + colorprefix = c_yellow; + } else if( worstrot < 2 && it->goes_bad() ) { + worstrot = 2; + colorprefix = c_light_cyan; + } else if( worstrot < 1 && it->is_food() ) { + worstrot = 1; + colorprefix = c_cyan; + } + } + } + } } contents_suffix_text = string_format( ngettext( " > %1$zd item", " > %1$zd items", contents.num_item_stacks() ), contents.num_item_stacks() );