From 34762ceb81f8799bc4078c3425ccc124990ef06f Mon Sep 17 00:00:00 2001 From: Sjoerd de Bruin Date: Thu, 20 Aug 2026 19:11:30 +0200 Subject: [PATCH] Fix #25558: plugin buttons ignore an explicitly set border (#26925) Themes that draw borders around image buttons also added one to buttons created by plugins, even when the script had explicitly asked for no border. --- distribution/changelog.txt | 1 + src/openrct2-ui/scripting/CustomWindow.cpp | 17 ++++++++++++----- src/openrct2-ui/scripting/ScWidget.hpp | 18 +++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 222c5dc35e..6b43859ced 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Fix: [#21632] [Plugin] Crash when loading custom image larger than 300 by 300 pixels. - Fix: [#25169] The convert command strips custom objects from the resulting park. - Fix: [#25496] The guest pickup button does not grey out when the guest’s state changes while the window is open. +- Fix: [#25558] [Plugin] Image buttons ignore their explicit border setting when a theme draws borders around them. - Fix: [#26811] Crash when a ride points to a non-existing station object. - Fix: [#26816] Water rides ignore zero clearances, preventing adjacent terrain modifications and building them anywhere. - Fix: [#26880] Max negative G-Force stat on flat track erroneously reads as 0.49g. diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 357d2ce4b6..221f92be9d 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -74,7 +74,7 @@ namespace OpenRCT2::Ui::Windows bool IsDisabled{}; bool IsVisible{}; bool IsPressed{}; - bool HasBorder{}; + std::optional HasBorder; bool ShowColumnHeaders{}; bool IsStriped{}; bool CanSelect{}; @@ -105,12 +105,10 @@ namespace OpenRCT2::Ui::Windows if (JS_IsString(jsImage) || JS_IsNumber(jsImage)) { result.Image = ImageId(ImageFromJSValue(ctx, jsImage)); - result.HasBorder = false; } else { result.Text = AsOrDefault(ctx, desc, "text", ""); - result.HasBorder = true; } JS_FreeValue(ctx, jsImage); result.IsPressed = AsOrDefault(ctx, desc, "isPressed", false); @@ -191,7 +189,12 @@ namespace OpenRCT2::Ui::Windows result.MaxLength = AsOrDefault(ctx, desc, "maxLength", 32); result.OnChange = JSToCallback(ctx, desc, "onChange"); } - result.HasBorder = AsOrDefault(ctx, desc, "border", result.HasBorder); + JSValue jsBorder = JS_GetPropertyStr(ctx, desc, "border"); + if (JS_IsBool(jsBorder)) + { + result.HasBorder = JS_ToBool(ctx, jsBorder) > 0; + } + JS_FreeValue(ctx, jsBorder); return result; } }; @@ -963,7 +966,11 @@ namespace OpenRCT2::Ui::Windows { if (desc.Image.HasValue()) { - widget.type = desc.HasBorder ? WidgetType::imgBtn : WidgetType::flatBtn; + // When the border is not specified, flatBtn lets the theme decide whether to draw one. + if (!desc.HasBorder.has_value()) + widget.type = WidgetType::flatBtn; + else + widget.type = *desc.HasBorder ? WidgetType::imgBtn : WidgetType::hiddenButton; widget.image = desc.Image; } else diff --git a/src/openrct2-ui/scripting/ScWidget.hpp b/src/openrct2-ui/scripting/ScWidget.hpp index 5ff2761b12..4a658d5891 100644 --- a/src/openrct2-ui/scripting/ScWidget.hpp +++ b/src/openrct2-ui/scripting/ScWidget.hpp @@ -557,6 +557,11 @@ namespace OpenRCT2::Scripting } private: + static bool isImageButton(WidgetType type) + { + return type == WidgetType::flatBtn || type == WidgetType::imgBtn || type == WidgetType::hiddenButton; + } + static JSValue border_get(JSContext* ctx, JSValue thisVal) { auto widget = GetWidget(thisVal); @@ -571,12 +576,10 @@ namespace OpenRCT2::Scripting JS_UNPACK_BOOL(valueBool, ctx, value); auto widget = GetWidget(thisVal); - if (widget != nullptr && (widget->type == WidgetType::flatBtn || widget->type == WidgetType::imgBtn)) + if (widget != nullptr && isImageButton(widget->type)) { - if (valueBool) - widget->type = WidgetType::imgBtn; - else - widget->type = WidgetType::flatBtn; + // hiddenButton rather than flatBtn, so that themes do not draw a border anyway. + widget->type = valueBool ? WidgetType::imgBtn : WidgetType::hiddenButton; Invalidate(thisVal); } return JS_UNDEFINED; @@ -610,7 +613,7 @@ namespace OpenRCT2::Scripting static JSValue image_get(JSContext* ctx, JSValue thisVal) { auto widget = GetWidget(thisVal); - if (widget != nullptr && (widget->type == WidgetType::flatBtn || widget->type == WidgetType::imgBtn)) + if (widget != nullptr && isImageButton(widget->type)) { if (GetTargetAPIVersion() <= kApiVersionG2Reorder) { @@ -624,7 +627,7 @@ namespace OpenRCT2::Scripting static JSValue image_set(JSContext* ctx, JSValue thisVal, JSValue value) { auto widget = GetWidget(thisVal); - if (widget != nullptr && (widget->type == WidgetType::flatBtn || widget->type == WidgetType::imgBtn)) + if (widget != nullptr && isImageButton(widget->type)) { widget->image = ImageId(ImageFromJSValue(ctx, value)); Invalidate(thisVal); @@ -1145,6 +1148,7 @@ namespace OpenRCT2::Scripting case WidgetType::button: case WidgetType::flatBtn: case WidgetType::imgBtn: + case WidgetType::hiddenButton: ScButtonWidget::AddFuncs(ctx, newObj); break; case WidgetType::checkbox: