2016-06-25 02:52:58 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-06-25 02:52:58 +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 02:52:58 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-06-25 02:52:58 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "EntranceObject.h"
|
|
|
|
|
|
2016-06-25 02:52:58 +01:00
|
|
|
#include "../core/IStream.hpp"
|
2020-10-02 11:31:20 +01:00
|
|
|
#include "../core/Json.hpp"
|
2017-06-23 23:17:22 +02:00
|
|
|
#include "../core/String.hpp"
|
2018-01-05 21:17:33 +00:00
|
|
|
#include "../drawing/Drawing.h"
|
2021-12-07 20:55:27 +00:00
|
|
|
#include "../drawing/Image.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Localisation.h"
|
2016-06-25 16:34:35 +01:00
|
|
|
|
2020-07-30 23:01:22 +02:00
|
|
|
void EntranceObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
|
2016-06-25 02:52:58 +01:00
|
|
|
{
|
2020-07-30 23:01:22 +02:00
|
|
|
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
|
2018-06-20 17:28:51 +02:00
|
|
|
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
|
|
|
|
|
_legacyType.text_height = stream->ReadValue<uint8_t>();
|
2016-06-25 02:52:58 +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-06-25 02:52:58 +01:00
|
|
|
}
|
2016-06-25 12:30:20 +01:00
|
|
|
|
|
|
|
|
void EntranceObject::Load()
|
|
|
|
|
{
|
2017-12-11 13:06:59 +00:00
|
|
|
GetStringTable().Sort();
|
2016-06-25 16:34:35 +01:00
|
|
|
_legacyType.string_idx = language_allocate_object_string(GetName());
|
2017-12-11 13:06:59 +00:00
|
|
|
_legacyType.image_id = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount());
|
2016-06-25 12:30:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntranceObject::Unload()
|
|
|
|
|
{
|
2016-06-25 16:34:35 +01:00
|
|
|
language_free_object_string(_legacyType.string_idx);
|
2017-12-11 13:06:59 +00:00
|
|
|
gfx_object_free_images(_legacyType.image_id, GetImageTable().GetCount());
|
2016-07-03 18:02:18 +01:00
|
|
|
|
|
|
|
|
_legacyType.string_idx = 0;
|
|
|
|
|
_legacyType.image_id = 0;
|
2016-06-25 12:30:20 +01:00
|
|
|
}
|
2016-06-25 14:44:04 +01:00
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
void EntranceObject::DrawPreview(rct_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 };
|
2016-07-02 12:29:13 +01:00
|
|
|
|
2021-11-29 14:36:36 +01:00
|
|
|
gfx_draw_sprite(dpi, ImageId(_legacyType.image_id + 1), screenCoords + ScreenCoordsXY{ -32, 14 });
|
|
|
|
|
gfx_draw_sprite(dpi, ImageId(_legacyType.image_id + 0), screenCoords + ScreenCoordsXY{ 0, 28 });
|
|
|
|
|
gfx_draw_sprite(dpi, ImageId(_legacyType.image_id + 2), screenCoords + ScreenCoordsXY{ 32, 44 });
|
2016-07-02 12:29:13 +01:00
|
|
|
}
|
2017-12-07 23:50:44 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
void EntranceObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2017-12-07 23:50:44 +00:00
|
|
|
{
|
2020-08-12 23:05:23 +01:00
|
|
|
Guard::Assert(root.is_object(), "EntranceObject::ReadJson expects parameter root to be object");
|
2017-12-07 23:50:44 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
json_t properties = root["properties"];
|
|
|
|
|
|
|
|
|
|
if (properties.is_object())
|
|
|
|
|
{
|
|
|
|
|
_legacyType.scrolling_mode = Json::GetNumber<uint8_t>(properties["scrollingMode"]);
|
|
|
|
|
_legacyType.text_height = Json::GetNumber<uint8_t>(properties["textHeight"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopulateTablesFromJson(context, root);
|
2017-12-07 23:50:44 +00:00
|
|
|
}
|
2021-12-03 19:55:25 +00:00
|
|
|
|
|
|
|
|
ImageIndex EntranceObject::GetImage(uint8_t sequence, Direction direction) const
|
|
|
|
|
{
|
|
|
|
|
if (sequence > 2)
|
|
|
|
|
return ImageIndexUndefined;
|
|
|
|
|
return _legacyType.image_id + ((direction & 3) * 3) + sequence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t EntranceObject::GetScrollingMode() const
|
|
|
|
|
{
|
|
|
|
|
return _legacyType.scrolling_mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t EntranceObject::GetTextHeight() const
|
|
|
|
|
{
|
|
|
|
|
return _legacyType.text_height;
|
|
|
|
|
}
|