-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: develop
Are you sure you want to change the base?
Expose progress bar widget to scripting #22069
Conversation
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.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start, but there is still a lot of implementation to do, see e.g.
https://github.com/OpenRCT2/OpenRCT2/blob/develop/src/openrct2-ui/scripting/ScWidget.hpp#L69
https://github.com/OpenRCT2/OpenRCT2/blob/develop/src/openrct2-ui/scripting/CustomWindow.cpp#L93
https://github.com/OpenRCT2/OpenRCT2/blob/develop/src/openrct2-ui/scripting/CustomWindow.cpp#L942
and maybe other places.
Edit: Didn't see your discussion until after my review.
distribution/openrct2.d.ts
Outdated
@@ -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"; |
There was a problem hiding this comment.
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
.
distribution/openrct2.d.ts
Outdated
|
||
type Widget = | ||
ButtonWidget | CheckboxWidget | ColourPickerWidget | CustomWidget | DropdownWidget | GroupBoxWidget | | ||
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget; | ||
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget | ProgressBarWidget; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
distribution/openrct2.d.ts
Outdated
@@ -4363,6 +4363,21 @@ declare global { | |||
textAlign: TextAlignment; | |||
} | |||
|
|||
interface ProgressBarWidget extends WidgetBase { |
There was a problem hiding this comment.
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.
distribution/openrct2.d.ts
Outdated
/** | ||
* The percentage of the bar to fill, ranging from 0-100 (inclusive). | ||
*/ | ||
percentage: number; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
* 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. | ||
*/ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Todo: Create |
widget.type = WindowWidgetType::ProgressBar; | ||
if (desc.IsDisabled) | ||
{ | ||
widget.colour = 1; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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,
});})(); |
Tested the implementation in my plugin and it seems to work fine. Do note that |
There was a problem hiding this 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.
distribution/openrct2.d.ts
Outdated
|
||
type Widget = | ||
ButtonWidget | CheckboxWidget | ColourPickerWidget | CustomWidget | DropdownWidget | GroupBoxWidget | | ||
LabelWidget | ListViewWidget | SpinnerWidget | TextBoxWidget | ViewportWidget; | ||
LabelWidget | ListViewWidget |ProgressBarWidget | SpinnerWidget | TextBoxWidget | ViewportWidget; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
/** | ||
* 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Todo: