1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/*
* The Mana World
* Copyright 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
* The Mana World is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* The Mana World is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
#include "status.h"
#include <guichan/widgets/label.hpp>
#include <sstream>
#include "button.h"
#include "progressbar.h"
#include "windowcontainer.h"
#include "../localplayer.h"
StatusWindow::StatusWindow(LocalPlayer *player):
Window(player->getName()),
mPlayer(player)
{
setWindowName("Status");
setResizable(true);
setDefaultSize((windowContainer->getWidth() - 365) / 2,
(windowContainer->getHeight() - 255) / 2, 365, 255);
loadWindowState();
// ----------------------
// Status Part
// ----------------------
mLvlLabel = new gcn::Label("Level:");
mGpLabel = new gcn::Label("Money:");
mHpLabel = new gcn::Label("HP:");
mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34);
mHpValueLabel = new gcn::Label("");
mXpLabel = new gcn::Label("Exp:");
mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211);
mXpValueLabel = new gcn::Label("");
mMpLabel = new gcn::Label("MP:");
mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230);
mMpValueLabel = new gcn::Label("");
mJobXpLabel = new gcn::Label("Job:");
mJobXpBar = new ProgressBar(1.0f, 60, 15, 220, 135, 203);
mJobValueLabel = new gcn::Label("");
int y = 3;
int x = 5;
mLvlLabel->setPosition(x, y);
x += mLvlLabel->getWidth() + 40;
mGpLabel->setPosition(x, y);
y += mLvlLabel->getHeight() + 5; // Next Row
x = 5;
mHpLabel->setPosition(x, y);
x += mHpLabel->getWidth() + 5;
mHpBar->setPosition(x, y);
x += mHpBar->getWidth() + 5;
mHpValueLabel->setPosition(x, y);
mXpLabel->setPosition(175, y);
mXpBar->setPosition(205, y);
mXpValueLabel->setPosition(290, y);
y += mHpLabel->getHeight() + 5; // Next Row
x = 5;
mMpLabel->setPosition(x, y);
x += mMpLabel->getWidth() + 5;
mMpBar->setPosition(x, y);
x += mMpBar->getWidth() + 5;
mMpValueLabel->setPosition(x, y);
mJobXpLabel->setPosition(175, y);
mJobXpBar->setPosition(225, y);
mJobValueLabel->setPosition(290, y);
add(mLvlLabel);
add(mGpLabel);
add(mHpLabel);
add(mHpValueLabel);
add(mMpLabel);
add(mMpValueLabel);
add(mXpLabel);
add(mXpValueLabel);
add(mJobXpLabel);
add(mJobValueLabel);
add(mHpBar);
add(mMpBar);
add(mXpBar);
add(mJobXpBar);
// ----------------------
// Stats Part
// ----------------------
// Static Labels
gcn::Label *mStatsTitleLabel = new gcn::Label("Stats");
gcn::Label *mStatsTotalLabel = new gcn::Label("Total");
gcn::Label *mStatsCostLabel = new gcn::Label("Cost");
// Derived Stats
mStatsAttackLabel = new gcn::Label("Attack:");
mStatsDefenseLabel= new gcn::Label("Defense:");
mStatsMagicAttackLabel = new gcn::Label("M.Attack:");
mStatsMagicDefenseLabel = new gcn::Label("M.Defense:");
mStatsAccuracyLabel = new gcn::Label("% Accuracy:");
mStatsEvadeLabel = new gcn::Label("% Evade:");
mStatsReflexLabel = new gcn::Label("% Reflex:");
mStatsAttackPoints = new gcn::Label("");
mStatsDefensePoints = new gcn::Label("");
mStatsMagicAttackPoints = new gcn::Label("");
mStatsMagicDefensePoints = new gcn::Label("");
mStatsAccuracyPoints = new gcn::Label("% Accuracy:");
mStatsEvadePoints = new gcn::Label("% Evade:");
mStatsReflexPoints = new gcn::Label("% Reflex:");
// New labels
for (int i = 0; i < 6; i++) {
mStatsLabel[i] = new gcn::Label();
mStatsDisplayLabel[i] = new gcn::Label();
mPointsLabel[i] = new gcn::Label("0");
}
mRemainingStatsPointsLabel = new gcn::Label();
// Set button events Id
mStatsButton[0] = new Button("+", "STR", this);
mStatsButton[1] = new Button("+", "AGI", this);
mStatsButton[2] = new Button("+", "VIT", this);
mStatsButton[3] = new Button("+", "INT", this);
mStatsButton[4] = new Button("+", "DEX", this);
mStatsButton[5] = new Button("+", "LUK", this);
// Set position
mStatsTitleLabel->setPosition(mMpLabel->getX(), mMpLabel->getY() + 23 );
mStatsTotalLabel->setPosition(110, mStatsTitleLabel->getY() + 15);
int totalLabelY = mStatsTotalLabel->getY();
mStatsCostLabel->setPosition(170, totalLabelY);
for (int i = 0; i < 6; i++)
{
mStatsLabel[i]->setPosition(5, mStatsTotalLabel->getY() + (i * 23) + 15);
mStatsDisplayLabel[i]->setPosition(115,
totalLabelY + (i * 23) + 15);
mStatsButton[i]->setPosition(145, totalLabelY + (i * 23) + 10);
mPointsLabel[i]->setPosition(175, totalLabelY + (i * 23) + 15);
}
mRemainingStatsPointsLabel->setPosition(5, mPointsLabel[5]->getY() + 25);
mStatsAttackLabel->setPosition(220, mStatsLabel[0]->getY());
mStatsDefenseLabel->setPosition(220, mStatsLabel[1]->getY());
mStatsMagicAttackLabel->setPosition(220, mStatsLabel[2]->getY());
mStatsMagicDefenseLabel->setPosition(220, mStatsLabel[3]->getY());
mStatsAccuracyLabel->setPosition(220, mStatsLabel[4]->getY());
mStatsEvadeLabel->setPosition(220, mStatsLabel[5]->getY());
mStatsReflexLabel->setPosition(220, mRemainingStatsPointsLabel->getY());
mStatsAttackPoints->setPosition(310, mStatsLabel[0]->getY());
mStatsDefensePoints->setPosition(310, mStatsLabel[1]->getY());
mStatsMagicAttackPoints->setPosition(310, mStatsLabel[2]->getY());
mStatsMagicDefensePoints->setPosition(310, mStatsLabel[3]->getY());
mStatsAccuracyPoints->setPosition(310, mStatsLabel[4]->getY());
mStatsEvadePoints->setPosition(310, mStatsLabel[5]->getY());
mStatsReflexPoints->setPosition(310, mRemainingStatsPointsLabel->getY());
// Assemble
add(mStatsTitleLabel);
add(mStatsTotalLabel);
add(mStatsCostLabel);
for(int i = 0; i < 6; i++)
{
add(mStatsLabel[i]);
add(mStatsDisplayLabel[i]);
add(mStatsButton[i]);
add(mPointsLabel[i]);
}
add(mStatsAttackLabel);
add(mStatsDefenseLabel);
add(mStatsMagicAttackLabel);
add(mStatsMagicDefenseLabel);
add(mStatsAccuracyLabel);
add(mStatsEvadeLabel);
add(mStatsReflexLabel);
add(mStatsAttackPoints);
add(mStatsDefensePoints);
add(mStatsMagicAttackPoints);
add(mStatsMagicDefensePoints);
add(mStatsAccuracyPoints);
add(mStatsEvadePoints);
add(mStatsReflexPoints);
add(mRemainingStatsPointsLabel);
}
void StatusWindow::update()
{
std::stringstream updateText;
// Status Part
// -----------
updateText.str("");
updateText << "Level: " << mPlayer->mLevel;
mLvlLabel->setCaption(updateText.str());
mLvlLabel->adjustSize();
updateText.str("");
updateText << "Money: " << mPlayer->mGp << " GP";
mGpLabel->setCaption(updateText.str());
mGpLabel->adjustSize();
updateText.str("");
updateText << "Job: " << mPlayer->mJobLevel;
mJobXpLabel->setCaption(updateText.str());
mJobXpLabel->adjustSize();
updateText.str("");
updateText << mPlayer->mHp << "/" << mPlayer->mMaxHp;
mHpValueLabel->setCaption(updateText.str());
mHpValueLabel->adjustSize();
updateText.str("");
updateText << mPlayer->mMp << "/" << mPlayer->mMaxMp;
mMpValueLabel->setCaption(updateText.str());
mMpValueLabel->adjustSize();
updateText.str("");
updateText << (int)mPlayer->mXp << "/" << (int)mPlayer->mXpForNextLevel;
mXpValueLabel->setCaption(updateText.str());
mXpValueLabel->adjustSize();
updateText.str("");
updateText << (int)mPlayer->mJobXp << "/" << (int)mPlayer->mJobXpForNextLevel;
mJobValueLabel->setCaption(updateText.str());
mJobValueLabel->adjustSize();
// HP Bar coloration
if (mPlayer->mHp < int(mPlayer->mMaxHp / 3))
{
mHpBar->setColor(223, 32, 32); // Red
}
else if (mPlayer->mHp < int((mPlayer->mMaxHp / 3) * 2))
{
mHpBar->setColor(230, 171, 34); // Orange
}
else
{
mHpBar->setColor(0, 171, 34); // Green
}
mHpBar->setProgress((float)mPlayer->mHp / (float)mPlayer->mMaxHp);
// mMpBar->setProgress((float)mPlayer->mp / (float)mPlayer->maxMp);
mXpBar->setProgress(
(float)mPlayer->mXp / (float)mPlayer->mXpForNextLevel);
mJobXpBar->setProgress(
(float)mPlayer->mJobXp / (float)mPlayer->mJobXpForNextLevel);
// Stats Part
// ----------
static const std::string attrNames[6] = {
"Strength",
"Agility",
"Vitality",
"Intelligence",
"Dexterity",
"Luck"
};
int statusPoints = mPlayer->mStatsPointsToAttribute;
updateText.str("");
updateText << "Remaining Status Points: " << statusPoints;
// Update labels
for (int i = 0; i < 6; i++) {
std::stringstream sstr;
mStatsLabel[i]->setCaption(attrNames[i]);
mStatsLabel[i]->adjustSize();
sstr.str("");
sstr << (int)mPlayer->mAttr[i];
mStatsDisplayLabel[i]->setCaption(sstr.str());
mStatsDisplayLabel[i]->adjustSize();
sstr.str("");
sstr << (int)mPlayer->mAttrUp[i];
mPointsLabel[i]->setCaption(sstr.str());
mPointsLabel[i]->adjustSize();
mStatsButton[i]->setEnabled(mPlayer->mAttrUp[i] <= statusPoints);
}
mRemainingStatsPointsLabel->setCaption(updateText.str());
mRemainingStatsPointsLabel->adjustSize();
// Derived Stats Points
// Attack TODO: Count equipped Weapons and items attack bonuses
updateText.str("");
updateText << int(mPlayer->ATK + mPlayer->ATK_BONUS);
mStatsAttackPoints->setCaption(updateText.str());
mStatsAttackPoints->adjustSize();
// Defense TODO: Count equipped Armors and items defense bonuses
updateText.str("");
updateText << int(mPlayer->DEF + mPlayer->DEF_BONUS);
mStatsDefensePoints->setCaption(updateText.str());
mStatsDefensePoints->adjustSize();
// Magic Attack TODO: Count equipped items M.Attack bonuses
updateText.str("");
updateText << int(mPlayer->MATK + mPlayer->MATK_BONUS);
mStatsMagicAttackPoints->setCaption(updateText.str());
mStatsMagicAttackPoints->adjustSize();
// Magic Defense TODO: Count equipped items M.Defense bonuses
updateText.str("");
updateText << int(mPlayer->MDEF + mPlayer->MDEF_BONUS);
mStatsMagicDefensePoints->setCaption(updateText.str());
mStatsMagicDefensePoints->adjustSize();
// Accuracy %
updateText.str("");
updateText << (int)mPlayer->HIT;
mStatsAccuracyPoints->setCaption(updateText.str());
mStatsAccuracyPoints->adjustSize();
// Evasion %
updateText.str("");
updateText << (int)mPlayer->FLEE;
mStatsEvadePoints->setCaption(updateText.str());
mStatsEvadePoints->adjustSize();
// Reflex %
updateText.str("");
updateText << ((int)mPlayer->DEX / 4); // + counter
mStatsReflexPoints->setCaption(updateText.str());
mStatsReflexPoints->adjustSize();
// Update Second column widgets position
mGpLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
mLvlLabel->getY());
mXpLabel->setPosition(mHpValueLabel->getX() + mHpValueLabel->getWidth() + 10,
mHpLabel->getY());
mXpBar->setPosition(mXpLabel->getX() + mXpLabel->getWidth() + 5,
mXpLabel->getY());
mXpValueLabel->setPosition(mXpBar->getX() + mXpBar->getWidth() + 5,
mXpLabel->getY());
mJobXpLabel->setPosition(mXpLabel->getX(), mMpLabel->getY());
mJobXpBar->setPosition(mXpBar->getX() + mXpBar->getWidth() -
mJobXpBar->getWidth(), mJobXpLabel->getY());
mJobValueLabel->setPosition(290, mJobXpLabel->getY());
}
void StatusWindow::draw(gcn::Graphics *g)
{
update();
Window::draw(g);
}
void StatusWindow::action(const std::string& eventId)
{
// Stats Part
if (eventId.length() == 3)
{
if (eventId == "STR")
{
player_node->raiseAttribute(LocalPlayer::STR);
}
if (eventId == "AGI")
{
player_node->raiseAttribute(LocalPlayer::AGI);
}
if (eventId == "VIT")
{
player_node->raiseAttribute(LocalPlayer::VIT);
}
if (eventId == "INT")
{
player_node->raiseAttribute(LocalPlayer::INT);
}
if (eventId == "DEX")
{
player_node->raiseAttribute(LocalPlayer::DEX);
}
if (eventId == "LUK")
{
player_node->raiseAttribute(LocalPlayer::LUK);
}
}
}
|