xoreos  0.0.5
ingame.cpp
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 #include <cassert>
26 
27 #include "src/common/error.h"
28 
29 #include "src/engines/nwn/module.h"
31 
39 
40 namespace Engines {
41 
42 namespace NWN {
43 
45  _module(&module), _lastCompassChange(0) {
46 
47  _main.reset(new IngameMainMenu(_module->getGameVersion(), console));
48 
49  _quickbar.reset (new Quickbar);
50  _quickchat.reset(new Quickchat(_quickbar->getHeight() - 3.0f));
51  _compass.reset (new Compass(_quickbar->getHeight() + _quickchat->getHeight() - 6.0f));
52 
53  _party.push_back(new PartyLeader(module));
54 
55  _lastPartyMemberChange.resize(1);
57 }
58 
60  hide();
61 }
62 
64  _main->show();
65  uint32 code = _main->run();
66  _main->hide();
67 
68  return code;
69 }
70 
72  _main->abort();
73 }
74 
76  _quickbar->show();
77  _quickchat->show();
78  _compass->show();
79 
80  for (Common::PtrVector<CharacterInfo>::iterator p = _party.begin(); p != _party.end(); ++p)
81  (*p)->show();
82 
83  if (_dialog)
84  _dialog->show();
85 }
86 
88  if (_dialog)
89  _dialog->hide();
90 
91  for (Common::PtrVector<CharacterInfo>::iterator p = _party.begin(); p != _party.end(); ++p)
92  (*p)->hide();
93 
94  _compass->hide();
95  _quickchat->hide();
96  _quickbar->hide();
97 }
98 
99 void IngameGUI::addEvent(const Events::Event &event) {
100  // The dialog takes preference
101  if (_dialog) {
102  _dialog->addEvent(event);
103  return;
104  }
105 
106  for (Common::PtrVector<CharacterInfo>::iterator p = _party.begin(); p != _party.end(); ++p)
107  (*p)->addEvent(event);
108 
109  _compass->addEvent(event);
110  _quickchat->addEvent(event);
111  _quickbar->addEvent(event);
112 }
113 
115  // The dialog takes preference
116  if (_dialog) {
117  if (_dialog->processEventQueue() != 0)
119 
120  return;
121  }
122 
123  for (Common::PtrVector<CharacterInfo>::iterator p = _party.begin(); p != _party.end(); ++p)
124  (*p)->processEventQueue();
125 
126  _compass->processEventQueue();
127  _quickchat->processEventQueue();
128  _quickbar->processEventQueue();
129 }
130 
131 void IngameGUI::setPortrait(size_t partyMember, const Common::UString &portrait) {
132  _party[partyMember]->setPortrait(portrait);
133 }
134 
135 void IngameGUI::setHealth(size_t partyMember, uint32 current, uint32 max) {
136  _party[partyMember]->setHealth(current, max);
137 }
138 
139 void IngameGUI::setName(size_t partyMember, const Common::UString &name) {
140  _party[partyMember]->setName(name);
141 }
142 
144  for (Common::PtrVector<CharacterInfo>::iterator p = _party.begin(); p != _party.end(); ++p)
145  (*p)->setArea(area);
146 }
147 
148 void IngameGUI::setHealthy(size_t partyMember) {
149  _party[partyMember]->setHealthColor(1.0f, 0.0f, 0.0f, 1.0f);
150 }
151 
152 void IngameGUI::setSick(size_t partyMember) {
153  _party[partyMember]->setHealthColor(189.0f / 255.0f, 146.0f / 255.0f, 74.0f / 255.0f, 1.0f);
154 }
155 
156 void IngameGUI::setPoisoned(size_t partyMember) {
157  _party[partyMember]->setHealthColor(132.0f / 255.0f, 182.0f / 255.0f, 74.0f / 255.0f, 1.0f);
158 }
159 
160 void IngameGUI::updatePartyMember(size_t partyMember, const Creature &creature, bool force) {
161  assert(partyMember < _party.size());
162 
163  uint32 lastPartyMemberChange = creature.lastChangedGUIDisplay();
164  if (!force && (lastPartyMemberChange <= _lastPartyMemberChange[partyMember]))
165  return;
166 
167  setPortrait(partyMember, creature.getPortrait());
168  setName (partyMember, creature.getName());
169  setHealth (partyMember, creature.getCurrentHP(), creature.getMaxHP());
170 
171  _lastPartyMemberChange[partyMember] = lastPartyMemberChange;
172 }
173 
175  return _dialog.get() != 0;
176 }
177 
179  Creature &pc, Object &obj, bool playHello) {
181 
182  if (conv.empty())
183  return true;
184 
185  try {
186  _dialog.reset(new Dialog(conv, pc, obj, *_module, playHello));
187 
188  _dialog->show();
189  } catch (...) {
190  _dialog.reset();
191 
192  Common::exceptionDispatcherWarning("Failed starting conversation \"%s\"", conv.c_str());
193  return false;
194  }
195 
196  return true;
197 }
198 
200  if (!_dialog)
201  return;
202 
203  _dialog->abort();
204  _dialog.reset();
205 }
206 
207 } // End of namespace NWN
208 
209 } // End of namespace Engines
The NWN ingame main menu.
void setPoisoned(size_t partyMember)
Set party member to "poisoned" (green health bar).
Definition: ingame.cpp:156
void setPortrait(size_t partyMember, const Common::UString &portrait)
Set the party member&#39;s portrait.
Definition: ingame.cpp:131
A class holding an UTF-8 string.
Definition: ustring.h:48
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:90
void addEvent(const Events::Event &event)
Definition: ingame.cpp:99
The NWN ingame quickbar.
Definition: quickbar.h:66
The ingame quickbar.
const Version & getGameVersion() const
Definition: module.cpp:119
The NWN ingame GUI elements.
The NWN ingame quickchat.
void setArea(const Common::UString &area)
Set the current area.
Definition: ingame.cpp:143
Common::ScopedPtr< Compass > _compass
The compass.
Definition: ingame.h:94
SDL_Event Event
Definition: types.h:42
std::vector< uint32 > _lastPartyMemberChange
The time that party member was changed last.
Definition: ingame.h:101
A vector of pointer to objects, with automatic deletion.
Definition: ptrvector.h:44
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
The context needed to run a Neverwinter Nights module.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Common::ScopedPtr< Quickchat > _quickchat
The quick chat.
Definition: ingame.h:93
Common::ScopedPtr< Quickbar > _quickbar
The quick bar.
Definition: ingame.h:92
IngameGUI(Module &module, ::Engines::Console *console=0)
Definition: ingame.cpp:44
The NWN ingame party leader panel.
The NWN ingame compass.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
The NWN ingame compass.
Definition: compass.h:48
int32 getMaxHP() const
Return the max HP this creature can have.
Definition: creature.cpp:246
Common::ScopedPtr< IngameMainMenu > _main
The ingame main menu.
Definition: ingame.h:90
uint32 showMain()
Show the ingame main menu.
Definition: ingame.cpp:63
The NWN ingame party leader bar.
Definition: partyleader.h:42
The NWN ingame dialog panel.
void stopConversation()
Stop a conversation.
Definition: ingame.cpp:199
void updatePartyMember(size_t partyMember, const Creature &creature, bool force=false)
Update the party member.
Definition: ingame.cpp:160
void abortMain()
Abort the ingame main menu.
Definition: ingame.cpp:71
void setSick(size_t partyMember)
Set party member to "sick" (brown health bar).
Definition: ingame.cpp:152
uint32_t uint32
Definition: types.h:204
int32 getCurrentHP() const
Return the current HP this creature has.
Definition: creature.cpp:242
void setHealth(size_t partyMember, uint32 current, uint32 max)
Set the party member&#39;s health.
Definition: ingame.cpp:135
A creature in a Neverwinter Nights area.
const Common::UString & getPortrait() const
Get the creature&#39;s portrait.
Definition: creature.cpp:222
void setName(size_t partyMember, const Common::UString &name)
Set the party member&#39;s name.
Definition: ingame.cpp:139
The NWN ingame quickchat.
Definition: quickchat.h:64
uint32 lastChangedGUIDisplay() const
Last time info was changed that&#39;s displayed in the GUI.
Definition: creature.cpp:178
Common::PtrVector< CharacterInfo > _party
The party member character panels.
Definition: ingame.h:103
bool hasRunningConversation() const
Do we have a currently running conversation?
Definition: ingame.cpp:174
void setHealthy(size_t partyMember)
Set party member to "healthy" (red health bar).
Definition: ingame.cpp:148
void hide()
Hide the ingame GUI elements.
Definition: ingame.cpp:87
The NWN ingame main menu.
Definition: main.h:39
bool startConversation(const Common::UString &conv, Creature &pc, Object &obj, bool playHello=true)
Start a conversation.
Definition: ingame.cpp:178
Common::ScopedPtr< Dialog > _dialog
The current dialog.
Definition: ingame.h:96
void show()
Show the ingame GUI elements.
Definition: ingame.cpp:75