1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Allow more fields to be optional

This commit is contained in:
Ted John
2021-01-25 02:32:18 +00:00
parent 136783270f
commit 2fcaed8165
3 changed files with 29 additions and 20 deletions

View File

@@ -1881,9 +1881,9 @@ declare global {
* By default, text buttons have borders and image buttons do not but it can be overridden.
*/
border?: boolean;
image: number;
isPressed: boolean;
text: string;
image?: number;
isPressed?: boolean;
text?: string;
onClick: () => void;
}
@@ -1946,8 +1946,8 @@ declare global {
readonly highlightedCell?: RowColumn;
canSelect?: boolean;
onHighlight: (item: number, column: number) => void;
onClick: (item: number, column: number) => void;
onHighlight?: (item: number, column: number) => void;
onClick?: (item: number, column: number) => void;
}
interface SpinnerWidget extends Widget {

View File

@@ -497,7 +497,7 @@ void CustomListView::MouseDown(const ScreenCoordsXY& pos)
auto hitResult = GetItemIndexAt(pos);
if (hitResult)
{
if (hitResult->Row != HEADER_ROW && OnClick.context() != nullptr && OnClick.is_function())
if (hitResult->Row != HEADER_ROW)
{
if (CanSelect)
{
@@ -506,12 +506,15 @@ void CustomListView::MouseDown(const ScreenCoordsXY& pos)
}
auto ctx = OnClick.context();
duk_push_int(ctx, static_cast<int32_t>(hitResult->Row));
auto dukRow = DukValue::take_from_stack(ctx, -1);
duk_push_int(ctx, static_cast<int32_t>(hitResult->Column));
auto dukColumn = DukValue::take_from_stack(ctx, -1);
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.ExecutePluginCall(Owner, OnClick, { dukRow, dukColumn }, false);
if (ctx != nullptr && OnClick.is_function())
{
duk_push_int(ctx, static_cast<int32_t>(hitResult->Row));
auto dukRow = DukValue::take_from_stack(ctx, -1);
duk_push_int(ctx, static_cast<int32_t>(hitResult->Column));
auto dukColumn = DukValue::take_from_stack(ctx, -1);
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.ExecutePluginCall(Owner, OnClick, { dukRow, dukColumn }, false);
}
}
}
if (hitResult && hitResult->Row == HEADER_ROW)
@@ -597,11 +600,14 @@ void CustomListView::Paint(rct_window* w, rct_drawpixelinfo* dpi, const rct_scro
// Columns
if (Columns.size() == 0)
{
const auto& text = item.Cells[0];
if (!text.empty())
if (item.Cells.size() != 0)
{
ScreenSize cellSize = { std::numeric_limits<int32_t>::max(), LIST_ROW_HEIGHT };
PaintCell(dpi, { 0, y }, cellSize, text.c_str(), isHighlighted);
const auto& text = item.Cells[0];
if (!text.empty())
{
ScreenSize cellSize = { std::numeric_limits<int32_t>::max(), LIST_ROW_HEIGHT };
PaintCell(dpi, { 0, y }, cellSize, text.c_str(), isHighlighted);
}
}
}
else

View File

@@ -164,12 +164,15 @@ namespace OpenRCT2::Ui::Windows
}
else if (result.Type == "dropdown")
{
auto dukItems = desc["items"].as_array();
for (const auto& dukItem : dukItems)
if (desc["items"].is_array())
{
result.Items.push_back(ProcessString(dukItem));
auto dukItems = desc["items"].as_array();
for (const auto& dukItem : dukItems)
{
result.Items.push_back(ProcessString(dukItem));
}
}
result.SelectedIndex = desc["selectedIndex"].as_int();
result.SelectedIndex = AsOrDefault(desc["selectedIndex"], 0);
result.OnChange = desc["onChange"];
}
else if (result.Type == "groupbox" || result.Type == "label")