1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 22:34:33 +01:00

Fix #13078: [Plugin] Add colour picker widget

This commit is contained in:
Ted John
2020-12-02 00:21:33 +00:00
parent a55bcff99c
commit 030713e126
8 changed files with 123 additions and 4 deletions

View File

@@ -91,6 +91,7 @@ namespace OpenRCT2::Ui::Windows
std::string Name;
ImageId Image;
std::string Text;
colour_t Colour;
std::string Tooltip;
std::vector<std::string> Items;
std::vector<ListViewItem> ListViewItems;
@@ -147,6 +148,15 @@ namespace OpenRCT2::Ui::Windows
result.IsChecked = AsOrDefault(desc["isChecked"], false);
result.OnChange = desc["onChange"];
}
else if (result.Type == "colourpicker")
{
auto colour = AsOrDefault(desc["colour"], 0);
if (colour < COLOUR_COUNT)
{
result.Colour = colour;
}
result.OnChange = desc["onChange"];
}
else if (result.Type == "dropdown")
{
auto dukItems = desc["items"].as_array();
@@ -510,7 +520,11 @@ namespace OpenRCT2::Ui::Windows
const auto widgetDesc = info.GetCustomWidgetDesc(w, widgetIndex);
if (widgetDesc != nullptr)
{
if (widgetDesc->Type == "dropdown")
if (widgetDesc->Type == "colourpicker")
{
WindowDropdownShowColour(w, widget, w->colours[widget->colour], widgetDesc->Colour);
}
else if (widgetDesc->Type == "dropdown")
{
widget--;
auto selectedIndex = widgetDesc->SelectedIndex;
@@ -550,7 +564,11 @@ namespace OpenRCT2::Ui::Windows
auto widgetDesc = info.GetCustomWidgetDesc(w, widgetIndex);
if (widgetDesc != nullptr)
{
if (widgetDesc->Type == "dropdown")
if (widgetDesc->Type == "colourpicker")
{
UpdateWidgetColour(w, widgetIndex, dropdownIndex);
}
else if (widgetDesc->Type == "dropdown")
{
UpdateWidgetSelectedIndex(w, widgetIndex - 1, dropdownIndex);
}
@@ -846,6 +864,12 @@ namespace OpenRCT2::Ui::Windows
}
widgetList.push_back(widget);
}
else if (desc.Type == "colourpicker")
{
widget.type = WindowWidgetType::ColourBtn;
widget.image = GetColourButtonImage(desc.Colour);
widgetList.push_back(widget);
}
else if (desc.Type == "dropdown")
{
widget.type = WindowWidgetType::DropdownMenu;
@@ -1102,6 +1126,33 @@ namespace OpenRCT2::Ui::Windows
}
}
void UpdateWidgetColour(rct_window* w, rct_widgetindex widgetIndex, colour_t colour)
{
if (w->custom_info != nullptr)
{
auto& customInfo = GetInfo(w);
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr)
{
auto& widget = w->widgets[widgetIndex];
auto lastColour = customWidgetInfo->Colour;
if (lastColour != colour && colour < COLOUR_COUNT)
{
customWidgetInfo->Colour = colour;
widget.image = GetColourButtonImage(colour);
widget_invalidate(w, widgetIndex);
std::vector<DukValue> args;
auto ctx = customWidgetInfo->OnChange.context();
duk_push_int(ctx, colour);
args.push_back(DukValue::take_from_stack(ctx));
InvokeEventHandler(customInfo.Owner, customWidgetInfo->OnChange, args);
}
}
}
}
void UpdateWidgetSelectedIndex(rct_window* w, rct_widgetindex widgetIndex, int32_t selectedIndex)
{
if (w->custom_info != nullptr)
@@ -1163,6 +1214,20 @@ namespace OpenRCT2::Ui::Windows
return {};
}
colour_t GetWidgetColour(rct_window* w, rct_widgetindex widgetIndex)
{
if (w->custom_info != nullptr)
{
auto& customInfo = GetInfo(w);
auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex);
if (customWidgetInfo != nullptr)
{
return customWidgetInfo->Colour;
}
}
return COLOUR_BLACK;
}
int32_t GetWidgetSelectedIndex(rct_window* w, rct_widgetindex widgetIndex)
{
if (w->custom_info != nullptr)