-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Rewrite and migrate V
menu to ImGui
#55503
base: master
Are you sure you want to change the base?
Conversation
b7854a4
to
121194d
Compare
121194d
to
b52ac09
Compare
05357ce
to
0bf3591
Compare
This pull request introduces 3 alerts when merging 0bf3591 into f889ed9 - view on LGTM.com new alerts:
|
0bf3591
to
cb976c3
Compare
This pull request introduces 3 alerts when merging cb976c3 into d055515 - view on LGTM.com new alerts:
|
cb976c3
to
218a9a1
Compare
d39553d
to
8c02583
Compare
This pull request introduces 1 alert when merging 8c02583 into 158205f - view on LGTM.com new alerts:
|
590cff8
to
9e5eeb2
Compare
4618af9
to
a73ed64
Compare
This pull request introduces 1 alert when merging 45e8b1e into 07d8e66 - view on LGTM.com new alerts:
|
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. |
Do we have a 'salvageable' label for PRs? |
I think I just need to ask a maintainer to reopen it when I continue working on it. |
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. |
V
menuV
menu to ImGui
de4d48d
to
d71a221
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that you’re not finished yet, but I like what you’re doing and want to help you get it right. Here are a few comments about things that I noticed as I read the code.
src/surroundings_menu.cpp
Outdated
std::string text; | ||
if( it->entities.size() > 1 ) { | ||
text = string_format( "[%d/%d] (%d) ", it->get_selected_index() + 1, it->entities.size(), | ||
it->totalcount ); | ||
} | ||
|
||
const int count = it->get_selected_count(); | ||
if( count > 1 ) { | ||
text += string_format( "%d ", count ); | ||
} | ||
|
||
text += itm->display_name( count ); | ||
nc_color color = it->get_selected_entity()->color_in_inventory(); | ||
cataimgui::draw_colored_text( text, color ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of allocating a string and appending a bunch of things to it (which can cause reallocation) before finally drawing the string, it would be better to simply call ImGui::Text
, ImGui::TextUnformatted
, or cataimgui::draw_colored_text
for each element individually. You can arrange multiple items on the same line by calling ImGui::SameLine(0, 0)
. Remember that all of this happens on every frame, so it’s best to avoid allocation.
const Character &you = get_player_character(); | ||
const bool inattentive = you.has_trait( trait_INATTENTIVE ); | ||
bool sees = mon->sees( you ) && !inattentive; | ||
cataimgui::draw_colored_text( sees ? "!" : " ", c_yellow ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When possible, prefer to just call ImGui::TextColored
instead, as it does less work than cataimuig::draw_colored_text
.
if( bar_width < bar_max_width ) { | ||
hp_text += "<color_c_white>"; | ||
for( int i = bar_max_width - bar_width; i > 0; i-- ) { | ||
hp_text += "."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to just call ImGui::TextUnformatted
in a loop than to repeatedly append to a string.
cataimgui::draw_colored_text( att_text, att_color ); | ||
|
||
ImGui::TableNextColumn(); | ||
std::string dist_text = get_distance_string( tripoint_rel_ms(), *it->get_selected_pos() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for the distance or HP of the monster to change between frames here? I believe the game is paused while in this view, so they cannot. It would be really great then if you could store the formatted distance string and HP bar on the map_entity
so that you only have to compute them once.
I assume the same applies to all entity types, so I won't call them out individually
switch( selected_tab ) { | ||
case surroundings_menu_tab_enum::items: | ||
item_data.selected_entry->select_next(); | ||
break; | ||
case surroundings_menu_tab_enum::monsters: | ||
monster_data.selected_entry->select_next(); | ||
break; | ||
case surroundings_menu_tab_enum::terfurn: | ||
terfurn_data.selected_entry->select_next(); | ||
break; | ||
default: | ||
debugmsg( "invalid tab selected" ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and every other method here seem very verbose and duplicative. Perhaps something like this would be better:
tab_data list;
switch( selected_tab ) {
case surroundings_menu_tab_enum::items:
list = item_data;
break;
case surroundings_menu_tab_enum::monsters:
list = monster_data;
break;
case surroundings_menu_tab_enum::terfurn:
list = terfurn_data;
break;
default:
debugmsg( "invalid tab selected" );
}
list.selected_entry->select_next();
They could be shortened further by putting the switch into a common method, perhaps called get_currently_selected_list
. Then it would just be:
get_currently_selected_list().selected_entry->select_next();
Yeah, it's still very WIP, but that's good feedback! |
29b141c
to
ee28e11
Compare
Summary
Infrastructure "Rewrite and migrate V menu to ImGui"
Purpose of change
Migrate to ImGui and increase maintainability and expandability.
Describe the solution
Completely remake everything using ImGui.
Structurally this is heavily reliant on code I wrote when I started this before ImGui two years ago. It might be a good idea to refactor some of that, but for now I mostly want to get it functional.
Describe alternatives you've considered
There is no alternative (except for implementation details).
Testing
Press
V
and play around with it.Additional context
Currently wip. Some basic functionality is implemented, so interested people can check it out and give feedback. The terrain/furniture tab won't be a part of the final version of this PR but is going to be added in another one.