1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-28 17:24:47 +01:00
Files
OpenRCT2/src/openrct2/actions/SignSetNameAction.cpp
Aaron van Geffen 05e56517ab Adopt existing namespaces into OpenRCT2 namespace (#22368)
* Put all of TitleSequenceManager into the same namespace

* Move RideConstructionState into the OpenRCT2 namespace

* Adopt existing namespaces into OpenRCT2 namespace

This adds `using namespace OpenRCT2` to compilation units where appropriate,
as a means to get the codebase to compile until these units have been placed
in a namespace of their own.
2024-07-26 09:59:58 +02:00

94 lines
2.7 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* 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 "SignSetNameAction.h"
#include "../Context.h"
#include "../Diagnostic.h"
#include "../drawing/Drawing.h"
#include "../localisation/StringIds.h"
#include "../ride/Ride.h"
#include "../world/Banner.h"
#include <string>
using namespace OpenRCT2;
SignSetNameAction::SignSetNameAction(BannerIndex bannerIndex, const std::string& name)
: _bannerIndex(bannerIndex)
, _name(name)
{
}
void SignSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit("id", _bannerIndex);
visitor.Visit("name", _name);
}
uint16_t SignSetNameAction::GetActionFlags() const
{
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
}
void SignSetNameAction::Serialise(DataSerialiser& stream)
{
GameAction::Serialise(stream);
stream << DS_TAG(_bannerIndex) << DS_TAG(_name);
}
GameActions::Result SignSetNameAction::Query() const
{
auto banner = GetBanner(_bannerIndex);
if (banner == nullptr)
{
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_SIGN, STR_NONE);
}
return GameActions::Result();
}
GameActions::Result SignSetNameAction::Execute() const
{
auto banner = GetBanner(_bannerIndex);
if (banner == nullptr)
{
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_SIGN, STR_NONE);
}
if (!_name.empty())
{
banner->flags &= ~BANNER_FLAG_LINKED_TO_RIDE;
banner->ride_index = RideId::GetNull();
banner->text = _name;
}
else
{
// If empty name take closest ride name.
RideId rideIndex = BannerGetClosestRideIndex({ banner->position.ToCoordsXY(), 16 });
if (rideIndex.IsNull())
{
banner->flags &= ~BANNER_FLAG_LINKED_TO_RIDE;
banner->ride_index = RideId::GetNull();
banner->text = {};
}
else
{
banner->flags |= BANNER_FLAG_LINKED_TO_RIDE;
banner->ride_index = rideIndex;
banner->text = {};
}
}
ScrollingTextInvalidate();
GfxInvalidateScreen();
return GameActions::Result();
}