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

Eat menu #33304

Closed
wants to merge 25 commits into from
Closed

Eat menu #33304

wants to merge 25 commits into from

Conversation

akozhevn
Copy link
Contributor

@akozhevn akozhevn commented Aug 17, 2019

Summary

SUMMARY: Interface "Replacing 'E'ating menu with a better one"

Purpose of change

Current menu is clunky and lacks QOL features

Describe the solution

Base the menu off of advancved inventory, so we get targeting, sorting and filtering for free
Ability to toggle between Food, Drugs - technically can filter with 'c:' but it's too many button presses
CBM opens eating menu when turned on
Add ability to warm up food from the menu
Add ability to cook using current ingredient from the menu

Describe alternatives you've considered

I think creating new menu is easier than adding all these features to current one, because current is generic code, shared between multiple menus.

Additional context

Large + help page
neat1

Small + mutation error
neat2

Furance menu + sorting
neat3

WIP for 'E'ating menu

# Explain why this change is being made
current one is clunky
@Petethegoat
Copy link
Contributor

Can we get some screenshots?

@anothersimulacrum
Copy link
Member

You need to astyle, and fix the build errors.

src/comestible_inv.cpp Outdated Show resolved Hide resolved
src/comestible_inv.cpp Outdated Show resolved Hide resolved
src/comestible_inv.cpp Outdated Show resolved Hide resolved
src/comestible_inv.cpp Outdated Show resolved Hide resolved
src/comestible_inv.cpp Outdated Show resolved Hide resolved
src/comestible_inv.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg
Copy link
Contributor

I can see that a lot of code is simply a copy of advanced inventory code. Maybe you can use some shared functions to reduce code duplication?

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Items: Food / Vitamins Comestibles and drinks Info / User Interface Game - player communication, menus, etc. Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones Quality of Life QoL: degree to which players are comfortable, and able to enjoy CDDA labels Aug 17, 2019
@BevapDin
Copy link
Contributor

Base the menu off of advancved inventory, so we get targeting

You mean by copying most of the content of "advanced_inv.cpp" and "advanced_inv.h". Any change to those files will not appear in the new menu and vice versa. This will lead to inconsistencies. It's generally not a good idea to copy that much code with little changes.

settings are saved within a session
can actually eat now
bionics have special eating menu when activated
can summon crafting menu from eating menu
refactoring to make it more modular, future support
fixing CBM menu showing wrong items
fixing heat_up not having shortcuts
reorganizing things a little
menu_color = it.color_in_inventory();

