diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 3f6cda7c36..7f4dc1075c 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -472,6 +472,16 @@ public: case INTENT_ACTION_TRACK_DESIGN_RESTORE_PROVISIONAL: TrackPlaceRestoreProvisional(); break; + + case INTENT_ACTION_SET_MAP_TOOLTIP: + { + auto ft = static_cast(intent.GetPointerExtra(INTENT_EXTRA_FORMATTER)); + if (ft != nullptr) + { + SetMapTooltip(*ft); + } + break; + } } } diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index c0d3e4abc5..204e6148d7 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -1082,8 +1082,9 @@ void process_mouse_over(const ScreenCoordsXY& screenCoords) int32_t cursorId; cursorId = CURSOR_ARROW; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_NONE); + SetMapTooltip(ft); window = window_find_from_point(screenCoords); if (window != nullptr) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 398291332e..e9287a21e4 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../windows/Window.h" #include "Viewport.h" #include "Window.h" @@ -118,9 +119,10 @@ InteractionInfo viewport_interaction_get_item_left(const ScreenCoordsXY& screenC auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark(); auto parkName = park.Name.c_str(); - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_STRING); ft.Add(parkName); + SetMapTooltip(ft); break; } default: @@ -267,9 +269,10 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen ride = get_ride(vehicle->ride); if (ride != nullptr && ride->status == RIDE_STATUS_CLOSED) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ride->FormatNameTo(ft); + SetMapTooltip(ft); } return info; } @@ -296,7 +299,7 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen if (ride->status != RIDE_STATUS_CLOSED) return info; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) @@ -365,6 +368,7 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen stationIndex--; stationIndex++; ft.Add(stationIndex); + SetMapTooltip(ft); return info; } case VIEWPORT_INTERACTION_ITEM_WALL: @@ -374,11 +378,12 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen auto banner = tileElement->AsWall()->GetBanner(); if (banner != nullptr) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID); banner->FormatTextTo(ft); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; } } @@ -391,11 +396,12 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen auto banner = tileElement->AsLargeScenery()->GetBanner(); if (banner != nullptr) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID); banner->FormatTextTo(ft); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; } } @@ -406,11 +412,12 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen auto banner = tileElement->AsBanner()->GetBanner(); sceneryEntry = get_banner_entry(banner->type); - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID); banner->FormatTextTo(ft, /*addColour*/ true); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; } default: @@ -426,13 +433,14 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen } } - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: sceneryEntry = tileElement->AsSmallScenery()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: @@ -441,6 +449,7 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen ft.Add(STR_QUEUE_LINE_MAP_TIP); else ft.Add(STR_FOOTPATH_MAP_TIP); + SetMapTooltip(ft); return info; case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: @@ -451,6 +460,7 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen ft.Add(STR_BROKEN); } ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; case VIEWPORT_INTERACTION_ITEM_PARK: @@ -462,18 +472,21 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(STR_OBJECT_SELECTION_PARK_ENTRANCE); + SetMapTooltip(ft); return info; case VIEWPORT_INTERACTION_ITEM_WALL: sceneryEntry = tileElement->AsWall()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); + SetMapTooltip(ft); return info; default: break; diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 41d8119161..42a68b213a 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -669,16 +669,16 @@ static void window_game_bottom_toolbar_draw_middle_panel(rct_drawpixelinfo* dpi, // Check if there is a map tooltip to draw rct_string_id stringId; - std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id)); + auto ft = GetMapTooltip(); + std::memcpy(&stringId, ft.Data(), sizeof(rct_string_id)); if (stringId == STR_NONE) { - gfx_draw_string_centred_wrapped( - dpi, gMapTooltipFormatArgs, middleWidgetCoords, width, STR_TITLE_SEQUENCE_OPENRCT2, w->colours[0]); + gfx_draw_string_centred_wrapped(dpi, ft.Data(), middleWidgetCoords, width, STR_TITLE_SEQUENCE_OPENRCT2, w->colours[0]); } else { // Show tooltip in bottom toolbar - gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, middleWidgetCoords, width, STR_STRINGID, w->colours[0]); + gfx_draw_string_centred_wrapped(dpi, ft.Data(), middleWidgetCoords, width, STR_STRINGID, w->colours[0]); } } diff --git a/src/openrct2-ui/windows/MapTooltip.cpp b/src/openrct2-ui/windows/MapTooltip.cpp index 0f094637a8..1218e0fced 100644 --- a/src/openrct2-ui/windows/MapTooltip.cpp +++ b/src/openrct2-ui/windows/MapTooltip.cpp @@ -39,6 +39,18 @@ static int32_t _cursorHoldDuration; static void window_map_tooltip_open(); +static Formatter _mapTooltipArgs; + +void SetMapTooltip(Formatter& ft) +{ + _mapTooltipArgs = ft; +} + +const Formatter& GetMapTooltip() +{ + return _mapTooltipArgs; +} + /** * * rct2: 0x006EE77A @@ -65,7 +77,7 @@ void window_map_tooltip_update_visibility() // Show or hide tooltip rct_string_id stringId; - std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id)); + std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(rct_string_id)); if (_cursorHoldDuration < 25 || stringId == STR_NONE || input_test_place_object_modifier( @@ -126,12 +138,13 @@ static void window_map_tooltip_update(rct_window* w) static void window_map_tooltip_paint(rct_window* w, rct_drawpixelinfo* dpi) { rct_string_id stringId; - std::memcpy(&stringId, gMapTooltipFormatArgs, sizeof(rct_string_id)); + std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(rct_string_id)); if (stringId == STR_NONE) { return; } ScreenCoordsXY stringCoords(w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2)); - gfx_draw_string_centred_wrapped(dpi, gMapTooltipFormatArgs, stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK); + gfx_draw_string_centred_wrapped( + dpi, _mapTooltipArgs.Data(), stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK); } diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index c42721031f..bd39047822 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -141,6 +141,8 @@ void window_ride_measurements_design_cancel(); extern RideSelection _window_track_list_item; rct_window* window_track_list_open(RideSelection item); +void SetMapTooltip(Formatter& ft); +const Formatter& GetMapTooltip(); void window_map_tooltip_update_visibility(); rct_window* window_maze_construction_open(); diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index 819239620b..941ac80136 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -38,7 +38,6 @@ thread_local char gCommonStringFormatBuffer[512]; thread_local uint8_t gCommonFormatArgs[80]; -thread_local uint8_t gMapTooltipFormatArgs[40]; #ifdef DEBUG // Set to true before a string format call to see details of the formatting. diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index 3b8fbecbfc..bdf3ac4e8d 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -68,7 +68,6 @@ extern const char* real_names[1024]; extern thread_local char gCommonStringFormatBuffer[512]; extern thread_local uint8_t gCommonFormatArgs[80]; -extern thread_local uint8_t gMapTooltipFormatArgs[40]; extern bool gDebugStringFormatting; extern const rct_string_id SpeedNames[5]; @@ -127,11 +126,6 @@ public: return Formatter{ gCommonFormatArgs }; } - static Formatter MapTooltip() - { - return Formatter{ gMapTooltipFormatArgs }; - } - auto Buf() { return CurrentBuf; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index ff44194aa6..6fe21eedbf 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2161,7 +2161,7 @@ int32_t get_peep_face_sprite_large(Peep* peep) void peep_set_map_tooltip(Peep* peep) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); if (peep->AssignedPeepType == PeepType::Guest) { ft.Add((peep->PeepFlags & PEEP_FLAGS_TRACKING) ? STR_TRACKED_GUEST_MAP_TIP : STR_GUEST_MAP_TIP); @@ -2175,6 +2175,10 @@ void peep_set_map_tooltip(Peep* peep) peep->FormatNameTo(ft); peep->FormatActionTo(ft); } + + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } /** diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 66d5a755d6..d4dc23034b 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -3306,10 +3306,13 @@ static void ride_track_set_map_tooltip(TileElement* tileElement) auto ride = get_ride(rideIndex); if (ride != nullptr) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ride->FormatNameTo(ft); ride->FormatStatusTo(ft); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } } @@ -3319,10 +3322,13 @@ static void ride_queue_banner_set_map_tooltip(TileElement* tileElement) auto ride = get_ride(rideIndex); if (ride != nullptr) { - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ride->FormatNameTo(ft); ride->FormatStatusTo(ft); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } } @@ -3337,13 +3343,16 @@ static void ride_station_set_map_tooltip(TileElement* tileElement) if (ride->stations[i].Start.isNull()) stationIndex--; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ft.Add(ride->num_stations <= 1 ? STR_RIDE_STATION : STR_RIDE_STATION_X); ride->FormatNameTo(ft); ft.Add(RideComponentNames[RideTypeDescriptors[ride->type].NameConvention.station].capitalised); ft.Add(stationIndex + 1); ride->FormatStatusTo(ft); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } } @@ -3366,7 +3375,7 @@ static void ride_entrance_set_map_tooltip(TileElement* tileElement) if (!ride_get_entrance_location(ride, stationIndex).isNull()) queueLength = ride->stations[stationIndex].QueueLength; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ft.Add(ride->num_stations <= 1 ? STR_RIDE_ENTRANCE : STR_RIDE_STATION_X_ENTRANCE); ride->FormatNameTo(ft); @@ -3388,6 +3397,9 @@ static void ride_entrance_set_map_tooltip(TileElement* tileElement) ft.Add(STR_QUEUE_PEOPLE); } ft.Add(queueLength); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } else { @@ -3397,7 +3409,7 @@ static void ride_entrance_set_map_tooltip(TileElement* tileElement) if (ride->stations[i].Start.isNull()) stationIndex--; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(ride->num_stations <= 1 ? STR_RIDE_EXIT : STR_RIDE_STATION_X_EXIT); ride->FormatNameTo(ft); @@ -3405,6 +3417,9 @@ static void ride_entrance_set_map_tooltip(TileElement* tileElement) ft.Increment(sizeof(uint16_t)); ft.Add(stationIndex + 1); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } } } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7a7d427d51..4cb8088424 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6224,13 +6224,16 @@ void Vehicle::SetMapToolbar() const if (curRide->vehicles[vehicleIndex] == vehicle->sprite_index) break; - auto ft = Formatter::MapTooltip(); + auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ft.Add(STR_MAP_TOOLTIP_STRINGID_STRINGID); curRide->FormatNameTo(ft); ft.Add(RideComponentNames[RideTypeDescriptors[curRide->type].NameConvention.vehicle].capitalised); ft.Add(vehicleIndex + 1); curRide->FormatStatusTo(ft); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); + intent.putExtra(INTENT_EXTRA_FORMATTER, &ft); + context_broadcast_intent(&intent); } } diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index b67b44c202..9484adeb3e 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -74,6 +74,7 @@ enum INTENT_EXTRA_LIST_COUNT, INTENT_EXTRA_PAGE, INTENT_EXTRA_BANNER_INDEX, + INTENT_EXTRA_FORMATTER, }; enum @@ -105,4 +106,5 @@ enum INTENT_ACTION_UPDATE_RESEARCH, INTENT_ACTION_TRACK_DESIGN_REMOVE_PROVISIONAL, INTENT_ACTION_TRACK_DESIGN_RESTORE_PROVISIONAL, + INTENT_ACTION_SET_MAP_TOOLTIP, };