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 #pragma once
8 
9 #include <map>
10 #include <memory>
11 #include <vector>
12 
13 #include "GDCore/Events/EventsList.h"
14 #include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
15 #include "GDCore/Project/BehaviorsSharedData.h"
16 #include "GDCore/Project/InitialInstancesContainer.h"
17 #include "GDCore/Project/Layer.h"
18 #include "GDCore/Project/LayersContainer.h"
19 #include "GDCore/Project/ObjectGroupsContainer.h"
20 #include "GDCore/Project/ObjectsContainer.h"
21 #include "GDCore/Project/VariablesContainer.h"
22 #include "GDCore/String.h"
23 
24 namespace gd {
25 class BaseEvent;
26 class Object;
27 class Project;
28 class InitialInstancesContainer;
29 } // namespace gd
30 class BaseProfiler;
31 #undef GetObject // Disable an annoying macro
32 
33 namespace gd {
34 
40 class GD_CORE_API Layout {
41  public:
42  Layout();
43  Layout(const Layout&);
44  virtual ~Layout();
45  Layout& operator=(const Layout& rhs);
46 
50  Layout* Clone() const { return new Layout(*this); };
51 
56 
60  void SetName(const gd::String& name_);
61 
65  const gd::String& GetName() const { return name; };
66 
70  const gd::String& GetMangledName() const { return mangledName; };
71 
75  void SetBackgroundColor(unsigned int r, unsigned int g, unsigned int b) {
76  backgroundColorR = r;
77  backgroundColorG = g;
78  backgroundColorB = b;
79  }
80 
84  unsigned int GetBackgroundColorRed() const { return backgroundColorR; }
85 
89  unsigned int GetBackgroundColorGreen() const { return backgroundColorG; }
90 
94  unsigned int GetBackgroundColorBlue() const { return backgroundColorB; }
95 
99  const gd::String& GetWindowDefaultTitle() const { return title; };
100 
104  void SetWindowDefaultTitle(const gd::String& title_) { title = title_; };
105 
107 
111 
115  return objectsContainer;
116  }
117 
122  return objectsContainer;
123  }
125 
131 
135  return initialInstances;
136  }
137 
142  return initialInstances;
143  }
145 
150 
154  const gd::EventsList& GetEvents() const { return events; }
155 
159  gd::EventsList& GetEvents() { return events; }
160 
162 
167 
173  inline const gd::VariablesContainer& GetVariables() const {
174  return variables;
175  }
176 
182  inline gd::VariablesContainer& GetVariables() { return variables; }
183 
185 
189 
193  const gd::LayersContainer& GetLayers() const { return layers; }
194 
198  gd::LayersContainer& GetLayers() { return layers; }
199 
203  bool HasLayerNamed(const gd::String& name) const;
204 
208  Layer& GetLayer(const gd::String& name);
209 
213  const Layer& GetLayer(const gd::String& name) const;
214 
218  Layer& GetLayer(std::size_t index);
219 
223  const Layer& GetLayer(std::size_t index) const;
224 
228  std::size_t GetLayerPosition(const gd::String& name) const;
229 
233  std::size_t GetLayersCount() const;
234 
238  void InsertNewLayer(const gd::String& name, std::size_t position);
239 
243  void InsertLayer(const Layer& theLayer, std::size_t position);
244 
248  void RemoveLayer(const gd::String& name);
249 
253  void SwapLayers(std::size_t firstLayerIndex, std::size_t secondLayerIndex);
254 
258  void MoveLayer(std::size_t oldIndex, std::size_t newIndex);
260 
269  void UpdateBehaviorsSharedData(gd::Project& project);
270 
274  std::vector<gd::String> GetAllBehaviorSharedDataNames() const;
275 
279  bool HasBehaviorSharedData(const gd::String& behaviorName);
280 
284  const gd::BehaviorsSharedData& GetBehaviorSharedData(
285  const gd::String& behaviorName) const;
286 
290  gd::BehaviorsSharedData& GetBehaviorSharedData(
291  const gd::String& behaviorName);
292 
296  const std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>&
297  GetAllBehaviorSharedData() const;
298 
304  return editorSettings;
305  }
306 
311  gd::EditorSettings& GetAssociatedEditorSettings() { return editorSettings; }
312 
316 
319  void DisableInputWhenFocusIsLost(bool disable = true) {
320  disableInputWhenNotFocused = disable;
321  }
322 
326  bool IsInputDisabledWhenFocusIsLost() { return disableInputWhenNotFocused; }
327 
331  void SetStandardSortMethod(bool enable = true) {
332  standardSortMethod = enable;
333  }
334 
338  bool StandardSortMethod() const { return standardSortMethod; }
339 
343  void SetStopSoundsOnStartup(bool enable = true) {
344  stopSoundsOnStartup = enable;
345  }
346 
351  bool StopSoundsOnStartup() const { return stopSoundsOnStartup; }
353 
358 
361  void SerializeTo(SerializerElement& element) const;
362 
366  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
368 
369  private:
370  gd::String name;
371  gd::String mangledName;
372  unsigned int backgroundColorR = 0;
373  unsigned int backgroundColorG = 0;
374  unsigned int backgroundColorB = 0;
375  gd::String title;
376  gd::VariablesContainer variables;
377  gd::ObjectsContainer objectsContainer;
378  gd::InitialInstancesContainer initialInstances;
379  gd::LayersContainer layers;
380  std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>
381  behaviorsSharedData;
382  bool stopSoundsOnStartup = true;
384  bool standardSortMethod = true;
385  bool disableInputWhenNotFocused = true;
389  badBehaviorSharedData;
392 
393  EventsList events;
394  gd::EditorSettings editorSettings;
395 
400  void Init(const gd::Layout& other);
401 
402  std::unique_ptr<gd::BehaviorsSharedData> CreateBehaviorsSharedData(
403  gd::Project& project,
404  const gd::String& name,
405  const gd::String& behaviorsType);
406 };
407 
413 std::vector<gd::String> GetHiddenLayers(const Layout& layout);
414 
424 gd::String GD_CORE_API GetTypeOfObject(const ObjectsContainer& game,
425  const ObjectsContainer& layout,
426  gd::String objectName,
427  bool searchInGroups = true);
433 bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer& project,
434  const gd::ObjectsContainer& layout,
435  const gd::String& objectOrGroupName,
436  const gd::String& behaviorName,
437  bool searchInGroups = true);
442 std::vector<gd::String> GD_CORE_API
444  const gd::ObjectsContainer& layout,
445  const gd::String& objectOrGroupName,
446  const gd::String& behaviorType,
447  bool searchInGroups);
448 
453 bool GD_CORE_API IsDefaultBehavior(const gd::ObjectsContainer& project,
454  const gd::ObjectsContainer& layout,
455  gd::String objectOrGroupName,
456  gd::String behaviorName,
457  bool searchInGroups = true);
458 
463 gd::String GD_CORE_API
465  const gd::ObjectsContainer& layout,
466  const gd::String& objectOrGroupName,
467  const gd::String& behaviorName,
468  bool searchInGroups = true);
474 gd::String GD_CORE_API GetTypeOfBehavior(const ObjectsContainer& game,
475  const ObjectsContainer& layout,
476  gd::String behaviorName,
477  bool searchInGroups = true);
478 
486 std::vector<gd::String> GD_CORE_API
487 GetBehaviorsOfObject(const ObjectsContainer& game,
488  const ObjectsContainer& layout,
489  const gd::String& objectName,
490  bool searchInGroups = true);
491 
492 } // namespace gd
493 
494 typedef gd::Layout Scene;
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:32
Defines a container of gd::InitialInstances.
Definition: InitialInstancesContainer.h:38
Represents a layer of a layout.
Definition: Layer.h:91
Contains the layers for a scene or a custom object.
Definition: LayersContainer.h:21
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:40
bool StopSoundsOnStartup() const
Definition: Layout.h:351
bool StandardSortMethod() const
Definition: Layout.h:338
const gd::String & GetMangledName() const
Definition: Layout.h:70
gd::ObjectsContainer & GetObjects()
return the objects of the scene.
Definition: Layout.h:114
unsigned int GetBackgroundColorGreen() const
Definition: Layout.h:89
void SetStandardSortMethod(bool enable=true)
Definition: Layout.h:331
gd::InitialInstancesContainer & GetInitialInstances()
Definition: Layout.h:141
bool IsInputDisabledWhenFocusIsLost()
Definition: Layout.h:326
void SetBackgroundColor(unsigned int r, unsigned int g, unsigned int b)
Definition: Layout.h:75
const gd::ObjectsContainer & GetObjects() const
Return the objects of the scene.
Definition: Layout.h:121
const gd::VariablesContainer & GetVariables() const
Get the variables of the scene.
Definition: Layout.h:173
const gd::EventsList & GetEvents() const
Definition: Layout.h:154
gd::EditorSettings & GetAssociatedEditorSettings()
Definition: Layout.h:311
const gd::LayersContainer & GetLayers() const
Get the layers of the scene.
Definition: Layout.h:193
const gd::String & GetName() const
Definition: Layout.h:65
const gd::String & GetWindowDefaultTitle() const
Definition: Layout.h:99
unsigned int GetBackgroundColorBlue() const
Definition: Layout.h:94
const gd::EditorSettings & GetAssociatedEditorSettings() const
Definition: Layout.h:303
const gd::InitialInstancesContainer & GetInitialInstances() const
Definition: Layout.h:134
unsigned int GetBackgroundColorRed() const
Definition: Layout.h:84
void SetStopSoundsOnStartup(bool enable=true)
Definition: Layout.h:343
gd::LayersContainer & GetLayers()
Get the layers of the scene.
Definition: Layout.h:198
void DisableInputWhenFocusIsLost(bool disable=true)
Definition: Layout.h:319
gd::EventsList & GetEvents()
Definition: Layout.h:159
Layout * Clone() const
Return a pointer to a copy of the layout.
Definition: Layout.h:50
gd::VariablesContainer & GetVariables()
Get the variables of the scene.
Definition: Layout.h:182
void SetWindowDefaultTitle(const gd::String &title_)
Definition: Layout.h:104
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
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:422
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:510
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:677
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:732
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:626
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:754
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:579
std::vector< gd::String > GetHiddenLayers(const Layout &layout)
Get the names of all layers from the given layout that are invisible.
Definition: Layout.cpp:411