2
// C++ Interface: IntegratedChatWidget
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
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 EMBEROGREINTEGRATEDCHATWIDGET_H
24
#define EMBEROGREINTEGRATEDCHATWIDGET_H
27
#include "WidgetPool.h"
28
#include <Eris/Entity.h>
29
#include "services/config/ConfigListener.h"
35
class EmberPhysicalEntity;
44
Shows chat bubbles over npc's heads when they say something.
45
The bubbles will disappear after a while (actually fade out) or when the player moves away. This can be set in the config file.
47
If the npc has a list of suggested responses these will be shown in a list of clickable buttons to the right.
49
@author Erik Hjortsberg
51
class IngameChatWidget : public Widget, public Ember::ConfigListenerContainer {
58
class MovableObjectListener : public Ogre::MovableObject::Listener
61
MovableObjectListener(EntityObserver& entityObserver, EmberPhysicalEntity* entity);
62
virtual ~MovableObjectListener();
64
virtual bool objectRendering (const Ogre::MovableObject * movableObject, const Ogre::Camera * camera);
65
void setObserving(bool isObserving);
68
EntityObserver& mEntityObserver;
69
EmberPhysicalEntity* mEntity;
73
class EntityObserver : public virtual sigc::trackable
76
EntityObserver(IngameChatWidget& chatWidget, EmberPhysicalEntity* entity);
77
virtual ~EntityObserver();
78
void updateLabel(const Ogre::Camera * camera);
81
IngameChatWidget& mChatWidget;
82
EmberPhysicalEntity* mEntity;
84
MovableObjectListener mMovableObjectListener;
85
Eris::Entity::AttrChangedSlot mExternalSlot; //, mNameSlot;
90
void entity_VisibilityChanged(bool visible);
91
void entity_BeingDeleted();
92
void entity_Say(const Atlas::Objects::Root& talk);
93
void entity_attributeChanged(const Atlas::Message::Element& attributeValue);
100
Holds the actual chat window and keeps track of fading, catching clicks etc.
102
class Label : public sigc::trackable
108
Label(CEGUI::Window* window, CEGUI::WindowManager* windowManager, IngameChatWidget& containerWidget, const std::string& prefix);
115
void updateText(const std::string& line);
119
gets the entity the window belongs to
121
EmberEntity* getEntity();
123
void setEntity(EmberEntity* entity);
125
void setActive(bool active);
126
bool getActive() const;
127
void markForRender();
129
CEGUI::Window* getWindow();
131
call this each frame to update the window
133
void frameStarted( const Ogre::FrameEvent & event );
136
positions the window on top of the entity
138
void placeWindowOnEntity();
140
IngameChatWidget& getIngameChatWidget() { return mContainerWidget;}
142
void updateEntityName();
146
CEGUI::Window* mWindow;
147
EmberEntity* mEntity;
148
std::vector<CEGUI::Window*> mResponseTextWidgets;
149
CEGUI::WindowManager* mWindowManager;
150
IngameChatWidget& mContainerWidget;
152
bool buttonResponse_Click(const CEGUI::EventArgs& args);
155
const std::string mPrefix;
156
bool mRenderNextFrame;
158
// CEGUI::Window* mNameWidget;
162
class LabelCreator : public WidgetPool<IngameChatWidget::Label>::WidgetCreator
165
LabelCreator(IngameChatWidget& ingameChatWidget);
166
virtual ~LabelCreator() {}
167
virtual IngameChatWidget::Label* createWidget(unsigned int currentPoolSize);
169
IngameChatWidget& mIngameChatWidget;
172
class ChatText : public sigc::trackable
175
ChatText(CEGUI::Window* window, const std::string& prefix);
176
virtual ~ChatText() {}
178
void updateText( const std::string & line);
181
call this each frame to update the window
183
bool frameStarted( const Ogre::FrameEvent & event );
185
float getElapsedTimeSinceLastUpdate();
188
increases the elapsed time with the supplied amount
190
void increaseElapsedTime(float timeSlice);
192
void attachToLabel(Label* label);
195
std::vector<CEGUI::Window*> mResponseTextWidgets;
197
CEGUI::Window* mWindow;
198
CEGUI::Window* mTextWidget;
199
CEGUI::Window* mResponseWidget;
200
float mElapsedTimeSinceLastUpdate;
203
bool buttonResponse_Click(const CEGUI::EventArgs& args);
207
class ChatTextCreator : public WidgetPool<IngameChatWidget::ChatText>::WidgetCreator
210
ChatTextCreator(IngameChatWidget& ingameChatWidget) : mIngameChatWidget(ingameChatWidget) {}
211
virtual ~ChatTextCreator() {}
212
virtual IngameChatWidget::ChatText* createWidget(unsigned int currentPoolSize);
214
IngameChatWidget& mIngameChatWidget;
217
typedef std::map<std::string, Label*> LabelMap;
218
typedef std::vector<Label*> LabelStore;
219
typedef std::stack<Label*> LabelStack;
220
typedef std::vector<EntityObserver*> EntityObserverStore;
221
typedef std::vector<Eris::TypeInfo*> TypeInfoStore;
222
friend class IngameChatWidget::EntityObserver;
225
virtual ~IngameChatWidget();
227
virtual void frameStarted(const Ogre::FrameEvent & event);
229
void removeWidget(const std::string& windowName);
231
// Label* getLabel();
232
// void returnLabel(Label* label);
234
void removeEntityObserver(EntityObserver* observer);
236
WidgetPool<Label>& getLabelPool();
237
WidgetPool<ChatText>& getChatTextPool();
239
float getTimeShown() {return mTimeShown;}
241
CEGUI::Window* getLabelSheet();
245
void View_EntitySeen(Eris::Entity* entity);
246
void ServerService_GotView(Eris::View* view);
248
void Config_TimeShown(const std::string& section, const std::string& key, varconf::Variable& variable);
249
void Config_DistanceShown(const std::string& section, const std::string& key, varconf::Variable& variable);
253
EntityObserverStore mEntityObservers;
255
TypeInfoStore mLabelTypes;
257
//the length in seconds a window should be shown after it has been activated
260
//how far away, in meters, the window should be visible
261
float mDistanceShown;
263
LabelCreator mLabelCreator;
264
WidgetPool<Label> mLabelPool;
266
ChatTextCreator mChatTextCreator;
267
WidgetPool<ChatText> mChatTextPool;
269
CEGUI::Window* mLabelSheet;
271
std::string mAvatarEntityId;
273
Ogre::Camera& mMainCamera;
277
inline float IngameChatWidget::ChatText::getElapsedTimeSinceLastUpdate() { return mElapsedTimeSinceLastUpdate;}