RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
customundoableactions.h
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #ifndef CUSTOMUNDOABLEACTIONS_H
31 #define CUSTOMUNDOABLEACTIONS_H
32 
33 #include "cengine/cgameobject.h"
34 #include "cengine/cgamescene.h"
36 #include "editor/editorwindow.h"
37 
42 class TranslateAction : public UndoableAction<CGameObject*, btVector3> {
43 public:
44  TranslateAction(CGameObject* game_obj, btVector3 translate_vec) :
45  UndoableAction(game_obj, translate_vec) {
46  m_oldValue = game_obj->transform().localPosition();
47  }
48 
49  virtual const char* getHint() const {
50  return "Translate";
51  }
52 
53  virtual void performAction() {
55  }
56 
58  return new TranslateAction(m_target, m_oldValue);
59  }
60 
61 protected:
62  btVector3 m_oldValue;
63 };
64 
65 
70 class ScaleAction : public UndoableAction<CGameObject*, btVector3> {
71 public:
72  ScaleAction(CGameObject* game_obj, btVector3 translate_vec, bool calc_size_on_execute = false) : UndoableAction(game_obj, translate_vec) {
73  m_oldValue = game_obj->transform().localScale();
74  m_calcSizeOnExecute = calc_size_on_execute;
75  }
76 
77  virtual const char* getHint() const {
78  return "Scale";
79  }
80 
81  virtual void performAction() {
83  if (m_calcSizeOnExecute && m_target->bPhysicsEnabled()) {
84  m_target->removeFromDynamicsWorld();
85  m_target->calcSize();
86  if(m_target->bulletProperties.physicsEnabled()) {
87  m_target->deployIntoDynamicsWorld();
88  }
89  }
90  }
91 
94  }
95 
96 protected:
97  btVector3 m_oldValue;
99 };
100 
105 class AddOrRemoveGameObjectAction: public UndoableAction<CGameScene*, CGameObject*> {
106 public:
108  CGameObject* game_obj, bool add_mode, std::string hint = std::string()) :
109  UndoableAction(scene, game_obj) {
110  m_editorWindow = editor_window;
111  m_addMode = add_mode;
112  m_hint = hint;
113  }
114 
115  virtual void performAction() {
116  if (m_addMode) {
118  m_editorWindow->selectGameObject(m_value);
119  } else {
121  m_editorWindow->repopulatePropertyBrowser();
122  m_editorWindow->selectMostRecentGameObject();
123  }
124  }
125 
127  return new AddOrRemoveGameObjectAction(m_editorWindow, m_target, m_value, !m_addMode, m_hint);
128  }
129 
130  virtual const char* getHint() const {
131  return m_hint.c_str();
132  }
133 
134  virtual void setHint(const std::string& hint) {
135  m_hint = hint;
136  }
137 
138  virtual void* getTarget() const {
139  return m_target;
140  }
141 
147  }
148 
149 private:
150  bool m_addMode;
151  std::string m_hint;
152  EditorWindow* m_editorWindow;
153 };
154 
161 private:
162  bool m_addMode;
163  EditorWindow* m_editorWindow;
164 
165 public:
166  DuplicateGameObject(EditorWindow* editor_window, CGameScene* scene, CGameObject* game_obj, bool add_mode) :
167  AddOrRemoveGameObjectAction(editor_window, scene, game_obj, add_mode)
168  {}
169 
170  virtual const char* getHint() const {
171  return "Duplicate GameObject";
172  }
173 };
174 
178 class RotateAction : public UndoableAction<CGameObject*, btQuaternion> {
179 public:
180  RotateAction(CGameObject* game_obj, btQuaternion rotation) : UndoableAction(game_obj, rotation) {
181  m_oldValue = game_obj->transform().localRotation();
182  }
183 
184  virtual const char* getHint() const {
185  return "Rotation";
186  }
187 
188  virtual void performAction() {
190  }
191 
193  return new RotateAction(m_target, m_oldValue);
194  }
195 
196 protected:
197  btQuaternion m_oldValue;
198 };
199 
204 class InspectorAction : public UndoableAction<QObject*, QVariant> {
205  Q_OBJECT
206 public:
207  InspectorAction(QObject* game_obj, QString property_name, QVariant value) : UndoableAction(game_obj, value) {
208  m_propertyName = property_name;
209  m_oldValue = game_obj->property(qPrintable(property_name));
210 
211  connect(this, SIGNAL(actionPerformed(QObject*, QString, QVariant, QVariant)),
212  EditorWindow::currentInstance, SLOT(onInspectorActionPeformed(QObject*, QString, QVariant, QVariant)));
213  }
214 
215  virtual const char* getHint() const {
216  return "Inspector";
217  }
218 
219  virtual void performAction() {
220  m_target->setProperty(qPrintable(m_propertyName), m_value);
222  }
223 
226  }
227 
228 protected:
229  QString m_propertyName;
230  QVariant m_oldValue;
231 
232 Q_SIGNALS:
233  void actionPerformed(QObject*, QString, QVariant, QVariant);
234 };
235 
236 #endif // CUSTOMUNDOABLEACTIONS_H
AddOrRemoveGameObjectAction(EditorWindow *editor_window, CGameScene *scene, CGameObject *game_obj, bool add_mode, std::string hint=std::string())
btQuaternion localRotation() const
Definition: transform.cpp:132
virtual IUndoableAction * getOppositeAction()
virtual const char * getHint() const
virtual const char * getHint() const
void selectMostRecentGameObject()
virtual void performAction()
ScaleAction(CGameObject *game_obj, btVector3 translate_vec, bool calc_size_on_execute=false)
void setLocalScale(float x, float y, float z)
Definition: transform.cpp:180
virtual const char * getHint() const
virtual void performAction()
void repopulatePropertyBrowser()
TranslateAction(CGameObject *game_obj, btVector3 translate_vec)
virtual void performAction()
const btVector3 & localPosition(UnitType unit_type=WORLD) const
Definition: transform.cpp:105
virtual const char * getHint() const
void selectGameObject(CGameObject *game_object)
void setLocalRotation(float w, float x, float y, float z)
Definition: transform.cpp:209
virtual void performAction()
virtual void * getTarget() const
virtual IUndoableAction * getOppositeAction()
virtual void setHint(const std::string &hint)
#define SAFE_RELEASE(x)
Definition: cobject.h:36
bool removeGameObject(uint uid)
Definition: cgamescene.cpp:350
static EditorWindow * currentInstance
Definition: editorwindow.h:69
virtual const char * getHint() const
btVector3 localScale() const
Definition: transform.cpp:123
const bool physicsEnabled() const
virtual IUndoableAction * getOppositeAction()
InspectorAction(QObject *game_obj, QString property_name, QVariant value)
virtual const char * getHint() const
DuplicateGameObject(EditorWindow *editor_window, CGameScene *scene, CGameObject *game_obj, bool add_mode)
void setLocalPosition(float x, float y, float z)
Definition: transform.cpp:165
void actionPerformed(QObject *, QString, QVariant, QVariant)
btQuaternion m_oldValue
Transform & transform()
Definition: clnode.cpp:69
void addGameObject(CGameObject *game_object)
Definition: cgamescene.cpp:244
virtual IUndoableAction * getOppositeAction()
virtual IUndoableAction * getOppositeAction()
RotateAction(CGameObject *game_obj, btQuaternion rotation)