2016-06-25 17:09:56 +01:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2016-06-25 17:09:56 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-06-25 17:09:56 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-06-25 17:09:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "FootpathObject.h"
|
|
|
|
|
|
2016-06-25 17:09:56 +01:00
|
|
|
#include "../core/IStream.hpp"
|
2020-08-12 23:05:23 +01:00
|
|
|
#include "../core/Json.hpp"
|
2018-01-05 21:17:33 +00:00
|
|
|
#include "../drawing/Drawing.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Language.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "../world/Footpath.h"
|
2016-06-25 17:09:56 +01:00
|
|
|
|
2020-07-30 23:01:22 +02:00
|
|
|
void FootpathObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
2016-06-25 17:09:56 +01:00
|
|
|
{
|
2020-07-30 23:01:22 +02:00
|
|
|
stream->Seek(10, OpenRCT2::STREAM_SEEK_CURRENT);
|
2019-03-16 14:21:44 +01:00
|
|
|
_legacyType.support_type = static_cast<RailingEntrySupportType>(stream->ReadValue<uint8_t>());
|
2018-06-20 17:28:51 +02:00
|
|
|
_legacyType.flags = stream->ReadValue<uint8_t>();
|
|
|
|
|
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
|
2020-07-30 23:01:22 +02:00
|
|
|
stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT);
|
2016-06-25 17:09:56 +01:00
|
|
|
|
2020-08-29 04:36:58 +02:00
|
|
|
GetStringTable().Read(context, stream, ObjectStringID::NAME);
|
2017-12-11 13:06:59 +00:00
|
|
|
GetImageTable().Read(context, stream);
|
2016-07-02 17:23:06 +01:00
|
|
|
|
|
|
|
|
// Validate properties
|
2019-03-16 14:21:44 +01:00
|
|
|
if (_legacyType.support_type >= RailingEntrySupportType::Count)
|
2016-07-02 17:23:06 +01:00
|
|
|
{
|
2020-10-10 12:21:07 -03:00
|
|
|
context->LogError(ObjectError::InvalidProperty, "RailingEntrySupportType not supported.");
|
2016-07-02 17:23:06 +01:00
|
|
|
}
|
2016-06-25 17:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FootpathObject::Load()
|
|
|
|
|
{
|
2017-12-11 13:06:59 +00:00
|
|
|
GetStringTable().Sort();
|
2023-01-17 00:12:35 +01:00
|
|
|
_legacyType.string_idx = LanguageAllocateObjectString(GetName());
|
2023-04-13 15:09:15 -04:00
|
|
|
_legacyType.image = LoadImages();
|
2016-06-25 17:09:56 +01:00
|
|
|
_legacyType.bridge_image = _legacyType.image + 109;
|
2019-01-20 21:38:38 +01:00
|
|
|
|
2021-09-05 18:44:43 +02:00
|
|
|
_pathSurfaceDescriptor.Name = _legacyType.string_idx;
|
|
|
|
|
_pathSurfaceDescriptor.Image = _legacyType.image;
|
|
|
|
|
_pathSurfaceDescriptor.PreviewImage = _legacyType.GetPreviewImage();
|
|
|
|
|
_pathSurfaceDescriptor.Flags = _legacyType.flags;
|
2019-01-20 21:38:38 +01:00
|
|
|
|
2021-09-05 18:44:43 +02:00
|
|
|
_queueSurfaceDescriptor.Name = _legacyType.string_idx;
|
|
|
|
|
_queueSurfaceDescriptor.Image = _legacyType.GetQueueImage();
|
|
|
|
|
_queueSurfaceDescriptor.PreviewImage = _legacyType.GetQueuePreviewImage();
|
|
|
|
|
_queueSurfaceDescriptor.Flags = _legacyType.flags | FOOTPATH_ENTRY_FLAG_IS_QUEUE;
|
2019-03-16 12:37:32 +01:00
|
|
|
|
2021-09-05 18:44:43 +02:00
|
|
|
_pathRailingsDescriptor.Name = _legacyType.string_idx;
|
|
|
|
|
_pathRailingsDescriptor.BridgeImage = _legacyType.bridge_image;
|
|
|
|
|
_pathRailingsDescriptor.PreviewImage = _legacyType.GetPreviewImage();
|
|
|
|
|
_pathRailingsDescriptor.Flags = _legacyType.flags;
|
|
|
|
|
_pathRailingsDescriptor.ScrollingMode = _legacyType.scrolling_mode;
|
|
|
|
|
_pathRailingsDescriptor.SupportType = _legacyType.support_type;
|
|
|
|
|
_pathRailingsDescriptor.RailingsImage = _legacyType.GetRailingsImage();
|
2016-06-25 17:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FootpathObject::Unload()
|
|
|
|
|
{
|
2023-01-17 00:12:35 +01:00
|
|
|
LanguageFreeObjectString(_legacyType.string_idx);
|
2023-04-13 15:09:15 -04:00
|
|
|
UnloadImages();
|
2016-07-03 18:02:18 +01:00
|
|
|
|
|
|
|
|
_legacyType.string_idx = 0;
|
|
|
|
|
_legacyType.image = 0;
|
2016-06-25 17:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-13 16:52:49 +01:00
|
|
|
void FootpathObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const
|
2016-07-02 12:29:13 +01:00
|
|
|
{
|
2020-06-23 23:32:34 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ width / 2, height / 2 };
|
2023-04-03 20:38:28 +02:00
|
|
|
GfxDrawSprite(dpi, ImageId(_pathSurfaceDescriptor.PreviewImage), screenCoords - ScreenCoordsXY{ 49, 17 });
|
|
|
|
|
GfxDrawSprite(dpi, ImageId(_queueSurfaceDescriptor.PreviewImage), screenCoords + ScreenCoordsXY{ 4, -17 });
|
2016-07-02 12:29:13 +01:00
|
|
|
}
|
2017-12-08 18:27:30 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
void FootpathObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2017-12-08 18:27:30 +00:00
|
|
|
{
|
|
|
|
|
}
|