mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Refactor paint banner to use ImageId
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../Paint.h"
|
||||
|
||||
#include "../../Game.h"
|
||||
#include "../../config/Config.h"
|
||||
#include "../../interface/Viewport.h"
|
||||
@@ -16,10 +18,8 @@
|
||||
#include "../../world/Banner.h"
|
||||
#include "../../world/Scenery.h"
|
||||
#include "../../world/TileInspector.h"
|
||||
#include "../Paint.h"
|
||||
#include "Paint.TileElement.h"
|
||||
|
||||
/** rct2: 0x0098D884 */
|
||||
// BannerBoundBoxes[rotation][0] is for the pole in the back
|
||||
// BannerBoundBoxes[rotation][1] is for the pole and the banner in the front
|
||||
constexpr CoordsXY BannerBoundBoxes[][2] = {
|
||||
@@ -29,20 +29,45 @@ constexpr CoordsXY BannerBoundBoxes[][2] = {
|
||||
{ { 2, 1 }, { 29, 1 } },
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006B9CC4
|
||||
*/
|
||||
void PaintBanner(paint_session* session, uint8_t direction, int32_t height, const BannerElement& bannerElement)
|
||||
static void PaintBannerScrollingText(
|
||||
paint_session* session, const BannerSceneryEntry& bannerEntry, Banner& banner, const BannerElement& bannerElement,
|
||||
Direction direction, int32_t height, const CoordsXYZ& bbOffset)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
session->InteractionType = ViewportInteractionItem::Banner;
|
||||
|
||||
if (dpi->zoom_level > ZoomLevel{ 1 } || gTrackDesignSaveMode || (session->ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
// If text on hidden direction or ghost
|
||||
direction = direction_reverse(direction) - 1;
|
||||
if (direction >= 2 || (bannerElement.IsGhost()))
|
||||
return;
|
||||
|
||||
height -= 16;
|
||||
auto scrollingMode = bannerEntry.scrolling_mode + (direction & 3);
|
||||
if (scrollingMode >= MAX_SCROLLING_TEXT_MODES)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto ft = Formatter();
|
||||
banner.FormatTextTo(ft, true);
|
||||
|
||||
char text[256];
|
||||
if (gConfigGeneral.upper_case_banners)
|
||||
{
|
||||
format_string_to_upper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data());
|
||||
}
|
||||
else
|
||||
{
|
||||
format_string(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data());
|
||||
}
|
||||
|
||||
auto stringWidth = gfx_get_string_width(text, FontSpriteBase::TINY);
|
||||
auto scroll = (gCurrentTicks / 2) % stringWidth;
|
||||
auto imageId = scrolling_text_setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, COLOUR_BLACK);
|
||||
PaintAddImageAsChild(session, imageId, { 0, 0, height + 22 }, { 1, 1, 21 }, bbOffset);
|
||||
}
|
||||
|
||||
void PaintBanner(paint_session* session, uint8_t direction, int32_t height, const BannerElement& bannerElement)
|
||||
{
|
||||
if (session->DPI.zoom_level > ZoomLevel{ 1 } || gTrackDesignSaveMode
|
||||
|| (session->ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
return;
|
||||
|
||||
auto banner = bannerElement.GetBanner();
|
||||
if (banner == nullptr)
|
||||
@@ -56,65 +81,35 @@ void PaintBanner(paint_session* session, uint8_t direction, int32_t height, cons
|
||||
return;
|
||||
}
|
||||
|
||||
session->InteractionType = ViewportInteractionItem::Banner;
|
||||
|
||||
height -= 16;
|
||||
|
||||
direction += bannerElement.GetPosition();
|
||||
direction &= 3;
|
||||
|
||||
CoordsXYZ boundBoxOffset = CoordsXYZ(BannerBoundBoxes[direction][0], height + 2);
|
||||
|
||||
uint32_t base_id = (direction << 1) + bannerEntry->image;
|
||||
uint32_t image_id = base_id;
|
||||
|
||||
if (bannerElement.IsGhost()) // if being placed
|
||||
ImageId imageTemplate;
|
||||
if (bannerElement.IsGhost())
|
||||
{
|
||||
session->InteractionType = ViewportInteractionItem::None;
|
||||
image_id |= CONSTRUCTION_MARKER;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::Palette44);
|
||||
}
|
||||
else if (OpenRCT2::TileInspector::IsElementSelected(reinterpret_cast<const TileElement*>(&bannerElement)))
|
||||
{
|
||||
image_id |= CONSTRUCTION_MARKER;
|
||||
imageTemplate = ImageId().WithRemap(FilterPaletteID::Palette44);
|
||||
}
|
||||
else
|
||||
{
|
||||
image_id |= (banner->colour << 19) | IMAGE_TYPE_REMAP;
|
||||
imageTemplate = ImageId().WithPrimary(banner->colour);
|
||||
}
|
||||
|
||||
PaintAddImageAsParent(session, image_id, { 0, 0, height }, { 1, 1, 0x15 }, boundBoxOffset);
|
||||
boundBoxOffset.x = BannerBoundBoxes[direction][1].x;
|
||||
boundBoxOffset.y = BannerBoundBoxes[direction][1].y;
|
||||
auto imageIndex = (direction << 1) + bannerEntry->image;
|
||||
auto imageId = imageTemplate.WithIndex(imageIndex);
|
||||
auto bbOffset = CoordsXYZ(BannerBoundBoxes[direction][0], height + 2);
|
||||
PaintAddImageAsParent(session, imageId, { 0, 0, height }, { 1, 1, 21 }, bbOffset);
|
||||
|
||||
image_id++;
|
||||
PaintAddImageAsParent(session, image_id, { 0, 0, height }, { 1, 1, 0x15 }, boundBoxOffset);
|
||||
bbOffset = CoordsXYZ(BannerBoundBoxes[direction][1], height + 2);
|
||||
PaintAddImageAsParent(session, imageId.WithIndexOffset(1), { 0, 0, height }, { 1, 1, 21 }, bbOffset);
|
||||
|
||||
// Opposite direction
|
||||
direction = direction_reverse(direction);
|
||||
direction--;
|
||||
// If text not showing / ghost
|
||||
if (direction >= 2 || (bannerElement.IsGhost()))
|
||||
return;
|
||||
|
||||
uint16_t scrollingMode = bannerEntry->scrolling_mode;
|
||||
if (scrollingMode >= MAX_SCROLLING_TEXT_MODES)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scrollingMode += direction;
|
||||
|
||||
auto ft = Formatter();
|
||||
banner->FormatTextTo(ft, /*addColour*/ true);
|
||||
|
||||
if (gConfigGeneral.upper_case_banners)
|
||||
{
|
||||
format_string_to_upper(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data());
|
||||
}
|
||||
else
|
||||
{
|
||||
format_string(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data());
|
||||
}
|
||||
|
||||
uint16_t string_width = gfx_get_string_width(gCommonStringFormatBuffer, FontSpriteBase::TINY);
|
||||
uint16_t scroll = (gCurrentTicks / 2) % string_width;
|
||||
auto scrollIndex = scrolling_text_setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, COLOUR_BLACK);
|
||||
PaintAddImageAsChild(
|
||||
session, scrollIndex, 0, 0, 1, 1, 0x15, height + 22, boundBoxOffset.x, boundBoxOffset.y, boundBoxOffset.z);
|
||||
PaintBannerScrollingText(session, *bannerEntry, *banner, bannerElement, direction, height, bbOffset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user