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

Rewrite and migrate V menu to ImGui #55503

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mqrause
Copy link
Contributor

@mqrause mqrause commented Feb 19, 2022

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.

@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Feb 19, 2022
@mqrause mqrause force-pushed the vmenu_rewrite branch 7 times, most recently from b7854a4 to 121194d Compare February 19, 2022 07:57
@NetSysFire NetSysFire added <Enhancement / Feature> New features, or enhancements on existing [C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. labels Feb 19, 2022
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 19, 2022
@mqrause mqrause force-pushed the vmenu_rewrite branch 2 times, most recently from 05357ce to 0bf3591 Compare February 20, 2022 10:12
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 20, 2022
@lgtm-com
Copy link

lgtm-com bot commented Feb 20, 2022

This pull request introduces 3 alerts when merging 0bf3591 into f889ed9 - view on LGTM.com

new alerts:

  • 3 for Empty branch of conditional

@lgtm-com
Copy link

lgtm-com bot commented Feb 21, 2022

This pull request introduces 3 alerts when merging cb976c3 into d055515 - view on LGTM.com

new alerts:

  • 2 for Constant return type on member
  • 1 for Empty branch of conditional

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 21, 2022
@mqrause mqrause force-pushed the vmenu_rewrite branch 2 times, most recently from d39553d to 8c02583 Compare February 21, 2022 10:49
@lgtm-com
Copy link

lgtm-com bot commented Feb 21, 2022

This pull request introduces 1 alert when merging 8c02583 into 158205f - view on LGTM.com

new alerts:

  • 1 for Empty branch of conditional

@mqrause mqrause force-pushed the vmenu_rewrite branch 2 times, most recently from 590cff8 to 9e5eeb2 Compare February 25, 2022 15:02
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 25, 2022
@mqrause mqrause force-pushed the vmenu_rewrite branch 2 times, most recently from 4618af9 to a73ed64 Compare February 25, 2022 19:13
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 16, 2022
@mqrause mqrause force-pushed the vmenu_rewrite branch 2 times, most recently from d1771c6 to 2b47cda Compare August 16, 2022 07:18
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 16, 2022
@lgtm-com
Copy link

lgtm-com bot commented Aug 16, 2022

This pull request introduces 1 alert when merging 2b47cda into 07d8e66 - view on LGTM.com

new alerts:

  • 1 for Comparison result is always the same

@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 16, 2022
@lgtm-com
Copy link

lgtm-com bot commented Aug 16, 2022

This pull request introduces 1 alert when merging 45e8b1e into 07d8e66 - view on LGTM.com

new alerts:

  • 1 for Comparison result is always the same

@stale
Copy link

stale bot commented Sep 21, 2022

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 Sep 21, 2022
@github-actions github-actions bot closed this Dec 6, 2022
@Zireael07
Copy link
Contributor

Do we have a 'salvageable' label for PRs?

@mqrause
Copy link
Contributor Author

mqrause commented Dec 6, 2022

I think I just need to ask a maintainer to reopen it when I continue working on it.

@Night-Pryanik Night-Pryanik reopened this Dec 6, 2022
@github-actions github-actions bot removed the stale Closed for lack of activity, but still valid. label Dec 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2023

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.

@github-actions github-actions bot added the stale Closed for lack of activity, but still valid. label Jan 5, 2023
@Night-Pryanik Night-Pryanik added (P5 - Long-term) Long-term WIP, may stay on the list for a while. and removed stale Closed for lack of activity, but still valid. labels Jan 5, 2023
@mqrause mqrause changed the title [CR] Rewrite and expand the V menu Rewrite and migrate V menu to ImGui Mar 11, 2024
This was referenced May 1, 2024
Copy link
Contributor

@db48x db48x left a 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.

Comment on lines +542 to +555
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 );
Copy link
Contributor

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 );
Copy link
Contributor

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 += ".";
Copy link
Contributor

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() );
Copy link
Contributor

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

Comment on lines +1116 to +1128
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" );
}
Copy link
Contributor

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();

@mqrause
Copy link
Contributor Author

mqrause commented Sep 6, 2024

Yeah, it's still very WIP, but that's good feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tooling Tooling that is not part of the main game but is part of the repo. <Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions (P5 - Long-term) Long-term WIP, may stay on the list for a while.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants