From 66a71e009d57af9848cc852cec7787e59cc160fa Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 3 Jun 2020 12:54:39 +0200 Subject: [PATCH] Create Rewind method on Formatter --- src/openrct2-ui/windows/Guest.cpp | 20 ++++++++++++-------- src/openrct2-ui/windows/Ride.cpp | 21 ++++++++++++++------- src/openrct2-ui/windows/RideList.cpp | 2 +- src/openrct2/localisation/Localisation.h | 7 ++++++- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 6c1aa80382..27304b7b4f 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1958,7 +1958,7 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item switch (item) { case SHOP_ITEM_BALLOON: - ft.Increment(-ft.NumBytes()); + ft.Rewind(); ft.Add(SPRITE_ID_PALETTE_COLOUR_1(peep->BalloonColour) | ShopItems[item].Image); break; case SHOP_ITEM_PHOTO: @@ -1967,14 +1967,15 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item ride->FormatNameTo(gCommonFormatArgs + 6); break; case SHOP_ITEM_UMBRELLA: - ft.Increment(-ft.NumBytes()); + ft.Rewind(); ft.Add(SPRITE_ID_PALETTE_COLOUR_1(peep->UmbrellaColour) | ShopItems[item].Image); break; case SHOP_ITEM_VOUCHER: switch (peep->VoucherType) { case VOUCHER_TYPE_PARK_ENTRY_FREE: - ft.Increment(-ft.NumBytes() + 6); + ft.Rewind(); + ft.Increment(6); ft.Add(STR_PEEP_INVENTORY_VOUCHER_PARK_ENTRY_FREE); ft.Add(STR_STRING); ft.Add(parkName); @@ -1983,30 +1984,33 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item ride = get_ride(peep->VoucherArguments); if (ride != nullptr) { - ft.Increment(-ft.NumBytes() + 6); + ft.Rewind(); + ft.Increment(6); ft.Add(STR_PEEP_INVENTORY_VOUCHER_RIDE_FREE); ride->FormatNameTo(gCommonFormatArgs + 8); } break; case VOUCHER_TYPE_PARK_ENTRY_HALF_PRICE: - ft.Increment(-ft.NumBytes() + 6); + ft.Rewind(); + ft.Increment(6); ft.Add(STR_PEEP_INVENTORY_VOUCHER_PARK_ENTRY_HALF_PRICE); ft.Add(STR_STRING); ft.Add(parkName); break; case VOUCHER_TYPE_FOOD_OR_DRINK_FREE: - ft.Increment(-ft.NumBytes() + 6); + ft.Rewind(); + ft.Increment(6); ft.Add(STR_PEEP_INVENTORY_VOUCHER_FOOD_OR_DRINK_FREE); ft.Add(ShopItems[peep->VoucherArguments].Naming.Singular); break; } break; case SHOP_ITEM_HAT: - ft.Increment(-ft.NumBytes()); + ft.Rewind(); ft.Add(SPRITE_ID_PALETTE_COLOUR_1(peep->HatColour) | ShopItems[item].Image); break; case SHOP_ITEM_TSHIRT: - ft.Increment(-ft.NumBytes()); + ft.Rewind(); ft.Add(SPRITE_ID_PALETTE_COLOUR_1(peep->tshirt_colour) | ShopItems[item].Image); break; case SHOP_ITEM_PHOTO2: diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 4d7821300a..8051818602 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -3797,21 +3797,24 @@ static void window_ride_operating_invalidate(rct_window* w) case RIDE_MODE_POWERED_LAUNCH: case RIDE_MODE_UPWARD_LAUNCH: case RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED: - ft.Increment(-ft.NumBytes() + 18); + ft.Rewind(); + ft.Increment(18); ft.Add((ride->launch_speed * 9) / 4); format = STR_RIDE_MODE_SPEED_VALUE; caption = STR_LAUNCH_SPEED; tooltip = STR_LAUNCH_SPEED_TIP; break; case RIDE_MODE_STATION_TO_STATION: - ft.Increment(-ft.NumBytes() + 18); + ft.Rewind(); + ft.Increment(18); ft.Add((ride->speed * 9) / 4); format = STR_RIDE_MODE_SPEED_VALUE; caption = STR_SPEED; tooltip = STR_SPEED_TIP; break; case RIDE_MODE_RACE: - ft.Increment(-ft.NumBytes() + 18); + ft.Rewind(); + ft.Increment(18); ft.Add(ride->num_laps); format = STR_NUMBER_OF_LAPS_VALUE; caption = STR_NUMBER_OF_LAPS; @@ -5844,10 +5847,12 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi { // sadly, STR_RIDE_TIME_ENTRY_WITH_SEPARATOR are defined with the separator AFTER an entry // therefore we set the last entry to use the no-separator format now, post-format - ft.Increment(-ft.NumBytes() + ((numTimes - 1) * 4)); + ft.Rewind(); + ft.Increment((numTimes - 1) * 4); ft.Add(STR_RIDE_TIME_ENTRY); } - ft.Increment(-ft.NumBytes() + (numTimes * 4)); + ft.Rewind(); + ft.Increment(numTimes * 4); ft.Add(0); ft.Add(0); ft.Add(0); @@ -5880,10 +5885,12 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi { // sadly, STR_RIDE_LENGTH_ENTRY_WITH_SEPARATOR are defined with the separator AFTER an entry // therefore we set the last entry to use the no-separator format now, post-format - ft.Increment(-ft.NumBytes() + ((numLengths - 1) * 4)); + ft.Rewind(); + ft.Increment((numLengths - 1) * 4); ft.Add(STR_RIDE_LENGTH_ENTRY); } - ft.Increment(-ft.NumBytes() + (numLengths * 4)); + ft.Rewind(); + ft.Increment(numLengths * 4); ft.Add(0); ft.Add(0); ft.Add(0); diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 454431c503..022b6a669f 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -744,7 +744,7 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, if (formatSecondaryEnabled) { - ft.Increment(-ft.NumBytes()); + ft.Rewind(); ft.Add(formatSecondary); } gfx_draw_string_left_clipped(dpi, format, gCommonFormatArgs, COLOUR_BLACK, { 160, y - 1 }, 157); diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index a8dcc93687..e5778bbb75 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -112,11 +112,16 @@ public: return CurrentBuf; } - void Increment(std::size_t count) + void Increment(size_t count) { CurrentBuf += count; } + void Rewind() + { + CurrentBuf -= NumBytes(); + } + std::size_t NumBytes() const { return CurrentBuf - StartBuf;