Skip to content

Commit

Permalink
AIM: Add key to step outside containers; mark other pane's container;…
Browse files Browse the repository at this point in the history
… less obtrusive popups (CleverRaven#67017)

* Replaces AIM_CONTAINER2 with a check in action_move_item()

* Be less strict on container interactions

* Simplify canputitems()

* Add stepping out of container view to the parent location

* Fix crash from non-carried bucket spilling, and made it spill at location rather than in player's pockets

* Make "can't put items there" messages less obtrusive

* Mark container if the other pane is viewing inside it

* Allow moving all between containers

* Swap panes when moving between container layers

* Make container marking recursive

* Remove unused variable

* Re-add "not enough room" warning

* Revert some of the spill changes

* Also show error if trying to move container into child container

* Update data/raw/keybindings.json

* Update data/raw/keybindings.json

---------

Co-authored-by: Maleclypse <54345792+Maleclypse@users.noreply.github.com>
  • Loading branch information
Kamayana and Maleclypse authored Jul 28, 2023
1 parent 3041ee3 commit 9eb4e70
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 149 deletions.
11 changes: 11 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,17 @@
{ "input_method": "keyboard_code", "key": "c", "mod": [ "shift" ] }
]
},
{
"type": "keybinding",
"id": "ITEMS_PARENT",
"category": "ADVANCED_INVENTORY",
"name": "Exit container to parent",
"bindings": [
{ "input_method": "keyboard_any", "key": "x" },
{ "input_method": "keyboard_char", "key": "X" },
{ "input_method": "keyboard_code", "key": "x", "mod": [ "shift" ] }
]
},
{
"type": "keybinding",
"id": "ITEMS_WORN",
Expand Down
3 changes: 2 additions & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4183,7 +4183,8 @@ void insert_item_activity_actor::finish( player_activity &act, Character &who )
int result = holster->fill_with( it, charges,
/*unseal_pockets=*/true,
/*allow_sealed=*/true,
/*ignore_settings*/true );
/*ignore_settings*/true,
/*into_bottom*/true );
success = result > 0;

if( success ) {
Expand Down
310 changes: 192 additions & 118 deletions src/advanced_inv.cpp

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/advanced_inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ class advanced_inventory
bool is_processing() const;

static std::string get_sortname( advanced_inv_sortby sortby );
bool move_all_items();
void print_items( const advanced_inventory_pane &pane, bool active );
void print_items( side p, bool active );
void recalc_pane( side p );
void redraw_pane( side p );
void redraw_sidebar();

bool move_all_items();
/**
* Fills drop_or_stash_item_info lists with the current contents of the active pane.
* Fills drop_or_stash_item_info lists with the current contents of the active pane, for use with move_all_items.
* @param player_character Reference to the player character.
* @param spane Reference to the active AIM pane.
* @param item_list Reference to the list to fill with items.
* @param fav_list Reference to the list to fill with favorited items.
* @param filter_buckets Whether to skip over containers that would spill in certain locations.
* @return a string description of why some items were skipped, if any.
*/
std::string fill_lists_with_pane_items( Character &player_character, advanced_inventory_pane &spane,
std::string fill_lists_with_pane_items( side &p, Character &player_character,
std::vector<drop_or_stash_item_info> &item_list,
std::vector<drop_or_stash_item_info> &fav_list, bool filter_buckets );
// Returns the x coordinate where the header started. The header is
Expand Down
21 changes: 2 additions & 19 deletions src/advanced_inv_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ void advanced_inv_area::init()
}
break;
case AIM_CONTAINER:
case AIM_CONTAINER2:
// set container position based on location
set_container_position();
// location always valid, actual check is done in canputitems()
Expand Down Expand Up @@ -199,8 +198,7 @@ bool advanced_inv_area::is_same( const advanced_inv_area &other ) const
// e.g. dragged vehicle (to the south) and AIM_SOUTH are the same.
if( id != AIM_INVENTORY && other.id != AIM_INVENTORY &&
id != AIM_WORN && other.id != AIM_WORN &&
( id != AIM_CONTAINER && other.id != AIM_CONTAINER ) &&
( id != AIM_CONTAINER2 && other.id != AIM_CONTAINER2 ) ) {
id != AIM_CONTAINER && other.id != AIM_CONTAINER ) {
// have a vehicle?... ...do the cargo index and pos match?... ...at least pos?
return veh == other.veh ? pos == other.pos && vstor == other.vstor : pos == other.pos;
}
Expand All @@ -210,22 +208,7 @@ bool advanced_inv_area::is_same( const advanced_inv_area &other ) const

bool advanced_inv_area::canputitems( const item_location &container ) const
{
bool canputitems = false;
switch( id ) {
case AIM_CONTAINER:
case AIM_CONTAINER2: {
if( container ) {
if( container.get_item()->is_container() ) {
canputitems = true;
}
}
break;
}
default:
canputitems = canputitemsloc;
break;
}
return canputitems;
return id != AIM_CONTAINER ? canputitemsloc : container && container.get_item()->is_container();
}

static tripoint aim_vector( aim_location id )
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum aim_location : char {
AIM_DRAGGED,
AIM_ALL,
AIM_CONTAINER,
AIM_CONTAINER2,
AIM_PARENT,
AIM_WORN,
NUM_AIM_LOCATIONS,
// only useful for AIM_ALL
Expand Down
5 changes: 3 additions & 2 deletions src/advanced_inv_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void advanced_inventory_pane::restore_area()
void advanced_inventory_pane::save_settings() const
{
save_state->container = container;
save_state->container_base_loc = container_base_loc;
save_state->in_vehicle = in_vehicle();
save_state->area_idx = get_area();
save_state->selected_idx = index;
Expand Down Expand Up @@ -78,6 +79,7 @@ void advanced_inventory_pane::load_settings( int saved_area_idx,
index = save_state->selected_idx;
filter = save_state->filter;
container = save_state->container;
container_base_loc = static_cast<aim_location>( save_state->container_base_loc );
}

bool advanced_inventory_pane::is_filtered( const advanced_inv_listitem &it ) const
Expand Down Expand Up @@ -215,7 +217,7 @@ void advanced_inventory_pane::add_items_from_area( advanced_inv_area &square,
}

u.worn.add_AIM_items_from_area( u, square, *this );
} else if( square.id == AIM_CONTAINER || square.id == AIM_CONTAINER2 ) {
} else if( square.id == AIM_CONTAINER ) {
square.volume = 0_ml;
square.weight = 0_gram;
if( container ) {
Expand All @@ -232,7 +234,6 @@ void advanced_inventory_pane::add_items_from_area( advanced_inv_area &square,
}
}
}
square.desc[0] = container->tname( 1, false );
}
} else {
bool is_in_vehicle = square.can_store_in_vehicle() && ( in_vehicle() || vehicle_override );
Expand Down
12 changes: 11 additions & 1 deletion src/advanced_inv_pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ class advanced_inventory_pane
* Whether to recalculate the content of this pane.
*/
bool recalc = false;
item_location target_item_after_recalc;

/**
*The active container item in container view.
* The active container item in container view.
*/
item_location container;
/**
* The original location from which container view was entered.
*/
aim_location container_base_loc = NUM_AIM_LOCATIONS;
/**
* The line number of the other pane's container, if it's inside this pane's aim location.
*/
int other_cont = -1;

void add_items_from_area( advanced_inv_area &square, bool vehicle_override = false );
/**
Expand Down
5 changes: 3 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11839,7 +11839,8 @@ void item::set_item_temperature( units::temperature new_temperature )
int item::fill_with( const item &contained, const int amount,
const bool unseal_pockets,
const bool allow_sealed,
const bool ignore_settings )
const bool ignore_settings,
const bool into_bottom )
{
if( amount <= 0 ) {
return 0;
Expand Down Expand Up @@ -11883,7 +11884,7 @@ int item::fill_with( const item &contained, const int amount,
}
}

if( !pocket->insert_item( contained_item ).success() ) {
if( !pocket->insert_item( contained_item, into_bottom ).success() ) {
if( count_by_charges ) {
debugmsg( "charges per remaining pocket volume does not fit in that very volume" );
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ class item : public visitable
int fill_with( const item &contained, int amount = INFINITE_CHARGES,
bool unseal_pockets = false,
bool allow_sealed = false,
bool ignore_settings = false );
bool ignore_settings = false,
bool into_bottom = false );

/**
* How much more of this liquid (in charges) can be put in this container.
Expand Down
3 changes: 3 additions & 0 deletions src/uistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct advanced_inv_pane_save_state {

bool in_vehicle = false;
item_location container;
int container_base_loc;

void serialize( JsonOut &json, const std::string &prefix ) const {
json.member( prefix + "sort_idx", sort_idx );
Expand All @@ -33,6 +34,7 @@ struct advanced_inv_pane_save_state {
json.member( prefix + "selected_idx", selected_idx );
json.member( prefix + "in_vehicle", in_vehicle );
json.member( prefix + "container", container );
json.member( prefix + "container_base_loc", container_base_loc );
}

void deserialize( const JsonObject &jo, const std::string &prefix ) {
Expand All @@ -42,6 +44,7 @@ struct advanced_inv_pane_save_state {
jo.read( prefix + "selected_idx", selected_idx );
jo.read( prefix + "in_vehicle", in_vehicle );
jo.read( prefix + "container", container );
jo.read( prefix + "container_base_loc", container_base_loc );
}
};

Expand Down

0 comments on commit 9eb4e70

Please sign in to comment.