Expose show/hideGridlines to scripting more safely (#24879)

Co-authored-by: guysv <sviryguy@gmail.com>
This commit is contained in:
Basssiiieandguysv authored and GitHub committed 2026-04-18 03:37:11 +00:00
1 parent efb268af7d
commit ce9470971c
5 files changed
+64 -3

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
0.5.1 (in development)
------------------------------------------------------------------------
- Feature: [#24242] [Plugin] Add ride-breakdown hooktype.
- Feature: [#24879] [Plugin] Add methods for showing and hiding gridlines.
- Fix: [#26352] Large scenery items are incorrectly labelled as 'banners' in the tile inspector.
- Fix: [#26352] The label for path additions is using the wrong text colour in the tile inspector.
- Fix: [#26360] Inverted Lay-down Roller Coaster helices are invisible when loading old saves.
+11
View File
@@ -4764,6 +4764,17 @@ declare global {
registerToolboxMenuItem(text: string, callback: () => void): void;
registerShortcut(desc: ShortcutDesc): void;
/**
* Show gridlines on the landscape for this plugin.
*/
showGridlines(): void;
/**
* Hide gridlines on the landscape for this plugin. Gridlines may stay shown if the
* game or other plugins have also requested gridlines.
*/
hideGridlines(): void;
}
/**
+47
View File
@@ -54,6 +54,8 @@ namespace OpenRCT2::Scripting
{ "real", ScenarioSource::Real }, { "extras", ScenarioSource::Extras }, { "other", ScenarioSource::Other },
};
static std::unordered_set<std::shared_ptr<Plugin>> _pluginsShowingGridlines;
inline JSValue ScenarioCategoryToJS(JSContext* ctx, Scenario::Category value)
{
const auto& entry = ScenarioCategoryMap.find(value);
@@ -443,6 +445,49 @@ namespace OpenRCT2::Scripting
return JS_UNDEFINED;
}
static JSValue showCurrentPluginGridlines(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv)
{
ScriptEngine* scriptEngine = gScUi.GetOpaque<ScriptEngine*>(thisVal);
if (!scriptEngine)
{
return JS_ThrowInternalError(ctx, "No script engine");
}
auto plugin = scriptEngine->GetExecInfo().GetCurrentPlugin();
auto result = _pluginsShowingGridlines.insert(plugin);
if (result.second)
{
// Plugin was not yet in the set; increment internal counter
ShowGridlines();
}
return JS_UNDEFINED;
}
static JSValue hideCurrentPluginGridlines(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv)
{
ScriptEngine* scriptEngine = gScUi.GetOpaque<ScriptEngine*>(thisVal);
if (!scriptEngine)
{
return JS_ThrowInternalError(ctx, "No script engine");
}
auto plugin = scriptEngine->GetExecInfo().GetCurrentPlugin();
hidePluginGridlines(plugin);
return JS_UNDEFINED;
}
public:
static void hidePluginGridlines(std::shared_ptr<Plugin> plugin)
{
auto result = _pluginsShowingGridlines.erase(plugin);
if (result == 1)
{
// Plugin was in the set before removal; decrement internal counter
HideGridlines();
}
}
private:
static void Finalize(JSRuntime* rt, JSValue thisVal)
{
// Do nothing as we don't need to free the script engine.
@@ -477,6 +522,8 @@ namespace OpenRCT2::Scripting
JS_CFUNC_DEF("registerMenuItem", 2, ScUi::registerMenuItem),
JS_CFUNC_DEF("registerToolboxMenuItem", 2, ScUi::registerToolboxMenuItem),
JS_CFUNC_DEF("registerShortcut", 1, ScUi::registerShortcut),
JS_CFUNC_DEF("showGridlines", 0, ScUi::showCurrentPluginGridlines),
JS_CFUNC_DEF("hideGridlines", 0, ScUi::hideCurrentPluginGridlines),
};
RegisterBase(ctx, "Ui", Finalize, funcs);
}
+4 -2
View File
@@ -67,8 +67,10 @@ void UiScriptExtensions::Extend(ScriptEngine& scriptEngine)
InitialiseCustomImages(scriptEngine);
InitialiseCustomMenuItems(scriptEngine);
scriptEngine.SubscribeToPluginStoppedEvent(
[](std::shared_ptr<Plugin> plugin) -> void { Ui::Windows::CloseWindowsOwnedByPlugin(plugin); });
scriptEngine.SubscribeToPluginStoppedEvent([](std::shared_ptr<Plugin> plugin) -> void {
ScUi::hidePluginGridlines(plugin);
Ui::Windows::CloseWindowsOwnedByPlugin(plugin);
});
scriptEngine.RegisterExtension(InitialiseContext, Unregister);
}
+1 -1
View File
@@ -42,7 +42,7 @@ namespace OpenRCT2
namespace OpenRCT2::Scripting
{
static constexpr int32_t kPluginApiVersion = 112;
static constexpr int32_t kPluginApiVersion = 113;
// Versions marking breaking changes.
static constexpr int32_t kApiVersionPeepDeprecation = 33;