~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/EntityCreator.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: EntityCreator
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Alexey Torkhov <atorkhov@gmail.com>, (C) 2008
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifndef EMBEROGRE_GUIENTITYCREATOR_H
 
24
#define EMBEROGRE_GUIENTITYCREATOR_H
 
25
 
 
26
#include "components/ogre/manipulation/EntityRecipe.h"
 
27
#include "components/ogre/model/Model.h"
 
28
#include "components/ogre/widgets/Widget.h"
 
29
#include <Eris/Connection.h>
 
30
#include <wfmath/point.h>
 
31
#include <wfmath/quaternion.h>
 
32
#include <CEGUIWindow.h>
 
33
#include <sigc++/signal.h>
 
34
#include <sigc++/connection.h>
 
35
 
 
36
namespace Eris
 
37
{
 
38
class TypeInfo;
 
39
}
 
40
 
 
41
namespace EmberOgre {
 
42
 
 
43
class DetachedEntity;
 
44
class ModelMount;
 
45
namespace Gui {
 
46
 
 
47
class EntityCreatorInputAdapter;
 
48
class EntityCreatorMoveAdapter;
 
49
class EntityCreatorMovement;
 
50
 
 
51
/**
 
52
 * @brief Helper class for Entity Creator.
 
53
 *
 
54
 * Helper class for Entity Creator. Called from Lua to handle showing preview and creating the entity.
 
55
 * 
 
56
 * @author Alexey Torkhov <atorkhov@gmail.com>
 
57
 */
 
58
class EntityCreator {
 
59
public:
 
60
        /**
 
61
         * Constructor.
 
62
         */
 
63
        EntityCreator();
 
64
 
 
65
        /**
 
66
         * Destructor.
 
67
         */
 
68
        ~EntityCreator();
 
69
 
 
70
        /**
 
71
         * Sets recipe that would be used for entity creation in future.
 
72
         */
 
73
        void setRecipe(EntityRecipe& recipe);
 
74
 
 
75
        /**
 
76
         * Toggles create mode and performs correspondent action.
 
77
         */
 
78
        void toggleCreateMode();
 
79
        
 
80
        /**
 
81
         * @brief Sets whether to randomize the orientation of all new entities.
 
82
         * If set, all new entities will have their orientation randomized along the vertical axis.
 
83
         * @param randomize Whether to randomize the orientation or not.
 
84
         */
 
85
        void setRandomizeOrientation(bool randomize);
 
86
 
 
87
        /**
 
88
         * Starts entity creation process.
 
89
         */
 
90
        void startCreation();
 
91
 
 
92
        /**
 
93
         * Stops entity creation process.
 
94
         */
 
95
        void stopCreation();
 
96
 
 
97
        /**
 
98
         * Composes entity
 
99
         */
 
100
        void createEntity();
 
101
 
 
102
        /**
 
103
         * Sends composed entity to server
 
104
         */
 
105
        void finalizeCreation();
 
106
 
 
107
        /**
 
108
         * Cleanup after creation of entity or cancel creation.
 
109
         */
 
110
        void cleanupCreation();
 
111
 
 
112
        /**
 
113
         * Sets preview model name
 
114
         */
 
115
        void setModel(const std::string& modelName);
 
116
 
 
117
        /**
 
118
         * Shows preview model part
 
119
         */
 
120
        void showModelPart(const std::string& partName);
 
121
 
 
122
        /**
 
123
         * Hide preview model part
 
124
         */
 
125
        void hideModelPart(const std::string& partName);
 
126
 
 
127
        /**
 
128
         * Called each frame to update a blurb with help text.
 
129
         */
 
130
        void showBlurb_frameStarted(const Ogre::FrameEvent& event);
 
131
 
 
132
        /**
 
133
         * Entity creator widget. Set from Lua, so it is public.
 
134
         */
 
135
        ::EmberOgre::Gui::Widget* mWidget;
 
136
        
 
137
        /**
 
138
        * @brief Emitted when all needed type info for the current recipe is loaded.
 
139
        */
 
140
        sigc::signal<void> EventTypeInfoLoaded;
 
141
 
 
142
        
 
143
        /**
 
144
         * @brief Makes sure that all types are loaded. This is needed for the type lookup we need to do in the recipes in order to get the default values.
 
145
         */
 
146
        void loadAllTypes();
 
147
 
 
148
 
 
149
protected:
 
150
        /**
 
151
         * Sets preview node properties basing on model. Code from EmberPhysicalEntity.
 
152
         * @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
153
         */
 
154
        void initFromModel();
 
155
 
 
156
        /**
 
157
         * Applies correct scaling basing on model definition. Code from EmberPhysicalEntity.
 
158
         * @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
159
         */
 
160
        void scaleNode();
 
161
 
 
162
        // Glue functions to allow code from EmberPhysicalEntity work without changes.
 
163
        Model::Model* getModel();
 
164
        bool hasBBox();
 
165
        const WFMath::AxisBox<3> & getBBox();
 
166
        
 
167
 
 
168
        /**
 
169
         * Sets Eris connection on connect to server event.
 
170
         */
 
171
        void connectedToServer(Eris::Connection* conn);
 
172
 
 
173
        /**
 
174
         * Eris connection.
 
175
         */
 
176
        Eris::Connection* mConn;
 
177
 
 
178
        /**
 
179
         * Stores, are we in create mode.
 
180
         */
 
181
        bool mCreateMode;
 
182
 
 
183
        /**
 
184
         * Pointer to recipe that is currently selected in widget.
 
185
         */
 
186
        EntityRecipe* mRecipe;
 
187
 
 
188
        /**
 
189
         * Connection to EntityRecipe::adapterValueChanged signal, when in create mode.
 
190
         */
 
191
        sigc::connection mRecipeConnection;
 
192
 
 
193
        /**
 
194
         * @brief Handler of EntityRecipe::adapterValueChanged signal.
 
195
         *
 
196
         * Called on EntityRecipe::adapterValueChanged signal and should update preview with new adapter values.
 
197
         *
 
198
         * TODO Unfortunately, this signal is never called. Need to find what happens with it in adapters class.
 
199
         */
 
200
        void adapterValueChanged();
 
201
        
 
202
        /**
 
203
         * @brief Checks whether the type info for the current recipe is fully bound.
 
204
         * If so, the EventTypeInfoLoaded signal will be emitted right away, else it will be emitted later on when the type is bound through the typeService_BoundType method.
 
205
         * Call this method right after a new entity recipe has been set, to make sure that the interface doesn't proceed until the type info is bound.
 
206
         */
 
207
        void checkTypeInfoBound();
 
208
        
 
209
        
 
210
        /**
 
211
         * @brief Listen for the bound signal for the type service, and if the type of our recipe has been bound emit the EventTypeInfoLoaded signal.
 
212
         * @param typeInfo The type info that was bound.
 
213
         */
 
214
        void typeService_BoundType(Eris::TypeInfo* typeInfo);
 
215
 
 
216
        /**
 
217
         * Current position of preview in the world.
 
218
         */
 
219
        WFMath::Point<3> mPos;
 
220
 
 
221
        /**
 
222
         * Current orientation of preview in the world.
 
223
         */
 
224
        WFMath::Quaternion mOrientation;
 
225
 
 
226
        /**
 
227
         * Adapter that listens to changes of terrain cursor changes and positions preview accordingly.
 
228
         */
 
229
        EntityCreatorMoveAdapter* mMoveAdapter;
 
230
 
 
231
        /**
 
232
         * Detached entity that is used in process of creating preview.
 
233
         */
 
234
        DetachedEntity* mEntity;
 
235
 
 
236
        /**
 
237
         * Preview scene node.
 
238
         */
 
239
        Ogre::SceneNode* mEntityNode;
 
240
 
 
241
        ModelMount* mModelMount;
 
242
        
 
243
        /**
 
244
         * Preview model.
 
245
         */
 
246
        Model::Model* mModel;
 
247
 
 
248
        /**
 
249
         * Message that is composed from recipe entity spec with placeholders substitued with adapters values.
 
250
         */
 
251
        Atlas::Message::MapType mEntityMessage;
 
252
 
 
253
        /**
 
254
         * Contains a blurb with help text.
 
255
         */
 
256
        CEGUI::Window* mBlurb;
 
257
 
 
258
        /**
 
259
         * Is blurb already shown.
 
260
         */
 
261
        bool mBlurbShown;
 
262
 
 
263
        /**
 
264
         * Parameters for blurb timing.
 
265
         */
 
266
        Ogre::Real mTimeUntilShowBlurb, mTimeBlurbShown, mTimeToShowBlurb;
 
267
        
 
268
        /**
 
269
        @brief If set to true, all new entities will have their orientation randomized around the vertical axis.
 
270
        */
 
271
        bool mRandomizeOrientation;
 
272
        
 
273
        /**
 
274
         * @brief The connection for the TypeInfo bound signal, used for making sure that the UI doesn't proceed until the type info has been correctly bound.
 
275
         */
 
276
//      sigc::connection mTypeInfoBoundConnection;
 
277
 
 
278
        EntityCreatorMovement* mMovement;
 
279
 
 
280
};
 
281
 
 
282
 
 
283
/**
 
284
 * Adapter for position entity preview.
 
285
 */
 
286
class EntityCreatorMoveAdapter : public Ogre::FrameListener
 
287
{
 
288
public:
 
289
        EntityCreatorMoveAdapter(EntityCreator& adapter);
 
290
        ~EntityCreatorMoveAdapter();
 
291
        /**
 
292
         * Registers adapter in input service.
 
293
         */
 
294
        void addAdapter();
 
295
        /**
 
296
         * Unregisters adapter in input service.
 
297
         */
 
298
        void removeAdapter();
 
299
        /**
 
300
         * Called each frame to update position of preview.
 
301
         */
 
302
        bool frameStarted(const Ogre::FrameEvent& event);
 
303
protected:
 
304
        EntityCreator& mEntityCreator;
 
305
};
 
306
 
 
307
}
 
308
 
 
309
}
 
310
 
 
311
#endif