mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add widget visible flag
This commit is contained in:
parent
c1a1f8f639
commit
be350f7e2e
|
@ -1872,6 +1872,7 @@ declare global {
|
|||
name?: string;
|
||||
tooltip?: string;
|
||||
isDisabled?: boolean;
|
||||
isVisible?: boolean;
|
||||
}
|
||||
|
||||
interface ButtonWidget extends Widget {
|
||||
|
|
|
@ -1442,7 +1442,7 @@ static void InputUpdateTooltip(rct_window* w, rct_widgetindex widgetIndex, const
|
|||
if (gTooltipCursor == screenCoords)
|
||||
{
|
||||
_tooltipNotShownTicks++;
|
||||
if (_tooltipNotShownTicks > 50)
|
||||
if (_tooltipNotShownTicks > 50 && WidgetIsVisible(w, widgetIndex))
|
||||
{
|
||||
gTooltipTimeout = 0;
|
||||
window_tooltip_open(w, widgetIndex, screenCoords);
|
||||
|
@ -1457,7 +1457,8 @@ static void InputUpdateTooltip(rct_window* w, rct_widgetindex widgetIndex, const
|
|||
reset_tooltip_not_shown();
|
||||
|
||||
if (w == nullptr || gTooltipWidget.window_classification != w->classification
|
||||
|| gTooltipWidget.window_number != w->number || gTooltipWidget.widget_index != widgetIndex)
|
||||
|| gTooltipWidget.window_number != w->number || gTooltipWidget.widget_index != widgetIndex
|
||||
|| !WidgetIsVisible(w, widgetIndex))
|
||||
{
|
||||
window_tooltip_close();
|
||||
}
|
||||
|
|
|
@ -829,6 +829,8 @@ static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetind
|
|||
|
||||
bool WidgetIsEnabled(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
if (!WidgetIsVisible(w, widgetIndex))
|
||||
return false;
|
||||
return (w->enabled_widgets & (1LL << widgetIndex)) != 0;
|
||||
}
|
||||
|
||||
|
@ -837,6 +839,11 @@ bool WidgetIsDisabled(rct_window* w, rct_widgetindex widgetIndex)
|
|||
return (w->disabled_widgets & (1LL << widgetIndex)) != 0;
|
||||
}
|
||||
|
||||
bool WidgetIsVisible(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
return w->widgets[widgetIndex].IsVisible();
|
||||
}
|
||||
|
||||
bool WidgetIsPressed(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
if (w->pressed_widgets & (1LL << widgetIndex))
|
||||
|
@ -1026,6 +1033,18 @@ void WidgetSetDisabled(rct_window* w, rct_widgetindex widgetIndex, bool value)
|
|||
}
|
||||
}
|
||||
|
||||
void WidgetSetVisible(rct_window* w, rct_widgetindex widgetIndex, bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
w->widgets[widgetIndex].flags &= ~WIDGET_FLAGS::IS_HIDDEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->widgets[widgetIndex].flags |= WIDGET_FLAGS::IS_HIDDEN;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetSetCheckboxValue(rct_window* w, rct_widgetindex widgetIndex, int32_t value)
|
||||
{
|
||||
if (value)
|
||||
|
|
|
@ -628,11 +628,13 @@ void WindowDrawWidgets(rct_window* w, rct_drawpixelinfo* dpi)
|
|||
widgetIndex = 0;
|
||||
for (widget = w->widgets; widget->type != WindowWidgetType::Last; widget++)
|
||||
{
|
||||
// Check if widget is outside the draw region
|
||||
if (w->windowPos.x + widget->left < dpi->x + dpi->width && w->windowPos.x + widget->right >= dpi->x)
|
||||
if (w->windowPos.y + widget->top < dpi->y + dpi->height && w->windowPos.y + widget->bottom >= dpi->y)
|
||||
WidgetDraw(dpi, w, widgetIndex);
|
||||
|
||||
if (widget->IsVisible())
|
||||
{
|
||||
// Check if widget is outside the draw region
|
||||
if (w->windowPos.x + widget->left < dpi->x + dpi->width && w->windowPos.x + widget->right >= dpi->x)
|
||||
if (w->windowPos.y + widget->top < dpi->y + dpi->height && w->windowPos.y + widget->bottom >= dpi->y)
|
||||
WidgetDraw(dpi, w, widgetIndex);
|
||||
}
|
||||
widgetIndex++;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace OpenRCT2::Ui::Windows
|
|||
std::optional<RowColumn> SelectedCell;
|
||||
bool IsChecked{};
|
||||
bool IsDisabled{};
|
||||
bool IsVisible{};
|
||||
bool IsPressed{};
|
||||
bool HasBorder{};
|
||||
bool ShowColumnHeaders{};
|
||||
|
@ -123,6 +124,7 @@ namespace OpenRCT2::Ui::Windows
|
|||
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"], "");
|
||||
if (result.Type == "button")
|
||||
|
@ -723,25 +725,6 @@ namespace OpenRCT2::Ui::Windows
|
|||
}
|
||||
}
|
||||
|
||||
static void window_custom_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{
|
||||
WindowDrawWidgets(w, dpi);
|
||||
window_custom_draw_tab_images(w, dpi);
|
||||
if (w->viewport != nullptr)
|
||||
{
|
||||
window_draw_viewport(dpi, w);
|
||||
}
|
||||
}
|
||||
|
||||
static void window_custom_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
|
||||
{
|
||||
const auto& info = GetInfo(w);
|
||||
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
|
||||
{
|
||||
info.ListViews[scrollIndex].Paint(w, dpi, &w->scrolls[scrollIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<rct_widgetindex> GetViewportWidgetIndex(rct_window* w)
|
||||
{
|
||||
rct_widgetindex widgetIndex = 0;
|
||||
|
@ -756,6 +739,29 @@ namespace OpenRCT2::Ui::Windows
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
static void window_custom_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{
|
||||
WindowDrawWidgets(w, dpi);
|
||||
window_custom_draw_tab_images(w, dpi);
|
||||
if (w->viewport != nullptr)
|
||||
{
|
||||
auto widgetIndex = GetViewportWidgetIndex(w);
|
||||
if (WidgetIsVisible(w, widgetIndex.value_or(false)))
|
||||
{
|
||||
window_draw_viewport(dpi, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void window_custom_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
|
||||
{
|
||||
const auto& info = GetInfo(w);
|
||||
if (scrollIndex < static_cast<int32_t>(info.ListViews.size()))
|
||||
{
|
||||
info.ListViews[scrollIndex].Paint(w, dpi, &w->scrolls[scrollIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
static void window_custom_update_viewport(rct_window* w)
|
||||
{
|
||||
auto viewportWidgetIndex = GetViewportWidgetIndex(w);
|
||||
|
@ -833,6 +839,8 @@ namespace OpenRCT2::Ui::Windows
|
|||
widget.flags |= WIDGET_FLAGS::IS_ENABLED;
|
||||
if (desc.IsDisabled)
|
||||
widget.flags |= WIDGET_FLAGS::IS_DISABLED;
|
||||
if (!desc.IsVisible)
|
||||
widget.flags |= WIDGET_FLAGS::IS_HIDDEN;
|
||||
|
||||
if (desc.Type == "button")
|
||||
{
|
||||
|
|
|
@ -318,6 +318,38 @@ namespace OpenRCT2::Scripting
|
|||
}
|
||||
}
|
||||
|
||||
bool isVisible_get() const
|
||||
{
|
||||
auto w = GetWindow();
|
||||
if (w != nullptr)
|
||||
{
|
||||
return WidgetIsVisible(w, _widgetIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void isVisible_set(bool value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
if (w != nullptr)
|
||||
{
|
||||
WidgetSetVisible(w, _widgetIndex, value);
|
||||
|
||||
auto widget = GetWidget();
|
||||
if (widget != nullptr)
|
||||
{
|
||||
if (widget->type == WindowWidgetType::DropdownMenu)
|
||||
{
|
||||
WidgetSetVisible(w, _widgetIndex + 1, value);
|
||||
}
|
||||
else if (widget->type == WindowWidgetType::Spinner)
|
||||
{
|
||||
WidgetSetVisible(w, _widgetIndex + 1, value);
|
||||
WidgetSetVisible(w, _widgetIndex + 2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string text_get() const
|
||||
{
|
||||
if (IsCustomWindow())
|
||||
|
@ -364,6 +396,7 @@ namespace OpenRCT2::Scripting
|
|||
dukglue_register_property(ctx, &ScWidget::width_get, &ScWidget::width_set, "width");
|
||||
dukglue_register_property(ctx, &ScWidget::height_get, &ScWidget::height_set, "height");
|
||||
dukglue_register_property(ctx, &ScWidget::isDisabled_get, &ScWidget::isDisabled_set, "isDisabled");
|
||||
dukglue_register_property(ctx, &ScWidget::isVisible_get, &ScWidget::isVisible_set, "isVisible");
|
||||
|
||||
// No so common
|
||||
dukglue_register_property(ctx, &ScWidget::text_get, &ScWidget::text_set, "text");
|
||||
|
|
|
@ -137,6 +137,7 @@ void WidgetDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetInd
|
|||
|
||||
bool WidgetIsEnabled(rct_window* w, rct_widgetindex widgetIndex);
|
||||
bool WidgetIsDisabled(rct_window* w, rct_widgetindex widgetIndex);
|
||||
bool WidgetIsVisible(rct_window* w, rct_widgetindex widgetIndex);
|
||||
bool WidgetIsPressed(rct_window* w, rct_widgetindex widgetIndex);
|
||||
bool WidgetIsHighlighted(rct_window* w, rct_widgetindex widgetIndex);
|
||||
bool WidgetIsActiveTool(rct_window* w, rct_widgetindex widgetIndex);
|
||||
|
@ -146,6 +147,7 @@ void WidgetScrollGetPart(
|
|||
|
||||
void WidgetSetEnabled(rct_window* w, rct_widgetindex widgetIndex, bool enabled);
|
||||
void WidgetSetDisabled(rct_window* w, rct_widgetindex widgetIndex, bool value);
|
||||
void WidgetSetVisible(rct_window* w, rct_widgetindex widgetIndex, bool value);
|
||||
void WidgetSetCheckboxValue(rct_window* w, rct_widgetindex widgetIndex, int32_t value);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -435,7 +435,7 @@ rct_widgetindex window_find_widget_from_point(rct_window* w, const ScreenCoordsX
|
|||
{
|
||||
break;
|
||||
}
|
||||
else if (widget->type != WindowWidgetType::Empty)
|
||||
else if (widget->type != WindowWidgetType::Empty && widget->IsVisible())
|
||||
{
|
||||
if (screenCoords.x >= w->windowPos.x + widget->left && screenCoords.x <= w->windowPos.x + widget->right
|
||||
&& screenCoords.y >= w->windowPos.y + widget->top && screenCoords.y <= w->windowPos.y + widget->bottom)
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace WIDGET_FLAGS
|
|||
const WidgetFlags IS_PRESSED = 1 << 2;
|
||||
const WidgetFlags IS_DISABLED = 1 << 3;
|
||||
const WidgetFlags TOOLTIP_IS_STRING = 1 << 4;
|
||||
const WidgetFlags IS_HIDDEN = 1 << 5;
|
||||
} // namespace WIDGET_FLAGS
|
||||
|
||||
enum class WindowWidgetType : uint8_t;
|
||||
|
@ -132,6 +133,11 @@ struct rct_widget
|
|||
else
|
||||
return top - 1;
|
||||
}
|
||||
|
||||
bool IsVisible() const
|
||||
{
|
||||
return !(flags & WIDGET_FLAGS::IS_HIDDEN);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue