GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
BehaviorConfigurationContainer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <map>
9 #include <memory>
10 
11 #include "GDCore/Project/QuickCustomization.h"
12 #include "GDCore/Project/QuickCustomizationVisibilitiesContainer.h"
13 #include "GDCore/Serialization/Serializer.h"
14 #include "GDCore/String.h"
15 
16 namespace gd {
17 class PropertyDescriptor;
18 class SerializerElement;
19 class Project;
20 class Layout;
21 class ArbitraryResourceWorker;
22 } // namespace gd
23 
24 namespace gd {
25 
35 class GD_CORE_API BehaviorConfigurationContainer {
36  public:
38  : folded(false),
39  quickCustomizationVisibility(QuickCustomization::Visibility::Default),
40  propertiesQuickCustomizationVisibilities() {};
42  const gd::String& type_)
43  : name(name_),
44  type(type_),
45  folded(false),
46  quickCustomizationVisibility(QuickCustomization::Visibility::Default),
47  propertiesQuickCustomizationVisibilities() {};
49 
53  const gd::String& GetName() const { return name; }
54 
58  void SetName(const gd::String& name_) { name = name_; }
59 
63  const gd::String& GetTypeName() const { return type; }
64 
68  void SetTypeName(const gd::String& type_) { type = type_; };
69 
77  std::map<gd::String, gd::PropertyDescriptor> GetProperties() const;
78 
85  bool UpdateProperty(const gd::String& name, const gd::String& value) {
86  return UpdateProperty(content, name, value);
87  };
88 
95  virtual bool RenameProperty(const gd::String &oldName,
96  const gd::String &newName) {
97  return RenameProperty(content, oldName, newName);
98  };
99 
106  void RemoveProperty(const gd::String &name) {
107  content.RemoveChild(name);
108  content.RemoveAttribute(name);
109  auto uncapitalizedName = name.UncapitalizeFirstLetter();
110  content.RemoveChild(uncapitalizedName);
111  content.RemoveAttribute(uncapitalizedName);
112  };
113 
119  bool HasPropertyValue(const gd::String name) const {
120  if (content.HasChild(name) || content.HasAttribute(name)) {
121  return true;
122  }
123  auto uncapitalizedName = name.UncapitalizeFirstLetter();
124  return content.HasChild(uncapitalizedName) ||
125  content.HasAttribute(uncapitalizedName);
126  }
127 
132  virtual void InitializeContent() {
133  InitializeContent(content);
134  };
135 
141  void ClearContent() {
142  content.Clear();
143  };
144 
148  virtual void SerializeTo(gd::SerializerElement& element) const {
149  element = content;
150  };
151 
155  virtual void UnserializeFrom(const gd::SerializerElement& element) {
156  content = element;
157  };
158 
159  const gd::SerializerElement& GetContent() const { return content; };
160  gd::SerializerElement& GetContent() { return content; };
161 
165  void SetFolded(bool fold = true) { folded = fold; }
166 
170  bool IsFolded() const { return folded; }
171 
177  QuickCustomization::Visibility visibility) {
178  quickCustomizationVisibility = visibility;
179  }
180 
186  return quickCustomizationVisibility;
187  }
188 
195  return propertiesQuickCustomizationVisibilities;
196  }
197 
204  return propertiesQuickCustomizationVisibilities;
205  }
206 
217  void ExposeResources(gd::ArbitraryResourceWorker& worker);
218 
219  protected:
235  virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
236  const gd::SerializerElement& behaviorContent) const;
237 
244  virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
245  const gd::String& name,
246  const gd::String& value) {
247  return false;
248  };
249 
256  virtual bool RenameProperty(gd::SerializerElement &behaviorContent,
257  const gd::String &oldName,
258  const gd::String &newName) {
259  return false;
260  };
261 
266  virtual void InitializeContent(gd::SerializerElement& behaviorContent) {};
267 
268  private:
269  gd::String name;
270  gd::String type;
272 
273  gd::SerializerElement content; // Storage for the behavior properties
274  bool folded;
275  QuickCustomization::Visibility quickCustomizationVisibility;
277  propertiesQuickCustomizationVisibilities;
278 };
279 
280 } // namespace gd
ArbitraryResourceWorker is used so as to inventory resources and sometimes update them.
Definition: ArbitraryResourceWorker.h:44
Base class for containers of behavior configuration. They can be attached to objects (Behavior) or la...
Definition: BehaviorConfigurationContainer.h:35
bool UpdateProperty(const gd::String &name, const gd::String &value)
Called when the IDE wants to update a custom property of the behavior.
Definition: BehaviorConfigurationContainer.h:85
const QuickCustomizationVisibilitiesContainer & GetPropertiesQuickCustomizationVisibilities() const
Get the map of properties and their visibility in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:203
void RemoveProperty(const gd::String &name)
Called when the IDE wants to remove a custom property from the behavior.
Definition: BehaviorConfigurationContainer.h:106
virtual bool RenameProperty(gd::SerializerElement &behaviorContent, const gd::String &oldName, const gd::String &newName)
Called when the IDE wants to rename a custom property of the object configuration.
Definition: BehaviorConfigurationContainer.h:256
bool HasPropertyValue(const gd::String name) const
Called to check if a property is overriden.
Definition: BehaviorConfigurationContainer.h:119
void SetName(const gd::String &name_)
Change the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:58
const gd::String & GetTypeName() const
Return the type of the behavior.
Definition: BehaviorConfigurationContainer.h:63
virtual bool UpdateProperty(gd::SerializerElement &behaviorContent, const gd::String &name, const gd::String &value)
Called when the IDE wants to update a custom property of the behavior.
Definition: BehaviorConfigurationContainer.h:244
const gd::String & GetName() const
Return the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:53
void SetQuickCustomizationVisibility(QuickCustomization::Visibility visibility)
Set if the whole behavior should be visible or not in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:176
QuickCustomization::Visibility GetQuickCustomizationVisibility() const
Get if the whole behavior should be visible or not in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:185
virtual void SerializeTo(gd::SerializerElement &element) const
Serialize the behavior content.
Definition: BehaviorConfigurationContainer.h:148
virtual void InitializeContent(gd::SerializerElement &behaviorContent)
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:266
QuickCustomizationVisibilitiesContainer & GetPropertiesQuickCustomizationVisibilities()
Get the map of properties and their visibility in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:194
void SetTypeName(const gd::String &type_)
Set the type of the behavior.
Definition: BehaviorConfigurationContainer.h:68
virtual void InitializeContent()
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:132
bool IsFolded() const
True if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:170
virtual void UnserializeFrom(const gd::SerializerElement &element)
Unserialize the behavior content.
Definition: BehaviorConfigurationContainer.h:155
void ClearContent()
Called to remove all properties values for the behavior.
Definition: BehaviorConfigurationContainer.h:141
void SetFolded(bool fold=true)
Set if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:165
virtual bool RenameProperty(const gd::String &oldName, const gd::String &newName)
Called when the IDE wants to rename a custom property of the object configuration.
Definition: BehaviorConfigurationContainer.h:95
Visibility
Definition: QuickCustomization.h:8
Definition: QuickCustomizationVisibilitiesContainer.h:11
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
String UncapitalizeFirstLetter() const
Returns the string with the first letter in lower case.
Definition: String.cpp:416
Definition: CommonTools.h:24