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

Expose progress bar widget to scripting #22069

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

Gymnasiast
Copy link
Member

@Gymnasiast Gymnasiast commented May 20, 2024

Todo:

  • Testing
  • Updating openrct2.d.ts
  • Move bitshifting/masking to functions/methods
  • Does colour need to be exposed manually, or is that part of the default specs already (like size and position is)?

@ltsSmitty
Copy link
Contributor

I also started working on this, so I appreciate it. I'm not sure how to piggyback on this draft but I've got some additional work done.

  • I'm not sure it makes sense to use text for the value since it's numerical; I'm thinking to use progress instead.
  • There's also work to be done in CustomWindow.cpp, which handles binding the onChange and the other things to the custom widgetDesc.

Would you like me to contribute to this or are you gonna keep working?

@Gymnasiast
Copy link
Member Author

Gymnasiast commented May 20, 2024

I also started working on this, so I appreciate it. I'm not sure how to piggyback on this draft but I've got some additional work done.

* I'm not sure it makes sense to use `text` for the value since it's numerical; I'm thinking to use `progress` instead.

* There's also work to be done in CustomWindow.cpp, which handles binding the onChange and the other things to the custom widgetDesc.

Would you like me to contribute to this or are you gonna keep working?

I hardly know what I’m doing, so I would like to pick the former. I’ll see if I can give you rights to write to this branch.

Edit: I have now given you access. Feel free to modify the code I already added as you see fit.

@Gymnasiast Gymnasiast added the changelog This issue/PR deserves a changelog entry. label May 20, 2024
Copy link
Contributor

@Sadret Sadret left a comment

Choose a reason for hiding this comment

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