// statuses
const auto &comest = it.get_comestible();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant to get the edible instead of querying it directly here (get_edible_comestible queries it anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the difference is between get_edible_comestible( p, it ); and it.get_comestible(); Edible and comestible are synonyms and it's not documented which function I should use when.
This code is copied from different places, so not sure what it actually needs to be. The functions seem different on the inside, so I don't know the consequences if we just replace comest with edible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the difference is between

Than look at the source of their implementation.

This code is copied from different places,

Copying code without understanding what it does (or even why it does it) is dangerous.

  • get_comestible returns an optional value, dereferencing the optional (as you do below via comest->) will cause UB when it does not actually contain a value. Your code does not check this, it just dereferences in the assumption that it will always contain a value. That leads to a crash when encountering non-food items (where comest is empty).

get_edible_comestible (which looks like a straight copy from "game_inventory.cpp", which is bad on its own) checks for the optional value being empty and returns a dummy value in that case.

Btw. this has nothing to do with edible vs comestible.

src/comestible_inv.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg ZhilkinSerg self-assigned this Sep 19, 2019
@codemime
Copy link
Contributor

3500+ lines of mostly copy-pasted code for a new non-generic menu (in addition to the existing ones) shoved into a single PR? I'd say it's a no-go.

@akozhevn
Copy link
Contributor Author

3500+ lines of mostly copy-pasted code for a new non-generic menu (in addition to the existing ones) shoved into a single PR? I'd say it's a no-go.

Ok, let's start with the problem - inventory-type menus are bad (no sorting, grouping by location is generally useless, no QOL features)
How do we improve? I believe incremental changes to current implementation will give mediocre results at best. So I created new base classes.
The code is generic and is only copy pasted if you ignore the overall structure. With it you can create more menus pretty easy. Existing implementation of advanced inventory (ai) doesn't support extension, so you would have to add a lot of these if(type1){} else if(type2){} ... for every new ai-looking menu. Would become a mess fast.
@codemime @BevapDin How about I create new PR, where I just refactor ai? So we can make menus based of that.

@kevingranade
Copy link
Member

I believe incremental changes to current implementation will give mediocre results at best.

That is not how that works, writing all-new code is easier, but it's also massively riskier. You've identified issues you have with the existing code, but I guarantee that the new code has it's own issues, if nothing else missing features compared to the old code.

The only sure way to prevent this is to incrementally adjust the existing code over time so that bugs and feature omissions are easier to spot and correct.

Cleaning up the advanced inventory code is something we would love soneone to tackle.

@ThomasLinkin
Copy link

True
I think you should change the existing code instead of creating a whole new one.

@@ -0,0 +1,104 @@
#pragma once
#ifndef comestible_inv_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifndef comestible_inv_H
#ifndef COMESTIBLE_INV_H

@@ -0,0 +1,104 @@
#pragma once
#ifndef comestible_inv_H
#define comestible_inv_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define comestible_inv_H
#define COMESTIBLE_INV_H

@@ -14,6 +15,6 @@ void remove_ammo( item &dis_item, player &p );
// same as above but for each item in the list
void remove_ammo( std::list<item> &dis_items, player &p );

const recipe *select_crafting_recipe( int &batch_size );
const recipe *select_crafting_recipe( int &batch_size, const std::string &filter = "" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const recipe *select_crafting_recipe( int &batch_size, const std::string &filter = "" );
const recipe *select_crafting_recipe( int &batch_size, const std::string &filter );

@@ -1424,7 +1424,7 @@ class player : public Character
* Start various types of crafts
* @param loc the location of the workbench. tripoint_zero indicates crafting from inventory.
*/
void craft( const tripoint &loc = tripoint_zero );
void craft( const tripoint &loc = tripoint_zero, const std::string &filter = "" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void craft( const tripoint &loc = tripoint_zero, const std::string &filter = "" );
void craft( const tripoint &loc = tripoint_zero, const std::string &filter );


eat_error = p.can_eat( it );

exipres_in = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exipres_in = "";
exipres_in.clear();

eat_error = p.can_eat( it );

exipres_in = "";
shelf_life = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shelf_life = "";
shelf_life.clear();

{
//Function is overriden in children. Code is to supress warnings/errors.
if( col == 0 ) {
print_str = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_str = "";
print_str.clear();

{
//Function is overriden in children. Code is to supress warnings/errors.
if( col == 0 ) {
print_str = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_str = "";
print_str.clear();

}
print_str = string_format( "%4d", stacks );
} else {
print_str = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_str = "";
print_str.clear();

string_format = "%d";
} else {
print_color = need_highlight ? c_yellow : c_dark_gray;
string_format = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string_format = "";
string_format.clear();

@akozhevn akozhevn mentioned this pull request Oct 6, 2019
3 tasks
@ZhilkinSerg ZhilkinSerg removed their assignment Oct 13, 2019
@stale
Copy link

stale bot commented Nov 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not 'bump' or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

@stale stale bot added the stale Closed for lack of activity, but still valid. label Nov 12, 2019
@ZhilkinSerg ZhilkinSerg added 0.E Feature Freeze and removed stale Closed for lack of activity, but still valid. labels Nov 12, 2019
@kevingranade
Copy link
Member

This large scale overhaul isn't going to happen in one shot, the options are incremental change or stick with the status quo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones Items: Food / Vitamins Comestibles and drinks Quality of Life QoL: degree to which players are comfortable, and able to enjoy CDDA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants