GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Layout.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 
7 #ifndef GDCORE_LAYOUT_H
8 #define GDCORE_LAYOUT_H
9 #include <map>
10 #include <memory>
11 #include <vector>
12 #include "GDCore/Events/EventsList.h"
13 #include "GDCore/Project/BehaviorsSharedData.h"
14 #include "GDCore/Project/InitialInstancesContainer.h"
15 #include "GDCore/Project/Layer.h"
16 #include "GDCore/Project/ObjectGroupsContainer.h"
17 #include "GDCore/Project/ObjectsContainer.h"
18 #include "GDCore/Project/VariablesContainer.h"
19 #include "GDCore/String.h"
20 #include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
21 
22 namespace gd {
23 class BaseEvent;
24 class Object;
25 class Project;
26 class InitialInstancesContainer;
27 } // namespace gd
28 class TiXmlElement;
29 class BaseProfiler;
30 #undef GetObject // Disable an annoying macro
31 
32 namespace gd {
33 
39 class GD_CORE_API Layout : public ObjectsContainer {
40  public:
41  Layout();
42  Layout(const Layout&);
43  virtual ~Layout();
44  Layout& operator=(const Layout& rhs);
45 
49  Layout* Clone() const { return new Layout(*this); };
50 
55 
59  void SetName(const gd::String& name_);
60 
64  const gd::String& GetName() const { return name; };
65 
69  const gd::String& GetMangledName() const { return mangledName; };
70 
74  void SetBackgroundColor(unsigned int r, unsigned int g, unsigned int b) {
75  backgroundColorR = r;
76  backgroundColorG = g;
77  backgroundColorB = b;
78  }
79 
83  unsigned int GetBackgroundColorRed() const { return backgroundColorR; }
84 
88  unsigned int GetBackgroundColorGreen() const { return backgroundColorG; }
89 
93  unsigned int GetBackgroundColorBlue() const { return backgroundColorB; }
94 
98  const gd::String& GetWindowDefaultTitle() const { return title; };
99 
103  void SetWindowDefaultTitle(const gd::String& title_) { title = title_; };
104 
106 
112 
116  return initialInstances;
117  }
118 
123  return initialInstances;
124  }
126 
131 
135  const gd::EventsList& GetEvents() const { return events; }
136 
140  gd::EventsList& GetEvents() { return events; }
141 
143 
148 
153  inline const gd::VariablesContainer& GetVariables() const {
154  return variables;
155  }
156 
161  inline gd::VariablesContainer& GetVariables() { return variables; }
162 
164 
170 
174  bool HasLayerNamed(const gd::String& name) const;
175 
179  Layer& GetLayer(const gd::String& name);
180 
184  const Layer& GetLayer(const gd::String& name) const;
185 
190  Layer& GetLayer(std::size_t index);
191 
196  const Layer& GetLayer(std::size_t index) const;
197 
201  std::size_t GetLayerPosition(const gd::String& name) const;
202 
206  std::size_t GetLayersCount() const;
207 
212  void InsertNewLayer(const gd::String& name, std::size_t position);
213 
221  void InsertLayer(const Layer& theLayer, std::size_t position);
222 
226  void RemoveLayer(const gd::String& name);
227 
231  void SwapLayers(std::size_t firstLayerIndex, std::size_t secondLayerIndex);
232 
236  void MoveLayer(std::size_t oldIndex, std::size_t newIndex);
237 
241  void SerializeLayersTo(SerializerElement& element) const;
242 
246  void UnserializeLayersFrom(const SerializerElement& element);
248 
257  void UpdateBehaviorsSharedData(gd::Project& project);
258 
262  std::vector<gd::String> GetAllBehaviorSharedDataNames() const;
263 
267  bool HasBehaviorSharedData(const gd::String& behaviorName);
268 
272  const gd::BehaviorsSharedData& GetBehaviorSharedData(
273  const gd::String& behaviorName) const;
274 
278  gd::BehaviorsSharedData& GetBehaviorSharedData(const gd::String& behaviorName);
279 
283  const std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>&
284  GetAllBehaviorSharedData() const;
285 
286 
292  return editorSettings;
293  }
294 
300  return editorSettings;
301  }
302 
306 
309  void DisableInputWhenFocusIsLost(bool disable = true) {
310  disableInputWhenNotFocused = disable;
311  }
312 
316  bool IsInputDisabledWhenFocusIsLost() { return disableInputWhenNotFocused; }
317 
321  void SetStandardSortMethod(bool enable = true) {
322  standardSortMethod = enable;
323  }
324 
328  bool StandardSortMethod() const { return standardSortMethod; }
329 
333  void SetStopSoundsOnStartup(bool enable = true) {
334  stopSoundsOnStartup = enable;
335  }
336 
341  bool StopSoundsOnStartup() const { return stopSoundsOnStartup; }
343 
348 
351  void SerializeTo(SerializerElement& element) const;
352 
356  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
358 
359 // TODO: GD C++ Platform specific code below
363  BaseProfiler* GetProfiler() const { return profiler; };
364 
368  void SetProfiler(BaseProfiler* profiler_) { profiler = profiler_; };
369 
370  private:
371  gd::String name;
372  gd::String mangledName;
373  unsigned int backgroundColorR;
374  unsigned int backgroundColorG;
375  unsigned int backgroundColorB;
376  gd::String title;
377  gd::VariablesContainer variables;
378  gd::InitialInstancesContainer initialInstances;
379  std::vector<gd::Layer> initialLayers;
380  std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>
381  behaviorsSharedData;
382  bool stopSoundsOnStartup;
384  bool standardSortMethod;
385  bool disableInputWhenNotFocused;
388  static gd::Layer badLayer;
391  badBehaviorSharedData;
394 
395  EventsList events;
396  gd::EditorSettings editorSettings;
397 
398 // TODO: GD C++ Platform specific code below
399 
400  BaseProfiler* profiler;
401 
406  void Init(const gd::Layout& other);
407 
408  std::unique_ptr<gd::BehaviorsSharedData> CreateBehaviorsSharedData(
409  gd::Project& project,
410  const gd::String& name,
411  const gd::String& behaviorsType);
412 };
413 
419  : public std::binary_function<std::unique_ptr<Layout>, gd::String, bool> {
420  bool operator()(const std::unique_ptr<Layout>& layout,
421  gd::String name) const {
422  return layout->GetName() == name;
423  }
424 };
425 
431 std::vector<gd::String> GetHiddenLayers(const Layout& layout);
432 
442 gd::String GD_CORE_API GetTypeOfObject(const ObjectsContainer& game,
443  const ObjectsContainer& layout,
444  gd::String objectName,
445  bool searchInGroups = true);
450 bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer &project,
451  const gd::ObjectsContainer &layout,
452  const gd::String &objectOrGroupName,
453  const gd::String &behaviorName,
454  bool searchInGroups = true);
458 std::vector<gd::String> GD_CORE_API GetBehaviorNamesInObjectOrGroup(
459  const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout,
460  const gd::String &objectOrGroupName, const gd::String &behaviorType,
461  bool searchInGroups);
462 
467 bool GD_CORE_API IsDefaultBehavior(const gd::ObjectsContainer& project,
468  const gd::ObjectsContainer& layout,
469  gd::String objectOrGroupName,
470  gd::String behaviorName,
471  bool searchInGroups = true);
472 
477  const gd::ObjectsContainer &layout,
478  const gd::String &objectOrGroupName,
479  const gd::String &behaviorName,
480  bool searchInGroups = true);
486 gd::String GD_CORE_API GetTypeOfBehavior(const ObjectsContainer& game,
487  const ObjectsContainer& layout,
488  gd::String behaviorName,
489  bool searchInGroups = true);
490 
498 std::vector<gd::String> GD_CORE_API
500  const ObjectsContainer& layout,
501  const gd::String& objectName,
502  bool searchInGroups = true);
503 
504 } // namespace gd
505 
506 typedef gd::Layout Scene;
507 
508 #endif // GDCORE_LAYOUT_H
Base class for defining data shared by behaviors having the same type and name.
Definition: BehaviorsSharedData.h:24
Container for arbitrary serialized data to be used by the editor to store settings.
Definition: EditorSettings.h:19
A list of events.
Definition: EventsList.h:33
Defines a container of gd::InitialInstances.
Definition: InitialInstancesContainer.h:38
Represents a layer of a layout.
Definition: Layer.h:91
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:39
bool StopSoundsOnStartup() const
Definition: Layout.h:341
bool StandardSortMethod() const
Definition: Layout.h:328
const gd::String & GetMangledName() const
Definition: Layout.h:69
unsigned int GetBackgroundColorGreen() const
Definition: Layout.h:88
void SetStandardSortMethod(bool enable=true)
Definition: Layout.h:321
gd::InitialInstancesContainer & GetInitialInstances()
Definition: Layout.h:122
bool IsInputDisabledWhenFocusIsLost()
Definition: Layout.h:316
void SetBackgroundColor(unsigned int r, unsigned int g, unsigned int b)
Definition: Layout.h:74
const gd::VariablesContainer & GetVariables() const
Definition: Layout.h:153
const gd::EventsList & GetEvents() const
Definition: Layout.h:135
gd::EditorSettings & GetAssociatedEditorSettings()
Definition: Layout.h:299
void SetProfiler(BaseProfiler *profiler_)
Definition: Layout.h:368
const gd::String & GetName() const
Definition: Layout.h:64
BaseProfiler * GetProfiler() const
Definition: Layout.h:363
const gd::String & GetWindowDefaultTitle() const
Definition: Layout.h:98
unsigned int GetBackgroundColorBlue() const
Definition: Layout.h:93
const gd::EditorSettings & GetAssociatedEditorSettings() const
Definition: Layout.h:291
const gd::InitialInstancesContainer & GetInitialInstances() const
Definition: Layout.h:115
unsigned int GetBackgroundColorRed() const
Definition: Layout.h:83
void SetStopSoundsOnStartup(bool enable=true)
Definition: Layout.h:333
void DisableInputWhenFocusIsLost(bool disable=true)
Definition: Layout.h:309
gd::EventsList & GetEvents()
Definition: Layout.h:140
Layout * Clone() const
Return a pointer to a copy of the layout.
Definition: Layout.h:49
gd::VariablesContainer & GetVariables()
Definition: Layout.h:161
void SetWindowDefaultTitle(const gd::String &title_)
Definition: Layout.h:103
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:36
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
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
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:30
Definition: CommonTools.h:24
gd::String GD_CORE_API GetTypeOfObject(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, gd::String name, bool searchInGroups)
Get a type from an object/group name.
Definition: Layout.cpp:447
std::vector< gd::String > GD_CORE_API GetBehaviorNamesInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorType, bool searchInGroups)
Get the names of behavior of a given type if an object or all objects of a group has it.
Definition: Layout.cpp:530
gd::String GD_CORE_API GetTypeOfBehaviorInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorName, bool searchInGroups)
Get the type of a behavior if an object or all objects of a group has it.
Definition: Layout.cpp:693
gd::String GD_CORE_API GetTypeOfBehavior(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, gd::String name, bool searchInGroups)
Get a type from a behavior name.
Definition: Layout.cpp:745
bool GD_CORE_API IsDefaultBehavior(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, gd::String objectOrGroupName, gd::String behaviorName, bool searchInGroups)
Check if a behavior is a default one or doesn't exist in an object or all objects of a group.
Definition: Layout.cpp:643
vector< gd::String > GD_CORE_API GetBehaviorsOfObject(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &name, bool searchInGroups)
Get behaviors of an object/group.
Definition: Layout.cpp:767
bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorName, bool searchInGroups)
Check if an object or all objects of a group has a behavior.
Definition: Layout.cpp:597
std::vector< gd::String > GetHiddenLayers(const Layout &layout)
Get the names of all layers from the given layout that are invisible.
Definition: Layout.cpp:436
Functor testing layout name.
Definition: Layout.h:419