Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] [CR] Adding grid view option for inventory #16519
Conversation
sctjkc01
added some commits
May 4, 2016
sctjkc01
changed the title
[WIP] [RC] Adding grid view option for inventory
[WIP] [CR] Adding grid view option for inventory
May 4, 2016
illi-kun
reviewed
May 4, 2016
|
|
||
| } else if(OPTIONS["INV_DISPLAY"] == "grid") { | ||
| if (multidrop) { | ||
| if(TERMX > 100) |
This comment has been minimized.
This comment has been minimized.
illi-kun
May 4, 2016
Member
{} are mandatory even for one-line conditions. More general note, you have to follow official code style.
This comment has been minimized.
This comment has been minimized.
sctjkc01
May 4, 2016
Author
Contributor
Fixed this issue on my working copy; I'll add that to the next big commit.
illi-kun
reviewed
May 4, 2016
|
|
||
| if (is_food()) { | ||
| if(rotten()) { | ||
| ret << _(parens ? " (rotten)" : " ROTTEN"); |
This comment has been minimized.
This comment has been minimized.
illi-kun
May 4, 2016
Member
_() marks strings for translation, so you need to modify this line to embrace only string " (rotten)"
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
illi-kun
May 4, 2016
Member
Oops, sorry, it should looks like:
ret << parens ? _( " (active)" ) : _( " ACTIVE" ) );
This comment has been minimized.
This comment has been minimized.
illi-kun
reviewed
May 4, 2016
| } | ||
|
|
||
| rtn = ret.str(); | ||
| ret.str(""); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sctjkc01
May 4, 2016
Author
Contributor
Was emptying ret before returning to calling function; not 100% certain if it was necessary. Removed on working copy.
illi-kun
reviewed
May 4, 2016
| std::string item::get_item_tags(bool parens) const | ||
| { | ||
| std::string rtn; | ||
| std::stringstream ret; |
This comment has been minimized.
This comment has been minimized.
illi-kun
reviewed
May 4, 2016
| { | ||
| std::string rtn; | ||
| std::stringstream ret; | ||
| ret.str(""); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sctjkc01
May 4, 2016
Author
Contributor
Converted ret to type std::ostringstream, removed ret.str(""); line, and removed unnecessary use of the std::string rtn variable, instead simply returning ret.str().
This comment has been minimized.
This comment has been minimized.
kevingranade
via email
May 4, 2016
Member
This comment has been minimized.
This comment has been minimized.
The intent of the new inventory view is to produce a more space-efficient display of the items within a user's inventory. As the inventory stands now, expanding beyond the original 80x24 creates a large, unused hunk of space down the middle: (Apologies for the odd item naming, I'm currently working that out.) Using the grid view instead would allow for a much more populated listing, which not only reclaims otherwise blank space on the horizontal vector, but also would allow for scrolling instead. Category separations would remain the same, and instead of everything being listed in two columns, the currently equipped stuff appears at the very top. Navigation through the inventory is intended to become more intuitive: all four arrow keys would be used to move the selector (in a text-edit fashion: moving down a row to a spot where no item exists should push the selector to the last item of the row below), only Enter would be used to examine or mark. The current system has the left arrow key switching columns (less than intuitive, as you start in the left column) and the right arrow key to interact. The sheet I've been using to plan out the grid view is available on Google Drive, if anyone is interested. This link will take you to it. In addition, I've (separately) implemented the display of two at-a-glance meters on the top right that lets you get a general idea of how much stuff you're carrying, ideal if you want a quick answer to "can I pick this up?" |
This comment has been minimized.
This comment has been minimized.
|
It's much easier to read the existing menu (with vertical lists of items). Maybe it's enough to add more columns to existing menu and not to rebuild it from scratch? BTW, I like these bars for weight/volume. |
This comment has been minimized.
This comment has been minimized.
|
The question then becomes, where do you make the column breaks? How would you decide "here's a good place to break the column"? The only spot I can think of to make the break is where a typical page break would be, however that would create an issue where one category continues to the next column. The items after the break could appear to be a part of the category at the top of the previous column. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I suppose that's true; Wielded / Weapon would always have one item (unless dual-wielding is implemented at some point). In that case, we could play off your idea, and have Wielded and Items Worn share the same column of space, Wielded atop Items Worn. This eliminates all the wasted space otherwise given to a full-fledged Wielded area (admittedly the same thing the current view does now).
The big change here would be, then, having several columns instead of just two or three. |
BevapDin
reviewed
May 5, 2016
| wprintz(w_inv, c_ltgray, "%3d", vol_carried); | ||
| void inventory_selector::print_bar(int y, int x, int carried, int capacity) const { | ||
| wmove(w_inv, y, x); | ||
| int barsize = static_cast<int>((carried * 24.0) / capacity); |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Can vol_capacity can be 0 (for a naked character), this should be handled here.
BevapDin
reviewed
May 5, 2016
| weight_color = c_red; | ||
| } | ||
| wprintz(w_inv, weight_color, "%6.1f", convert_weight(weight_carried) + 0.05 ); // +0.05 to round up; | ||
| wprintz(w_inv, c_ltgray, "/%-6.1f %s", convert_weight(g->u.weight_capacity()), _(weight_units())); |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
The result of weight_units is already translated, no need to translate it again.
BevapDin
reviewed
May 5, 2016
| if(barsize > 18) { color = c_red; } | ||
|
|
||
| std::stringstream bar; | ||
| bar.str(""); |
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
May 5, 2016
| bar << "|"; | ||
| } else if(barsize == (i*2)-1) { | ||
| bar << "\\"; | ||
| } else break; |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Please read doc/CODE_STYLE.txt and apply the styling from there. Especially here.
BevapDin
reviewed
May 5, 2016
| } | ||
| const std::string name = cur_entry.category->name; | ||
| if(curr_line >= 3 && curr_line < TERMY) { | ||
| center_print(w_inv, curr_line, c_magenta, _("--- %s ---"), name.c_str()); // Center print header |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
The comment here is a bit pointless, the called function is named center_print, one would assume that it "center prints" its arguments.
BevapDin
reviewed
May 5, 2016
| // End Cell Border Stuff | ||
| } | ||
|
|
||
| std::string item_name = it.label(); // Get object's display name |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
The comment is lying. item::label returns either a the (item instance specific) label (if it has one) or the name of the item type.
Why are you not using item::display_name?
BevapDin
reviewed
May 5, 2016
| } | ||
|
|
||
| if(curr_line >= 2 && curr_line + 1 < TERMY) { // Second line | ||
| // Cell Border Stuff |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Instead of wrapping coding between "foo begin" and "foo end" comments, you could move it into a separate function (with a proper name) and call it from here.
void print_cell_border( ... ) {
...
}
...
{
if(curr_line >= 2 && curr_line + 1 < TERMY) {
print_cell_border( ... );It does not need to be a free function, it could be a lambda.
BevapDin
reviewed
May 5, 2016
| mvwprintz(w_inv, curr_line + 1, 10 + (row_i * 25), fill, it.get_mod_string().c_str()); // Show mod count (if any) | ||
| } | ||
|
|
||
| std::string temp[2]; |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Consider using std::array<std::string, 2> as type instead of a raw array. split_names should accept that one instead of raw pointer. When looking at split_names, one can't see what the pointer is supposed to be, no documentation that it should point to an array with at least 2 elements. Using std::array documents that requirement and triggers a compiler error if the argument don't match that requirement.
BevapDin
reviewed
May 5, 2016
| } | ||
| } | ||
| } | ||
| return rtn; |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
What's the point of unconditionally returning the parameter? The caller already has that value. Returning void should be fine.
BevapDin
reviewed
May 5, 2016
| mvwputch(w_inv, curr_line + 3, x + (row_i * 25), fill, ' '); | ||
| } | ||
| mvwputch(w_inv, curr_line + 3, 26 + (row_i * 25), c_white, LINE_XOXO); | ||
| // End Cell Border Stuff |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
I haven't counted it, but this block ("Cell Border Stuff") seems the be repeated several times. It should go into a function / local lambda.
BevapDin
reviewed
May 5, 2016
| total_height += 2; | ||
|
|
||
| // Then the carried stuff | ||
| for(size_t a = 0; a < inv.size(); a++) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Is the body of this loop a direct copy of the body of the loop above? Why would you do such a thing? Move the code into a function and call it from within both loops.
BevapDin
reviewed
May 5, 2016
| auto const &nc_text = get_item_hp_bar(damage); | ||
| damtext = "<color_" + string_from_color(nc_text.second) + ">" + nc_text.first + " </color>"; | ||
|
|
||
| if(!grid) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
May 5, 2016
Contributor
Out of curiosity: why is the item health bar not added here when in grid view? The code in inventory_ui.cpp seems to add it anyway. This adds quite some dependency between this function and the inventory code.
This comment has been minimized.
This comment has been minimized.
|
Pull Request closed, starting fresh in PR #16632. |



sctjkc01 commentedMay 4, 2016
•
edited
One thing I was interested in doing was creating a new view for the inventory; while it's still very much a work-in-progress as of right now, I was hoping to implement some form of a grid view option for people who have increased the size of their window.
My line of thinking is, people who increase their window / terminal size might see the inventory being paginated, and see an inefficient use of the new width. The game simply prints out two (or three, for multidrop) columns of your gear and calls it good.
I've planned out a grid view, which (hopefully) makes better use of a larger screen width, while still being mostly friendly to the default 80w x 24h. The hope is producing a better* way of seeing one's inventory. The planner I've produced has both 80w x 24h and 128w x 48h (the latter being a 1024x768 resolution) planned; the solid white line indicates where the smaller resolution ends.
( * "better" is subjective, original list view still available )
In addition, I've added a pair of bars, allowing for at-a-glance gauging of how much weight and volume you're carrying.
Thoughts? Concerns? Complements or jeers?
(Additionally, if anyone knows how one could add a single option without breaking compatibility with older saves, I'm all ears; currently I've blindly duplicated the previous enum options, see the edit in cdfb407, options.cpp, but that seems to break saves.)