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  virtual BehaviorConfigurationContainer* Clone() const {
50  return new BehaviorConfigurationContainer(*this);
51  }
52 
56  const gd::String& GetName() const { return name; }
57 
61  void SetName(const gd::String& name_) { name = name_; }
62 
66  const gd::String& GetTypeName() const { return type; }
67 
71  void SetTypeName(const gd::String& type_) { type = type_; };
72 
80  std::map<gd::String, gd::PropertyDescriptor> GetProperties() const;
81 
89  bool UpdateProperty(const gd::String& name, const gd::String& value) {
90  return UpdateProperty(content, name, value);
91  };
92 
97  virtual void InitializeContent() { InitializeContent(content); };
98 
102  virtual void SerializeTo(gd::SerializerElement& element) const {
103  element = content;
104  };
105 
109  virtual void UnserializeFrom(const gd::SerializerElement& element) {
110  content = element;
111  };
112 
113  const gd::SerializerElement& GetContent() const { return content; };
114  gd::SerializerElement& GetContent() { return content; };
115 
119  void SetFolded(bool fold = true) { folded = fold; }
120 
124  bool IsFolded() const { return folded; }
125 
131  QuickCustomization::Visibility visibility) {
132  quickCustomizationVisibility = visibility;
133  }
134 
140  return quickCustomizationVisibility;
141  }
142 
149  return propertiesQuickCustomizationVisibilities;
150  }
151 
158  return propertiesQuickCustomizationVisibilities;
159  }
160 
171  void ExposeResources(gd::ArbitraryResourceWorker& worker);
172 
173  protected:
189  virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
190  const gd::SerializerElement& behaviorContent) const;
191 
199  virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
200  const gd::String& name,
201  const gd::String& value) {
202  return false;
203  };
204 
209  virtual void InitializeContent(gd::SerializerElement& behaviorContent) {};
210 
211  private:
212  gd::String name;
213  gd::String type;
215 
216  gd::SerializerElement content; // Storage for the behavior properties
217  bool folded;
218  QuickCustomization::Visibility quickCustomizationVisibility;
220  propertiesQuickCustomizationVisibilities;
221 };
222 
223 } // 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:89
const QuickCustomizationVisibilitiesContainer & GetPropertiesQuickCustomizationVisibilities() const
Get the map of properties and their visibility in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:157
void SetName(const gd::String &name_)
Change the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:61
const gd::String & GetTypeName() const
Return the type of the behavior.
Definition: BehaviorConfigurationContainer.h:66
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:199
const gd::String & GetName() const
Return the name identifying the behavior.
Definition: BehaviorConfigurationContainer.h:56
void SetQuickCustomizationVisibility(QuickCustomization::Visibility visibility)
Set if the whole behavior should be visible or not in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:130
QuickCustomization::Visibility GetQuickCustomizationVisibility() const
Get if the whole behavior should be visible or not in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:139
virtual void SerializeTo(gd::SerializerElement &element) const
Serialize the behavior content.
Definition: BehaviorConfigurationContainer.h:102
virtual void InitializeContent(gd::SerializerElement &behaviorContent)
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:209
QuickCustomizationVisibilitiesContainer & GetPropertiesQuickCustomizationVisibilities()
Get the map of properties and their visibility in the Quick Customization.
Definition: BehaviorConfigurationContainer.h:148
void SetTypeName(const gd::String &type_)
Set the type of the behavior.
Definition: BehaviorConfigurationContainer.h:71
virtual void InitializeContent()
Called to initialize the content with the default properties for the behavior.
Definition: BehaviorConfigurationContainer.h:97
bool IsFolded() const
True if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:124
virtual void UnserializeFrom(const gd::SerializerElement &element)
Unserialize the behavior content.
Definition: BehaviorConfigurationContainer.h:109
void SetFolded(bool fold=true)
Set if the behavior configuration panel should be folded in the UI.
Definition: BehaviorConfigurationContainer.h:119
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
Definition: CommonTools.h:24