Cafu Engine
DialogEntityHierarchy.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_MAPEDITOR_DIALOG_ENTITY_HIERARCHY_HPP_INCLUDED
8 #define CAFU_MAPEDITOR_DIALOG_ENTITY_HIERARCHY_HPP_INCLUDED
9 
10 #include "ObserverPattern.hpp"
11 
12 #include "wx/panel.h"
13 #include "wx/dataview.h"
14 #include "wx/treectrl.h"
15 
16 
17 class ChildFrameT;
18 class MapDocumentT;
19 
20 
21 namespace MapEditor
22 {
23  class EntityHierarchyDialogT : public wxTreeCtrl, public ObserverT
24  {
25  public:
26 
27  EntityHierarchyDialogT(ChildFrameT* Parent, wxWindow* WinParent);
29 
30  // Implementation of the ObserverT interface.
31  void NotifySubjectChanged_Selection(SubjectT* Subject, const ArrayT<MapElementT*>& OldSelection, const ArrayT<MapElementT*>& NewSelection) override;
32  void NotifySubjectChanged_Groups(SubjectT* Subject) override;
33  void NotifySubjectChanged_Created(SubjectT* Subject, const ArrayT< IntrusivePtrT<cf::GameSys::EntityT> >& Entities) override;
34  void NotifySubjectChanged_Created(SubjectT* Subject, const ArrayT<MapPrimitiveT*>& Primitives) override;
35  void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT< IntrusivePtrT<cf::GameSys::EntityT> >& Entities) override;
36  void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT<MapPrimitiveT*>& Primitives) override;
37  void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail) override;
38  void Notify_EntChanged(SubjectT* Subject, const ArrayT< IntrusivePtrT<MapEditor::CompMapEntityT> >& Entities, EntityModDetailE Detail) override;
39  void Notify_VarChanged(SubjectT* Subject, const cf::TypeSys::VarBaseT& Var) override;
40  void NotifySubjectDies(SubjectT* dyingSubject) override;
41 
42  /// Redraws the whole tree.
43  void RefreshTree();
44 
45 
46  private:
47 
48  void AddChildren(const wxTreeItemId& Item, bool Recursive);
49 
50  /// Recursively searches the tree for an item associated with a specified EntityT.
51  /// @param StartingItem Item to start the recursive search at.
52  /// @param Entity The entity whose tree item we are interested in.
53  const wxTreeItemId FindTreeItem(const wxTreeItemId& StartingItem, IntrusivePtrT<cf::GameSys::EntityT> Entity) const;
54 
55  /// Recursively gets all tree items, beginning with the passed tree item.
56  void GetTreeItems(const wxTreeItemId& StartingItem, ArrayT<wxTreeItemId>& Items);
57 
58  /// Updates the labels of all items in the tree.
59  void UpdateAllLabels();
60 
61  /// Updates the colors of all items in the tree.
62  void UpdateAllGroupColors();
63 
64  MapDocumentT* m_MapDoc;
65  ChildFrameT* m_Parent;
66  bool m_IsRecursiveSelfNotify;
68 
69  void OnKeyDown (wxKeyEvent& KE);
70  void OnTreeLeftClick (wxMouseEvent& ME);
71  void OnSelectionChanging (wxTreeEvent& TE);
72  void OnSelectionChanged (wxTreeEvent& TE);
73  void OnBeginLabelEdit (wxTreeEvent& TE);
74  void OnEndLabelEdit (wxTreeEvent& TE);
75  void OnGetTooltip (wxTreeEvent& TE);
76  void OnTreeItemRightClick(wxTreeEvent& TE);
77  void OnBeginDrag (wxTreeEvent& TE);
78  void OnEndDrag (wxTreeEvent& TE);
79 
80  DECLARE_EVENT_TABLE()
81  };
82 
83 
84  class EntityHierarchyModelT : public wxDataViewModel
85  {
86  public:
87 
88  enum ColumnT
89  {
90  COLUMN_ENTITY_NAME = 0,
91  COLUMN_NUM_PRIMITIVES,
92  NR_OF_COLUMNS
93  };
94 
96 
97 
98  private:
99 
100  // Override / implement base class methods.
101  unsigned int GetColumnCount() const override;
102  wxString GetColumnType(unsigned int col) const override;
103 
104  void GetValue(wxVariant& Variant, const wxDataViewItem& Item, unsigned int col) const override;
105  bool SetValue(const wxVariant& Variant, const wxDataViewItem& Item, unsigned int col) override;
106 
107  wxDataViewItem GetParent(const wxDataViewItem& Item) const override;
108  bool IsContainer(const wxDataViewItem& Item) const override;
109  bool HasContainerColumns(const wxDataViewItem& Item) const override;
110  unsigned int GetChildren(const wxDataViewItem& Item, wxDataViewItemArray& Children) const override;
111 
112  IntrusivePtrT<cf::GameSys::EntityT> m_RootEntity; ///< The root of the entity hierarchy.
113  };
114 
115 
116  class EntityHierarchyCtrlT : public wxDataViewCtrl, public ObserverT
117  {
118  public:
119 
120  EntityHierarchyCtrlT(ChildFrameT* MainFrame, wxWindow* Parent);
122 
123  // Implementation of the ObserverT interface.
124  void NotifySubjectChanged_Selection(SubjectT* Subject, const ArrayT<MapElementT*>& OldSelection, const ArrayT<MapElementT*>& NewSelection) override;
125  void NotifySubjectChanged_Created(SubjectT* Subject, const ArrayT< IntrusivePtrT<cf::GameSys::EntityT> >& Entities) override;
126  void NotifySubjectChanged_Created(SubjectT* Subject, const ArrayT<MapPrimitiveT*>& Primitives) override;
127  void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT< IntrusivePtrT<cf::GameSys::EntityT> >& Entities) override;
128  void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT<MapPrimitiveT*>& Primitives) override;
129  void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail) override;
130  void Notify_EntChanged(SubjectT* Subject, const ArrayT< IntrusivePtrT<MapEditor::CompMapEntityT> >& Entities, EntityModDetailE Detail) override;
131  void Notify_VarChanged(SubjectT* Subject, const cf::TypeSys::VarBaseT& Var) override;
132  void NotifySubjectDies(SubjectT* dyingSubject) override;
133 
134 
135  private:
136 
137  ChildFrameT* m_MainFrame;
138  MapDocumentT* m_MapDoc;
139  bool m_IsRecursiveSelfNotify;
140  IntrusivePtrT<cf::GameSys::EntityT> m_DraggedEntity;
141 
142  void OnSelectionChanged(wxDataViewEvent& Event);
143  void OnEndItemEdit(wxDataViewEvent& Event);
144  void OnTreeItemContextMenu(wxDataViewEvent& Event);
145  void OnBeginDrag(wxDataViewEvent& Event);
146  void OnCheckDrag(wxDataViewEvent& Event);
147  void OnEndDrag(wxDataViewEvent& Event);
148 
149  DECLARE_EVENT_TABLE()
150  };
151 
152 
153  class EntityHierarchyPanelT : public wxPanel
154  {
155  public:
156 
157  EntityHierarchyPanelT(ChildFrameT* MainFrame, const wxSize& Size);
158 
159 
160  private:
161 
162  /// IDs for the controls whose events we are interested in.
163  enum
164  {
165  ID_TREECTRL = wxID_HIGHEST + 1,
166  ID_BUTTON_ADD,
167  ID_BUTTON_UP,
168  ID_BUTTON_DOWN,
169  ID_BUTTON_DELETE
170  };
171 
172  // void OnButton(wxCommandEvent& Event);
173  // void OnButtonUpdate(wxUpdateUIEvent& UE);
174 
175  ChildFrameT* m_MainFrame;
176  EntityHierarchyDialogT* m_OldTreeCtrl;
177  EntityHierarchyCtrlT* m_TreeCtrl;
178 
179  DECLARE_EVENT_TABLE()
180  };
181 }
182 
183 #endif
MapElemModDetailE
Definition: ObserverPattern.hpp:37
void NotifySubjectChanged_Selection(SubjectT *Subject, const ArrayT< MapElementT * > &OldSelection, const ArrayT< MapElementT * > &NewSelection) override
Notifies the observer that the selection in the current subject has been changed. ...
Definition: DialogEntityHierarchy.cpp:1079
void Notify_EntChanged(SubjectT *Subject, const ArrayT< IntrusivePtrT< MapEditor::CompMapEntityT > > &Entities, EntityModDetailE Detail) override
Definition: DialogEntityHierarchy.cpp:1168
Definition: DialogEntityHierarchy.hpp:84
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
void NotifySubjectChanged_Groups(SubjectT *Subject) override
Notifies the observer that the groups in the current subject have been changed (new group added...
Definition: DialogEntityHierarchy.cpp:242
void Notify_VarChanged(SubjectT *Subject, const cf::TypeSys::VarBaseT &Var) override
Notifies the observer that a variable has changed.
Definition: DialogEntityHierarchy.cpp:1182
void NotifySubjectDies(SubjectT *dyingSubject) override
This method is called whenever a subject is about the be destroyed (and become unavailable).
Definition: DialogEntityHierarchy.cpp:1203
Definition: DialogEntityHierarchy.hpp:153
void NotifySubjectChanged_Created(SubjectT *Subject, const ArrayT< IntrusivePtrT< cf::GameSys::EntityT > > &Entities) override
Notifies the observer that one or more entities have been created.
Definition: DialogEntityHierarchy.cpp:248
Definition: DialogEntityHierarchy.hpp:23
void NotifySubjectDies(SubjectT *dyingSubject) override
This method is called whenever a subject is about the be destroyed (and become unavailable).
Definition: DialogEntityHierarchy.cpp:328
EntityModDetailE
Definition: ObserverPattern.hpp:47
This class represents a child frame.
Definition: ChildFrame.hpp:55
Definition: ObserverPattern.hpp:64
void RefreshTree()
Redraws the whole tree.
Definition: DialogEntityHierarchy.cpp:338
void NotifySubjectChanged_Modified(SubjectT *Subject, const ArrayT< MapElementT * > &MapElements, MapElemModDetailE Detail) override
Definition: DialogEntityHierarchy.cpp:280
Definition: ObserverPattern.hpp:158
void NotifySubjectChanged_Modified(SubjectT *Subject, const ArrayT< MapElementT * > &MapElements, MapElemModDetailE Detail) override
Definition: DialogEntityHierarchy.cpp:1153
void Notify_VarChanged(SubjectT *Subject, const cf::TypeSys::VarBaseT &Var) override
Notifies the observer that a variable has changed.
Definition: DialogEntityHierarchy.cpp:301
This is the common base class for the VarT classes.
Definition: Variables.hpp:113
Definition: DialogEntityHierarchy.hpp:116
void NotifySubjectChanged_Deleted(SubjectT *Subject, const ArrayT< IntrusivePtrT< cf::GameSys::EntityT > > &Entities) override
Notifies the observer that one or more entities have been deleted.
Definition: DialogEntityHierarchy.cpp:1130
void Notify_EntChanged(SubjectT *Subject, const ArrayT< IntrusivePtrT< MapEditor::CompMapEntityT > > &Entities, EntityModDetailE Detail) override
Definition: DialogEntityHierarchy.cpp:291
This file provides the classes for the Observer pattern as described in the book by the GoF...
void NotifySubjectChanged_Deleted(SubjectT *Subject, const ArrayT< IntrusivePtrT< cf::GameSys::EntityT > > &Entities) override
Notifies the observer that one or more entities have been deleted.
Definition: DialogEntityHierarchy.cpp:264
void NotifySubjectChanged_Selection(SubjectT *Subject, const ArrayT< MapElementT * > &OldSelection, const ArrayT< MapElementT * > &NewSelection) override
Notifies the observer that the selection in the current subject has been changed. ...
Definition: DialogEntityHierarchy.cpp:211
void NotifySubjectChanged_Created(SubjectT *Subject, const ArrayT< IntrusivePtrT< cf::GameSys::EntityT > > &Entities) override
Notifies the observer that one or more entities have been created.
Definition: DialogEntityHierarchy.cpp:1110