Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E]ating menu stays open on last item #29148

Merged
merged 2 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_MENU",
"type": "activity_type",
"stop_phrase": "Stop eating?",
"suspendable": false,
"based_on": "neither",
"no_resume": true
}
]
13 changes: 13 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_MENU" ), eat_menu_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_MENU" ), eat_menu_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 @@ -2519,6 +2521,12 @@ void activity_handlers::wear_do_turn( player_activity *, player * )
activity_on_turn_wear();
}

// This activity opens the menu (it's not meant to queue consumption of items)
void activity_handlers::eat_menu_do_turn( player_activity *, player * )
{
g->eat();
}

void activity_handlers::move_items_do_turn( player_activity *, player * )
{
activity_on_turn_move_items();
Expand Down Expand Up @@ -2729,6 +2737,11 @@ void activity_handlers::aim_finish( player_activity *, player * )
// you only re-enter if it gets set again.
return;
}
void activity_handlers::eat_menu_finish( player_activity *, player * )
{
// Only exists to keep the eat activity alive between turns
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_menu_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_menu_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_MENU" ) ) ){
u.assign_activity( activity_id( "ACT_EAT_MENU" ) );
}

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_MENU" ) ) && 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_MENU" ) ) ) {
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