Files
OpenRCT2-Web/src/openrct2/object/BannerObject.cpp
T

103 lines
3.7 KiB
C++
Raw Normal View History

2016-06-25 23:43:30 +01:00
/*****************************************************************************
2018-06-15 14:07:34 +02:00
* Copyright (c) 2014-2018 OpenRCT2 developers
2016-06-25 23:43:30 +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 23:43:30 +01:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-06-25 23:43:30 +01:00
*****************************************************************************/
2018-06-22 23:03:20 +02:00
#include "BannerObject.h"
2016-06-25 23:43:30 +01:00
#include "../core/IStream.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-02 20:36:42 +01:00
#include "../object/Object.h"
#include "../object/ObjectRepository.h"
2017-12-11 22:01:56 +00:00
#include "ObjectJsonHelpers.h"
2018-01-02 20:36:42 +01:00
#include "ObjectList.h"
2016-06-25 23:43:30 +01:00
2018-06-22 23:03:20 +02:00
void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
2016-06-25 23:43:30 +01:00
{
stream->Seek(6, STREAM_SEEK_CURRENT);
_legacyType.banner.scrolling_mode = stream->ReadValue<uint8_t>();
_legacyType.banner.flags = stream->ReadValue<uint8_t>();
_legacyType.banner.price = stream->ReadValue<int16_t>();
_legacyType.banner.scenery_tab_id = stream->ReadValue<uint8_t>();
stream->Seek(1, STREAM_SEEK_CURRENT);
2016-06-25 23:43:30 +01:00
2017-12-11 13:06:59 +00:00
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
2016-06-25 23:43:30 +01:00
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);
2016-06-25 23:43:30 +01:00
2017-12-11 13:06:59 +00:00
GetImageTable().Read(context, stream);
2016-07-02 17:23:06 +01:00
// Validate properties
if (_legacyType.large_scenery.price <= 0)
{
context->LogError(OBJECT_ERROR_INVALID_PROPERTY, "Price can not be free or negative.");
}
// Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
auto identifier = GetIdentifier();
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);
if (item != nullptr)
{
2018-07-30 22:01:04 +02:00
auto sourceGame = item->GetFirstSourceGame();
if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS
|| sourceGame == OBJECT_SOURCE_TIME_TWISTER
|| sourceGame == OBJECT_SOURCE_CUSTOM)
{
auto scgPathX = Object::GetScgPathXHeader();
SetPrimarySceneryGroup(&scgPathX);
}
}
2016-06-25 23:43:30 +01:00
}
void BannerObject::Load()
{
2017-12-11 13:06:59 +00:00
GetStringTable().Sort();
2016-06-25 23:43:30 +01:00
_legacyType.name = language_allocate_object_string(GetName());
2017-12-11 13:06:59 +00:00
_legacyType.image = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount());
2016-06-25 23:43:30 +01:00
}
void BannerObject::Unload()
{
language_free_object_string(_legacyType.name);
2017-12-11 13:06:59 +00:00
gfx_object_free_images(_legacyType.image, GetImageTable().GetCount());
_legacyType.name = 0;
_legacyType.image = 0;
2016-06-25 23:43:30 +01:00
}
2018-06-22 23:03:20 +02:00
void BannerObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const
2016-07-02 12:29:13 +01:00
{
int32_t x = width / 2;
int32_t y = height / 2;
2016-07-02 12:29:13 +01:00
uint32_t imageId = 0x20D00000 | _legacyType.image;
2016-07-02 12:29:13 +01:00
gfx_draw_sprite(dpi, imageId + 0, x - 12, y + 8, 0);
gfx_draw_sprite(dpi, imageId + 1, x - 12, y + 8, 0);
}
2017-12-11 22:01:56 +00:00
2018-06-22 23:03:20 +02:00
void BannerObject::ReadJson(IReadObjectContext* context, const json_t* root)
2017-12-11 22:01:56 +00:00
{
auto properties = json_object_get(root, "properties");
_legacyType.banner.scrolling_mode = json_integer_value(json_object_get(properties, "scrollingMode"));
_legacyType.banner.price = json_integer_value(json_object_get(properties, "price"));
_legacyType.banner.flags = ObjectJsonHelpers::GetFlags<uint8_t>(
properties,
{
{ "hasPrimaryColour", BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR },
});
2017-12-11 22:01:56 +00:00
SetPrimarySceneryGroup(ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup")));
ObjectJsonHelpers::LoadStrings(root, GetStringTable());
2018-02-08 21:31:30 +00:00
ObjectJsonHelpers::LoadImages(context, root, GetImageTable());
2017-12-11 22:01:56 +00:00
}