xoreos  0.0.5
partyleader.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 "src/common/util.h"
26 
27 #include "src/aurora/talkman.h"
28 
29 #include "src/graphics/graphics.h"
30 
35 
37 
38 #include "src/engines/nwn/module.h"
39 
40 namespace Engines {
41 
42 namespace NWN {
43 
44 static const char * const kButtonTags[] = {
45  "ButtonMap" , "ButtonJournal" , "ButtonRest" , "ButtonOptions",
46  "ButtonInventory", "ButtonCharacter", "ButtonSpells", "ButtonPlayers"
47 };
48 
49 static const char * const kButtonModels[] = {
50  "pb_but_map", "pb_but_jour", "pb_but_rest" , "pb_but_opts",
51  "pb_but_inv", "pb_but_char", "pb_but_spell", "pb_but_pvp"
52 };
53 
54 static const uint32 kButtonTooltips[] = {
55  7036, 7037, 8105, 7040, 7035, 7039, 7038, 8106
56 };
57 
58 PartyLeader::PartyLeader(Module &module) : _module(&module),
59  _currentHP(1), _maxHP(1) {
60 
61  // The panel
62 
63  WidgetPanel *playerPanel = new WidgetPanel(*this, "LeaderPanel", "pnl_party_bar");
64 
65  playerPanel->setPosition(- playerPanel->getWidth(), 0.0f, 0.0f);
66 
67  addWidget(playerPanel);
68 
69 
70  // Buttons
71 
72  float buttonsX = - playerPanel->getWidth () + 4.0f;
73  float buttonsY = - playerPanel->getHeight() + 57.0f;
74 
75  for (int i = 0; i < 8; i++) {
76  WidgetButton *button = new WidgetButton(*this, kButtonTags[i], kButtonModels[i]);
77 
78  button->setTooltip(TalkMan.getString(kButtonTooltips[i]));
79  button->setTooltipPosition(0.0f, -10.0f, -1.0f);
80 
81  const float x = buttonsX + ((i / 4) * 36.0f);
82  const float y = buttonsY - ((i % 4) * 18.0f);
83  const float z = -100.0f;
84 
85  button->setPosition(x, y, z);
86 
87  addWidget(button);
88  }
89 
90  getWidget("ButtonPlayers", true)->setDisabled(true);
91 
92 
93  // Portrait
94 
95  _portrait =
96  new PortraitWidget(*this, "LeaderPortrait", "gui_po_nwnlogo_", Portrait::kSizeMedium);
97 
98  _portrait->setPosition(-67.0f, -103.0f, -100.0f);
99  _portrait->setTooltipPosition(-50.0f, 50.0f, -1.0f);
100 
102 
103 
104  // Health bar
105 
106  _health = new QuadWidget(*this, "LeaderHealthbar", "", 0.0f, 0.0f, 6.0f, 100.0f);
107 
108  _health->setColor(1.0f, 0.0f, 0.0f, 1.0f);
109  _health->setPosition(-76.0f, -103.0f, -100.0f);
110 
112 
113 
115  notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
116 }
117 
119 }
120 
122  _currentPortrait = portrait;
123  _portrait->setPortrait(portrait);
124 }
125 
127  _name = name;
128 
130 }
131 
133  _area = area;
134 
136 }
137 
138 void PartyLeader::setHealthColor(float r, float g, float b, float a) {
139  _health->setColor(r, g, b, a);
140 }
141 
142 void PartyLeader::setHealth(int32 current, int32 max) {
143  _currentHP = current;
144  _maxHP = max;
145 
146  float barLength = 0.0f;
147  if (_maxHP > 0)
148  barLength = CLIP(((float) current) / ((float) max), 0.0f, 1.0f) * 100.0f;
149 
150  _health->setHeight(barLength);
151 
153 }
154 
156  if (widget.getTag() == "ButtonOptions") {
157  removeFocus();
158  _module->showMenu();
159  return;
160  }
161 
162 }
163 
165  Common::UString tooltip =
166  Common::UString::format("%s %d/%d\n%s",
168 
169  _portrait->setTooltip(tooltip);
170 }
171 
172 void PartyLeader::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight),
173  int newWidth, int newHeight) {
174 
175  setPosition(newWidth / 2.0f, newHeight / 2.0f, -10.0f);
176 }
177 
178 } // End of namespace NWN
179 
180 } // End of namespace Engines
A NWN panel widget.
Definition: panel.h:41
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: button.cpp:72
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
void showMenu()
Show the ingame main menu.
Definition: module.cpp:671
void setPortrait(const Common::UString &portrait)
Set the portrait image.
The global graphics manager.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A NWN button widget.
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPosition(float x, float y, float z)
Set the GUI&#39;s position.
Definition: gui.cpp:394
float getHeight() const
Get the widget&#39;s height.
Definition: modelwidget.cpp:82
virtual void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: widget.cpp:154
static const char *const kButtonModels[]
Definition: partyleader.cpp:49
void removeFocus()
Forcefully remove the focus from the current widget.
Definition: gui.cpp:422
void setName(const Common::UString &name)
Set the character name.
A NWN button widget.
Definition: button.h:39
The context needed to run a Neverwinter Nights module.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
void setHealth(int32 current, int32 max)
Set the character health.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
A NWN quad widget.
Common::UString _name
Definition: partyleader.h:71
void setArea(const Common::UString &area)
Set the area the character is in.
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
void setTooltip(const Common::UString &text)
Definition: nwnwidget.cpp:67
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
Common::UString _area
Definition: partyleader.h:72
The NWN ingame party leader panel.
static const char *const kButtonTags[]
Definition: partyleader.cpp:44
void setHeight(float h)
Definition: quadwidget.cpp:80
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
void setPortrait(const Common::UString &name)
Definition: portrait.cpp:340
void setHealthColor(float r, float g, float b, float a)
Set the health bar color.
void setColor(float r, float g, float b, float a)
Definition: quadwidget.cpp:68
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
Common::UString _currentPortrait
Definition: partyleader.h:69
A widget in a GUI.
Definition: widget.h:40
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: portrait.cpp:333
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
PartyLeader(Module &module)
Definition: partyleader.cpp:58
static const uint32 kButtonTooltips[]
Definition: partyleader.cpp:54
float getWidth() const
Get the widget&#39;s width.
Definition: modelwidget.cpp:78
A portrait model and widget.
A NWN portrait widget.
Definition: portrait.h:121
void setTooltipPosition(float x, float y, float z)
Definition: nwnwidget.cpp:74
A NWN quad widget.
Definition: quadwidget.h:49
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
T CLIP(T v, T amin, T amax)
Definition: util.h:72
A NWN panel widget.
PortraitWidget * _portrait
Definition: partyleader.h:66
int32_t int32
Definition: types.h:203
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: quadwidget.cpp:61