mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Add name get / set to widget
This commit is contained in:
@@ -101,7 +101,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::optional<RowColumn> HighlightedCell;
|
||||
std::optional<RowColumn> LastHighlightedCell;
|
||||
std::optional<RowColumn> SelectedCell;
|
||||
std::optional<size_t> ColumnHeaderPressed;
|
||||
std::optional<int32_t> ColumnHeaderPressed;
|
||||
bool ColumnHeaderPressedCurrentState{};
|
||||
bool ShowColumnHeaders{};
|
||||
bool IsStriped{};
|
||||
|
||||
@@ -1102,6 +1102,33 @@ namespace OpenRCT2::Ui::Windows
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string GetWidgetName(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
if (w->custom_info != nullptr)
|
||||
{
|
||||
const auto& customInfo = GetInfo(w);
|
||||
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
|
||||
if (customWidgetInfo != nullptr)
|
||||
{
|
||||
return customWidgetInfo->Name;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void SetWidgetName(rct_window* w, rct_widgetindex widgetIndex, const std::string_view& name)
|
||||
{
|
||||
if (w->custom_info != nullptr)
|
||||
{
|
||||
auto& customInfo = GetInfo(w);
|
||||
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
|
||||
if (customWidgetInfo != nullptr)
|
||||
{
|
||||
customWidgetInfo->Name = std::string(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomListView* GetCustomListView(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
if (w->custom_info != nullptr)
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
void UpdateWidgetText(rct_window* w, rct_widgetindex widget, const std::string_view& string_view);
|
||||
rct_window* FindCustomWindowByClassification(const std::string_view& classification);
|
||||
std::optional<rct_widgetindex> FindWidgetIndexByName(rct_window* w, const std::string_view& name);
|
||||
std::string GetWidgetName(rct_window* w, rct_widgetindex widgetIndex);
|
||||
void SetWidgetName(rct_window* w, rct_widgetindex widgetIndex, const std::string_view& name);
|
||||
CustomListView* GetCustomListView(rct_window* w, rct_widgetindex widgetIndex);
|
||||
} // namespace OpenRCT2::Ui::Windows
|
||||
|
||||
|
||||
@@ -43,6 +43,25 @@ namespace OpenRCT2::Scripting
|
||||
static DukValue ToDukValue(duk_context* ctx, rct_window* w, rct_widgetindex widgetIndex);
|
||||
|
||||
private:
|
||||
std::string name_get() const
|
||||
{
|
||||
auto w = GetWindow();
|
||||
if (w != nullptr && IsCustomWindow())
|
||||
{
|
||||
return OpenRCT2::Ui::Windows::GetWidgetName(w, _widgetIndex);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void name_set(const std::string& value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
if (w != nullptr && IsCustomWindow())
|
||||
{
|
||||
OpenRCT2::Ui::Windows::SetWidgetName(w, _widgetIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
std::string type_get() const
|
||||
{
|
||||
auto widget = GetWidget();
|
||||
@@ -253,6 +272,7 @@ namespace OpenRCT2::Scripting
|
||||
static void Register(duk_context* ctx)
|
||||
{
|
||||
// Common
|
||||
dukglue_register_property(ctx, &ScWidget::name_get, &ScWidget::name_set, "name");
|
||||
dukglue_register_property(ctx, &ScWidget::type_get, nullptr, "type");
|
||||
dukglue_register_property(ctx, &ScWidget::x_get, &ScWidget::x_set, "x");
|
||||
dukglue_register_property(ctx, &ScWidget::y_get, &ScWidget::y_set, "y");
|
||||
|
||||
Reference in New Issue
Block a user