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

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/IngameChatWidget.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: IntegratedChatWidget
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
 
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 EMBEROGREINTEGRATEDCHATWIDGET_H
 
24
#define EMBEROGREINTEGRATEDCHATWIDGET_H
 
25
 
 
26
#include "Widget.h"
 
27
#include "WidgetPool.h"
 
28
#include <Eris/Entity.h>
 
29
#include "services/config/ConfigListener.h"
 
30
 
 
31
namespace EmberOgre {
 
32
 
 
33
class GUIManager;
 
34
class Widget;
 
35
class EmberPhysicalEntity;
 
36
class EmberEntity;
 
37
 
 
38
namespace Gui {
 
39
 
 
40
 
 
41
 
 
42
/**
 
43
 
 
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.
 
46
 
 
47
If the npc has a list of suggested responses these will be shown in a list of clickable buttons to the right.
 
48
 
 
49
@author Erik Hjortsberg
 
50
*/
 
51
class IngameChatWidget : public Widget, public Ember::ConfigListenerContainer {
 
52
 
 
53
 
 
54
        
 
55
 
 
56
        class EntityObserver;
 
57
        class Label;
 
58
        class MovableObjectListener : public Ogre::MovableObject::Listener
 
59
        {
 
60
                public:
 
61
                        MovableObjectListener(EntityObserver& entityObserver, EmberPhysicalEntity* entity);
 
62
                        virtual ~MovableObjectListener();
 
63
                        
 
64
                        virtual bool objectRendering (const Ogre::MovableObject * movableObject, const Ogre::Camera * camera);
 
65
                        void setObserving(bool isObserving);
 
66
                        
 
67
                private:
 
68
                        EntityObserver& mEntityObserver;
 
69
                        EmberPhysicalEntity* mEntity;
 
70
                        bool mIsObserving;
 
71
        };
 
72
        
 
73
        class EntityObserver : public virtual sigc::trackable
 
74
        {
 
75
                public:
 
76
                        EntityObserver(IngameChatWidget& chatWidget, EmberPhysicalEntity* entity);
 
77
                        virtual ~EntityObserver();
 
78
                        void updateLabel(const Ogre::Camera * camera);
 
79
                        
 
80
                protected:
 
81
                        IngameChatWidget& mChatWidget;
 
82
                        EmberPhysicalEntity* mEntity;
 
83
                        Label* mLabel;
 
84
                        MovableObjectListener mMovableObjectListener;
 
85
                        Eris::Entity::AttrChangedSlot mExternalSlot; //, mNameSlot;
 
86
                        
 
87
                        void showLabel();
 
88
                        void hideLabel();
 
89
                        
 
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);
 
94
                        
 
95
                
 
96
        };
 
97
 
 
98
        class ChatText;
 
99
        /**
 
100
        Holds the actual chat window and keeps track of fading, catching clicks etc.
 
101
        */
 
102
        class Label : public sigc::trackable
 
103
        {
 
104
                public:
 
105
                        /**
 
106
                        
 
107
                        */
 
108
                        Label(CEGUI::Window* window, CEGUI::WindowManager* windowManager, IngameChatWidget& containerWidget, const std::string& prefix);
 
109
                        
 
110
                        virtual ~Label();
 
111
 
 
112
                        /**
 
113
                        
 
114
                        */
 
115
                        void updateText(const std::string& line);
 
116
                
 
117
                        
 
118
                        /**
 
119
                        gets the entity the window belongs to
 
120
                        */
 
121
                        EmberEntity* getEntity();
 
122
                        
 
123
                        void setEntity(EmberEntity* entity);
 
124
                        
 
125
                        void setActive(bool active);
 
126
                        bool getActive() const;
 
127
                        void markForRender();
 
128
                        
 
129
                        CEGUI::Window* getWindow();
 
130
                        /**
 
131
                        call this each frame to update the window
 
132
                        */
 
133
                        void frameStarted( const Ogre::FrameEvent & event );
 
134
 
 
135
                        /**
 
136
                        positions the window on top of the entity
 
137
                        */
 
138
                        void placeWindowOnEntity();
 
139
                        
 
140
                        IngameChatWidget& getIngameChatWidget() { return mContainerWidget;}
 
141
                        
 
142
                        void updateEntityName();
 
143
                        
 
144
                protected:
 
145
                        
 
146
                        CEGUI::Window* mWindow;
 
147
                        EmberEntity* mEntity;
 
148
                        std::vector<CEGUI::Window*> mResponseTextWidgets;
 
149
                        CEGUI::WindowManager* mWindowManager;
 
150
                        IngameChatWidget& mContainerWidget;
 
151
                        
 
152
                        bool buttonResponse_Click(const CEGUI::EventArgs& args);
 
153
                        
 
154
                        bool mActive;
 
155
                        const std::string mPrefix;
 
156
                        bool mRenderNextFrame;
 
157
                        ChatText* mChatText;
 
158
//                      CEGUI::Window* mNameWidget;
 
159
                
 
160
        };
 
161
        
 
162
        class LabelCreator : public WidgetPool<IngameChatWidget::Label>::WidgetCreator
 
163
        {
 
164
                public:
 
165
                        LabelCreator(IngameChatWidget& ingameChatWidget);
 
166
                        virtual ~LabelCreator() {}
 
167
                        virtual IngameChatWidget::Label* createWidget(unsigned int currentPoolSize);
 
168
                protected:
 
169
                        IngameChatWidget& mIngameChatWidget;
 
170
        };
 
171
        
 
172
        class ChatText : public sigc::trackable
 
173
        {
 
174
                public:
 
175
                        ChatText(CEGUI::Window* window, const std::string& prefix);
 
176
                        virtual ~ChatText() {}
 
177
                        
 
178
                        void updateText( const std::string & line);
 
179
                        
 
180
                        /**
 
181
                        call this each frame to update the window
 
182
                        */
 
183
                        bool frameStarted( const Ogre::FrameEvent & event );
 
184
                        
 
185
                        float getElapsedTimeSinceLastUpdate();
 
186
                        
 
187
                        /**
 
188
                        increases the elapsed time with the supplied amount
 
189
                        */
 
190
                        void increaseElapsedTime(float timeSlice);
 
191
                        
 
192
                        void attachToLabel(Label* label);
 
193
                        
 
194
                protected:
 
195
                        std::vector<CEGUI::Window*> mResponseTextWidgets;
 
196
                        Label* mLabel;
 
197
                        CEGUI::Window* mWindow;
 
198
                        CEGUI::Window* mTextWidget;
 
199
                        CEGUI::Window* mResponseWidget;
 
200
                        float mElapsedTimeSinceLastUpdate;
 
201
                        std::string mPrefix;
 
202
                        
 
203
                        bool buttonResponse_Click(const CEGUI::EventArgs& args);
 
204
        };
 
205
        
 
206
        
 
207
        class ChatTextCreator : public WidgetPool<IngameChatWidget::ChatText>::WidgetCreator
 
208
        {
 
209
                public:
 
210
                        ChatTextCreator(IngameChatWidget& ingameChatWidget) : mIngameChatWidget(ingameChatWidget) {}
 
211
                        virtual ~ChatTextCreator() {}
 
212
                        virtual IngameChatWidget::ChatText* createWidget(unsigned int currentPoolSize);
 
213
                protected:
 
214
                        IngameChatWidget& mIngameChatWidget;
 
215
        };
 
216
        
 
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;
 
223
public:
 
224
        IngameChatWidget();
 
225
    virtual ~IngameChatWidget();
 
226
        void buildWidget();
 
227
        virtual void frameStarted(const Ogre::FrameEvent & event);
 
228
        
 
229
        void removeWidget(const std::string& windowName);
 
230
        
 
231
//      Label* getLabel();
 
232
//      void returnLabel(Label* label);
 
233
        
 
234
        void removeEntityObserver(EntityObserver* observer);
 
235
        
 
236
        WidgetPool<Label>& getLabelPool();
 
237
        WidgetPool<ChatText>& getChatTextPool();
 
238
        
 
239
        float getTimeShown() {return mTimeShown;} 
 
240
        
 
241
        CEGUI::Window* getLabelSheet();
 
242
        
 
243
protected:
 
244
        
 
245
        void View_EntitySeen(Eris::Entity* entity);
 
246
        void ServerService_GotView(Eris::View* view);
 
247
 
 
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);
 
250
 
 
251
                
 
252
                
 
253
        EntityObserverStore mEntityObservers;
 
254
        
 
255
        TypeInfoStore mLabelTypes;
 
256
        
 
257
        //the length in seconds a window should be shown after it has been activated
 
258
        float mTimeShown;
 
259
        
 
260
        //how far away, in meters, the window should be visible
 
261
        float mDistanceShown;
 
262
        
 
263
        LabelCreator mLabelCreator;     
 
264
        WidgetPool<Label> mLabelPool;
 
265
        
 
266
        ChatTextCreator mChatTextCreator;       
 
267
        WidgetPool<ChatText> mChatTextPool;
 
268
        
 
269
        CEGUI::Window* mLabelSheet;
 
270
        
 
271
        std::string mAvatarEntityId;
 
272
        
 
273
        Ogre::Camera& mMainCamera;
 
274
 
 
275
};
 
276
 
 
277
inline float IngameChatWidget::ChatText::getElapsedTimeSinceLastUpdate() { return mElapsedTimeSinceLastUpdate;}
 
278
 
 
279
 
 
280
}
 
281
}
 
282
 
 
283
#endif