@@ -4277,11 +4277,11 @@ declare global {
*/
type WidgetType =
"button" | "checkbox" | "colourpicker" | "custom" | "dropdown" | "groupbox" |
"label" | "listview" | "spinner" | "textbox" | "viewport";
"label" | "listview" | "spinner" | "textbox" | "viewport" | "progress_bar";
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be alphabetically ordered.
To follow the naming convention, it should be called progressbar.


type Widget =
ButtonWidget | CheckboxWidget | ColourPickerWidget | CustomWidget | DropdownWidget | GroupBoxWidget |
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget;
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget | ProgressBarWidget;
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

@@ -4363,6 +4363,21 @@ declare global {
textAlign: TextAlignment;
}

interface ProgressBarWidget extends WidgetBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Alphabetical order. Note that SortOrder is just a helper for list view.

/**
* The percentage of the bar to fill, ranging from 0-100 (inclusive).
*/
percentage: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

For the API I would prefer a fraction between 0 and 1, but I see that it is a percentage internally, so I'm fine with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree standardization is key here. The only existing use of percent in the api is for ride downtime, which is represented from 0-100. I'm in favor of keeping that structure for now.

distribution/openrct2.d.ts Outdated Show resolved Hide resolved
* Used to specify a range of values between which the bar will start blinking.
* Set both of these to the same value to disable blinking entirely.
* The range is inclusive.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This mechanism is weird. Doesn't setting to -1 and 101 also mean there is no blinking? Anyways, I would suggest null values to hide the implementation details.

Copy link
Member Author

Choose a reason for hiding this comment

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

You cannot set it to -1, it’s an unsigned integer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. What about 0? Then an empty bar would blink, but you cannot see that :P
But again, I would prefer null values in both getter and setter.

@Sadret
Copy link
Contributor

Sadret commented May 20, 2024

Todo: Create ProgressBarDesc and add it to WidgetDesc in the docs.

widget.type = WindowWidgetType::ProgressBar;
if (desc.IsDisabled)
{
widget.colour = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure what to do for disabled state, so I went ahead and set it to white and not blinking. Some screenshots of my attempts are in discord.

Copy link
Contributor

Choose a reason for hiding this comment

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

after all the feedback, decided to just remove any isDisabled functionality and leave it up to the implementer to do, whether they want to recolor, hide, etc.

@ltsSmitty
Copy link
Contributor

Here's a simple plugin to see the capabilities.

(function(){'use strict';
var startup = function () {
    if (typeof ui !== "undefined") {
        var menuItemName = "Progress Bar";
        ui.registerMenuItem(menuItemName, open);
    }
};
var open = function () {
    ui.openWindow(windowDesc);
};
var windowDesc = {
    title: "Progress Bar",
    width: 200,
    height: 120,
    colours: [1, 1],
    widgets: [
        {
            type: "progressbar",
            width: 150,
            height: 20,
            x: 10,
            y: 25,
            colour: 30,
            percentage: 90,
            lowerBlinkBound: 80,
            upperBlinkBound: 20
        },
        {
            type: "progressbar",
            width: 100,
            height: 10,
            x: 10,
            y: 70,
            colour: 7,
            percentage: 80,
            lowerBlinkBound: 67,
            upperBlinkBound: 100
        },
        {
            type: "progressbar",
            width: 100,
            height: 10,
            x: 10,
            y: 90,
            colour: 50,
            percentage: 10,
            isDisabled: true
        }
    ],
    classification: "test"
};
registerPlugin({
    name: "Progress Bar Test",
    version: "1.0",
    authors: ["ltsSmitty"],
    type: "remote",
    licence: "MIT",
    targetApiVersion: 70,
    main: startup,
});})();

@mrmagic2020
Copy link
Contributor

Tested the implementation in my plugin and it seems to work fine. Do note that ProgressBarDesc is missing in type WidgetDesc in the API reference. See: https://github.com/OpenRCT2/OpenRCT2/blob/bbb5b92610dbffef1fce680f6948830c08ef9d91/distribution/openrct2.d.ts#L4448C18

Copy link
Contributor

@Sadret Sadret left a comment

Choose a reason for hiding this comment

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

Looks good, but I would still strongly prefer null values for the blink bounds.


type Widget =
ButtonWidget | CheckboxWidget | ColourPickerWidget | CustomWidget | DropdownWidget | GroupBoxWidget |
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget;
LabelWidget | ListViewWidget |ProgressBarWidget | SpinnerWidget | TextBoxWidget | ViewportWidget;
Copy link
Contributor

Choose a reason for hiding this comment

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

space between | and ProgressBarWidget

uint8_t LowerBlinkBound{}; // progress bar blink when below
uint8_t UpperBlinkBound{}; // progress bar blink when above
uint8_t LowerBlinkBound{}; // progress bar will blink when above the lower bound
uint8_t UpperBlinkBound{}; // and below upper bound
Copy link
Contributor

@Sadret Sadret May 21, 2024

Choose a reason for hiding this comment

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

Wait, what? I thought it was below the lower bound or above the upper bound.

But this way it also makes sense. It's just a bit weird that you cannot make it blink at only one value though: Both bounds are inclusive, but if both are the same, blinking is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it's a bit unintuitive. I'll make a note in the .d.ts that the bar will blink when the percentage is between the upper and lower bound values, which I think will clear it up a bit. And I think this confirms keeping a strictly numerical value instead of using null.

Comment on lines +4406 to +4411
/**
* Used to specify a range of values between which the bar will start blinking.
* The bar will blink when lowerBlinkBound <= percentage <= upperBlinkBound.
* Set both upper and lower bounds to the same value to disable blinking.
*/
lowerBlinkBound: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

@Sadret how about this for the description?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ltsSmitty Wouldn’t it be better to make it blink below the lower bound or above the upper bound? I imagine people would normally want the bar to blink either when the value is too low or too high. And if the higher bound is set lower than the lower bound, the bar can blink if the value is in between.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ltsSmitty This description seems fine.

@mrmagic2020 I agree that it would make more sense; I can imagine more use cases where you want it to blink when the value is very low or very high than cases where you want it to blink in the middle but not at the extreme cases. The problem is that the progress bar widget does not support it, so we would have to rewrite that one, too. That's possible and actually probably not too much work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog This issue/PR deserves a changelog entry.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants