2
// C++ Interface: EntityCreator
7
// Author: Alexey Torkhov <atorkhov@gmail.com>, (C) 2008
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.
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.
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.//
23
#ifndef EMBEROGRE_GUIENTITYCREATOR_H
24
#define EMBEROGRE_GUIENTITYCREATOR_H
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>
47
class EntityCreatorInputAdapter;
48
class EntityCreatorMoveAdapter;
49
class EntityCreatorMovement;
52
* @brief Helper class for Entity Creator.
54
* Helper class for Entity Creator. Called from Lua to handle showing preview and creating the entity.
56
* @author Alexey Torkhov <atorkhov@gmail.com>
71
* Sets recipe that would be used for entity creation in future.
73
void setRecipe(EntityRecipe& recipe);
76
* Toggles create mode and performs correspondent action.
78
void toggleCreateMode();
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.
85
void setRandomizeOrientation(bool randomize);
88
* Starts entity creation process.
93
* Stops entity creation process.
103
* Sends composed entity to server
105
void finalizeCreation();
108
* Cleanup after creation of entity or cancel creation.
110
void cleanupCreation();
113
* Sets preview model name
115
void setModel(const std::string& modelName);
118
* Shows preview model part
120
void showModelPart(const std::string& partName);
123
* Hide preview model part
125
void hideModelPart(const std::string& partName);
128
* Called each frame to update a blurb with help text.
130
void showBlurb_frameStarted(const Ogre::FrameEvent& event);
133
* Entity creator widget. Set from Lua, so it is public.
135
::EmberOgre::Gui::Widget* mWidget;
138
* @brief Emitted when all needed type info for the current recipe is loaded.
140
sigc::signal<void> EventTypeInfoLoaded;
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.
151
* Sets preview node properties basing on model. Code from EmberPhysicalEntity.
152
* @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
154
void initFromModel();
157
* Applies correct scaling basing on model definition. Code from EmberPhysicalEntity.
158
* @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
162
// Glue functions to allow code from EmberPhysicalEntity work without changes.
163
Model::Model* getModel();
165
const WFMath::AxisBox<3> & getBBox();
169
* Sets Eris connection on connect to server event.
171
void connectedToServer(Eris::Connection* conn);
176
Eris::Connection* mConn;
179
* Stores, are we in create mode.
184
* Pointer to recipe that is currently selected in widget.
186
EntityRecipe* mRecipe;
189
* Connection to EntityRecipe::adapterValueChanged signal, when in create mode.
191
sigc::connection mRecipeConnection;
194
* @brief Handler of EntityRecipe::adapterValueChanged signal.
196
* Called on EntityRecipe::adapterValueChanged signal and should update preview with new adapter values.
198
* TODO Unfortunately, this signal is never called. Need to find what happens with it in adapters class.
200
void adapterValueChanged();
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.
207
void checkTypeInfoBound();
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.
214
void typeService_BoundType(Eris::TypeInfo* typeInfo);
217
* Current position of preview in the world.
219
WFMath::Point<3> mPos;
222
* Current orientation of preview in the world.
224
WFMath::Quaternion mOrientation;
227
* Adapter that listens to changes of terrain cursor changes and positions preview accordingly.
229
EntityCreatorMoveAdapter* mMoveAdapter;
232
* Detached entity that is used in process of creating preview.
234
DetachedEntity* mEntity;
237
* Preview scene node.
239
Ogre::SceneNode* mEntityNode;
241
ModelMount* mModelMount;
246
Model::Model* mModel;
249
* Message that is composed from recipe entity spec with placeholders substitued with adapters values.
251
Atlas::Message::MapType mEntityMessage;
254
* Contains a blurb with help text.
256
CEGUI::Window* mBlurb;
259
* Is blurb already shown.
264
* Parameters for blurb timing.
266
Ogre::Real mTimeUntilShowBlurb, mTimeBlurbShown, mTimeToShowBlurb;
269
@brief If set to true, all new entities will have their orientation randomized around the vertical axis.
271
bool mRandomizeOrientation;
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.
276
// sigc::connection mTypeInfoBoundConnection;
278
EntityCreatorMovement* mMovement;
284
* Adapter for position entity preview.
286
class EntityCreatorMoveAdapter : public Ogre::FrameListener
289
EntityCreatorMoveAdapter(EntityCreator& adapter);
290
~EntityCreatorMoveAdapter();
292
* Registers adapter in input service.
296
* Unregisters adapter in input service.
298
void removeAdapter();
300
* Called each frame to update position of preview.
302
bool frameStarted(const Ogre::FrameEvent& event);
304
EntityCreator& mEntityCreator;