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 #ifndef GDCORE_BEHAVIORCONFIGURATIONCONTAINER_H
7 #define GDCORE_BEHAVIORCONFIGURATIONCONTAINER_H
8 
9 #include <map>
10 #include <memory>
11 #include "GDCore/Serialization/Serializer.h"
12 #include "GDCore/String.h"
13 
14 namespace gd {
15 class PropertyDescriptor;
16 class SerializerElement;
17 class Project;
18 class Layout;
19 } // namespace gd
20 
21 namespace gd {
22 
32 class GD_CORE_API BehaviorConfigurationContainer {
33  public:
34  BehaviorConfigurationContainer() : folded(false){};
36  const gd::String& type_)
37  : name(name_), type(type_), folded(false){};
39  virtual BehaviorConfigurationContainer* Clone() const { return new BehaviorConfigurationContainer(*this); }
40 
44  const gd::String& GetName() const { return name; }
45 
49  void SetName(const gd::String& name_) { name = name_; }
50 
54  const gd::String& GetTypeName() const { return type; }
55 
59  void SetTypeName(const gd::String& type_) { type = type_; };
60 
68  std::map<gd::String, gd::PropertyDescriptor> GetProperties() const;
69 
70 
78  bool UpdateProperty(const gd::String& name, const gd::String& value) {
79  return UpdateProperty(content, name, value);
80  };
81 
86  virtual void InitializeContent() {
87  InitializeContent(content);
88  };
89 
93  virtual void SerializeTo(gd::SerializerElement& element) const {
94  element = content;
95  };
96 
100  virtual void UnserializeFrom(const gd::SerializerElement& element) {
101  content = element;
102  };
103 
104  const gd::SerializerElement& GetContent() const { return content; };
105  gd::SerializerElement& GetContent() { return content; };
106 
110  void SetFolded(bool fold = true) { folded = fold; }
111 
115  bool IsFolded() const { return folded; }
116 
117 
118 protected:
134  virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
135  const gd::SerializerElement& behaviorContent) const;
136 
144  virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
145  const gd::String& name,
146  const gd::String& value) {
147  return false;
148  };
149 
154  virtual void InitializeContent(gd::SerializerElement& behaviorContent){};
155 
156  private:
157  gd::String name;
158  gd::String type;
160 
161  gd::SerializerElement content; // Storage for the behavior properties
162  bool folded;
163 };
164 
165 } // namespace gd
166 
167 #endif // GDCORE_BEHAVIORCONFIGURATIONCONTAINER_H
Base class for containers of behavior configuration. They can be attached to objects (Behavior) or la...
Definition: BehaviorConfigurationContainer.h:32
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:78
void SetName(const gd::String &name_)
Change the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:49
const gd::String & GetTypeName() const
Return the type of the behavior.
Definition: BehaviorConfigurationContainer.h:54
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:144
const gd::String & GetName() const
Return the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:44
virtual void SerializeTo(gd::SerializerElement &element) const
Serialize the behavior content.
Definition: BehaviorConfigurationContainer.h:93
virtual void InitializeContent(gd::SerializerElement &behaviorContent)
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:154
void SetTypeName(const gd::String &type_)
Set the type of the behavior.
Definition: BehaviorConfigurationContainer.h:59
virtual void InitializeContent()
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:86
bool IsFolded() const
True if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:115
virtual void UnserializeFrom(const gd::SerializerElement &element)
Unserialize the behavior content.
Definition: BehaviorConfigurationContainer.h:100
void SetFolded(bool fold=true)
Set if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:110
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:31
Definition: CommonTools.h:24