diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 22030b4a60..d4869fde9a 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -339,6 +339,7 @@ declare global { } interface ButtonWidget extends Widget { + image: number; text: string; onClick: () => void; } diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 27525ed3e2..4dd1756ec1 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -93,6 +93,7 @@ namespace OpenRCT2::Ui::Windows int32_t Width{}; int32_t Height{}; std::string Name; + ImageId Image; std::string Text; std::vector Items; int32_t SelectedIndex{}; @@ -136,13 +137,24 @@ namespace OpenRCT2::Ui::Windows result.Y = desc["y"].as_int(); result.Width = desc["width"].as_int(); result.Height = desc["height"].as_int(); + if (desc["isDisabled"].type() == DukValue::Type::BOOLEAN) + result.IsDisabled = desc["isDisabled"].as_bool(); if (desc["name"].type() == DukValue::Type::STRING) { result.Name = desc["name"].as_string(); } if (result.Type == "button") { - result.Text = ProcessString(desc["text"]); + auto dukImage = desc["image"]; + if (dukImage.type() == DukValue::Type::NUMBER) + { + auto img = dukImage.as_uint(); + result.Image = ImageId::FromUInt32(img); + } + else + { + result.Text = ProcessString(desc["text"]); + } result.OnClick = desc["onClick"]; } else if (result.Type == "checkbox") @@ -518,9 +530,17 @@ namespace OpenRCT2::Ui::Windows if (desc.Type == "button") { - widget.type = WWT_BUTTON; - widget.string = (utf8*)desc.Text.c_str(); - widget.flags |= WIDGET_FLAGS::TEXT_IS_STRING; + if (desc.Image.HasValue()) + { + widget.type = WWT_FLATBTN; + widget.image = desc.Image.ToUInt32(); + } + else + { + widget.type = WWT_BUTTON; + widget.string = (utf8*)desc.Text.c_str(); + widget.flags |= WIDGET_FLAGS::TEXT_IS_STRING; + } widgetList.push_back(widget); } else if (desc.Type == "checkbox") diff --git a/src/openrct2-ui/scripting/ScWidget.hpp b/src/openrct2-ui/scripting/ScWidget.hpp index 3a43538db2..b6aff6d54d 100644 --- a/src/openrct2-ui/scripting/ScWidget.hpp +++ b/src/openrct2-ui/scripting/ScWidget.hpp @@ -206,12 +206,33 @@ namespace OpenRCT2::Scripting } } + uint32_t image_get() + { + if (IsCustomWindow()) + { + auto widget = GetWidget(); + if (widget != nullptr && widget->type == WWT_FLATBTN) + { + return widget->image; + } + } + return 0; + } + void image_set(uint32_t value) + { + auto widget = GetWidget(); + if (widget != nullptr && widget->type == WWT_FLATBTN) + { + widget->image = value; + } + } + std::string text_get() { if (IsCustomWindow()) { auto widget = GetWidget(); - if (widget != nullptr && widget->string != nullptr) + if (widget != nullptr && (widget->flags & WIDGET_FLAGS::TEXT_IS_STRING) && widget->string != nullptr) { return widget->string; } @@ -253,6 +274,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScWidget::isDisabled_get, &ScWidget::isDisabled_set, "isDisabled"); // No so common + dukglue_register_property(ctx, &ScWidget::image_get, &ScWidget::image_set, "image"); dukglue_register_property(ctx, &ScWidget::text_get, &ScWidget::text_set, "text"); dukglue_register_property(ctx, &ScWidget::isChecked_get, &ScWidget::isChecked_set, "isChecked"); dukglue_register_property(ctx, &ScWidget::viewport_get, nullptr, "viewport");