mirror of https://github.com/OpenRCT2/OpenRCT2.git
Tooltip 2 (#13159)
* Use ScreenCoords for tooltip * Remove temporary variables * Small refactor * Fix #13151. Not passing tooltip arguments correctly for ride window * Fix Server List window version tooltip * Fix cheats tooltip event * Add static to function decl * Remove unreachable break statements in Ride.cpp * Apply review suggestions Co-authored-by: Tulio Leao <tupaschoal@gmail.com>
This commit is contained in:
parent
803bbfeeb0
commit
cd39c30989
|
@ -57,8 +57,7 @@ ScreenCoordsXY gInputDragLast;
|
|||
|
||||
uint16_t gTooltipTimeout;
|
||||
widget_ref gTooltipWidget;
|
||||
int32_t gTooltipCursorX;
|
||||
int32_t gTooltipCursorY;
|
||||
ScreenCoordsXY gTooltipCursor;
|
||||
|
||||
static int16_t _clickRepeatTicks;
|
||||
|
||||
|
@ -598,8 +597,7 @@ static void input_scroll_begin(rct_window* w, rct_widgetindex widgetIndex, const
|
|||
gPressedWidget.window_classification = w->classification;
|
||||
gPressedWidget.window_number = w->number;
|
||||
gPressedWidget.widget_index = widgetIndex;
|
||||
gTooltipCursorX = screenCoords.x;
|
||||
gTooltipCursorY = screenCoords.y;
|
||||
gTooltipCursor = screenCoords;
|
||||
|
||||
int32_t scroll_area, scroll_id;
|
||||
ScreenCoordsXY scrollCoords;
|
||||
|
@ -681,16 +679,16 @@ static void input_scroll_continue(rct_window* w, rct_widgetindex widgetIndex, co
|
|||
|
||||
if (_currentScrollArea == SCROLL_PART_HSCROLLBAR_THUMB)
|
||||
{
|
||||
int32_t originalTooltipCursorX = gTooltipCursorX;
|
||||
gTooltipCursorX = screenCoords.x;
|
||||
int32_t originalTooltipCursorX = gTooltipCursor.x;
|
||||
gTooltipCursor.x = screenCoords.x;
|
||||
input_scroll_part_update_hthumb(w, widgetIndex, screenCoords.x - originalTooltipCursorX, scroll_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentScrollArea == SCROLL_PART_VSCROLLBAR_THUMB)
|
||||
{
|
||||
int32_t originalTooltipCursorY = gTooltipCursorY;
|
||||
gTooltipCursorY = screenCoords.y;
|
||||
int32_t originalTooltipCursorY = gTooltipCursor.y;
|
||||
gTooltipCursor.y = screenCoords.y;
|
||||
input_scroll_part_update_vthumb(w, widgetIndex, screenCoords.y - originalTooltipCursorY, scroll_id);
|
||||
return;
|
||||
}
|
||||
|
@ -1422,7 +1420,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, con
|
|||
{
|
||||
if (gTooltipWidget.window_classification == 255)
|
||||
{
|
||||
if (gTooltipCursorX == screenCoords.x && gTooltipCursorY == screenCoords.y)
|
||||
if (gTooltipCursor == screenCoords)
|
||||
{
|
||||
_tooltipNotShownTicks++;
|
||||
if (_tooltipNotShownTicks > 50)
|
||||
|
@ -1433,8 +1431,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, con
|
|||
}
|
||||
|
||||
gTooltipTimeout = 0;
|
||||
gTooltipCursorX = screenCoords.x;
|
||||
gTooltipCursorY = screenCoords.y;
|
||||
gTooltipCursor = screenCoords;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -333,6 +333,7 @@ static void window_cheats_misc_dropdown(rct_window *w, rct_widgetindex widgetInd
|
|||
static void window_cheats_guests_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
||||
static void window_cheats_misc_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
||||
static void window_cheats_rides_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
||||
static OpenRCT2String window_cheats_rides_tooltip(rct_window* const w, rct_widgetindex widgetIndex, rct_string_id fallback);
|
||||
static void window_cheats_update(rct_window *w);
|
||||
static void window_cheats_invalidate(rct_window *w);
|
||||
static void window_cheats_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
||||
|
@ -371,6 +372,7 @@ static rct_window_event_list window_cheats_rides_events([](auto& events)
|
|||
{
|
||||
events.mouse_up = &window_cheats_rides_mouseup;
|
||||
events.update = &window_cheats_update;
|
||||
events.tooltip = &window_cheats_rides_tooltip;
|
||||
events.invalidate = &window_cheats_invalidate;
|
||||
events.paint = &window_cheats_paint;
|
||||
});
|
||||
|
@ -1003,6 +1005,17 @@ static void window_cheats_update(rct_window* w)
|
|||
widget_invalidate(w, WIDX_TAB_1 + w->page);
|
||||
}
|
||||
|
||||
static OpenRCT2String window_cheats_rides_tooltip(rct_window* const w, rct_widgetindex widgetIndex, rct_string_id fallback)
|
||||
{
|
||||
if (widgetIndex == WIDX_FAST_LIFT_HILL)
|
||||
{
|
||||
auto ft = Formatter{};
|
||||
ft.Add<uint16_t>(255);
|
||||
return { fallback, ft };
|
||||
}
|
||||
return { fallback, {} };
|
||||
}
|
||||
|
||||
static void window_cheats_invalidate(rct_window* w)
|
||||
{
|
||||
int32_t i;
|
||||
|
@ -1025,8 +1038,6 @@ static void window_cheats_invalidate(rct_window* w)
|
|||
// Set title
|
||||
w->widgets[WIDX_TITLE].text = window_cheats_page_titles[w->page];
|
||||
|
||||
auto ft = Formatter::Common();
|
||||
|
||||
switch (w->page)
|
||||
{
|
||||
case WINDOW_CHEATS_PAGE_MONEY:
|
||||
|
@ -1047,11 +1058,15 @@ static void window_cheats_invalidate(rct_window* w)
|
|||
}
|
||||
break;
|
||||
case WINDOW_CHEATS_PAGE_GUESTS:
|
||||
{
|
||||
auto ft = Formatter::Common();
|
||||
ft.Add<int32_t>(MONEY(1000, 00));
|
||||
widget_set_checkbox_value(w, WIDX_GUEST_IGNORE_RIDE_INTENSITY, gCheatsIgnoreRideIntensity);
|
||||
widget_set_checkbox_value(w, WIDX_DISABLE_VANDALISM, gCheatsDisableVandalism);
|
||||
widget_set_checkbox_value(w, WIDX_DISABLE_LITTERING, gCheatsDisableLittering);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WINDOW_CHEATS_PAGE_MISC:
|
||||
w->widgets[WIDX_OPEN_CLOSE_PARK].text = (gParkFlags & PARK_FLAGS_PARK_OPEN) ? STR_CHEAT_CLOSE_PARK
|
||||
: STR_CHEAT_OPEN_PARK;
|
||||
|
@ -1061,7 +1076,6 @@ static void window_cheats_invalidate(rct_window* w)
|
|||
widget_set_checkbox_value(w, WIDX_DISABLE_PLANT_AGING, gCheatsDisablePlantAging);
|
||||
break;
|
||||
case WINDOW_CHEATS_PAGE_RIDES:
|
||||
ft.Add<uint16_t>(255);
|
||||
widget_set_checkbox_value(w, WIDX_FAST_LIFT_HILL, gCheatsFastLiftHill);
|
||||
widget_set_checkbox_value(w, WIDX_DISABLE_BRAKES_FAILURE, gCheatsDisableBrakesFailure);
|
||||
widget_set_checkbox_value(w, WIDX_DISABLE_ALL_BREAKDOWNS, gCheatsDisableAllBreakdowns);
|
||||
|
|
|
@ -686,9 +686,6 @@ static void window_editor_inventions_list_scrollpaint(rct_window* w, rct_drawpix
|
|||
static void window_editor_inventions_list_drag_open(ResearchItem* researchItem)
|
||||
{
|
||||
char buffer[256], *ptr;
|
||||
int32_t stringWidth;
|
||||
rct_window* w;
|
||||
|
||||
window_close_by_class(WC_EDITOR_INVENTION_LIST_DRAG);
|
||||
_editorInventionsListDraggedItem = *researchItem;
|
||||
rct_string_id stringId = researchItem->GetName();
|
||||
|
@ -710,16 +707,15 @@ static void window_editor_inventions_list_drag_open(ResearchItem* researchItem)
|
|||
format_string(ptr, 256, stringId, nullptr);
|
||||
}
|
||||
|
||||
stringWidth = gfx_get_string_width(buffer);
|
||||
auto stringWidth = gfx_get_string_width(buffer);
|
||||
window_editor_inventions_list_drag_widgets[0].right = stringWidth;
|
||||
|
||||
w = window_create(
|
||||
ScreenCoordsXY(gTooltipCursorX - (stringWidth / 2), gTooltipCursorY - 7), stringWidth, 14,
|
||||
&window_editor_inventions_list_drag_events, WC_EDITOR_INVENTION_LIST_DRAG,
|
||||
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_SNAPPING);
|
||||
auto* w = window_create(
|
||||
gTooltipCursor - ScreenCoordsXY{ stringWidth / 2, 7 }, stringWidth, 14, &window_editor_inventions_list_drag_events,
|
||||
WC_EDITOR_INVENTION_LIST_DRAG, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_SNAPPING);
|
||||
w->widgets = window_editor_inventions_list_drag_widgets;
|
||||
w->colours[1] = COLOUR_WHITE;
|
||||
input_window_position_begin(w, 0, ScreenCoordsXY(gTooltipCursorX, gTooltipCursorY));
|
||||
input_window_position_begin(w, 0, gTooltipCursor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -534,6 +534,7 @@ static void window_ride_vehicle_resize(rct_window *w);
|
|||
static void window_ride_vehicle_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget *widget);
|
||||
static void window_ride_vehicle_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
|
||||
static void window_ride_vehicle_update(rct_window *w);
|
||||
static OpenRCT2String window_ride_vehicle_tooltip(rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback);
|
||||
static void window_ride_vehicle_invalidate(rct_window *w);
|
||||
static void window_ride_vehicle_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
||||
static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
|
||||
|
@ -636,6 +637,7 @@ static rct_window_event_list window_ride_vehicle_events([](auto& events)
|
|||
events.mouse_down = &window_ride_vehicle_mousedown;
|
||||
events.dropdown = &window_ride_vehicle_dropdown;
|
||||
events.update = &window_ride_vehicle_update;
|
||||
events.tooltip = &window_ride_vehicle_tooltip;
|
||||
events.invalidate = &window_ride_vehicle_invalidate;
|
||||
events.paint = &window_ride_vehicle_paint;
|
||||
events.scroll_paint = &window_ride_vehicle_scrollpaint;
|
||||
|
@ -2777,6 +2779,56 @@ static void window_ride_vehicle_update(rct_window* w)
|
|||
widget_invalidate(w, WIDX_TAB_2);
|
||||
}
|
||||
|
||||
static OpenRCT2String window_ride_vehicle_tooltip(
|
||||
rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback)
|
||||
{
|
||||
auto ride = get_ride(w->number);
|
||||
if (ride == nullptr)
|
||||
return { STR_NONE, {} };
|
||||
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_VEHICLE_TRAINS:
|
||||
case WIDX_VEHICLE_TRAINS_DECREASE:
|
||||
case WIDX_VEHICLE_TRAINS_INCREASE:
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Increment(12);
|
||||
|
||||
RIDE_COMPONENT_TYPE vehicleType = RideTypeDescriptors[ride->type].NameConvention.vehicle;
|
||||
rct_string_id stringId = RideComponentNames[vehicleType].count;
|
||||
if (ride->max_trains > 1)
|
||||
{
|
||||
stringId = RideComponentNames[vehicleType].count_plural;
|
||||
}
|
||||
ft.Add<rct_string_id>(stringId);
|
||||
ft.Add<uint16_t>(ride->max_trains);
|
||||
return { fallback, ft };
|
||||
}
|
||||
case WIDX_VEHICLE_CARS_PER_TRAIN:
|
||||
case WIDX_VEHICLE_CARS_PER_TRAIN_DECREASE:
|
||||
case WIDX_VEHICLE_CARS_PER_TRAIN_INCREASE:
|
||||
{
|
||||
auto rideEntry = ride->GetRideEntry();
|
||||
if (rideEntry == nullptr)
|
||||
return { STR_NONE, {} };
|
||||
|
||||
auto ft = Formatter();
|
||||
ft.Increment(16);
|
||||
ft.Add<uint16_t>(std::max(1, ride->min_max_cars_per_train & 0xF) - rideEntry->zero_cars);
|
||||
|
||||
rct_string_id stringId = RideComponentNames[RIDE_COMPONENT_TYPE_CAR].singular;
|
||||
if ((ride->min_max_cars_per_train & 0xF) - rideEntry->zero_cars > 1)
|
||||
{
|
||||
stringId = RideComponentNames[RIDE_COMPONENT_TYPE_CAR].plural;
|
||||
}
|
||||
ft.Add<rct_string_id>(stringId);
|
||||
return { fallback, ft };
|
||||
}
|
||||
}
|
||||
return { fallback, {} };
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006B222C
|
||||
|
@ -2851,21 +2903,8 @@ static void window_ride_vehicle_invalidate(rct_window* w)
|
|||
ft.Add<rct_string_id>(stringId);
|
||||
ft.Add<uint16_t>(ride->num_vehicles);
|
||||
|
||||
stringId = RideComponentNames[vehicleType].count;
|
||||
if (ride->max_trains > 1)
|
||||
{
|
||||
stringId = RideComponentNames[vehicleType].count_plural;
|
||||
}
|
||||
ft.Add<rct_string_id>(stringId);
|
||||
ft.Add<uint16_t>(ride->max_trains);
|
||||
ft.Add<uint16_t>(std::max(1, ride->min_max_cars_per_train & 0xF) - rideEntry->zero_cars);
|
||||
ft.Increment(8);
|
||||
|
||||
stringId = RideComponentNames[RIDE_COMPONENT_TYPE_CAR].singular;
|
||||
if ((ride->min_max_cars_per_train & 0xF) - rideEntry->zero_cars > 1)
|
||||
{
|
||||
stringId = RideComponentNames[RIDE_COMPONENT_TYPE_CAR].plural;
|
||||
}
|
||||
ft.Add<rct_string_id>(stringId);
|
||||
ride->FormatNameTo(ft);
|
||||
|
||||
window_ride_anchor_border_widgets(w);
|
||||
|
|
|
@ -78,6 +78,7 @@ static void window_server_list_scroll_getsize(rct_window *w, int32_t scrollIndex
|
|||
static void window_server_list_scroll_mousedown(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
|
||||
static void window_server_list_scroll_mouseover(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
|
||||
static void window_server_list_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text);
|
||||
static OpenRCT2String window_server_list_tooltip(rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback);
|
||||
static void window_server_list_invalidate(rct_window *w);
|
||||
static void window_server_list_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
||||
static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
|
||||
|
@ -93,6 +94,7 @@ static rct_window_event_list window_server_list_events([](auto& events)
|
|||
events.scroll_mousedown = &window_server_list_scroll_mousedown;
|
||||
events.scroll_mouseover = &window_server_list_scroll_mouseover;
|
||||
events.text_input = &window_server_list_textinput;
|
||||
events.tooltip = &window_server_list_tooltip;
|
||||
events.invalidate = &window_server_list_invalidate;
|
||||
events.paint = &window_server_list_paint;
|
||||
events.scroll_paint = &window_server_list_scrollpaint;
|
||||
|
@ -359,10 +361,15 @@ static void window_server_list_textinput(rct_window* w, rct_widgetindex widgetIn
|
|||
}
|
||||
}
|
||||
|
||||
static OpenRCT2String window_server_list_tooltip(rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback)
|
||||
{
|
||||
auto ft = Formatter();
|
||||
ft.Add<char*>(_version.c_str());
|
||||
return { fallback, ft };
|
||||
}
|
||||
|
||||
static void window_server_list_invalidate(rct_window* w)
|
||||
{
|
||||
auto ft = Formatter::Common();
|
||||
ft.Add<char*>(_version.c_str());
|
||||
window_server_list_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
||||
window_server_list_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
|
||||
window_server_list_widgets[WIDX_TITLE].right = w->width - 2;
|
||||
|
|
|
@ -40,46 +40,42 @@ static int16_t _tooltipNumLines;
|
|||
|
||||
void window_tooltip_reset(const ScreenCoordsXY& screenCoords)
|
||||
{
|
||||
gTooltipCursorX = screenCoords.x;
|
||||
gTooltipCursorY = screenCoords.y;
|
||||
gTooltipCursor = screenCoords;
|
||||
gTooltipTimeout = 0;
|
||||
gTooltipWidget.window_classification = 255;
|
||||
input_set_state(InputState::Normal);
|
||||
input_set_flag(INPUT_FLAG_4, false);
|
||||
}
|
||||
|
||||
void window_tooltip_show(const OpenRCT2String& message, ScreenCoordsXY screenCoords)
|
||||
// Returns the width of the new tooltip text
|
||||
static int32_t FormatTextForTooltip(const OpenRCT2String& message)
|
||||
{
|
||||
rct_window* w;
|
||||
int32_t width, height;
|
||||
|
||||
w = window_find_by_class(WC_ERROR);
|
||||
if (w != nullptr)
|
||||
return;
|
||||
|
||||
char* buffer = gCommonStringFormatBuffer;
|
||||
|
||||
format_string(buffer, sizeof(gCommonStringFormatBuffer), message.str, message.args.Data());
|
||||
format_string(_tooltipText, sizeof(_tooltipText), message.str, message.args.Data());
|
||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
||||
|
||||
int32_t tooltip_text_width;
|
||||
tooltip_text_width = gfx_get_string_width_new_lined(buffer);
|
||||
buffer = gCommonStringFormatBuffer;
|
||||
tooltip_text_width = std::min(tooltip_text_width, 196);
|
||||
auto textWidth = gfx_get_string_width_new_lined(_tooltipText);
|
||||
textWidth = std::min(textWidth, 196);
|
||||
|
||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
||||
|
||||
int32_t numLines, fontSpriteBase;
|
||||
tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &numLines, &fontSpriteBase);
|
||||
|
||||
textWidth = gfx_wrap_string(_tooltipText, textWidth + 1, &numLines, &fontSpriteBase);
|
||||
_tooltipNumLines = numLines;
|
||||
width = tooltip_text_width + 3;
|
||||
height = ((numLines + 1) * font_get_line_height(gCurrentFontSpriteBase)) + 4;
|
||||
return textWidth;
|
||||
}
|
||||
|
||||
void window_tooltip_show(const OpenRCT2String& message, ScreenCoordsXY screenCoords)
|
||||
{
|
||||
auto* w = window_find_by_class(WC_ERROR);
|
||||
if (w != nullptr)
|
||||
return;
|
||||
|
||||
int32_t textWidth = FormatTextForTooltip(message);
|
||||
int32_t width = textWidth + 3;
|
||||
int32_t height = ((_tooltipNumLines + 1) * font_get_line_height(FONT_SPRITE_BASE_MEDIUM)) + 4;
|
||||
window_tooltip_widgets[WIDX_BACKGROUND].right = width;
|
||||
window_tooltip_widgets[WIDX_BACKGROUND].bottom = height;
|
||||
|
||||
std::memcpy(_tooltipText, buffer, sizeof(_tooltipText));
|
||||
|
||||
int32_t screenWidth = context_get_width();
|
||||
int32_t screenHeight = context_get_height();
|
||||
screenCoords.x = std::clamp(screenCoords.x - (width / 2), 0, screenWidth - width);
|
||||
|
|
|
@ -83,8 +83,7 @@ extern widget_ref gPressedWidget;
|
|||
|
||||
extern uint16_t gTooltipTimeout;
|
||||
extern widget_ref gTooltipWidget;
|
||||
extern int32_t gTooltipCursorX;
|
||||
extern int32_t gTooltipCursorY;
|
||||
extern ScreenCoordsXY gTooltipCursor;
|
||||
|
||||
extern TOOL_IDX gCurrentToolId;
|
||||
extern widget_ref gCurrentToolWidget;
|
||||
|
|
Loading…
Reference in New Issue