mirror of https://github.com/OpenRCT2/OpenRCT2.git
Implement API for image buttons
This commit is contained in:
parent
00293d20e8
commit
9dd9e600b5
|
@ -339,6 +339,7 @@ declare global {
|
|||
}
|
||||
|
||||
interface ButtonWidget extends Widget {
|
||||
image: number;
|
||||
text: string;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ namespace OpenRCT2::Ui::Windows
|
|||
int32_t Width{};
|
||||
int32_t Height{};
|
||||
std::string Name;
|
||||
ImageId Image;
|
||||
std::string Text;
|
||||
std::vector<std::string> 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")
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue