From 7efe73f6ac02edaabbd35641dbb94b20a5f683a8 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 7 Dec 2024 13:40:30 +0100 Subject: [PATCH] Add checks to ensure an animation object is selected for each peep type --- data/language/en-GB.txt | 6 ++++++ .../windows/EditorObjectSelection.cpp | 2 +- src/openrct2/Editor.cpp | 18 ++++++++++++++++++ src/openrct2/EditorObjectSelectionSession.cpp | 17 +++++++++++++++++ src/openrct2/EditorObjectSelectionSession.h | 1 + src/openrct2/localisation/StringIds.h | 7 +++++++ src/openrct2/object/ObjectRepository.cpp | 5 ++++- src/openrct2/object/ObjectRepository.h | 4 ++++ src/openrct2/object/PeepAnimationsObject.cpp | 6 ++++++ src/openrct2/object/PeepAnimationsObject.h | 1 + 10 files changed, 65 insertions(+), 2 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 2d0186395e..ac017e7b0d 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3781,3 +3781,9 @@ STR_6714 :Filename STR_6715 :Date modified STR_6716 :File size STR_6717 :File size {STRINGID} +STR_6718 :Peep Animations +STR_6719 :At least one guest peep animations object must be selected +STR_6720 :At least one handyman peep animations object must be selected +STR_6721 :At least one mechanic peep animations object must be selected +STR_6722 :At least one security peep animations object must be selected +STR_6723 :At least one entertainer peep animations object must be selected diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 12803bb9e9..ebda03eda8 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -179,7 +179,7 @@ namespace OpenRCT2::Ui::Windows }; static ObjectSubTab kPeepObjectSubTabs[] = { - { STR_OBJECT_SELECTION_PEEP_NAMES, ObjectType::PeepAnimations, FILTER_NONE, SPR_G2_PEEP_ANIMATIONS, 1, 1 }, + { STR_OBJECT_SELECTION_PEEP_ANIMATIONS, ObjectType::PeepAnimations, FILTER_NONE, SPR_G2_PEEP_ANIMATIONS, 1, 1 }, { STR_OBJECT_SELECTION_PEEP_NAMES, ObjectType::PeepNames, FILTER_NONE, SPR_TAB_GUESTS_0, 1, 1 }, }; diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 9117c690ce..7bef462b2f 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -36,6 +36,7 @@ #include "object/DefaultObjects.h" #include "object/ObjectManager.h" #include "object/ObjectRepository.h" +#include "peep/PeepAnimations.h" #include "rct1/RCT1.h" #include "scenario/Scenario.h" #include "ui/UiContext.h" @@ -447,6 +448,23 @@ namespace OpenRCT2::Editor } } + using OpenRCT2::AnimationPeepType; + constexpr std::pair kPeepCheckPairs[] = { + { AnimationPeepType::Guest, STR_AT_LEAST_ONE_GUEST_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED }, + { AnimationPeepType::Handyman, STR_AT_LEAST_ONE_HANDYMAN_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED }, + { AnimationPeepType::Mechanic, STR_AT_LEAST_ONE_MECHANIC_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED }, + { AnimationPeepType::Security, STR_AT_LEAST_ONE_SECURITY_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED }, + { AnimationPeepType::Entertainer, STR_AT_LEAST_ONE_ENTERTAINER_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED }, + }; + + for (auto& pair : kPeepCheckPairs) + { + if (!EditorCheckObjectGroupAtLeastOneOfPeepTypeSelected(EnumValue(pair.first))) + { + return { ObjectType::PeepAnimations, pair.second }; + } + } + return { ObjectType::None, STR_NONE }; } diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 711cb3325b..946c29313b 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -687,6 +687,23 @@ bool EditorCheckObjectGroupAtLeastOneSelected(ObjectType checkObjectType) return false; } +bool EditorCheckObjectGroupAtLeastOneOfPeepTypeSelected(uint8_t peepType) +{ + auto numObjects = std::min(ObjectRepositoryGetItemsCount(), _objectSelectionFlags.size()); + const ObjectRepositoryItem* items = ObjectRepositoryGetItems(); + + for (size_t i = 0; i < numObjects; i++) + { + const auto isAnimObjectType = items[i].Type == ObjectType::PeepAnimations; + const bool isSelected = _objectSelectionFlags[i] & ObjectSelectionFlags::Selected; + if (isAnimObjectType && isSelected && items[i].PeepAnimationsInfo.PeepType == peepType) + { + return true; + } + } + return false; +} + bool EditorCheckObjectGroupAtLeastOneSurfaceSelected(bool queue) { auto numObjects = std::min(ObjectRepositoryGetItemsCount(), _objectSelectionFlags.size()); diff --git a/src/openrct2/EditorObjectSelectionSession.h b/src/openrct2/EditorObjectSelectionSession.h index de3de17b07..73300148fd 100644 --- a/src/openrct2/EditorObjectSelectionSession.h +++ b/src/openrct2/EditorObjectSelectionSession.h @@ -29,6 +29,7 @@ extern std::vector _objectSelectionFlags; extern uint32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)]; bool EditorCheckObjectGroupAtLeastOneSelected(ObjectType checkObjectType); +bool EditorCheckObjectGroupAtLeastOneOfPeepTypeSelected(uint8_t peepType); bool EditorCheckObjectGroupAtLeastOneSurfaceSelected(bool queue); void EditorObjectFlagsFree(); void UnloadUnselectedObjects(); diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 3a5e7af55f..7eabb2768e 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -1696,6 +1696,13 @@ enum : StringId STR_AT_LEAST_ONE_PEEP_NAMES_OBJECT_MUST_BE_SELECTED = 6676, + STR_OBJECT_SELECTION_PEEP_ANIMATIONS = 6718, + STR_AT_LEAST_ONE_GUEST_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED = 6719, + STR_AT_LEAST_ONE_HANDYMAN_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED = 6720, + STR_AT_LEAST_ONE_MECHANIC_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED = 6721, + STR_AT_LEAST_ONE_SECURITY_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED = 6722, + STR_AT_LEAST_ONE_ENTERTAINER_PEEP_ANIMATIONS_OBJECT_MUST_BE_SELECTED = 6723, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings }; diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index ac42fbfb97..8668f7e54c 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -76,7 +76,7 @@ class ObjectFileIndex final : public FileIndex { private: static constexpr uint32_t MAGIC_NUMBER = 0x5844494F; // OIDX - static constexpr uint16_t VERSION = 29; + static constexpr uint16_t VERSION = 30; static constexpr auto PATTERN = "*.dat;*.pob;*.json;*.parkobj"; IObjectRepository& _objectRepository; @@ -160,6 +160,9 @@ protected: case ObjectType::FootpathSurface: ds << item.FootpathSurfaceInfo.Flags; break; + case ObjectType::PeepAnimations: + ds << item.PeepAnimationsInfo.PeepType; + break; default: // Switch processes only ObjectType::Ride and ObjectType::SceneryGroup break; diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 41265a57f6..484b2c52ee 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -63,6 +63,10 @@ struct ObjectRepositoryItem { uint8_t Flags{}; } FootpathSurfaceInfo; + struct + { + uint8_t PeepType{}; + } PeepAnimationsInfo; [[nodiscard]] ObjectSourceGame GetFirstSourceGame() const { diff --git a/src/openrct2/object/PeepAnimationsObject.cpp b/src/openrct2/object/PeepAnimationsObject.cpp index 48afe042ce..300f143613 100644 --- a/src/openrct2/object/PeepAnimationsObject.cpp +++ b/src/openrct2/object/PeepAnimationsObject.cpp @@ -16,6 +16,7 @@ #include "../core/Json.hpp" #include "../peep/PeepAnimations.h" #include "../rct12/RCT12.h" +#include "ObjectRepository.h" using namespace OpenRCT2; @@ -155,3 +156,8 @@ void PeepAnimationsObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_ GfxDrawSprite(dpi, ImageId(_imageOffsetId + 1, COLOUR_BRIGHT_RED, COLOUR_TEAL), centre + ScreenCoordsXY{ +32, -24 }); GfxDrawSprite(dpi, ImageId(_imageOffsetId + 3, COLOUR_BRIGHT_RED, COLOUR_TEAL), centre + ScreenCoordsXY{ -32, +32 }); } + +void PeepAnimationsObject::SetRepositoryItem(ObjectRepositoryItem* item) const +{ + item->PeepAnimationsInfo.PeepType = EnumValue(_peepType); +} diff --git a/src/openrct2/object/PeepAnimationsObject.h b/src/openrct2/object/PeepAnimationsObject.h index e8f131f179..767d00383c 100644 --- a/src/openrct2/object/PeepAnimationsObject.h +++ b/src/openrct2/object/PeepAnimationsObject.h @@ -48,4 +48,5 @@ public: }; void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override; + void SetRepositoryItem(ObjectRepositoryItem* item) const override; };