Skip to content

Commit

Permalink
Disable the variable editor button for object parameters (#7202)
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H authored Nov 28, 2024
1 parent eae75bd commit 8743f70
Show file tree
Hide file tree
Showing 29 changed files with 237 additions and 111 deletions.
20 changes: 0 additions & 20 deletions Core/GDCore/IDE/EventsFunctionTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,6 @@ void EventsFunctionTools::ObjectEventsFunctionToObjectsContainer(
"for the parent. ");
return;
}

gd::EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
eventsBasedObject, outputObjectsContainer);
}

void EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
const gd::EventsBasedObject& eventsBasedObject,
gd::ObjectsContainer& outputObjectsContainer) {
auto &children = eventsBasedObject.GetObjects().GetObjects();
for (auto &childObject : children) {
auto child = childObject.get();
outputObjectsContainer.InsertObject(
*child, outputObjectsContainer.GetObjectsCount());
}
auto &childrenGroups = eventsBasedObject.GetObjects().GetObjectGroups();
for (size_t index = 0; index < childrenGroups.Count(); ++index) {
auto &childGroup = childrenGroups.Get(index);
outputObjectsContainer.GetObjectGroups().Insert(
childGroup, outputObjectsContainer.GetObjectGroups().Count());
}
}

} // namespace gd
4 changes: 0 additions & 4 deletions Core/GDCore/IDE/EventsFunctionTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,5 @@ class GD_CORE_API EventsFunctionTools {
const gd::EventsBasedObject& eventsBasedObject,
const gd::EventsFunction& eventsFunction,
gd::ObjectsContainer& outputObjectsContainer);

