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

make clause of widget to support displaying global_val #71070

Merged
merged 6 commits into from
Jan 24, 2024
Merged

make clause of widget to support displaying global_val #71070

merged 6 commits into from
Jan 24, 2024

Conversation

PipeYume
Copy link
Contributor

@PipeYume PipeYume commented Jan 19, 2024

Summary

Features "make clause of widget to support displaying global_val and other custom entries"

Purpose of change

Allow widgets to display anything you want to display.

If you have a custom variable and you want to display it in a widget, you just need to use the clause and set parse_tags to true.

At this point, the values such as <global_val:XXX> in the 'text' will be converted to the corresponding text.

Describe the solution

In widget.cpp, add this to allow to parse tags.

        if( wp->should_parse_tags ) {
            parse_tags( txt, get_player_character(), get_player_character() );
        }

Also, in npctalk.cpp, I modify parse_tags function to make it support color tags:
Now, it will not remove the color tags automatically.

Describe alternatives you've considered

None.

Testing

I didn't find where to place a ui test, so I place it here.

[
  {
    "copy-from": "legacy_classic_sidebar",
    "type": "widget",
    "id": "legacy_classic_sidebar",
    "extend": { "widgets": [ "widget_ui_test" ] }
  },
  {
    "id": "widget_ui_test",
    "type": "widget",
    "label": "Test",
    "style": "text",
    "height": 1,
    "clauses": [ { "id": "clause_test", "text": "<global_val:display_text>", "parse_tags": true } ]
  },
  {
    "id": "EOC_widget_ui_test",
    "//": "",
    "type": "effect_on_condition",
    "global": true,
    "recurrence": 1,
    "effect": [
      {
        "if": { "or": [ { "not": { "math": [ "test_count" ] } }, { "math": [ "test_count", ">=", "4" ] } ] },
        "then": { "math": [ "test_count", "=", "0" ] }
      },
      { "math": [ "test_count", "++" ] },
      {
        "switch": { "math": [ "test_count" ] },
        "cases": [
          { "case": 1, "effect": { "set_string_var": "red", "target_var": { "context_val": "color" } } },
          { "case": 2, "effect": { "set_string_var": "white", "target_var": { "context_val": "color" } } },
          { "case": 3, "effect": { "set_string_var": "yellow", "target_var": { "context_val": "color" } } },
          { "case": 4, "effect": { "set_string_var": "green", "target_var": { "context_val": "color" } } }
        ]
      },
      {
        "set_string_var": "<color_white>[<color_<context_val:color>>]<global_val:test_count>[</color>]</color>",
        "target_var": { "global_val": "display_text" },
        "parse_tags": true
      }
    ]
  }
]

It seems like this:
https://github.com/CleverRaven/Cataclysm-DDA/assets/81861009/3b53d41b-8541-460e-bbc7-9ed02d4c073e

Additional context

src/npc.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added <Enhancement / Feature> New features, or enhancements on existing <Documentation> Design documents, internal info, guides and help. NPC / Factions NPCs, AI, Speech, Factions, Ownership Info / User Interface Game - player communication, menus, etc. [C++] Changes (can be) made in C++. Previously named `Code` [Markdown] Markdown issues and PRs labels Jan 19, 2024
@github-actions github-actions bot requested a review from dseguin January 19, 2024 05:57
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @wapcaplet

@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Jan 19, 2024
@PipeYume PipeYume requested a review from Qrox January 19, 2024 07:14
src/npctalk.cpp Show resolved Hide resolved
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Jan 19, 2024
@Maleclypse Maleclypse merged commit 926fcc7 into CleverRaven:master Jan 24, 2024
26 checks passed
@PipeYume PipeYume deleted the WIDGET_VARIABLE branch February 11, 2024 05:38
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 BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` <Documentation> Design documents, internal info, guides and help. <Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants