Compare commits

...

5 Commits

8 changed files with 104 additions and 126 deletions
@@ -53,7 +53,12 @@ class HIDDeviceUSB implements HIDDevice {
public String getSerialNumber() {
String result = null;
if (Build.VERSION.SDK_INT >= 21) {
result = mDevice.getSerialNumber();
try {
result = mDevice.getSerialNumber();
}
catch (SecurityException exception) {
//Log.w(TAG, "App permissions mean we cannot get serial number for device " + getDeviceName() + " message: " + exception.getMessage());
}
}
if (result == null) {
result = "";
+6 -12
View File
@@ -1339,15 +1339,12 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
// if worn, we need to fix with the worn index number (starts at -2, as -1 is weapon)
int idx = srcarea == AIM_INVENTORY ? sitem->idx : player::worn_position_to_index( sitem->idx ) + 1;
// make sure advanced inventory is reopened after activity completion.
do_return_entry();
if( srcarea == AIM_WORN && destarea == AIM_INVENTORY ) {
// this is ok because worn items are never stacked (can't move more than 1).
player_character.takeoff( idx );
// make sure advanced inventory is reopened after activity completion.
do_return_entry();
// exit so that the action can be carried out
exit = true;
} else {
// important if item is worn
if( player_character.can_drop( *sitem->items.front() ).success() ) {
@@ -1370,14 +1367,11 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
player_character.assign_activity( player_activity( drop_activity_actor(
to_drop, placement, force_ground
) ) );
// make sure advanced inventory is reopened after activity completion.
do_return_entry();
// exit so that the activity can be carried out
exit = true;
}
}
// exit so that the activity can be carried out
exit = true;
} else {
bool can_stash = false;
if( sitem->items.front()->count_by_charges() ) {
+13 -5
View File
@@ -100,7 +100,7 @@ namespace liquid_handler
{
void handle_all_liquid( item liquid, const int radius, const item *const avoid )
{
while( liquid.charges > 0 ) {
while( liquid.charges > 0 && can_handle_liquid( liquid ) ) {
// handle_liquid allows to pour onto the ground, which will handle all the liquid and
// set charges to 0. This allows terminating the loop.
// The result of handle_liquid is ignored, the player *has* to handle all the liquid.
@@ -438,10 +438,7 @@ static bool perform_liquid_transfer( item &liquid, const tripoint *const source_
}
}
bool handle_liquid( item &liquid, const item *const source, const int radius,
const tripoint *const source_pos,
const vehicle *const source_veh, const int part_num,
const monster *const source_mon )
bool can_handle_liquid( const item &liquid )
{
if( liquid.made_of_from_type( phase_id::SOLID ) ) {
dbg( D_ERROR ) << "game:handle_liquid: Tried to handle_liquid a non-liquid!";
@@ -453,6 +450,17 @@ bool handle_liquid( item &liquid, const item *const source, const int radius,
add_msg( _( "The %s froze solid before you could finish." ), liquid.tname() );
return false;
}
return true;
}
bool handle_liquid( item &liquid, const item *const source, const int radius,
const tripoint *const source_pos,
const vehicle *const source_veh, const int part_num,
const monster *const source_mon )
{
if( !can_handle_liquid( liquid ) ) {
return false;
}
struct liquid_dest_opt liquid_target;
if( get_liquid_target( liquid, source, radius, source_pos, source_veh, source_mon,
liquid_target ) ) {
+2
View File
@@ -87,6 +87,8 @@ bool handle_liquid_from_container( item *in_container, item &container,
*/
bool handle_liquid_from_container( item &container, int radius = 0 );
bool can_handle_liquid( const item &liquid );
/**
* This may start a player activity if either \p source_pos or \p source_veh is not
* null.
+64 -94
View File
@@ -2350,6 +2350,8 @@ inventory_multiselector::inventory_multiselector( Character &p,
ctxt.register_action( "RIGHT", to_translation( "Mark/unmark selected item" ) );
ctxt.register_action( "DROP_NON_FAVORITE", to_translation( "Mark/unmark non-favorite items" ) );
max_chosen_count = std::numeric_limits<decltype( max_chosen_count )>::max();
for( inventory_column * const &elem : get_all_columns() ) {
elem->set_multiselect( true );
}
@@ -2363,6 +2365,53 @@ void inventory_multiselector::rearrange_columns( size_t client_width )
selection_col->set_visibility( !is_overflown( client_width ) );
}
void inventory_multiselector::set_chosen_count( inventory_entry &entry, size_t count )
{
const item_location &it = entry.any_item();
/* Since we're modifying selection of this entry, we need to clear out
anything that's been set before.
*/
for( const item_location &loc : entry.locations ) {
for( auto iter = to_use.begin(); iter != to_use.end(); ) {
if( iter->first == loc ) {
to_use.erase( iter );
} else {
++iter;
}
}
}
if( count == 0 ) {
entry.chosen_count = 0;
} else {
entry.chosen_count = std::min( {count, max_chosen_count, entry.get_available_count() } );
if( it->count_by_charges() ) {
auto iter = find_if( to_use.begin(), to_use.end(), [&it]( drop_location drop ) {
return drop.first == it;
} );
if( iter == to_use.end() ) {
to_use.emplace_back( it, static_cast<int>( entry.chosen_count ) );
}
} else {
for( const item_location &loc : entry.locations ) {
if( count == 0 ) {
break;
}
auto iter = find_if( to_use.begin(), to_use.end(), [&loc]( drop_location drop ) {
return drop.first == loc;
} );
if( iter == to_use.end() ) {
to_use.emplace_back( loc, 1 );
}
count--;
}
}
}
on_change( entry );
}
inventory_compare_selector::inventory_compare_selector( Character &p ) :
inventory_multiselector( p, default_preset, _( "ITEMS TO COMPARE" ) ) {}
@@ -2440,8 +2489,7 @@ inventory_iuse_selector::inventory_iuse_selector(
const GetStats &get_st
) :
inventory_multiselector( p, preset, selector_title ),
get_stats( get_st ),
max_chosen_count( std::numeric_limits<decltype( max_chosen_count )>::max() )
get_stats( get_st )
{}
drop_locations inventory_iuse_selector::execute()
{
@@ -2501,6 +2549,12 @@ drop_locations inventory_iuse_selector::execute()
continue;
}
break;
} else if( input.action == "EXAMINE" ) {
const inventory_entry &selected = get_active_column().get_selected();
if( selected ) {
const item *sitem = selected.any_item().get_item();
action_examine( sitem );
}
} else if( input.action == "QUIT" ) {
return drop_locations();
} else if( input.action == "INVENTORY_FILTER" ) {
@@ -2512,53 +2566,13 @@ drop_locations inventory_iuse_selector::execute()
}
drop_locations dropped_pos_and_qty;
for( const std::pair<const item_location *const, int> &use_pair : to_use ) {
dropped_pos_and_qty.push_back( std::make_pair( *use_pair.first, use_pair.second ) );
for( const std::pair<const item_location, int> use_pair : to_use ) {
dropped_pos_and_qty.push_back( use_pair );
}
return dropped_pos_and_qty;
}
void inventory_iuse_selector::set_chosen_count( inventory_entry &entry, size_t count )
{
const item_location &it = entry.any_item();
std::map<const item_location *, int> temp_use;
if( count == 0 ) {
entry.chosen_count = 0;
for( const item_location &loc : entry.locations ) {
temp_use[&loc] = 0;
}
} else {
entry.chosen_count = std::min( std::min( count, max_chosen_count ), entry.get_available_count() );
if( it->count_by_charges() ) {
temp_use[&it] = entry.chosen_count;
} else {
for( const item_location &loc : entry.locations ) {
if( count == 0 ) {
break;
}
temp_use[&loc] = 1;
count--;
}
}
}
// Optimisation to reduce the scale of looping if otherwise done in the preceeding code.
for( auto iter : temp_use ) {
for( const item_location &x : usable_locs ) {
if( x == *iter.first ) {
if( iter.second > 0 ) {
to_use[&x] = iter.second;
} else {
to_use.erase( &x );
}
}
}
}
on_change( entry );
}
inventory_selector::stats inventory_iuse_selector::get_raw_stats() const
{
if( get_stats ) {
@@ -2572,7 +2586,6 @@ inventory_drop_selector::inventory_drop_selector( Character &p,
const std::string &selection_column_title,
const bool warn_liquid ) :
inventory_multiselector( p, preset, selection_column_title ),
max_chosen_count( std::numeric_limits<decltype( max_chosen_count )>::max() ),
warn_liquid( warn_liquid )
{
#if defined(__ANDROID__)
@@ -2604,7 +2617,7 @@ void inventory_drop_selector::process_selected( int &count,
void inventory_drop_selector::deselect_contained_items()
{
std::vector<item_location> inventory_items;
for( std::pair<item_location, int> &drop : dropping ) {
for( std::pair<item_location, int> &drop : to_use ) {
item_location loc_front = drop.first;
inventory_items.push_back( loc_front );
}
@@ -2709,7 +2722,7 @@ drop_locations inventory_drop_selector::execute()
count = 0;
} else if( input.action == "CONFIRM" ) {
if( dropping.empty() ) {
if( to_use.empty() ) {
popup_getkey( _( "No items were selected. Use %s to select them." ),
ctxt.get_desc( "RIGHT" ) );
continue;
@@ -2733,7 +2746,7 @@ drop_locations inventory_drop_selector::execute()
ask, no, yes
} should_drop_liquid = drop_liquid::ask;
for( const std::pair<item_location, int> &drop_pair : dropping ) {
for( const std::pair<item_location, int> &drop_pair : to_use ) {
bool should_drop = true;
if( drop_pair.first->made_of_from_type( phase_id::LIQUID ) ) {
if( should_drop_liquid == drop_liquid::ask ) {
@@ -2756,55 +2769,12 @@ drop_locations inventory_drop_selector::execute()
return dropped_pos_and_qty;
}
void inventory_drop_selector::set_chosen_count( inventory_entry &entry, size_t count )
{
const item_location &it = entry.any_item();
if( count == 0 ) {
entry.chosen_count = 0;
for( const item_location &loc : entry.locations ) {
for( auto iter = dropping.begin(); iter != dropping.end(); ) {
if( iter->first == loc ) {
dropping.erase( iter );
} else {
++iter;
}
}
}
} else {
entry.chosen_count = std::min( std::min( count, max_chosen_count ), entry.get_available_count() );
if( it->count_by_charges() ) {
auto iter = find_if( dropping.begin(), dropping.end(), [&it]( drop_location drop ) {
return drop.first == it;
} );
if( iter == dropping.end() ) {
dropping.emplace_back( it, static_cast<int>( entry.chosen_count ) );
}
} else {
for( const item_location &loc : entry.locations ) {
if( count == 0 ) {
break;
}
auto iter = find_if( dropping.begin(), dropping.end(), [&loc]( drop_location drop ) {
return drop.first == loc;
} );
if( iter == dropping.end() ) {
dropping.emplace_back( loc, 1 );
}
count--;
}
}
}
on_change( entry );
}
inventory_selector::stats inventory_drop_selector::get_raw_stats() const
{
return get_weight_and_volume_stats(
u.weight_carried_with_tweaks( dropping ),
u.weight_carried_with_tweaks( to_use ),
u.weight_capacity(),
u.volume_carried_with_tweaks( dropping ),
u.volume_capacity_with_tweaks( dropping ),
u.volume_carried_with_tweaks( to_use ),
u.volume_capacity_with_tweaks( to_use ),
u.max_single_item_length(), u.max_single_item_volume() );
}
+6 -10
View File
@@ -734,7 +734,10 @@ class inventory_multiselector : public inventory_selector
const std::string &selection_column_title = "" );
protected:
void rearrange_columns( size_t client_width ) override;
size_t max_chosen_count;
void set_chosen_count( inventory_entry &entry, size_t count );
std::vector<std::pair<item_location, int>> to_use;
std::vector<item_location> usable_locs;
private:
std::unique_ptr<inventory_column> selection_col;
};
@@ -747,7 +750,6 @@ class inventory_compare_selector : public inventory_multiselector
protected:
std::vector<const item *> compared;
void toggle_entry( inventory_entry *entry );
};
@@ -756,7 +758,7 @@ class inventory_compare_selector : public inventory_multiselector
class inventory_iuse_selector : public inventory_multiselector
{
public:
using GetStats = std::function<stats( const std::map<const item_location *, int> & )>;
using GetStats = std::function<stats( const std::vector<std::pair<item_location, int>> )>;
inventory_iuse_selector( Character &p,
const std::string &selector_title,
const inventory_selector_preset &preset = default_preset,
@@ -765,13 +767,9 @@ class inventory_iuse_selector : public inventory_multiselector
protected:
stats get_raw_stats() const override;
void set_chosen_count( inventory_entry &entry, size_t count );
private:
GetStats get_stats;
std::map<const item_location *, int> to_use;
std::vector<item_location> usable_locs;
size_t max_chosen_count;
};
class inventory_drop_selector : public inventory_multiselector
@@ -786,13 +784,11 @@ class inventory_drop_selector : public inventory_multiselector
protected:
stats get_raw_stats() const override;
/** Toggle item dropping */
void set_chosen_count( inventory_entry &entry, size_t count );
void process_selected( int &count, const std::vector<inventory_entry *> &selected );
private:
void deselect_contained_items();
std::vector<std::pair<item_location, int>> dropping;
size_t max_chosen_count;
bool warn_liquid;
};
+3 -3
View File
@@ -9518,12 +9518,12 @@ cata::optional<int> iuse::wash_items( player *p, bool soft_items, bool hard_item
return location->has_flag( flag_FILTHY ) && ( ( soft_items && location->is_soft() ) ||
( hard_items && !location->is_soft() ) );
} );
auto make_raw_stats = [available_water, available_cleanser](
const std::map<const item_location *, int> &locs
auto make_raw_stats = [available_water,
available_cleanser]( const std::vector<std::pair<item_location, int>> &locs
) {
units::volume total_volume = 0_ml;
for( const auto &pair : locs ) {
total_volume += ( *pair.first )->volume( false, true );
total_volume += pair.first->volume( false, true );
}
washing_requirements required = washing_requirements_for_volume( total_volume );
auto to_string = []( int val ) -> std::string {
+4 -1
View File
@@ -33,6 +33,7 @@
#include "active_item_cache.h"
#include "activity_actor.h"
#include "activity_actor_definitions.h"
#include "activity_type.h"
#include "assign.h"
#include "auto_pickup.h"
@@ -333,13 +334,15 @@ void player_activity::deserialize( JsonIn &jsin )
// this may cause inconvenience but should avoid any lasting damage to npcs
if( is_obsolete || ( has_actor && ( data.has_null( "actor" ) || !data.has_member( "actor" ) ) ) ) {
type = activity_id( "ACT_MIGRATION_CANCEL" );
actor = std::make_unique<migration_cancel_activity_actor>();
} else {
data.read( "actor", actor );
}
if( !data.read( "position", tmppos ) ) {
tmppos = INT_MIN; // If loading a save before position existed, hope.
}
data.read( "actor", actor );
data.read( "moves_total", moves_total );
data.read( "moves_left", moves_left );
data.read( "index", index );