From 75fa347b1f261676f4ea5065d0d25ca2b2ee02b2 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 13 Apr 2019 02:01:46 +0200 Subject: [PATCH] Refactor and fix ui crash - Fix crash on closing out of craft selection without selecting a craft to work on - Apply copyedits from code review - Remove vehicle::use_workbench and merge with iexamine --- src/crafting.cpp | 16 ++++----- src/iexamine.cpp | 62 +++++++++++++++++++++++++--------- src/iexamine.h | 3 ++ src/vehicle.h | 1 - src/vehicle_use.cpp | 82 +-------------------------------------------- 5 files changed, 59 insertions(+), 105 deletions(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index aaace93403941..53dbc767f2d4b 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -559,9 +559,9 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l item *newit_in_vehicle = &items_at_part[items_at_part.size() - 1]; p.add_msg_player_or_npc( - string_format( pgettext( "item, furniture", "You put the %s on the %s" ), + string_format( pgettext( "item, furniture", "You put the %s on the %s." ), newit.tname(), vp->part().name() ), - string_format( pgettext( "item, furniture", " puts the %s on the %s" ), + string_format( pgettext( "item, furniture", " puts the %s on the %s." ), newit.tname(), vp->part().name() ) ); return item_location( vehicle_cursor( vp->vehicle(), vp->part_index() ), newit_in_vehicle ); @@ -573,7 +573,7 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l "Not enough space on the %s. You drop the %s on the ground." ), vp->part().name(), newit.tname() ), string_format( pgettext( "furniture, item", - "Not enough space on the %s. drops the %s on the ground" ), + "Not enough space on the %s. drops the %s on the ground." ), vp->part().name(), newit.tname() ) ); return item_location( map_cursor( loc ), &g->m.add_item_or_charges( loc, newit ) ); @@ -582,9 +582,9 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l if( g->m.has_furn( loc ) ) { const furn_t &workbench = g->m.furn( loc ).obj(); p.add_msg_player_or_npc( - string_format( pgettext( "item, furniture", "You put the %s on the %s" ), + string_format( pgettext( "item, furniture", "You put the %s on the %s." ), newit.tname(), workbench.name() ), - string_format( pgettext( "item, furniture", " puts the %s on the %s" ), + string_format( pgettext( "item, furniture", " puts the %s on the %s." ), newit.tname(), workbench.name() ) ); } @@ -646,7 +646,7 @@ void player::start_craft( const recipe &making, int batch_size, bool is_long, co craft_in_inventory = set_item_inventory( *this, craft ); if( !has_item( *craft_in_inventory ) ) { - add_msg_if_player( _( "Activate the %s to start crafting" ), craft.tname() ); + add_msg_if_player( _( "Activate the %s to start crafting." ), craft.tname() ); return; } } @@ -662,9 +662,9 @@ void player::start_craft( const recipe &making, int batch_size, bool is_long, co activity.values.push_back( is_long ); add_msg_player_or_npc( - string_format( pgettext( "in progress craft", "You start working on the %s" ), + string_format( pgettext( "in progress craft", "You start working on the %s." ), craft.tname() ), - string_format( pgettext( "in progress craft", " starts working on the %s" ), + string_format( pgettext( "in progress craft", " starts working on the %s." ), craft.tname() ) ); } diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 2909f7bae8395..727cd3060b067 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -50,7 +50,10 @@ #include "ui.h" #include "uistate.h" #include "units.h" +#include "vehicle.h" +#include "vehicle_selector.h" #include "vpart_position.h" +#include "vpart_reference.h" #include "weather.h" const mtype_id mon_dark_wyrm( "mon_dark_wyrm" ); @@ -4509,7 +4512,38 @@ void iexamine::open_safe( player &, const tripoint &examp ) void iexamine::workbench( player &p, const tripoint &examp ) { - const furn_t &f_workbench = g->m.furn( examp ).obj(); + workbench_internal( p, examp, cata::nullopt ); +} + +void iexamine::workbench_internal( player &p, const tripoint &examp, + const cata::optional &part ) +{ + std::vector crafts; + std::string name; + + bool items_at_loc = false; + + if( part ) { + name = part->part().name(); + auto items_at_part = part->vehicle().get_items( part->part_index() ); + + for( item &it : items_at_part ) { + if( it.is_craft() ) { + crafts.emplace_back( item_location( vehicle_cursor( part->vehicle(), part->part_index() ), &it ) ); + } + } + } else { + name = g->m.furn( examp ).obj().name(); + + auto items_at_furn = g->m.i_at( examp ); + items_at_loc = !items_at_furn.empty(); + + for( item &it : items_at_furn ) { + if( it.is_craft() ) { + crafts.emplace_back( item_location( map_cursor( examp ), &it ) ); + } + } + } uilist amenu; @@ -4521,22 +4555,15 @@ void iexamine::workbench( player &p, const tripoint &examp ) get_items }; - auto items_at_furn = g->m.i_at( examp ); - std::vector crafts; - for( item &it : items_at_furn ) { - if( it.is_craft() ) { - crafts.emplace_back( item_location( map_cursor( examp ), &it ) ); - } + amenu.text = string_format( pgettext( "furniture", "What to do at the %s?" ), name ); + amenu.addentry( start_craft, true, '1', _( "Craft items" ) ); + amenu.addentry( repeat_craft, true, '2', _( "Recraft last recipe" ) ); + amenu.addentry( start_long_craft, true, '3', _( "Craft as long as possible" ) ); + amenu.addentry( work_on_craft, !crafts.empty(), '4', _( "Work on craft" ) ); + if( !part ) { + amenu.addentry( get_items, items_at_loc, '5', _( "Get items" ) ); } - amenu.text = string_format( pgettext( "furniture", "What to do at the %s?" ), - f_workbench.name() ); - amenu.addentry( start_craft, true, '1', _( "Craft items" ) ); - amenu.addentry( repeat_craft, true, '2', _( "Recraft last recipe" ) ); - amenu.addentry( start_long_craft, true, '3', _( "Craft as long as possible" ) ); - amenu.addentry( work_on_craft, !crafts.empty(), '4', _( "Work on craft" ) ); - amenu.addentry( get_items, !items_at_furn.empty(), '5', _( "Get items" ) ); - amenu.query(); option choice = static_cast