forked from rosebudai/OpenRCT2-Web
Swap Duktape for quickjs-ng
Co-authored-by: Basssiiie <Basssiiie@users.noreply.github.com> Co-authored-by: Tulio Leao <tupaschoal@gmail.com>
This commit is contained in:
1 parent
69518538fd
commit
16cd1c07ff
143 files changed
+97493
-120975
No files matched your search
@@ -17,13 +17,14 @@
|
||||
#include "../windows/Windows.h"
|
||||
#include "CustomListView.h"
|
||||
#include "ScUi.hpp"
|
||||
#include "ScWindow.hpp"
|
||||
#include "ScWindow.h"
|
||||
|
||||
#include <limits>
|
||||
#include <openrct2/SpriteIds.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
#include <openrct2/interface/ColourWithFlags.h>
|
||||
#include <openrct2/interface/Viewport.h>
|
||||
#include <openrct2/interface/Window.h>
|
||||
#include <openrct2/scripting/Plugin.h>
|
||||
#include <optional>
|
||||
@@ -82,114 +83,118 @@ namespace OpenRCT2::Ui::Windows
|
||||
bool CanSelect{};
|
||||
|
||||
// Event handlers
|
||||
DukValue OnClick;
|
||||
DukValue OnChange;
|
||||
DukValue OnDraw;
|
||||
DukValue OnIncrement;
|
||||
DukValue OnDecrement;
|
||||
DukValue OnHighlight;
|
||||
JSCallback OnClick;
|
||||
JSCallback OnChange;
|
||||
JSCallback OnDraw;
|
||||
JSCallback OnIncrement;
|
||||
JSCallback OnDecrement;
|
||||
JSCallback OnHighlight;
|
||||
|
||||
static CustomWidgetDesc FromDukValue(DukValue desc)
|
||||
static CustomWidgetDesc FromJSValue(JSContext* ctx, JSValue desc)
|
||||
{
|
||||
CustomWidgetDesc result;
|
||||
result.Type = desc["type"].as_string();
|
||||
result.X = desc["x"].as_int();
|
||||
result.Y = desc["y"].as_int();
|
||||
result.Width = desc["width"].as_int();
|
||||
result.Height = desc["height"].as_int();
|
||||
result.IsDisabled = AsOrDefault(desc["isDisabled"], false);
|
||||
result.IsVisible = AsOrDefault(desc["isVisible"], true);
|
||||
result.Name = AsOrDefault(desc["name"], "");
|
||||
result.Tooltip = AsOrDefault(desc["tooltip"], "");
|
||||
result.Type = JSToStdString(ctx, desc, "type");
|
||||
result.X = JSToInt(ctx, desc, "x");
|
||||
result.Y = JSToInt(ctx, desc, "y");
|
||||
result.Width = JSToInt(ctx, desc, "width");
|
||||
result.Height = JSToInt(ctx, desc, "height");
|
||||
result.IsDisabled = AsOrDefault(ctx, desc, "isDisabled", false);
|
||||
result.IsVisible = AsOrDefault(ctx, desc, "isVisible", true);
|
||||
result.Name = AsOrDefault(ctx, desc, "name", "");
|
||||
result.Tooltip = AsOrDefault(ctx, desc, "tooltip", "");
|
||||
if (result.Type == "button")
|
||||
{
|
||||
auto dukImage = desc["image"];
|
||||
if (dukImage.type() == DukValue::Type::STRING || dukImage.type() == DukValue::Type::NUMBER)
|
||||
JSValue jsImage = JS_GetPropertyStr(ctx, desc, "image");
|
||||
if (JS_IsString(jsImage) || JS_IsNumber(jsImage))
|
||||
{
|
||||
result.Image = ImageId(ImageFromDuk(dukImage));
|
||||
result.Image = ImageId(ImageFromJSValue(ctx, jsImage));
|
||||
result.HasBorder = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
result.HasBorder = true;
|
||||
}
|
||||
result.IsPressed = AsOrDefault(desc["isPressed"], false);
|
||||
result.OnClick = desc["onClick"];
|
||||
JS_FreeValue(ctx, jsImage);
|
||||
result.IsPressed = AsOrDefault(ctx, desc, "isPressed", false);
|
||||
result.OnClick = JSToCallback(ctx, desc, "onClick");
|
||||
}
|
||||
else if (result.Type == "checkbox")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
result.IsChecked = AsOrDefault(desc["isChecked"], false);
|
||||
result.OnChange = desc["onChange"];
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
result.IsChecked = AsOrDefault(ctx, desc, "isChecked", false);
|
||||
result.OnChange = JSToCallback(ctx, desc, "onChange");
|
||||
}
|
||||
else if (result.Type == "colourpicker")
|
||||
{
|
||||
auto colour = AsOrDefault(desc["colour"], 0);
|
||||
auto colour = AsOrDefault(ctx, desc, "colour", 0);
|
||||
if (colour < kColourNumTotal)
|
||||
{
|
||||
result.Colour = static_cast<Drawing::Colour>(colour);
|
||||
}
|
||||
result.OnChange = desc["onChange"];
|
||||
result.OnChange = JSToCallback(ctx, desc, "onChange");
|
||||
}
|
||||
else if (result.Type == "custom")
|
||||
{
|
||||
result.OnDraw = desc["onDraw"];
|
||||
result.OnDraw = JSToCallback(ctx, desc, "onDraw");
|
||||
}
|
||||
else if (result.Type == "dropdown")
|
||||
{
|
||||
if (desc["items"].is_array())
|
||||
{
|
||||
auto dukItems = desc["items"].as_array();
|
||||
for (const auto& dukItem : dukItems)
|
||||
{
|
||||
result.Items.push_back(ProcessString(dukItem));
|
||||
}
|
||||
}
|
||||
result.SelectedIndex = AsOrDefault(desc["selectedIndex"], 0);
|
||||
result.OnChange = desc["onChange"];
|
||||
JSIterateArray(ctx, desc, "items", [&result](JSContext* ctx2, JSValue val) {
|
||||
result.Items.push_back(JSToStdString(ctx2, val));
|
||||
});
|
||||
result.SelectedIndex = AsOrDefault(ctx, desc, "selectedIndex", 0);
|
||||
result.OnChange = JSToCallback(ctx, desc, "onChange");
|
||||
}
|
||||
else if (result.Type == "groupbox")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
}
|
||||
else if (result.Type == "label")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
if (ProcessString(desc["textAlign"]) == "centred")
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
if (JSToStdString(ctx, desc, "textAlign") == "centred")
|
||||
{
|
||||
result.TextAlign = TextAlignment::centre;
|
||||
}
|
||||
}
|
||||
else if (result.Type == "listview")
|
||||
{
|
||||
result.ListViewColumns = FromDuk<std::vector<ListViewColumn>>(desc["columns"]);
|
||||
result.ListViewItems = FromDuk<std::vector<ListViewItem>>(desc["items"]);
|
||||
result.SelectedCell = FromDuk<std::optional<RowColumn>>(desc["selectedCell"]);
|
||||
result.ShowColumnHeaders = AsOrDefault(desc["showColumnHeaders"], false);
|
||||
result.IsStriped = AsOrDefault(desc["isStriped"], false);
|
||||
result.OnClick = desc["onClick"];
|
||||
result.OnHighlight = desc["onHighlight"];
|
||||
result.CanSelect = AsOrDefault(desc["canSelect"], false);
|
||||
if (desc["scrollbars"].type() == DukValue::UNDEFINED)
|
||||
JSValue cols = JS_GetPropertyStr(ctx, desc, "columns");
|
||||
JSValue items = JS_GetPropertyStr(ctx, desc, "items");
|
||||
JSValue selected = JS_GetPropertyStr(ctx, desc, "selectedCell");
|
||||
JSValue scrollbars = JS_GetPropertyStr(ctx, desc, "scrollbars");
|
||||
result.ListViewColumns = ListViewColumnVecFromJS(ctx, cols);
|
||||
result.ListViewItems = ListViewItemVecFromJS(ctx, items);
|
||||
result.SelectedCell = RowColumnFromJS(ctx, selected);
|
||||
result.ShowColumnHeaders = AsOrDefault(ctx, desc, "showColumnHeaders", false);
|
||||
result.IsStriped = AsOrDefault(ctx, desc, "isStriped", false);
|
||||
result.OnClick = JSToCallback(ctx, desc, "onClick");
|
||||
result.OnHighlight = JSToCallback(ctx, desc, "onHighlight");
|
||||
result.CanSelect = AsOrDefault(ctx, desc, "canSelect", false);
|
||||
if (JS_IsUndefined(scrollbars))
|
||||
result.Scrollbars = ScrollbarType::Vertical;
|
||||
else
|
||||
result.Scrollbars = FromDuk<ScrollbarType>(desc["scrollbars"]);
|
||||
result.Scrollbars = ScrollbarTypeFromJS(ctx, scrollbars);
|
||||
JS_FreeValue(ctx, cols);
|
||||
JS_FreeValue(ctx, items);
|
||||
JS_FreeValue(ctx, selected);
|
||||
JS_FreeValue(ctx, scrollbars);
|
||||
}
|
||||
else if (result.Type == "spinner")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
result.OnIncrement = desc["onIncrement"];
|
||||
result.OnDecrement = desc["onDecrement"];
|
||||
result.OnClick = desc["onClick"];
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
result.OnIncrement = JSToCallback(ctx, desc, "onIncrement");
|
||||
result.OnDecrement = JSToCallback(ctx, desc, "onDecrement");
|
||||
result.OnClick = JSToCallback(ctx, desc, "onClick");
|
||||
}
|
||||
else if (result.Type == "textbox")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
result.MaxLength = AsOrDefault(desc["maxLength"], 32);
|
||||
result.OnChange = desc["onChange"];
|
||||
result.Text = AsOrDefault(ctx, desc, "text", "");
|
||||
result.MaxLength = AsOrDefault(ctx, desc, "maxLength", 32);
|
||||
result.OnChange = JSToCallback(ctx, desc, "onChange");
|
||||
}
|
||||
result.HasBorder = AsOrDefault(desc["border"], result.HasBorder);
|
||||
result.HasBorder = AsOrDefault(ctx, desc, "border", result.HasBorder);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -202,53 +207,53 @@ namespace OpenRCT2::Ui::Windows
|
||||
ScreenCoordsXY offset;
|
||||
std::vector<CustomWidgetDesc> Widgets;
|
||||
|
||||
static CustomTabDesc FromDukValue(const DukValue& desc)
|
||||
static CustomTabDesc FromJSValue(JSContext* ctx, JSValue desc)
|
||||
{
|
||||
CustomTabDesc result;
|
||||
auto dukImage = desc["image"];
|
||||
if (dukImage.type() == DukValue::Type::STRING || dukImage.type() == DukValue::Type::NUMBER)
|
||||
JSValue jsImage = JS_GetPropertyStr(ctx, desc, "image");
|
||||
if (JS_IsString(jsImage) || JS_IsNumber(jsImage))
|
||||
{
|
||||
result.imageFrameBase = ImageId(ImageFromDuk(dukImage));
|
||||
result.imageFrameBase = ImageId(ImageFromJSValue(ctx, jsImage));
|
||||
result.imageFrameCount = 0;
|
||||
result.imageFrameDuration = 0;
|
||||
}
|
||||
else if (dukImage.type() == DukValue::Type::OBJECT)
|
||||
else if (JS_IsObject(jsImage))
|
||||
{
|
||||
result.imageFrameBase = ImageId(dukImage["frameBase"].as_uint());
|
||||
result.imageFrameCount = AsOrDefault(dukImage["frameCount"], 0);
|
||||
result.imageFrameDuration = AsOrDefault(dukImage["frameDuration"], 0);
|
||||
result.imageFrameBase = ImageId(JSToInt64(ctx, jsImage, "frameBase"));
|
||||
result.imageFrameCount = AsOrDefault(ctx, jsImage, "frameCount", 0);
|
||||
result.imageFrameDuration = AsOrDefault(ctx, jsImage, "frameDuration", 0);
|
||||
|
||||
if (dukImage["primaryColour"].type() == DukValue::Type::NUMBER)
|
||||
auto primaryCol = JSToOptionalInt64(ctx, jsImage, "primaryColour");
|
||||
if (primaryCol.has_value())
|
||||
{
|
||||
result.imageFrameBase = result.imageFrameBase.WithPrimary(
|
||||
static_cast<Colour>(dukImage["primaryColour"].as_uint()));
|
||||
result.imageFrameBase = result.imageFrameBase.WithPrimary(static_cast<Colour>(primaryCol.value()));
|
||||
|
||||
if (dukImage["secondaryColour"].type() == DukValue::Type::NUMBER)
|
||||
auto secondaryCol = JSToOptionalInt64(ctx, jsImage, "secondaryColour");
|
||||
if (secondaryCol.has_value())
|
||||
{
|
||||
result.imageFrameBase = result.imageFrameBase.WithSecondary(
|
||||
static_cast<Colour>(dukImage["secondaryColour"].as_uint()));
|
||||
result.imageFrameBase = result.imageFrameBase.WithSecondary(static_cast<Colour>(secondaryCol.value()));
|
||||
|
||||
if (dukImage["tertiaryColour"].type() == DukValue::Type::NUMBER)
|
||||
auto tertiaryCol = JSToOptionalInt64(ctx, jsImage, "tertiaryColour");
|
||||
if (tertiaryCol.has_value())
|
||||
{
|
||||
result.imageFrameBase = result.imageFrameBase.WithTertiary(
|
||||
static_cast<Colour>(dukImage["tertiaryColour"].as_uint()));
|
||||
static_cast<Colour>(tertiaryCol.value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto dukCoord = dukImage["offset"];
|
||||
if (dukCoord.type() == DukValue::Type::OBJECT)
|
||||
JSValue jsCoord = JS_GetPropertyStr(ctx, jsImage, "offset");
|
||||
if (JS_IsObject(jsCoord))
|
||||
{
|
||||
result.offset = { AsOrDefault(dukCoord["x"], 0), AsOrDefault(dukCoord["y"], 0) };
|
||||
result.offset = { AsOrDefault(ctx, jsCoord, "x", 0), AsOrDefault(ctx, jsCoord, "y", 0) };
|
||||
}
|
||||
JS_FreeValue(ctx, jsCoord);
|
||||
}
|
||||
if (desc["widgets"].is_array())
|
||||
{
|
||||
auto dukWidgets = desc["widgets"].as_array();
|
||||
std::transform(dukWidgets.begin(), dukWidgets.end(), std::back_inserter(result.Widgets), [](const DukValue& w) {
|
||||
return CustomWidgetDesc::FromDukValue(w);
|
||||
});
|
||||
}
|
||||
JS_FreeValue(ctx, jsImage);
|
||||
|
||||
JSIterateArray(ctx, desc, "widgets", [&result](JSContext* ctx2, JSValue x) {
|
||||
result.Widgets.push_back(CustomWidgetDesc::FromJSValue(ctx2, x));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -271,9 +276,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::optional<int32_t> TabIndex;
|
||||
|
||||
// Event handlers
|
||||
DukValue OnClose;
|
||||
DukValue OnUpdate;
|
||||
DukValue OnTabChange;
|
||||
JSCallback OnClose;
|
||||
JSCallback OnUpdate;
|
||||
JSCallback OnTabChange;
|
||||
|
||||
CustomWindowDesc() = default;
|
||||
|
||||
@@ -282,65 +287,49 @@ namespace OpenRCT2::Ui::Windows
|
||||
return MinWidth || MinHeight || MaxWidth || MaxHeight;
|
||||
}
|
||||
|
||||
static CustomWindowDesc FromDukValue(DukValue desc)
|
||||
static CustomWindowDesc FromJSValue(JSContext* ctx, JSValue desc)
|
||||
{
|
||||
CustomWindowDesc result;
|
||||
result.Classification = desc["classification"].as_string();
|
||||
result.X = GetOptionalInt(desc["x"]);
|
||||
result.Y = GetOptionalInt(desc["y"]);
|
||||
result.size.width = desc["width"].as_int();
|
||||
result.size.height = desc["height"].as_int();
|
||||
result.MinWidth = GetOptionalInt(desc["minWidth"]);
|
||||
result.MaxWidth = GetOptionalInt(desc["maxWidth"]);
|
||||
result.MinHeight = GetOptionalInt(desc["minHeight"]);
|
||||
result.MaxHeight = GetOptionalInt(desc["maxHeight"]);
|
||||
result.Title = desc["title"].as_string();
|
||||
result.Id = GetOptionalInt(desc["id"]);
|
||||
result.TabIndex = GetOptionalInt(desc["tabIndex"]);
|
||||
result.Classification = JSToStdString(ctx, desc, "classification");
|
||||
result.X = JSToOptionalInt(ctx, desc, "x");
|
||||
result.Y = JSToOptionalInt(ctx, desc, "y");
|
||||
result.size.width = JSToInt(ctx, desc, "width");
|
||||
result.size.height = JSToInt(ctx, desc, "height");
|
||||
result.MinWidth = JSToOptionalInt(ctx, desc, "minWidth");
|
||||
result.MaxWidth = JSToOptionalInt(ctx, desc, "maxWidth");
|
||||
result.MinHeight = JSToOptionalInt(ctx, desc, "minHeight");
|
||||
result.MaxHeight = JSToOptionalInt(ctx, desc, "maxHeight");
|
||||
result.Title = JSToStdString(ctx, desc, "title");
|
||||
result.Id = JSToOptionalInt(ctx, desc, "id");
|
||||
result.TabIndex = JSToOptionalInt(ctx, desc, "tabIndex");
|
||||
|
||||
if (desc["widgets"].is_array())
|
||||
{
|
||||
auto dukWidgets = desc["widgets"].as_array();
|
||||
std::transform(dukWidgets.begin(), dukWidgets.end(), std::back_inserter(result.Widgets), [](const DukValue& w) {
|
||||
return CustomWidgetDesc::FromDukValue(w);
|
||||
});
|
||||
}
|
||||
JSIterateArray(ctx, desc, "widgets", [&result](JSContext* ctx2, JSValue val) {
|
||||
result.Widgets.push_back(CustomWidgetDesc::FromJSValue(ctx2, val));
|
||||
});
|
||||
|
||||
if (desc["tabs"].is_array())
|
||||
{
|
||||
auto dukTabs = desc["tabs"].as_array();
|
||||
std::transform(dukTabs.begin(), dukTabs.end(), std::back_inserter(result.Tabs), [](const DukValue& w) {
|
||||
return CustomTabDesc::FromDukValue(w);
|
||||
});
|
||||
}
|
||||
JSIterateArray(ctx, desc, "tabs", [&result](JSContext* ctx2, JSValue x) {
|
||||
result.Tabs.push_back(CustomTabDesc::FromJSValue(ctx2, x));
|
||||
});
|
||||
|
||||
if (desc["colours"].is_array())
|
||||
{
|
||||
auto dukColours = desc["colours"].as_array();
|
||||
std::transform(dukColours.begin(), dukColours.end(), std::back_inserter(result.Colours), [](const DukValue& w) {
|
||||
ColourWithFlags c = { Colour::black };
|
||||
if (w.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
uint8_t colour = (w.as_uint() & ~kLegacyColourFlagTranslucent) % kColourNumTotal;
|
||||
bool isTranslucent = (w.as_uint() & kLegacyColourFlagTranslucent);
|
||||
c.colour = static_cast<Colour>(colour);
|
||||
c.flags.set(ColourFlag::translucent, isTranslucent);
|
||||
}
|
||||
return c;
|
||||
});
|
||||
}
|
||||
JSIterateArray(ctx, desc, "colours", [&result](JSContext* ctx2, JSValue x) {
|
||||
ColourWithFlags c = { Colour::black };
|
||||
if (JS_IsNumber(x))
|
||||
{
|
||||
int32_t xValue = JSToInt(ctx2, x);
|
||||
uint8_t colour = (xValue & ~kLegacyColourFlagTranslucent) % kColourNumTotal;
|
||||
bool isTranslucent = (xValue & kLegacyColourFlagTranslucent);
|
||||
c.colour = static_cast<Colour>(colour);
|
||||
c.flags.set(ColourFlag::translucent, isTranslucent);
|
||||
}
|
||||
result.Colours.push_back(c);
|
||||
});
|
||||
|
||||
result.OnClose = desc["onClose"];
|
||||
result.OnUpdate = desc["onUpdate"];
|
||||
result.OnTabChange = desc["onTabChange"];
|
||||
result.OnClose = JSToCallback(ctx, desc, "onClose");
|
||||
result.OnUpdate = JSToCallback(ctx, desc, "onUpdate");
|
||||
result.OnTabChange = JSToCallback(ctx, desc, "onTabChange");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::optional<int32_t> GetOptionalInt(DukValue input)
|
||||
{
|
||||
return input.type() == DukValue::Type::NUMBER ? std::make_optional(input.as_int()) : std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
class CustomWindowInfo
|
||||
@@ -392,9 +381,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
class CustomWindow;
|
||||
static CustomWindowInfo& GetInfo(CustomWindow* w);
|
||||
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler);
|
||||
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const JSCallback& jsCallback);
|
||||
static void InvokeEventHandler(
|
||||
const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler, const std::vector<DukValue>& args);
|
||||
const std::shared_ptr<Plugin>& owner, const JSCallback& jsCallback, const std::vector<JSValue>& args);
|
||||
|
||||
class CustomWindow final : public Window
|
||||
{
|
||||
@@ -559,18 +548,19 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (widgetDesc != nullptr && widgetDesc->Type == "custom")
|
||||
{
|
||||
auto& onDraw = widgetDesc->OnDraw;
|
||||
if (onDraw.is_function())
|
||||
if (onDraw.IsValid())
|
||||
{
|
||||
RenderTarget widgetRT;
|
||||
if (ClipRenderTarget(
|
||||
widgetRT, rt, { windowPos.x + widget.left, windowPos.y + widget.top }, widget.width() - 1,
|
||||
widget.height() - 1))
|
||||
{
|
||||
auto ctx = onDraw.context();
|
||||
auto dukWidget = ScWidget::ToDukValue(ctx, this, widgetIndex);
|
||||
auto dukG = GetObjectAsDukValue(ctx, std::make_shared<ScGraphicsContext>(ctx, widgetRT));
|
||||
auto ctx = onDraw.context;
|
||||
auto jsWidget = gScWidget.New(ctx, this, widgetIndex);
|
||||
auto gfx = gScGraphicsContext.New(ctx, widgetRT);
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
scriptEngine.ExecutePluginCall(_info.Owner, widgetDesc->OnDraw, dukWidget, { dukG }, false);
|
||||
scriptEngine.ExecutePluginCall(_info.Owner, onDraw.callback, jsWidget, { gfx }, false);
|
||||
JS_FreeValue(ctx, jsWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,10 +604,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
widgetSetCheckboxValue(*this, widgetIndex, isChecked);
|
||||
|
||||
std::vector<DukValue> args;
|
||||
auto ctx = widgetDesc->OnChange.context();
|
||||
duk_push_boolean(ctx, isChecked);
|
||||
args.push_back(DukValue::take_from_stack(ctx));
|
||||
std::vector<JSValue> args;
|
||||
args.push_back(JS_NewBool(widgetDesc->OnChange.context, isChecked));
|
||||
InvokeEventHandler(_info.Owner, widgetDesc->OnChange, args);
|
||||
}
|
||||
else if (widgetDesc->Type == "spinner")
|
||||
@@ -707,10 +695,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
UpdateWidgetText(this, widgetIndex, text);
|
||||
|
||||
std::vector<DukValue> args;
|
||||
auto ctx = widgetDesc->OnChange.context();
|
||||
duk_push_lstring(ctx, text.data(), text.size());
|
||||
args.push_back(DukValue::take_from_stack(ctx));
|
||||
std::vector<JSValue> args;
|
||||
std::string textStr(text);
|
||||
args.push_back(JSFromStdString(widgetDesc->OnChange.context, textStr));
|
||||
InvokeEventHandler(_info.Owner, widgetDesc->OnChange, args);
|
||||
}
|
||||
}
|
||||
@@ -1127,9 +1114,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
WindowNumber CustomWindow::_nextWindowNumber;
|
||||
|
||||
WindowBase* WindowCustomOpen(std::shared_ptr<Plugin> owner, DukValue dukDesc)
|
||||
WindowBase* WindowCustomOpen(JSContext* ctx, std::shared_ptr<Plugin> owner, JSValue descVal)
|
||||
{
|
||||
auto desc = CustomWindowDesc::FromDukValue(dukDesc);
|
||||
auto desc = CustomWindowDesc::FromJSValue(ctx, descVal);
|
||||
WindowFlags windowFlags = { WindowFlag::resizable, WindowFlag::transparent };
|
||||
auto* windowMgr = GetWindowManager();
|
||||
|
||||
@@ -1151,17 +1138,17 @@ namespace OpenRCT2::Ui::Windows
|
||||
return w->getInfo();
|
||||
}
|
||||
|
||||
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler)
|
||||
static void InvokeEventHandler(const std::shared_ptr<Plugin>& owner, const JSCallback& jsCallback)
|
||||
{
|
||||
std::vector<DukValue> args;
|
||||
InvokeEventHandler(owner, dukHandler, args);
|
||||
std::vector<JSValue> args;
|
||||
InvokeEventHandler(owner, jsCallback, args);
|
||||
}
|
||||
|
||||
static void InvokeEventHandler(
|
||||
const std::shared_ptr<Plugin>& owner, const DukValue& dukHandler, const std::vector<DukValue>& args)
|
||||
const std::shared_ptr<Plugin>& owner, const JSCallback& jsCallback, const std::vector<JSValue>& args)
|
||||
{
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
scriptEngine.ExecutePluginCall(owner, dukHandler, args, false);
|
||||
scriptEngine.ExecutePluginCall(owner, jsCallback.callback, args, false);
|
||||
}
|
||||
|
||||
std::string GetWindowTitle(WindowBase* w)
|
||||
@@ -1245,10 +1232,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
auto* windowMgr = GetWindowManager();
|
||||
windowMgr->InvalidateWidget(*w, widgetIndex);
|
||||
|
||||
std::vector<DukValue> args;
|
||||
auto ctx = customWidgetInfo->OnChange.context();
|
||||
duk_push_int(ctx, EnumValue(colour));
|
||||
args.push_back(DukValue::take_from_stack(ctx));
|
||||
std::vector<JSValue> args;
|
||||
args.push_back(JS_NewInt32(customWidgetInfo->OnChange.context, EnumValue(colour)));
|
||||
InvokeEventHandler(customInfo.Owner, customWidgetInfo->OnChange, args);
|
||||
}
|
||||
}
|
||||
@@ -1293,10 +1278,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
if (lastSelectedIndex != selectedIndex)
|
||||
{
|
||||
std::vector<DukValue> args;
|
||||
auto ctx = customWidgetInfo->OnChange.context();
|
||||
duk_push_int(ctx, selectedIndex);
|
||||
args.push_back(DukValue::take_from_stack(ctx));
|
||||
std::vector<JSValue> args;
|
||||
args.push_back(JS_NewInt32(customWidgetInfo->OnChange.context, selectedIndex));
|
||||
InvokeEventHandler(customInfo.Owner, customWidgetInfo->OnChange, args);
|
||||
}
|
||||
}
|
||||
@@ -1499,7 +1482,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
windowMgr->Close(*window);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2::Ui::Windows
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user