static void CopyEventsBasedObjectChildrenToObjectsContainer(
const gd::EventsBasedObject &eventsBasedObject,
gd::ObjectsContainer &outputObjectsContainer);
};
} // namespace gd
9 changes: 6 additions & 3 deletions Core/GDCore/IDE/ProjectBrowserHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ void ProjectBrowserHelper::ExposeEventsFunctionsExtensionEvents(
gd::ArbitraryEventsWorkerWithContext &worker) {
// Add (free) events functions
for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) {
gd::ObjectsContainer parameterObjectsContainer;
gd::ObjectsContainer parameterObjectsContainer(
gd::ObjectsContainer::SourceType::Function);
auto projectScopedContainers = gd::ProjectScopedContainers::
MakeNewProjectScopedContainersForFreeEventsFunction(
project, eventsFunctionsExtension, *eventsFunction,
Expand Down Expand Up @@ -209,7 +210,8 @@ void ProjectBrowserHelper::ExposeEventsBasedBehaviorEvents(
auto &behaviorEventsFunctions = eventsBasedBehavior.GetEventsFunctions();
for (auto &&eventsFunction : behaviorEventsFunctions.GetInternalVector()) {

gd::ObjectsContainer parameterObjectsContainers;
gd::ObjectsContainer parameterObjectsContainers(
gd::ObjectsContainer::SourceType::Function);
auto projectScopedContainers = gd::ProjectScopedContainers::
MakeNewProjectScopedContainersForBehaviorEventsFunction(
project, eventsFunctionsExtension, eventsBasedBehavior,
Expand All @@ -236,7 +238,8 @@ void ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
auto &objectEventsFunctions = eventsBasedObject.GetEventsFunctions();
for (auto &&eventsFunction : objectEventsFunctions.GetInternalVector()) {

gd::ObjectsContainer parameterObjectsContainers;
gd::ObjectsContainer parameterObjectsContainers(
gd::ObjectsContainer::SourceType::Function);
auto projectScopedContainers = gd::ProjectScopedContainers::
MakeNewProjectScopedContainersForObjectEventsFunction(
project, eventsFunctionsExtension, eventsBasedObject,
Expand Down
3 changes: 2 additions & 1 deletion Core/GDCore/Project/EventsBasedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ EventsBasedObject::EventsBasedObject()
areaMinZ(0),
areaMaxX(64),
areaMaxY(64),
areaMaxZ(64) {
areaMaxZ(64),
objectsContainer(gd::ObjectsContainer::SourceType::Object) {
}

EventsBasedObject::~EventsBasedObject() {}
Expand Down
8 changes: 6 additions & 2 deletions Core/GDCore/Project/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ namespace gd {

gd::BehaviorsSharedData Layout::badBehaviorSharedData("", "");

Layout::Layout(const Layout& other) { Init(other); }
Layout::Layout(const Layout &other)
: objectsContainer(gd::ObjectsContainer::SourceType::Scene) {
Init(other);
}

Layout& Layout::operator=(const Layout& other) {
if (this != &other) Init(other);
Expand All @@ -53,7 +56,8 @@ Layout::Layout()
stopSoundsOnStartup(true),
standardSortMethod(true),
disableInputWhenNotFocused(true),
variables(gd::VariablesContainer::SourceType::Scene) {}
variables(gd::VariablesContainer::SourceType::Scene),
objectsContainer(gd::ObjectsContainer::SourceType::Scene) {}

void Layout::SetName(const gd::String& name_) {
name = name_;
Expand Down
5 changes: 4 additions & 1 deletion Core/GDCore/Project/ObjectsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace gd {

ObjectsContainer::ObjectsContainer() {
ObjectsContainer::ObjectsContainer(
const ObjectsContainer::SourceType sourceType_)
: sourceType(sourceType_) {
rootFolder = gd::make_unique<gd::ObjectFolderOrObject>("__ROOT");
}

Expand All @@ -34,6 +36,7 @@ ObjectsContainer& ObjectsContainer::operator=(
}

void ObjectsContainer::Init(const gd::ObjectsContainer& other) {
sourceType = other.sourceType;
initialObjects = gd::Clone(other.initialObjects);
objectGroups = other.objectGroups;
// The objects folders are not copied.
Expand Down
25 changes: 17 additions & 8 deletions Core/GDCore/Project/ObjectsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_OBJECTSCONTAINER_H
#define GDCORE_OBJECTSCONTAINER_H
#pragma once

#include <memory>
#include <vector>
#include <set>
Expand Down Expand Up @@ -36,15 +36,25 @@ namespace gd {
*/
class GD_CORE_API ObjectsContainer {
public:
enum SourceType {
Unknown,
Global,
Scene,
Object,
Function,
};

/**
* \brief Default constructor creating a container without any objects.
* \brief Constructor creating a container without any objects.
*/
ObjectsContainer();
ObjectsContainer(const SourceType sourceType);
virtual ~ObjectsContainer();

ObjectsContainer(const ObjectsContainer&);
ObjectsContainer& operator=(const ObjectsContainer& rhs);

SourceType GetSourceType() const { return sourceType; }

/** \name Objects management
* Members functions related to objects management.
*/
Expand All @@ -58,7 +68,7 @@ class GD_CORE_API ObjectsContainer {
/**
* \brief Return a reference to the object called \a name.
*/
Object& GetObject(const gd::String& name);
gd::Object& GetObject(const gd::String& name);

/**
* \brief Return a reference to the object called \a name.
Expand All @@ -69,7 +79,7 @@ class GD_CORE_API ObjectsContainer {
* \brief Return a reference to the object at position \a index in the objects
* list
*/
Object& GetObject(std::size_t index);
gd::Object& GetObject(std::size_t index);

/**
* \brief Return a reference to the object at position \a index in the objects
Expand Down Expand Up @@ -235,6 +245,7 @@ class GD_CORE_API ObjectsContainer {
gd::ObjectGroupsContainer objectGroups;

private:
SourceType sourceType = Unknown;
std::unique_ptr<gd::ObjectFolderOrObject> rootFolder;

/**
Expand All @@ -245,5 +256,3 @@ class GD_CORE_API ObjectsContainer {
};

} // namespace gd

#endif // GDCORE_OBJECTSCONTAINER_H
40 changes: 34 additions & 6 deletions Core/GDCore/Project/ObjectsContainersList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ gd::String ObjectsContainersList::GetTypeOfObject(
return "";
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::GetTypeOfObject(emptyObjectsContainer, *objectsContainers[0],
objectName, true);
}
Expand All @@ -439,7 +440,8 @@ bool ObjectsContainersList::HasBehaviorInObjectOrGroup(
return false;
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::HasBehaviorInObjectOrGroup(
emptyObjectsContainer, *objectsContainers[0], objectOrGroupName,
behaviorName, true);
Expand Down Expand Up @@ -468,7 +470,8 @@ gd::String ObjectsContainersList::GetTypeOfBehaviorInObjectOrGroup(
return "";
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::GetTypeOfBehaviorInObjectOrGroup(
emptyObjectsContainer, *objectsContainers[0], objectOrGroupName,
behaviorName, searchInGroups);
Expand All @@ -495,7 +498,8 @@ gd::String ObjectsContainersList::GetTypeOfBehavior(
return "";
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::GetTypeOfBehavior(emptyObjectsContainer, *objectsContainers[0],
behaviorName, searchInGroups);
}
Expand All @@ -521,7 +525,8 @@ std::vector<gd::String> ObjectsContainersList::GetBehaviorsOfObject(
return behaviors;
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::GetBehaviorsOfObject(emptyObjectsContainer,
*objectsContainers[0], objectName,
searchInGroups);
Expand All @@ -546,7 +551,8 @@ std::vector<gd::String> ObjectsContainersList::GetBehaviorNamesInObjectOrGroup(
return behaviors;
}
if (objectsContainers.size() == 1) {
gd::ObjectsContainer emptyObjectsContainer;
gd::ObjectsContainer emptyObjectsContainer(
gd::ObjectsContainer::SourceType::Unknown);
return gd::GetBehaviorNamesInObjectOrGroup(emptyObjectsContainer,
*objectsContainers[0], objectOrGroupName, behaviorType,
searchInGroups);
Expand Down Expand Up @@ -615,6 +621,28 @@ std::vector<gd::String> ObjectsContainersList::GetAnimationNamesOfObject(
return animationNames;
}

const ObjectsContainer *
ObjectsContainersList::GetObjectsContainerFromObjectName(
const gd::String &objectOrGroupName) const {
for (auto it = objectsContainers.rbegin(); it != objectsContainers.rend();
++it) {
if ((*it)->HasObjectNamed(objectOrGroupName) ||
(*it)->GetObjectGroups().Has(objectOrGroupName)) {
return *it;
}
}
return nullptr;
}

const gd::ObjectsContainer::SourceType
ObjectsContainersList::GetObjectsContainerSourceType(
const gd::String &objectOrGroupName) const {
const auto *objectsContainer =
GetObjectsContainerFromObjectName(objectOrGroupName);
return objectsContainer ? objectsContainer->GetSourceType()
: gd::ObjectsContainer::SourceType::Unknown;
}

const gd::ObjectsContainer &
ObjectsContainersList::GetObjectsContainer(std::size_t index) const {
return *objectsContainers[index];
Expand Down
15 changes: 14 additions & 1 deletion Core/GDCore/Project/ObjectsContainersList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include <vector>

#include "Variable.h"
#include "GDCore/Project/ObjectsContainer.h"

namespace gd {
class String;
class Project;
class Layout;
class ObjectsContainer;
class VariablesContainer;
class Object;
class ObjectConfiguration;
Expand Down Expand Up @@ -190,6 +190,19 @@ class GD_CORE_API ObjectsContainersList {
std::function<void(const gd::String& variableName,
const gd::Variable& variable)> fn) const;

/**
* \brief Return the source type of the container for the specified object or
* group of objects.
*/
const gd::ObjectsContainer::SourceType GetObjectsContainerSourceType(
const gd::String& objectOrGroupName) const;

/**
* Get the objects container for for the specified object or group of objects.
*/
const ObjectsContainer *
GetObjectsContainerFromObjectName(const gd::String &objectOrGroupName) const;

/**
* \brief Return a the objects container at position \a index.
*
Expand Down
8 changes: 6 additions & 2 deletions Core/GDCore/Project/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Project::Project()
gdMajorVersion(gd::VersionWrapper::Major()),
gdMinorVersion(gd::VersionWrapper::Minor()),
gdBuildVersion(gd::VersionWrapper::Build()),
variables(gd::VariablesContainer::SourceType::Global) {}
variables(gd::VariablesContainer::SourceType::Global),
objectsContainer(gd::ObjectsContainer::SourceType::Global) {}

Project::~Project() {}

Expand Down Expand Up @@ -1230,7 +1231,10 @@ gd::SourceFile& Project::InsertNewSourceFile(const gd::String& name,
return newlyInsertedSourceFile;
}

Project::Project(const Project& other) { Init(other); }
Project::Project(const Project &other)
: objectsContainer(gd::ObjectsContainer::SourceType::Global) {
Init(other);
}

Project& Project::operator=(const Project& other) {
if (this != &other) Init(other);
Expand Down
15 changes: 4 additions & 11 deletions Core/GDCore/Project/ProjectScopedContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForObjectEventsFunction(
project, eventsBasedObject, eventsFunction, parameterObjectsContainer);

ProjectScopedContainers projectScopedContainers(
ObjectsContainersList::MakeNewObjectsContainersListForContainer(
ObjectsContainersList::MakeNewObjectsContainersListForContainers(
eventsBasedObject.GetObjects(),
parameterObjectsContainer),
VariablesContainersList::
MakeNewVariablesContainersListForEventsFunctionsExtension(
Expand Down Expand Up @@ -180,17 +181,9 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForEventsBasedObject(
eventsFunctionsExtension.GetName(), eventsBasedObject.GetName()),
"Object", outputObjectsContainer.GetObjectsCount());

// TODO: We should avoid to do a copy of the objects container here - as this results
// in an objects container that contains temporary objects. This can create issues in the
// UI (for example, a tree view that keeps references on objects).
// Search for "ProjectScopedContainers wrongly containing temporary objects containers or objects"
// in the codebase.
gd::EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
eventsBasedObject, outputObjectsContainer);

ProjectScopedContainers projectScopedContainers(
ObjectsContainersList::MakeNewObjectsContainersListForContainer(
outputObjectsContainer),
ObjectsContainersList::MakeNewObjectsContainersListForContainers(
eventsBasedObject.GetObjects(), outputObjectsContainer),
VariablesContainersList::
MakeNewVariablesContainersListForEventsFunctionsExtension(
eventsFunctionsExtension),
Expand Down
Loading

0 comments on commit 8743f70

Please sign in to comment.