-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Body Graph UI #57222
Body Graph UI #57222
Conversation
For body parts (not sub parts) the protection values are an average. Might be a decent idea to add "average" just for them. |
You can mirror the ASCII art at runtime instead of re-drawing it in JSON quick and dirty deferred POCdiff --git a/data/json/bodypart_graphs/arms.json b/data/json/bodypart_graphs/arms.json
index 25fab8d52e..f0067f8415 100644
--- a/data/json/bodypart_graphs/arms.json
+++ b/data/json/bodypart_graphs/arms.json
@@ -5,28 +5,7 @@
"parent_bodypart": "arm_r",
"fill_sym": "#",
"fill_color": "white",
- "rows": [
- " ",
- " 11111 ",
- " 11111111 ",
- " 111111111 ",
- " 111111111 ",
- " 211111111 ",
- " 2222221111 ",
- " 2222222211 ",
- " 444 2222222222 ",
- " 444444 2222222222 ",
- " 444444444 22222222222 ",
- " 444444444444 22222222222 ",
- " 4444444444444422222222222 ",
- " 444444444442222222222 ",
- " 444444443333322222 ",
- " 444333333322 ",
- " 3333333 ",
- " 33 ",
- " ",
- " "
- ],
+ "mirror" : "arm_l",
"parts": {
"1": { "sub_body_parts": [ "arm_shoulder_r" ], "select_color": "red" },
"2": { "sub_body_parts": [ "arm_upper_r" ], "select_color": "red" },
diff --git a/src/bodygraph.cpp b/src/bodygraph.cpp
index af9763f90f..462b5bbb11 100644
--- a/src/bodygraph.cpp
+++ b/src/bodygraph.cpp
@@ -80,6 +80,8 @@ void bodygraph::load( const JsonObject &jo, const std::string & )
rows.emplace_back( row );
}
}
+ } else if( !was_loaded || jo.has_string( "mirror" ) ) {
+ mirror = jo.get_string( "mirror" );
}
if( !was_loaded || jo.has_object( "parts" ) ) {
@@ -344,6 +346,15 @@ void bodygraph_display::draw_graph()
{
werase( w_graph );
const bodygraph_part *selected_graph = std::get<2>( partlist[sel_part] );
+
+ auto const &all = bodygraph_full_body->get_all();
+ bool const mirror = !id->mirror.empty();
+ auto const it =
+ !mirror ? all.cend()
+ : std::find_if( all.cbegin(), all.cend(), [&]( decltype( *all.cbegin() ) &el ) {
+ return el.id->id.str() == id->mirror;
+ } );
+
std::string selected_sym;
if( !!selected_graph ) {
for( const auto &bgp : id->parts ) {
@@ -352,22 +363,27 @@ void bodygraph_display::draw_graph()
}
}
}
- for( unsigned i = 0; i < id->rows.size() && i < BPGRAPH_MAXROWS; i++ ) {
- for( unsigned j = 0; j < id->rows[i].size() && j < BPGRAPH_MAXCOLS; j++ ) {
+ decltype( id->rows ) const &rows = mirror ? it->id->rows : id->rows;
+ int i = 0;
+ for( auto const &row : rows ) {
+ int x = mirror ? row.size() - 1 : 0;
+ for( auto const &col : row ) {
std::string sym = id->fill_sym;
- nc_color col = id->fill_color;
- auto iter = id->parts.find( id->rows[i][j] );
+ nc_color color = id->fill_color;
+ auto iter = id->parts.find( col );
if( iter != id->parts.end() ) {
sym = iter->second.sym;
}
- if( id->rows[i][j] == " " ) {
- col = c_unset;
+ if( col == " " ) {
+ color = c_unset;
sym = " ";
- } else if( id->rows[i][j] == selected_sym ) {
- col = id->parts.at( selected_sym ).sel_color;
+ } else if( col == selected_sym ) {
+ color = id->parts.at( selected_sym ).sel_color;
}
- mvwputch( w_graph, point( j, i ), col, sym );
+ mvwputch( w_graph, point( x, i ), color, sym );
+ x = mirror ? x - 1 : x + 1;
}
+ i++;
}
wnoutrefresh( w_graph );
} Many other transformations can be done the same way. |
Going to be really fun drawing all the mutant parts. |
This is absolutely incredible, can't wait for this, love the ascii art. |
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com> Co-authored-by: Dillon Matchett <dillon.matchett@gmail.com> Co-authored-by: Binrui Dong <brett.browning.dong@gmail.com>
This implementation is simpler, but achieves the same goal. Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>
Co-authored-by: Qrox <qrox@sina.com>
Co-authored-by: Qrox <qrox@sina.com>
Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>
Hopefully this will eventually be how wounds are shown as well. |
I'm wondering if there should be a merger (or at least unification) between this and the medical menu introduced in #54763 due to a fair bit of overlap between the two; in my opinion, it doesn't really make sense to keep this as two separate displays. (Reasons against merging them could be just down to personally preference on wanting / not wanting a large ascii art diagram for whatever a player is currently doing.) I also wonder if the ascii art should be hidden or represented in text based on if |
Almost certainly the two will be integrated, but it might wait until after the wounds overhaul in 0.H-experimental. |
* Body Graph: new jsonized body_graph objects * Body Graph: basic UI functionality + full body and head graphs * Body Graph: torso graph * Body Graph: arm graphs * Body Graph: hand graphs * Body Graph: leg graphs * Body Graph: foot graphs * info construction works * Body Graph: display armor data in right pane * Body Graph: apply suggestions from code review Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com> Co-authored-by: Dillon Matchett <dillon.matchett@gmail.com> Co-authored-by: Binrui Dong <brett.browning.dong@gmail.com> * Body Graph: mirror opposite graphs as suggested by andrei8l This implementation is simpler, but achieves the same goal. Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com> * Body Graph: extract strings and update documentation * Body Graph: use border_helper to draw window borders Co-authored-by: Qrox <qrox@sina.com> * Body Graph: only init windows from resize call Co-authored-by: Qrox <qrox@sina.com> * Body Graph: apply suggestions from code review Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com> Co-authored-by: bombasticSlacks <dillon.matchett@gmail.com> Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com> Co-authored-by: Binrui Dong <brett.browning.dong@gmail.com> Co-authored-by: Qrox <qrox@sina.com>
Summary
None
Alternative summary: "Data driven body graphs"
Purpose of change
I really wanted to create some infrastructure for creating cool interactive body diagrams in ascii art. This includes a new UI for viewing body part status info.
Describe the solution
2022-04-28.04-16-57.mp4
JSON data
I've added a new JSON data type
"body_graph"
:Each entry in
"parts"
can also define a"nested_graph"
field which points to another body_graph, so when the player selects that part they are taken to the nested graph.See the updated documentation for more details about these fields.
Body Graph UI
I created a new UI accessible from the
@
menu (uses thes
hotkey by default):This UI shows the player's body in graph form using the body_graph objects. Each main body part has a nested graph that leads to a detailed view of its sub parts.
Currently the UI is used to show equipment stats for that body part in the right pane. (The right info pane was only possible thanks to @bombasticSlacks!)
Describe alternatives you've considered
Stay in the past, with boring text.
Testing
See video and screenshots.
Additional context
TODO: