Skip to content

Commit

Permalink
[E]ating menu now stays open on the previous item after consuming som…
Browse files Browse the repository at this point in the history
…ething
  • Loading branch information
cafeoh committed Apr 16, 2019
1 parent fff1726 commit f2ba7c8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
8 changes: 8 additions & 0 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,13 @@
"suspendable": false,
"based_on": "neither",
"no_resume": true
},
{
"id": "ACT_EAT",
"type": "activity_type",
"stop_phrase": "Stop eating?",
"suspendable": false,
"based_on": "neither",
"no_resume": true
}
]
10 changes: 10 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ activity_handlers::do_turn_functions = {
{ activity_id( "ACT_AIM" ), aim_do_turn },
{ activity_id( "ACT_PICKUP" ), pickup_do_turn },
{ activity_id( "ACT_WEAR" ), wear_do_turn },
{ activity_id( "ACT_EAT" ), eat_do_turn },
{ activity_id( "ACT_MOVE_ITEMS" ), move_items_do_turn },
{ activity_id( "ACT_MOVE_LOOT" ), move_loot_do_turn },
{ activity_id( "ACT_ADV_INVENTORY" ), adv_inventory_do_turn },
Expand Down Expand Up @@ -142,6 +143,7 @@ activity_handlers::finish_functions = {
{ activity_id( "ACT_VIBE" ), vibe_finish },
{ activity_id( "ACT_ATM" ), atm_finish },
{ activity_id( "ACT_AIM" ), aim_finish },
{ activity_id( "ACT_EAT" ), eat_finish },
{ activity_id( "ACT_WASH" ), washing_finish },
{ activity_id( "ACT_HACKSAW" ), hacksaw_finish },
{ activity_id( "ACT_CHOP_TREE" ), chop_tree_finish },
Expand Down Expand Up @@ -2518,6 +2520,10 @@ void activity_handlers::wear_do_turn( player_activity *, player * )
{
activity_on_turn_wear();
}
void activity_handlers::eat_do_turn( player_activity *, player * )
{
g->eat();
}

void activity_handlers::move_items_do_turn( player_activity *, player * )
{
Expand Down Expand Up @@ -2729,6 +2735,10 @@ void activity_handlers::aim_finish( player_activity *, player * )
// you only re-enter if it gets set again.
return;
}
void activity_handlers::eat_finish( player_activity *, player * )
{
return;
}

void activity_handlers::hacksaw_do_turn( player_activity *act, player *p )
{
Expand Down
2 changes: 2 additions & 0 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void oxytorch_do_turn( player_activity *act, player *p );
void aim_do_turn( player_activity *act, player *p );
void pickup_do_turn( player_activity *act, player *p );
void wear_do_turn( player_activity *act, player *p );
void eat_do_turn( player_activity *act, player *p );
void move_items_do_turn( player_activity *act, player *p );
void move_loot_do_turn( player_activity *act, player *p );
void adv_inventory_do_turn( player_activity *act, player *p );
Expand Down Expand Up @@ -125,6 +126,7 @@ void build_finish( player_activity *act, player *p );
void vibe_finish( player_activity *act, player *p );
void atm_finish( player_activity *act, player *p );
void aim_finish( player_activity *act, player *p );
void eat_finish( player_activity *act, player *p );
void washing_finish( player_activity *act, player *p );
void hacksaw_finish( player_activity *act, player *p );
void chop_tree_finish( player_activity *act, player *p );
Expand Down
5 changes: 5 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9502,8 +9502,13 @@ void game::eat( int pos )
return;
}

if(!u.has_activity( activity_id( "ACT_EAT" ) ) ){
u.assign_activity( activity_id( "ACT_EAT" ) );
}

auto item_loc = game_menus::inv::consume( u );
if( !item_loc ) {
u.cancel_activity();
add_msg( _( "Never mind." ) );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,6 @@ class game
void drop_in_direction(); // Drop w/ direction 'D'

void butcher(); // Butcher a corpse 'B'
void eat( int pos = INT_MIN ); // Eat food or fuel 'E' (or 'a')
void use_item( int pos = INT_MIN ); // Use item; also tries E,R,W 'a'

void change_side( int pos = INT_MIN ); // Change the side on which an item is worn 'c'
Expand All @@ -977,6 +976,7 @@ class game
void mend( int pos = INT_MIN );
void autoattack();
public:
void eat( int pos = INT_MIN ); // Eat food or fuel 'E' (or 'a')
void reload_item(); // Reload an item
void reload_weapon( bool try_everything = true ); // Reload a wielded gun/tool 'r'
// Places the player at the specified point; hurts feet, lists items etc.
Expand Down
21 changes: 21 additions & 0 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
inv_s.set_hint( hint );
inv_s.set_display_stats( false );

std::pair<size_t, size_t> init_pair;
bool init_selection = false;

if( u.has_activity( activity_id( "ACT_EAT" ) ) && u.activity.values.size() >= 2 ) {
init_pair.first = u.activity.values[0];
init_pair.second = u.activity.values[1];
init_selection = true;
}

do {
u.inv.restack( u );
Expand All @@ -78,6 +86,12 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
inv_s.add_character_items( u );
inv_s.add_nearby_items( radius );

if( init_selection ) {
inv_s.update();
inv_s.select_position( init_pair );
init_selection = false;
}

if( inv_s.empty() ) {
const std::string msg = none_message.empty()
? _( "You don't have the necessary item at hand." )
Expand All @@ -93,6 +107,13 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
continue;
}

if( u.has_activity( activity_id( "ACT_EAT" ) ) ) {
u.activity.values.clear();
init_pair = inv_s.get_selection_position();
u.activity.values.push_back( init_pair.first );
u.activity.values.push_back( init_pair.second );
}

return location;

} while( true );
Expand Down
29 changes: 23 additions & 6 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ class inventory_column
/** Selects the specified location. */
bool select( const item_location &loc );

/**
* Change the selection.
* @param new_index Index of the entry to select.
* @param dir If the entry is not selectable, move in the specified direction
*/
void select( size_t new_index, scroll_direction dir );

size_t get_selected_index() {
return selected_index;
}

void set_multiselect( bool multiselect ) {
this->multiselect = multiselect;
}
Expand Down Expand Up @@ -320,12 +331,6 @@ class inventory_column
std::vector<std::string> text;
};

/**
* Change the selection.
* @param new_index Index of the entry to select.
* @param dir If the entry is not selectable, move in the specified direction
*/
void select( size_t new_index, scroll_direction dir );
/**
* Move the selection.
*/
Expand Down Expand Up @@ -539,6 +544,18 @@ class inventory_selector
return get_active_column().get_selected();
}

void select_position( std::pair<size_t, size_t> position ) {
set_active_column( position.first );
get_active_column().select( position.second, scroll_direction::BACKWARD );
}

std::pair<size_t, size_t> get_selection_position() {
std::pair<size_t, size_t> position;
position.first = active_column_index;
position.second = get_active_column().get_selected_index();
return position;
}

inventory_column &get_column( size_t index ) const;
inventory_column &get_active_column() const {
return get_column( active_column_index );
Expand Down

0 comments on commit f2ba7c8

Please sign in to comment.