2018-12-05 20:33:45 +00:00
|
|
|
/*****************************************************************************
|
2026-01-05 14:42:59 +01:00
|
|
|
* Copyright (c) 2014-2026 OpenRCT2 developers
|
2018-12-05 20:33:45 +00:00
|
|
|
*
|
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
|
*
|
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "StationObject.h"
|
|
|
|
|
|
2024-10-15 17:39:54 +02:00
|
|
|
#include "../core/Guard.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
#include "../core/IStream.hpp"
|
2020-10-02 11:31:20 +01:00
|
|
|
#include "../core/Json.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
#include "../core/String.hpp"
|
|
|
|
|
#include "../drawing/Drawing.h"
|
2026-01-11 19:18:53 +01:00
|
|
|
#include "../drawing/ScrollingText.h"
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
namespace OpenRCT2
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::Load()
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
GetStringTable().Sort();
|
|
|
|
|
NameStringId = LanguageAllocateObjectString(GetName());
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
auto numImages = GetImageTable().GetCount();
|
2026-02-23 23:53:56 +01:00
|
|
|
if (numImages == 0)
|
|
|
|
|
return;
|
2025-08-17 11:46:03 +02:00
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
baseImageIndex = LoadImages();
|
|
|
|
|
|
|
|
|
|
entranceBackIndex = baseImageIndex;
|
|
|
|
|
entranceFrontIndex = entranceBackIndex + 4;
|
|
|
|
|
|
|
|
|
|
exitBackIndex = entranceBackIndex + 8;
|
|
|
|
|
exitFrontIndex = entranceBackIndex + 12;
|
|
|
|
|
|
|
|
|
|
if (!(Flags & StationObjectFlags::isTransparent))
|
|
|
|
|
{
|
|
|
|
|
if (numImages > 16)
|
|
|
|
|
shelterIndex = entranceBackIndex + 16;
|
|
|
|
|
|
|
|
|
|
return;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
2026-02-23 23:53:56 +01:00
|
|
|
|
|
|
|
|
entranceBackGlassIndex = entranceBackIndex + 16;
|
|
|
|
|
entranceFrontGlassIndex = entranceBackIndex + 20;
|
|
|
|
|
|
|
|
|
|
exitBackGlassIndex = entranceBackIndex + 24;
|
|
|
|
|
exitFrontGlassIndex = entranceBackIndex + 28;
|
|
|
|
|
|
|
|
|
|
if (numImages > 32)
|
|
|
|
|
shelterIndex = entranceBackIndex + 32;
|
|
|
|
|
|
|
|
|
|
if (numImages > 44)
|
|
|
|
|
shelterGlassIndex = entranceBackIndex + 44;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::Unload()
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
LanguageFreeObjectString(NameStringId);
|
|
|
|
|
UnloadImages();
|
|
|
|
|
|
|
|
|
|
NameStringId = 0;
|
2026-02-23 23:53:56 +01:00
|
|
|
baseImageIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
entranceBackIndex = kImageIndexUndefined;
|
|
|
|
|
entranceFrontIndex = kImageIndexUndefined;
|
|
|
|
|
exitBackIndex = kImageIndexUndefined;
|
|
|
|
|
exitFrontIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
entranceBackGlassIndex = kImageIndexUndefined;
|
|
|
|
|
entranceFrontGlassIndex = kImageIndexUndefined;
|
|
|
|
|
exitBackGlassIndex = kImageIndexUndefined;
|
|
|
|
|
exitFrontGlassIndex = kImageIndexUndefined;
|
|
|
|
|
|
|
|
|
|
shelterIndex = kImageIndexUndefined;
|
|
|
|
|
shelterGlassIndex = kImageIndexUndefined;
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-26 12:58:33 +01:00
|
|
|
void StationObject::DrawPreview(Drawing::RenderTarget& rt, int32_t width, int32_t height) const
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ width / 2, (height / 2) + 16 };
|
|
|
|
|
|
2026-01-28 10:06:45 +01:00
|
|
|
auto colour0 = Drawing::Colour::lightBlue;
|
|
|
|
|
auto colour1 = Drawing::Colour::bordeauxRed;
|
2025-08-17 11:46:03 +02:00
|
|
|
auto tcolour0 = colour0;
|
|
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
// Draw back sprite
|
|
|
|
|
auto backImageId = ImageId(entranceBackIndex, colour0, colour1);
|
|
|
|
|
GfxDrawSprite(rt, backImageId, screenCoords);
|
2025-08-17 11:46:03 +02:00
|
|
|
if (Flags & StationObjectFlags::isTransparent)
|
|
|
|
|
{
|
2026-02-23 23:53:56 +01:00
|
|
|
auto tImageId = ImageId(entranceBackGlassIndex).WithTransparency(tcolour0);
|
2025-08-17 11:46:03 +02:00
|
|
|
GfxDrawSprite(rt, tImageId, screenCoords);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 23:53:56 +01:00
|
|
|
// Draw front sprite
|
|
|
|
|
auto frontImageId = ImageId(entranceFrontIndex, colour0, colour1);
|
|
|
|
|
GfxDrawSprite(rt, frontImageId, screenCoords);
|
2025-08-17 11:46:03 +02:00
|
|
|
if (Flags & StationObjectFlags::isTransparent)
|
|
|
|
|
{
|
2026-02-23 23:53:56 +01:00
|
|
|
auto frontGlassImageId = ImageId(entranceFrontGlassIndex).WithTransparency(tcolour0);
|
|
|
|
|
GfxDrawSprite(rt, frontGlassImageId, screenCoords);
|
2025-08-17 11:46:03 +02:00
|
|
|
}
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-17 11:46:03 +02:00
|
|
|
void StationObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2025-08-17 11:46:03 +02:00
|
|
|
Guard::Assert(root.is_object(), "StationObject::ReadJson expects parameter root to be object");
|
|
|
|
|
|
|
|
|
|
auto properties = root["properties"];
|
|
|
|
|
|
|
|
|
|
if (properties.is_object())
|
|
|
|
|
{
|
|
|
|
|
Height = Json::GetNumber<int32_t>(properties["height"]);
|
|
|
|
|
ScrollingMode = Json::GetNumber<uint8_t>(properties["scrollingMode"], kScrollingModeNone);
|
|
|
|
|
Flags = Json::GetFlags<uint32_t>(
|
|
|
|
|
properties,
|
|
|
|
|
{
|
|
|
|
|
{ "hasPrimaryColour", StationObjectFlags::hasPrimaryColour },
|
|
|
|
|
{ "hasSecondaryColour", StationObjectFlags::hasSecondaryColour },
|
|
|
|
|
{ "isTransparent", StationObjectFlags::isTransparent },
|
|
|
|
|
{ "noPlatforms", StationObjectFlags::noPlatforms },
|
|
|
|
|
{ "hasShelter", StationObjectFlags::hasShelter },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopulateTablesFromJson(context, root);
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
2025-08-17 11:46:03 +02:00
|
|
|
} // namespace OpenRCT2
|