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

Add data-driven moddable sidebar widgets #44683

Merged
merged 7 commits into from
Aug 11, 2021

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented Oct 7, 2020

Summary

Features "Add data-driven moddable sidebar widgets"

Purpose of change

The right sidebar has a number of usability problems. Customizing it requires editing some rather convoluted and finicky panel.cpp code, which makes people (at least me) disinclined to try and improve them.

But possibly the biggest problem with the right sidebar panels is how hard-coded they often are. Making the description and layout of the sidebar more data-driven will:

  • make it easier to mod
  • allow more rapid prototyping of sidebar layouts
  • allow showing debug information that is not normally available to the player

Describe the solution

Define a new widget class implementing JSON objects of type "widget", that can display:

  • numeric values ("Focus: 120")
  • graph of symbols (||..., ||\.. and so on)

Connect these widgets to avatar attributes (HP, pain, thirst etc.) to allow generalized sidebar customization with JSON, and recreation of the existing sidebar info in data-driven form.

  • Write documentation first, as a wishlist
  • Add JSON equivalent for some major existing sidebar features
  • Add test cases for widget JSON loading and correct rendering
  • Implement widget class using generic_factory
  • Add graphing function(s)
  • Add data-source connector function(s)
  • Add colorization support (maybe)
  • Add option to use the new sidebar in game
  • Add a bunch more tests using show and layout with an avatar

The } sidebar configuration menu now includes a "Custom" section that may be added to any of the four layouts (both wide and narrow). For now, this section displays only basic info, similar to the existing builtin sidebars - HP for each body part, stamina, speed, focus, movement, sound, fatigue, STR, DEX, INT, and PER.

Describe alternatives you've considered

This is pull request 1 of 2 or more. Here is the initial implementation and demonstration of concepts; it is entirely playable, though not intended as a final "production" draft.

Future PRs will build on this foundation to make it a more complete solution for information display to the player. I hope it can eventually be used to phase out the hard-coded sidebar.

Continued in #47620

Testing

Unit tests can be run with tests/cata_test '[sidebar],[widget]'

In-game, use the } sidebar configurator to enable the Custom section.

Edit data/json/sidebar.json to customize it however you like.

Additional context

Example of default "Custom" sidebar in "labels" layout mode:

image

And in "labels-narrow" layout mode:

image

@Night-Pryanik
Copy link
Contributor

Related issue: #23079.

@I-am-Erk
Copy link
Member

I-am-Erk commented Oct 7, 2020

Food for thought while you're digging around in here, I would love to be able to define tiles instead of ascii characters for the sidebar. I can tell you more about my ideas if you like

@wapcaplet wapcaplet force-pushed the w-sidebar-json branch 2 times, most recently from 863b9dd to a810a5e Compare October 11, 2020 19:32
@wapcaplet wapcaplet marked this pull request as ready for review October 11, 2020 19:33
@wapcaplet wapcaplet added <Enhancement / Feature> New features, or enhancements on existing Controls / Input Keyboard, mouse, keybindings, input UI, etc. Info / User Interface Game - player communication, menus, etc. and removed Controls / Input Keyboard, mouse, keybindings, input UI, etc. labels Oct 11, 2020
@wapcaplet
Copy link
Contributor Author

This will remain in WIP, probably until after 0.F, since it is a significant new feature. But I have taken off the "Draft" status - this is essentially complete and working now (with tests and documentation), well enough for others to test and review it (please do!)

@jbytheway
Copy link
Contributor

You have some clang-tidy issues to deal with.

@stale
Copy link

stale bot commented Dec 8, 2020

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 Dec 8, 2020
@wapcaplet wapcaplet removed the stale Closed for lack of activity, but still valid. label Dec 9, 2020
@Raikiri
Copy link

Raikiri commented Dec 18, 2020

There's unreasonable amount of wasted space there, especially on small phone screens. I really hope that with this we could make an essentials-only version for compact view.

@wapcaplet
Copy link
Contributor Author

This PR is functionally complete and playable as-is; aside from some clang-tidy cleanup and occasional rebasing to keep it in sync until after 0.F, I don't plan to expand it further here.

In short, I am tying a knot on this PR and have opened #47620 for further enhancements.

@wapcaplet wapcaplet force-pushed the w-sidebar-json branch 3 times, most recently from d297625 to bc57a71 Compare February 23, 2021 02:56
@wapcaplet wapcaplet marked this pull request as ready for review March 1, 2021 20:45
@wapcaplet wapcaplet changed the title [WIP][CR] Add data-driven moddable sidebar Add data-driven moddable sidebar widgets Mar 1, 2021
@wapcaplet
Copy link
Contributor Author

wapcaplet commented Mar 17, 2021

Reconsidering the large size of this PR, I am thinking of breaking it up somewhat:

  • Widget class: ~500 lines
  • Documentation: ~300 lines
  • Tests and test data: ~500 lines
  • In-game sidebar panel: ~500 lines (mostly JSON)

The in-game panel provided with this PR is rudimentary, hardly more than a demo, and only work on wide sidebar layouts. So I am once again putting this back to DRAFT state, and may end up closing this PR entirely in favor of a new set of cleaner submissions. Thanks for playing!

The initial version of the sidebar remains rudimentary (see screenshots) but the commits are fairly clean (rebased many times) so I think this is finally good to go.

This commit adds a `widget` class for rendering a UI view of some
internal value or status variable of an `avatar` (player character).
It includes a generic factory wrapper to load widgets from JSON.

widget_var for linking avatar attributes to widgets:
- focus, move, pain, speed, stamina, stats, HP per bodypart and more

widget class to render avatar variables in UI with labels and layout:
- uses generic_factory to load JSON from widget types
- JSON: id, label, style, var, colors, symbols, width, fill, etc.
- show() to render widget value from avatar instance
- layout() to arrange widgets and do max width padding/alignment
- get_var_value() to return avatar's current "var" value
- color_value_string() to render value with colors
- supporting: value_color(), value_string(), graph(), num()
Build on the data-driven sidebar `widget` class, defining a collection
of numeric and graph display elements, including familiar as well as new
informational displays:

- HP bar graphs for each body part, in familiar `|||||` form
- Classic and extended (10-character) stamina graph
- Numeric indicators for sound, focus, pain, moves, str, dex, int, per
- Encumbrance bar graphs for each body part
- Warmth numbers for each body part
- Wide and Narrow root layouts with basic info
Add a "Custom" sidebar section that can be toggled on for each
sidebar layout (classic/labels and narrow/compact), loading from the
"root_layout_wide" or "root_layout_narrow" widget.
Overview and technical docs on using the custom sidebar widgets
@ZhilkinSerg
Copy link
Contributor

Works fine for me. I think it would make sense to move sidebar.json to a separate folder (e.g. data/json/ui or data/core/ui).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants