xoreos  0.0.5
dialog.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef ENGINES_NWN_GUI_INGAME_DIALOG_H
26 #define ENGINES_NWN_GUI_INGAME_DIALOG_H
27 
28 #include <list>
29 
30 #include "src/common/scopedptr.h"
31 #include "src/common/ptrlist.h"
32 
33 #include "src/events/types.h"
34 #include "src/events/notifyable.h"
35 
36 #include "src/graphics/types.h"
38 
40 
42 
43 namespace Common {
44  class UString;
45 }
46 
47 namespace Aurora {
48  class DLGFile;
49 }
50 
51 namespace Graphics {
52  namespace Aurora {
53  class Text;
54  }
55 }
56 
57 namespace Engines {
58 
59 namespace NWN {
60 
61 class Portrait;
62 
63 class Object;
64 class Creature;
65 
66 class Module;
67 
68 // TODO: Scrollbars. Need to restructure/rewrite the scrollbar element/widget for that
69 
71 public:
72  DialogBox(float width, float height);
73  ~DialogBox();
74 
75  void show();
76  void hide();
77 
78  // Size and position
79 
80  float getWidth () const;
81  float getHeight() const;
82 
84  void getPosition(float &x, float &y, float &z) const;
85 
87  void setPosition(float x, float y, float z);
88 
89  // Changing contents
90 
92  void clear();
93 
95  void setPortrait(const Common::UString &portrait);
97  void setName(const Common::UString &name);
98 
100  void clearEntry();
102  void setEntry(const Common::UString &entry);
103 
105  void clearReplies();
107  void addReply(const Common::UString &reply, uint32 id);
109  void finishReplies();
110 
111  // Events
112 
114  void mouseMove(int x, int y);
116  void mouseClick(int x, int y);
118  void pickReply(uint32 n);
119 
121  uint32 getPickedID() const;
122 
123 
124  // Renderable
125  void calculateDistance();
127 
128 private:
130  struct Reply {
133 
134  Reply(const Common::UString &r = "", uint32 i = 0xFFFFFFFF);
135  };
136 
138  struct ReplyLine {
141 
142  std::list<Reply>::const_iterator reply;
143 
144  ReplyLine();
145  ReplyLine(std::list<Reply>::const_iterator &i);
146  };
147 
148  float _width;
149  float _height;
150 
151  float _x;
152  float _y;
153  float _z;
154 
159 
162 
164  std::list<Reply> _replies;
165 
167  std::list<ReplyLine> _replyLines;
168 
171 
172  std::list<ReplyLine>::iterator _highlightedReply;
173  std::list<Reply>::const_iterator _pickedReply;
174 
175 
176  void showEntry();
177  void hideEntry();
178 
179  void showReplies();
180  void hideReplies();
181 
183  bool isIn(float x, float y) const;
184 
186  void setHighlight(const std::list<ReplyLine>::iterator &h);
187 };
188 
189 class Dialog : public Events::Notifyable {
190 public:
191  Dialog(const Common::UString &conv, Creature &pc, Object &obj,
192  Module &module, bool playHello = true);
193  ~Dialog();
194 
196  bool hasEnded() const;
197 
198  void show();
199  void hide();
200 
201  void abort();
202 
204  void addEvent(const Events::Event &event);
206  int processEventQueue();
207 
208 protected:
209  void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
210 
211 private:
213 
216 
218 
220 
222 
223  std::list<Events::Event> _eventQueue;
224 
225 
226  void updateBox();
227 
228  Object *getSpeaker();
229 
230  void playSound(bool greeting);
231 
232  void playAnimation();
233  void stopAnimation();
234 
236  void mouseMove();
238  void mouseClick(const Events::Event &event);
240  void keyPressed(const Events::Event &event);
241 
242  void checkPicked();
243 };
244 
245 } // End of namespace NWN
246 
247 } // End of namespace Engines
248 
249 #endif // ENGINES_NWN_GUI_INGAME_DIALOG_H
Common::ScopedPtr< Portrait > _portrait
The current speaker&#39;s portrait.
Definition: dialog.h:156
Basic event types.
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: dialog.cpp:678
Definition: 2dafile.h:39
float getWidth() const
Return the box&#39;s width.
Definition: dialog.cpp:143
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPortrait(const Common::UString &portrait)
Set the current speaker&#39;s portrait.
Definition: dialog.cpp:226
float _height
The box&#39;s height.
Definition: dialog.h:149
std::list< Reply >::const_iterator _pickedReply
The picked (clicked) reply.
Definition: dialog.h:173
uint32 _replyCount
The number of replies.
Definition: dialog.h:169
void setName(const Common::UString &name)
Set the current speaker&#39;s name.
Definition: dialog.cpp:230
Reply(const Common::UString &r="", uint32 i=0xFFFFFFFF)
Definition: dialog.cpp:70
void addEvent(const Events::Event &event)
Add a single event for consideration into the event queue.
Definition: dialog.cpp:588
A handle to a font.
Definition: fonthandle.h:52
int processEventQueue()
Process the current event queue.
Definition: dialog.cpp:592
void hide()
Hide the dialog.
Definition: dialog.cpp:573
std::list< Reply >::const_iterator reply
Definition: dialog.h:142
Common::ScopedPtr< Aurora::DLGFile > _dlg
The conversation file.
Definition: dialog.h:221
void setPosition(float x, float y, float z)
Set the box&#39;s position.
Definition: dialog.cpp:157
void pickReply(uint32 n)
Pick the reply number n.
Definition: dialog.cpp:420
void clearReplies()
Clear the PC replies.
Definition: dialog.cpp:312
Graphics::Aurora::Text * line
Definition: dialog.h:140
void mouseMove()
The mouse was moved.
Definition: dialog.cpp:614
std::list< Reply > _replies
The PC replies.
Definition: dialog.h:164
Basic graphics types.
uint32 getPickedID() const
Return the reply ID that was clicked.
Definition: dialog.cpp:430
void abort()
Abort the current conversation.
Definition: dialog.cpp:577
void playSound(bool greeting)
Play a conversation sound.
Definition: dialog.cpp:743
float _replyCountWidth
The max width of a reply number text.
Definition: dialog.h:170
A simple scoped smart pointer template.
SDL_Event Event
Definition: types.h:42
A list storing pointer to objects, with automatic deletion.
Common::UString _entry
The NPC entry.
Definition: dialog.h:163
A GUI element.
float _x
The box&#39;s X position.
Definition: dialog.h:151
void render(Graphics::RenderPass pass)
Render the object.
Definition: dialog.cpp:487
A text object.
Definition: text.h:42
Common::ScopedPtr< Graphics::Aurora::Text > _name
The current speaker&#39;s name.
Definition: dialog.h:158
RenderPass
Definition: types.h:97
void stopAnimation()
Stop a conversation animation.
Definition: dialog.cpp:783
void showEntry()
Show the entry.
Definition: dialog.cpp:236
Common::PtrList< Graphics::Aurora::Text > _entryLines
The NPC text lines.
Definition: dialog.h:166
Object * _object
The conversation&#39;s NPC.
Definition: dialog.h:215
void show()
Show the box.
Definition: dialog.cpp:106
void updateBox()
Update the box&#39;s contents.
Definition: dialog.cpp:687
void getPosition(float &x, float &y, float &z) const
Return the box&#39;s position.
Definition: dialog.cpp:151
Graphics::Aurora::Text * count
Definition: dialog.h:139
float _y
The box&#39;s Y position.
Definition: dialog.h:152
Creature * _pc
The conversation&#39;s PC.
Definition: dialog.h:214
void setEntry(const Common::UString &entry)
Set the NPC entry.
Definition: dialog.cpp:262
Dialog(const Common::UString &conv, Creature &pc, Object &obj, Module &module, bool playHello=true)
Definition: dialog.cpp:543
A handle to an Aurora font.
void keyPressed(const Events::Event &event)
A keyboard key was pressed.
Definition: dialog.cpp:629
void calculateDistance()
Calculate the object&#39;s distance.
Definition: dialog.cpp:483
void hideReplies()
Hide the replies.
Definition: dialog.cpp:302
std::list< ReplyLine >::iterator _highlightedReply
The currently highlighted reply.
Definition: dialog.h:172
A class that can be notified by the NotificationManager.
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
void mouseClick(int x, int y)
Notify the box that the mouse was clicked.
Definition: dialog.cpp:411
void mouseMove(int x, int y)
Notify the box that the mouse was moved.
Definition: dialog.cpp:393
Module * _module
The module this dialog is in.
Definition: dialog.h:217
DialogBox(float width, float height)
Definition: dialog.cpp:83
void showReplies()
Show the replies.
Definition: dialog.cpp:292
void show()
Show the dialog.
Definition: dialog.cpp:569
An element of the GUI.
Definition: guielement.h:33
float _z
The box&#39;s Z position.
Definition: dialog.h:153
void hideEntry()
Hide the entry.
Definition: dialog.cpp:242
Graphics::Aurora::FontHandle _font
The dialog font.
Definition: dialog.h:161
uint32_t uint32
Definition: types.h:204
Common::ScopedPtr< DialogBox > _dlgBox
The actual dialog box.
Definition: dialog.h:219
void addReply(const Common::UString &reply, uint32 id)
Add a PC reply.
Definition: dialog.cpp:330
void mouseClick(const Events::Event &event)
The mouse was clicked.
Definition: dialog.cpp:621
void clear()
Clear the complete contents.
Definition: dialog.cpp:218
bool hasEnded() const
Has the conversation ended?
Definition: dialog.cpp:565
void setHighlight(const std::list< ReplyLine >::iterator &h)
Set the highlighted reply.
Definition: dialog.cpp:437
void clearEntry()
Clear the NPC entry.
Definition: dialog.cpp:248
bool isIn(float x, float y) const
Are the coordinates inside the box?
Definition: dialog.cpp:134
A line of a PC reply.
Definition: dialog.h:138
#define pass
Definition: fft.cpp:257
void finishReplies()
Finished adding PC replies.
Definition: dialog.cpp:334
void hide()
Hide the box.
Definition: dialog.cpp:120
void playAnimation()
Play a conversation animation.
Definition: dialog.cpp:769
Common::UString _conv
The conversation file.
Definition: dialog.h:212
float _width
The box&#39;s width.
Definition: dialog.h:148
Common::UString reply
Definition: dialog.h:131
A NWN GUI.
std::list< ReplyLine > _replyLines
The PC text lines.
Definition: dialog.h:167
float getHeight() const
Return the box&#39;s height.
Definition: dialog.cpp:147
std::list< Events::Event > _eventQueue
The event queue.
Definition: dialog.h:223
Object * getSpeaker()
Get the current speaker.
Definition: dialog.cpp:732