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
|
/*
* The Mana World
* Copyright (C) 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gui/status.h"
#include "localplayer.h"
#include "units.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/progressbar.h"
#include "gui/widgets/windowcontainer.h"
#include "net/net.h"
#include "net/ea/playerhandler.h"
#include "utils/gettext.h"
#include "utils/mathutils.h"
#include "utils/strprintf.h"
#include "utils/stringutils.h"
StatusWindow::StatusWindow(LocalPlayer *player):
Window(player->getName()),
mPlayer(player),
mCurrency(0)
{
setWindowName("Status");
setCloseButton(true);
setDefaultSize(400, 345, ImageRect::CENTER);
// ----------------------
// Status Part
// ----------------------
mLvlLabel = new Label(strprintf(_("Level: %d"), 0));
mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0));
mGpLabel = new Label(strprintf(_("Money: %s"),
Units::formatCurrency(mCurrency).c_str()));
mHpLabel = new Label(_("HP:"));
mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34);
mXpLabel = new Label(_("Exp:"));
mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211);
mMpLabel = new Label(_("MP:"));
mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230);
mJobLabel = new Label(_("Job:"));
mJobBar = new ProgressBar(1.0f, 80, 15, 220, 135, 203);
// ----------------------
// Stats Part
// ----------------------
// Static Labels
gcn::Label *mStatsTitleLabel = new Label(_("Stats"));
gcn::Label *mStatsTotalLabel = new Label(_("Total"));
gcn::Label *mStatsCostLabel = new Label(_("Cost"));
mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER);
// Derived Stats
mStatsAttackLabel = new Label(_("Attack:"));
mStatsDefenseLabel= new Label(_("Defense:"));
mStatsMagicAttackLabel = new Label(_("M.Attack:"));
mStatsMagicDefenseLabel = new Label(_("M.Defense:"));
// Gettext flag for next line: xgettext:no-c-format
mStatsAccuracyLabel = new Label(_("% Accuracy:"));
// Gettext flag for next line: xgettext:no-c-format
mStatsEvadeLabel = new Label(_("% Evade:"));
// Gettext flag for next line: xgettext:no-c-format
mStatsReflexLabel = new Label(_("% Reflex:"));
mStatsAttackPoints = new Label;
mStatsDefensePoints = new Label;
mStatsMagicAttackPoints = new Label;
mStatsMagicDefensePoints = new Label;
mStatsAccuracyPoints = new Label;
mStatsEvadePoints = new Label;
mStatsReflexPoints = new Label;
// New labels
for (int i = 0; i < 6; i++)
{
mStatsLabel[i] = new Label("0");
mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER);
mStatsDisplayLabel[i] = new Label;
mPointsLabel[i] = new Label("0");
mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER);
}
mRemainingStatsPointsLabel = new 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);
// Assemble
ContainerPlacer place;
place = getPlacer(0, 0);
place(0, 0, mLvlLabel, 3);
place(5, 0, mJobLvlLabel, 3);
place(8, 0, mGpLabel, 3);
place(1, 1, mHpLabel).setPadding(3);
place(2, 1, mHpBar, 3);
place(6, 1, mXpLabel).setPadding(3);
place(7, 1, mXpBar, 3);
place(1, 2, mMpLabel).setPadding(3);
place(2, 2, mMpBar, 3);
place(6, 2, mJobLabel).setPadding(3);
place(7, 2, mJobBar, 3);
place.getCell().matchColWidth(0, 1);
place = getPlacer(0, 3);
place(0, 0, mStatsTitleLabel, 5);
place(5, 1, mStatsTotalLabel, 5);
place(12, 1, mStatsCostLabel, 5);
for (int i = 0; i < 6; i++)
{
place(0, 2 + i, mStatsLabel[i], 7).setPadding(5);
place(7, 2 + i, mStatsDisplayLabel[i]).setPadding(5);
place(10, 2 + i, mStatsButton[i]);
place(12, 2 + i, mPointsLabel[i]).setPadding(5);
}
place(14, 2, mStatsAttackLabel, 7).setPadding(5);
place(14, 3, mStatsDefenseLabel, 7).setPadding(5);
place(14, 4, mStatsMagicAttackLabel, 7).setPadding(5);
place(14, 5, mStatsMagicDefenseLabel, 7).setPadding(5);
place(14, 6, mStatsAccuracyLabel, 7).setPadding(5);
place(14, 7, mStatsEvadeLabel, 7).setPadding(5);
place(14, 8, mStatsReflexLabel, 7).setPadding(5);
place(21, 2, mStatsAttackPoints, 3).setPadding(5);
place(21, 3, mStatsDefensePoints, 3).setPadding(5);
place(21, 4, mStatsMagicAttackPoints, 3).setPadding(5);
place(21, 5, mStatsMagicDefensePoints, 3).setPadding(5);
place(21, 6, mStatsAccuracyPoints, 3).setPadding(5);
place(21, 7, mStatsEvadePoints, 3).setPadding(5);
place(21, 8, mStatsReflexPoints, 3).setPadding(5);
place(0, 8, mRemainingStatsPointsLabel, 3).setPadding(5);
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
loadWindowState();
}
void StatusWindow::update()
{
// Status Part
// -----------
mLvlLabel->setCaption(strprintf(_("Level: %d"), mPlayer->getLevel()));
mLvlLabel->adjustSize();
mJobLvlLabel->setCaption(strprintf(_("Job: %d"), mPlayer->mJobLevel));
mJobLvlLabel->adjustSize();
if (mCurrency != mPlayer->getMoney()) {
mCurrency = mPlayer->getMoney();
mGpLabel->setCaption(strprintf(_("Money: %s"),
Units::formatCurrency(mCurrency).c_str()));
mGpLabel->adjustSize();
}
updateHPBar(mHpBar, true);
updateMPBar(mMpBar, true);
updateXPBar(mXpBar, false);
updateJobBar(mJobBar, false);
// Stats Part
// ----------
static const char *attrNames[6] = {
N_("Strength"),
N_("Agility"),
N_("Vitality"),
N_("Intelligence"),
N_("Dexterity"),
N_("Luck")
};
int statusPoints = mPlayer->mStatsPointsToAttribute;
// Update labels
for (int i = 0; i < 6; i++)
{
mStatsLabel[i]->setCaption(gettext(attrNames[i]));
mStatsDisplayLabel[i]->setCaption(toString((int) mPlayer->mAttr[i]));
mPointsLabel[i]->setCaption(toString((int) mPlayer->mAttrUp[i]));
mStatsLabel[i]->adjustSize();
mStatsDisplayLabel[i]->adjustSize();
mPointsLabel[i]->adjustSize();
mStatsButton[i]->setEnabled(mPlayer->mAttrUp[i] <= statusPoints);
}
mRemainingStatsPointsLabel->setCaption(
strprintf(_("Remaining Status Points: %d"), statusPoints));
mRemainingStatsPointsLabel->adjustSize();
// Derived Stats Points
// Attack TODO: Count equipped Weapons and items attack bonuses
mStatsAttackPoints->setCaption(
toString(mPlayer->ATK + mPlayer->ATK_BONUS));
mStatsAttackPoints->adjustSize();
// Defense TODO: Count equipped Armors and items defense bonuses
mStatsDefensePoints->setCaption(
toString(mPlayer->DEF + mPlayer->DEF_BONUS));
mStatsDefensePoints->adjustSize();
// Magic Attack TODO: Count equipped items M.Attack bonuses
mStatsMagicAttackPoints->setCaption(
toString(mPlayer->MATK + mPlayer->MATK_BONUS));
mStatsMagicAttackPoints->adjustSize();
// Magic Defense TODO: Count equipped items M.Defense bonuses
mStatsMagicDefensePoints->setCaption(
toString(mPlayer->MDEF + mPlayer->MDEF_BONUS));
mStatsMagicDefensePoints->adjustSize();
// Accuracy %
mStatsAccuracyPoints->setCaption(toString(mPlayer->HIT));
mStatsAccuracyPoints->adjustSize();
// Evasion %
mStatsEvadePoints->setCaption(toString(mPlayer->FLEE));
mStatsEvadePoints->adjustSize();
// Reflex %
mStatsReflexPoints->setCaption(toString(mPlayer->DEX / 4)); // + counter
mStatsReflexPoints->adjustSize();
}
void StatusWindow::draw(gcn::Graphics *g)
{
update();
Window::draw(g);
}
void StatusWindow::action(const gcn::ActionEvent &event)
{
// Stats Part
// Net::getPlayerHandler()->increaseStat(?);
if (event.getId().length() == 3)
{
if (event.getId() == "STR")
Net::getPlayerHandler()->increaseStat(LocalPlayer::STR);
if (event.getId() == "AGI")
Net::getPlayerHandler()->increaseStat(LocalPlayer::AGI);
if (event.getId() == "VIT")
Net::getPlayerHandler()->increaseStat(LocalPlayer::VIT);
if (event.getId() == "INT")
Net::getPlayerHandler()->increaseStat(LocalPlayer::INT);
if (event.getId() == "DEX")
Net::getPlayerHandler()->increaseStat(LocalPlayer::DEX);
if (event.getId() == "LUK")
Net::getPlayerHandler()->increaseStat(LocalPlayer::LUK);
}
}
void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
{
if (showMax)
bar->setText(toString(player_node->getHp()) +
"/" + toString(player_node->getMaxHp()));
else
bar->setText(toString(player_node->getHp()));
// HP Bar coloration
int r1 = 255;
int g1 = 255;
int b1 = 255;
int r2 = 255;
int g2 = 255;
int b2 = 255;
float weight = 1.0f;
int curHP = player_node->getHp();
int thresholdLevel = player_node->getMaxHp() / 4;
if (curHP < (thresholdLevel*2))
{
r1 = 0xcc; g1 = 0x00; b1 = 0x00;
r2 = 0xcc; g2 = 0xcc; b2 = 0x00;
weight = (float) (curHP - (thresholdLevel)) / (float) thresholdLevel;
// Reddish Brown -> Red
}
else if (curHP < thresholdLevel*2)
{
r1 = 0xcc; g1 = 0xcc; b1 = 0x00;
r2 = 0xff; g2 = 0xcc; b2 = 0x00;
weight = (float) (curHP - (thresholdLevel * 2)) / (float) thresholdLevel;
// Orange -> Reddish Brown
}
else
{
r1 = 0xff; g1 = 0xcc; b1 = 0x00;
r2 = 0x99; g2 = 0xff; b2 = 0x99;
weight = (float) (curHP - (thresholdLevel * 3)) / (float) thresholdLevel;
// Green -> Orange
}
//safety checks
if (weight>1.0f) weight=1.0f;
if (weight<0.0f) weight=0.0f;
//Do the color blend
r1 = (int) weightedAverage(r1, r2, weight);
g1 = (int) weightedAverage(g1, g2, weight);
b1 = (int) weightedAverage(b1, b2, weight);
//more safety checks
if (r1 > 255) r1 = 255;
if (g1 > 255) g1 = 255;
if (b1 > 255) b1 = 255;
bar->setColor(r1, g1, b1);
bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
}
void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax)
{
if (showMax)
bar->setText(toString(player_node->mMp) +
"/" + toString(player_node->mMaxMp));
else
bar->setText(toString(player_node->mMp));
if (player_node->MATK <= 0)
bar->setColor(100, 100, 100); // grey, to indicate that we lack magic
else
bar->setColor(26, 102, 230); // blue, to indicate that we have magic
bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp);
}
void StatusWindow::updateXPBar(ProgressBar *bar, bool percent)
{
if (player_node->mXpForNextLevel == 0) {
bar->setText(_("Max level"));
bar->setProgress(1.0);
} else {
if (percent)
{
float xp = (float) player_node->getXp() /
player_node->mXpForNextLevel;
bar->setText(toString((float) ((int) (xp * 10000.0f)) / 100.0f) +
"%");
}
else
bar->setText(toString(player_node->getXp()) +
"/" + toString(player_node->mXpForNextLevel));
bar->setProgress((float) player_node->getXp() /
(float) player_node->mXpForNextLevel);
}
}
void StatusWindow::updateJobBar(ProgressBar *bar, bool percent)
{
if (player_node->mJobXpForNextLevel == 0) {
bar->setText(_("Max level"));
bar->setProgress(1.0);
} else {
if (percent)
{
float xp = (float) player_node->mJobXp /
player_node->mJobXpForNextLevel;
bar->setText(toString((float) ((int) (xp * 10000.0f)) / 100.0f) +
"%");
}
else
bar->setText(toString(player_node->mJobXp) +
"/" + toString(player_node->mJobXpForNextLevel));
bar->setProgress((float) player_node->mJobXp /
(float) player_node->mJobXpForNextLevel);
}
}
|