From 23a8914de7ac7e3efba715c19ea753187672a04f Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Tue, 25 Oct 2022 21:44:58 +0200 Subject: [PATCH] Allow adding images to MusicObjects --- distribution/changelog.txt | 1 + src/openrct2/object/MusicObject.cpp | 9 ++++++++- src/openrct2/object/MusicObject.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 7c51077234..818fce129a 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -4,6 +4,7 @@ - Improved: [#18192] Tycoon Park has been added Extras tab. - Improved: [#18214] Competition scenarios have received their own section. - Improved: [#18250] Added modern style file and folder pickers on Windows. +- Improved: [#18422] Allow adding images to music objects. - Change: [#18230] Make the large flat to steep pieces available on the corkscrew roller coaster without cheats. - Change: [#18381] Convert custom invisible paths to the built-in ones. - Fix: [#14312] Research ride type message incorrect. diff --git a/src/openrct2/object/MusicObject.cpp b/src/openrct2/object/MusicObject.cpp index eec2442ec5..bdf1659fa9 100644 --- a/src/openrct2/object/MusicObject.cpp +++ b/src/openrct2/object/MusicObject.cpp @@ -18,6 +18,7 @@ #include "../core/IStream.hpp" #include "../core/Json.hpp" #include "../core/Path.hpp" +#include "../drawing/Image.h" #include "../localisation/StringIds.h" #include "../ride/Ride.h" #include "RideObject.h" @@ -71,6 +72,9 @@ void MusicObject::Load() track.Size = track.Asset.GetSize(); } } + + _hasPreview = !!GetImageTable().GetCount(); + _previewImageId = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount()); } void MusicObject::Unload() @@ -84,7 +88,10 @@ void MusicObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t hei // Write (no image) int32_t x = width / 2; int32_t y = height / 2; - DrawTextBasic(dpi, { x, y }, STR_WINDOW_NO_IMAGE, {}, { TextAlignment::CENTRE }); + if (_hasPreview) + gfx_draw_sprite(dpi, ImageId(_previewImageId), { 0, 0 }); + else + DrawTextBasic(dpi, { x, y }, STR_WINDOW_NO_IMAGE, {}, { TextAlignment::CENTRE }); } void MusicObject::ReadJson(IReadObjectContext* context, json_t& root) diff --git a/src/openrct2/object/MusicObject.h b/src/openrct2/object/MusicObject.h index 9aaf0cd620..7145c6b9a7 100644 --- a/src/openrct2/object/MusicObject.h +++ b/src/openrct2/object/MusicObject.h @@ -49,6 +49,8 @@ private: MusicNiceFactor _niceFactor; AudioSampleTable _sampleTable; AudioSampleTable _loadedSampleTable; + bool _hasPreview{}; + uint32_t _previewImageId{}; public: StringId NameStringId{};