/
MenuCharacter.cpp
590 lines (495 loc) · 22.1 KB
/
MenuCharacter.cpp
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/*
Copyright © 2011-2012 Clint Bellanger
This file is part of FLARE.
FLARE 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 3 of the License, or (at your option) any later version.
FLARE 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
FLARE. If not, see http://www.gnu.org/licenses/
*/
/**
* class MenuCharacter
*/
#include "FileParser.h"
#include "Menu.h"
#include "MenuCharacter.h"
#include "SharedResources.h"
#include "Settings.h"
#include "StatBlock.h"
#include "UtilsParsing.h"
#include "WidgetButton.h"
#include "WidgetListBox.h"
using namespace std;
MenuCharacter::MenuCharacter(StatBlock *_stats) {
stats = _stats;
skill_points = 0;
visible = false;
newPowerNotification = false;
for (int i=0; i<CSTAT_COUNT; i++) {
cstat[i].label = new WidgetLabel();
cstat[i].value = new WidgetLabel();
cstat[i].hover.x = cstat[i].hover.y = 0;
cstat[i].hover.w = cstat[i].hover.h = 0;
cstat[i].visible = true;
}
for (int i=0; i<14; i++) {
show_stat[i] = true;
}
closeButton = new WidgetButton(mods->locate("images/menus/buttons/button_x.png"));
// Upgrade buttons
for (int i=0; i<4; i++) {
upgradeButton[i] = new WidgetButton(mods->locate("images/menus/buttons/upgrade.png"));
upgradeButton[i]->enabled = false;
show_upgrade[i] = true;
}
physical_up = false;
mental_up = false;
offense_up = false;
defense_up = false;
// menu title
labelCharacter = new WidgetLabel();
// stat list
statList = new WidgetListBox(13+stats->vulnerable.size(), 10, mods->locate("images/menus/buttons/listbox_char.png"));
// Load config settings
FileParser infile;
if(infile.open(mods->locate("menus/character.txt"))) {
while(infile.next()) {
infile.val = infile.val + ',';
if(infile.key == "close") {
close_pos.x = eatFirstInt(infile.val,',');
close_pos.y = eatFirstInt(infile.val,',');
} else if(infile.key == "caption") {
title = eatLabelInfo(infile.val);
} else if(infile.key == "upgrade_physical") {
upgrade_pos[0].x = eatFirstInt(infile.val,',');
upgrade_pos[0].y = eatFirstInt(infile.val,',');
} else if(infile.key == "upgrade_mental") {
upgrade_pos[1].x = eatFirstInt(infile.val,',');
upgrade_pos[1].y = eatFirstInt(infile.val,',');
} else if(infile.key == "upgrade_offense") {
upgrade_pos[2].x = eatFirstInt(infile.val,',');
upgrade_pos[2].y = eatFirstInt(infile.val,',');
} else if(infile.key == "upgrade_defense") {
upgrade_pos[3].x = eatFirstInt(infile.val,',');
upgrade_pos[3].y = eatFirstInt(infile.val,',');
} else if(infile.key == "statlist") {
statlist_pos.x = eatFirstInt(infile.val,',');
statlist_pos.y = eatFirstInt(infile.val,',');
} else if(infile.key == "label_name") {
label_pos[0] = eatLabelInfo(infile.val);
cstat[CSTAT_NAME].visible = !label_pos[0].hidden;
} else if(infile.key == "label_level") {
label_pos[1] = eatLabelInfo(infile.val);
cstat[CSTAT_LEVEL].visible = !label_pos[1].hidden;
} else if(infile.key == "label_physical") {
label_pos[2] = eatLabelInfo(infile.val);
cstat[CSTAT_PHYSICAL].visible = !label_pos[2].hidden;
} else if(infile.key == "label_mental") {
label_pos[3] = eatLabelInfo(infile.val);
cstat[CSTAT_MENTAL].visible = !label_pos[3].hidden;
} else if(infile.key == "label_offense") {
label_pos[4] = eatLabelInfo(infile.val);
cstat[CSTAT_OFFENSE].visible = !label_pos[4].hidden;
} else if(infile.key == "label_defense") {
label_pos[5] = eatLabelInfo(infile.val);
cstat[CSTAT_DEFENSE].visible = !label_pos[5].hidden;
} else if(infile.key == "name") {
value_pos[0].x = eatFirstInt(infile.val,',');
value_pos[0].y = eatFirstInt(infile.val,',');
value_pos[0].w = eatFirstInt(infile.val,',');
value_pos[0].h = eatFirstInt(infile.val,',');
} else if(infile.key == "level") {
value_pos[1].x = eatFirstInt(infile.val,',');
value_pos[1].y = eatFirstInt(infile.val,',');
value_pos[1].w = eatFirstInt(infile.val,',');
value_pos[1].h = eatFirstInt(infile.val,',');
} else if(infile.key == "physical") {
value_pos[2].x = eatFirstInt(infile.val,',');
value_pos[2].y = eatFirstInt(infile.val,',');
value_pos[2].w = eatFirstInt(infile.val,',');
value_pos[2].h = eatFirstInt(infile.val,',');
} else if(infile.key == "mental") {
value_pos[3].x = eatFirstInt(infile.val,',');
value_pos[3].y = eatFirstInt(infile.val,',');
value_pos[3].w = eatFirstInt(infile.val,',');
value_pos[3].h = eatFirstInt(infile.val,',');
} else if(infile.key == "offense") {
value_pos[4].x = eatFirstInt(infile.val,',');
value_pos[4].y = eatFirstInt(infile.val,',');
value_pos[4].w = eatFirstInt(infile.val,',');
value_pos[4].h = eatFirstInt(infile.val,',');
} else if(infile.key == "defense") {
value_pos[5].x = eatFirstInt(infile.val,',');
value_pos[5].y = eatFirstInt(infile.val,',');
value_pos[5].w = eatFirstInt(infile.val,',');
value_pos[5].h = eatFirstInt(infile.val,',');
} else if(infile.key == "unspent") {
value_pos[6].x = eatFirstInt(infile.val,',');
value_pos[6].y = eatFirstInt(infile.val,',');
value_pos[6].w = eatFirstInt(infile.val,',');
value_pos[6].h = eatFirstInt(infile.val,',');
} else if (infile.key == "show_unspent"){
if (eatFirstInt(infile.val,',') == 0) cstat[CSTAT_UNSPENT].visible = false;
} else if (infile.key == "show_upgrade_physical"){
if (eatFirstInt(infile.val,',') == 0) show_upgrade[0] = false;
} else if (infile.key == "show_upgrade_mental"){
if (eatFirstInt(infile.val,',') == 0) show_upgrade[1] = false;
} else if (infile.key == "show_upgrade_offense"){
if (eatFirstInt(infile.val,',') == 0) show_upgrade[2] = false;
} else if (infile.key == "show_upgrade_defense"){
if (eatFirstInt(infile.val,',') == 0) show_upgrade[3] = false;
} else if (infile.key == "show_maxhp"){
if (eatFirstInt(infile.val,',') == 0) show_stat[0] = false;
} else if (infile.key == "show_hpregen"){
if (eatFirstInt(infile.val,',') == 0) show_stat[1] = false;
} else if (infile.key == "show_maxmp"){
if (eatFirstInt(infile.val,',') == 0) show_stat[2] = false;
} else if (infile.key == "show_mpregen"){
if (eatFirstInt(infile.val,',') == 0) show_stat[3] = false;
} else if (infile.key == "show_accuracy_v1"){
if (eatFirstInt(infile.val,',') == 0) show_stat[4] = false;
} else if (infile.key == "show_accuracy_v5"){
if (eatFirstInt(infile.val,',') == 0) show_stat[5] = false;
} else if (infile.key == "show_avoidance_v1"){
if (eatFirstInt(infile.val,',') == 0) show_stat[6] = false;
} else if (infile.key == "show_avoidance_v5"){
if (eatFirstInt(infile.val,',') == 0) show_stat[7] = false;
} else if (infile.key == "show_melee"){
if (eatFirstInt(infile.val,',') == 0) show_stat[8] = false;
} else if (infile.key == "show_ranged"){
if (eatFirstInt(infile.val,',') == 0) show_stat[9] = false;
} else if (infile.key == "show_mental"){
if (eatFirstInt(infile.val,',') == 0) show_stat[10] = false;
} else if (infile.key == "show_crit"){
if (eatFirstInt(infile.val,',') == 0) show_stat[11] = false;
} else if (infile.key == "show_absorb"){
if (eatFirstInt(infile.val,',') == 0) show_stat[12] = false;
} else if (infile.key == "show_resists"){
if (eatFirstInt(infile.val,',') == 0) show_stat[13] = false;
}
}
infile.close();
} else fprintf(stderr, "Unable to open menus/character.txt!\n");
loadGraphics();
}
void MenuCharacter::update() {
// close button
closeButton->pos.x = window_area.x + close_pos.x;
closeButton->pos.y = window_area.y + close_pos.y;
// menu title
labelCharacter->set(window_area.x+title.x, window_area.y+title.y, title.justify, title.valign, msg->get("Character"), font->getColor("menu_normal"));
// upgrade buttons
for (int i=0; i<4; i++) {
upgradeButton[i]->pos.x = window_area.x+upgrade_pos[i].x;
upgradeButton[i]->pos.y = window_area.y+upgrade_pos[i].y;
}
// stat list
statList->pos.x = window_area.x+statlist_pos.x;
statList->pos.y = window_area.y+statlist_pos.y;
// setup static labels
cstat[CSTAT_NAME].label->set(window_area.x+label_pos[0].x, window_area.y+label_pos[0].y, label_pos[0].justify, label_pos[0].valign, msg->get("Name"), font->getColor("menu_normal"));
cstat[CSTAT_LEVEL].label->set(window_area.x+label_pos[1].x, window_area.y+label_pos[1].y, label_pos[1].justify, label_pos[1].valign, msg->get("Level"), font->getColor("menu_normal"));
cstat[CSTAT_PHYSICAL].label->set(window_area.x+label_pos[2].x, window_area.y+label_pos[2].y, label_pos[2].justify, label_pos[2].valign, msg->get("Physical"), font->getColor("menu_normal"));
cstat[CSTAT_MENTAL].label->set(window_area.x+label_pos[3].x, window_area.y+label_pos[3].y, label_pos[3].justify, label_pos[3].valign, msg->get("Mental"), font->getColor("menu_normal"));
cstat[CSTAT_OFFENSE].label->set(window_area.x+label_pos[4].x, window_area.y+label_pos[4].y, label_pos[4].justify, label_pos[4].valign, msg->get("Offense"), font->getColor("menu_normal"));
cstat[CSTAT_DEFENSE].label->set(window_area.x+label_pos[5].x, window_area.y+label_pos[5].y, label_pos[5].justify, label_pos[5].valign, msg->get("Defense"), font->getColor("menu_normal"));
// setup hotspot locations
cstat[CSTAT_NAME].setHover(window_area.x+value_pos[0].x, window_area.y+value_pos[0].y, value_pos[0].w, value_pos[0].h);
cstat[CSTAT_LEVEL].setHover(window_area.x+value_pos[1].x, window_area.y+value_pos[1].y, value_pos[1].w, value_pos[1].h);
cstat[CSTAT_PHYSICAL].setHover(window_area.x+value_pos[2].x, window_area.y+value_pos[2].y, value_pos[2].w, value_pos[2].h);
cstat[CSTAT_MENTAL].setHover(window_area.x+value_pos[3].x, window_area.y+value_pos[3].y, value_pos[3].w, value_pos[3].h);
cstat[CSTAT_OFFENSE].setHover(window_area.x+value_pos[4].x, window_area.y+value_pos[4].y, value_pos[4].w, value_pos[4].h);
cstat[CSTAT_DEFENSE].setHover(window_area.x+value_pos[5].x, window_area.y+value_pos[5].y, value_pos[5].w, value_pos[5].h);
cstat[CSTAT_UNSPENT].setHover(window_area.x+value_pos[6].x, window_area.y+value_pos[6].y, value_pos[6].w, value_pos[6].h);
}
void MenuCharacter::loadGraphics() {
background = IMG_Load(mods->locate("images/menus/character.png").c_str());
if(!background) {
fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError());
SDL_Quit();
exit(1);
}
// optimize
SDL_Surface *cleanup = background;
background = SDL_DisplayFormatAlpha(background);
SDL_FreeSurface(cleanup);
}
/**
* Rebuild all stat values and tooltip info
*/
void MenuCharacter::refreshStats() {
stringstream ss;
// update stat text
cstat[CSTAT_NAME].value->set(window_area.x+value_pos[0].x+4, window_area.y+value_pos[0].y+value_pos[0].h/2, JUSTIFY_LEFT, VALIGN_CENTER, stats->name, font->getColor("menu_normal"));
ss.str("");
ss << stats->level;
cstat[CSTAT_LEVEL].value->set(window_area.x+value_pos[1].x+value_pos[1].w/2, window_area.y+value_pos[1].y+value_pos[1].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), font->getColor("menu_normal"));
ss.str("");
ss << stats->get_physical();
cstat[CSTAT_PHYSICAL].value->set(window_area.x+value_pos[2].x+value_pos[2].w/2, window_area.y+value_pos[2].y+value_pos[2].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), bonusColor(stats->physical_additional));
ss.str("");
ss << stats->get_mental();
cstat[CSTAT_MENTAL].value->set(window_area.x+value_pos[3].x+value_pos[3].w/2, window_area.y+value_pos[3].y+value_pos[3].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), bonusColor(stats->mental_additional));
ss.str("");
ss << stats->get_offense();
cstat[CSTAT_OFFENSE].value->set(window_area.x+value_pos[4].x+value_pos[4].w/2, window_area.y+value_pos[4].y+value_pos[4].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), bonusColor(stats->offense_additional));
ss.str("");
ss << stats->get_defense();
cstat[CSTAT_DEFENSE].value->set(window_area.x+value_pos[5].x+value_pos[5].w/2, window_area.y+value_pos[5].y+value_pos[5].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), bonusColor(stats->defense_additional));
ss.str("");
if (skill_points > 0) ss << skill_points << " " << msg->get("points remaining");
else ss.str("");
cstat[CSTAT_UNSPENT].value->set(window_area.x+value_pos[6].x+value_pos[6].w/2, window_area.y+value_pos[6].y+value_pos[6].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), font->getColor("menu_bonus"));
ss.str("");
// scrolling stat list
statList->clear();
statList->refresh();
if (show_stat[0]) {
ss.str("");
ss << msg->get("Max HP:") << " " << stats->maxhp;
statList->append(ss.str(),msg->get("Each point of Physical grants +%d HP. Each level grants +%d HP", stats->hp_per_physical, stats->hp_per_level));
}
if (show_stat[1]) {
ss.str("");
ss << msg->get("HP Regen:") << " " << stats->hp_per_minute;
statList->append(ss.str(),msg->get("Ticks of HP regen per minute. Each point of Physical grants +%d HP regen. Each level grants +%d HP regen",stats->hp_regen_per_physical, stats->hp_regen_per_level));
}
if (show_stat[2]) {
ss.str("");
ss << msg->get("Max MP:") << " " << stats->maxmp;
statList->append(ss.str(),msg->get("Each point of Mental grants +%d MP. Each level grants +%d MP", stats->mp_per_mental, stats->mp_per_level));
}
if (show_stat[3]) {
ss.str("");
ss << msg->get("MP Regen:") << " " << stats->mp_per_minute;
statList->append(ss.str(),msg->get("Ticks of MP regen per minute. Each point of Mental grants +%d MP regen. Each level grants +%d MP regen", stats->mp_regen_per_mental, stats->mp_regen_per_level));
}
if (show_stat[4]) {
ss.str("");
ss << msg->get("Accuracy (vs lvl 1):") << " " << stats->accuracy << "%";
statList->append(ss.str(),msg->get("Each point of Offense grants +%d accuracy. Each level grants +%d accuracy", stats->accuracy_per_offense, stats->accuracy_per_level));
}
if (show_stat[5]) {
ss.str("");
ss << msg->get("Accuracy (vs lvl 5):") << " " << (stats->accuracy-20) << "%";
statList->append(ss.str(),msg->get("Each point of Offense grants +%d accuracy. Each level grants +%d accuracy", stats->accuracy_per_offense, stats->accuracy_per_level));
}
if (show_stat[6]) {
ss.str("");
ss << msg->get("Avoidance (vs lvl 1):") << " " << stats->avoidance << "%";
statList->append(ss.str(),msg->get("Each point of Defense grants +%d avoidance. Each level grants +%d avoidance", stats->avoidance_per_defense, stats->avoidance_per_level));
}
if (show_stat[7]) {
ss.str("");
ss << msg->get("Avoidance (vs lvl 5):") << " " << (stats->avoidance-20) << "%";
statList->append(ss.str(),msg->get("Each point of Defense grants +%d avoidance. Each level grants +%d avoidance", stats->avoidance_per_defense, stats->avoidance_per_level));
}
int bonus;
if (show_stat[8]) {
bonus = stats->get_physical() * stats->bonus_per_physical;
ss.str("");
ss << msg->get("Melee Damage:") << " ";
if (stats->dmg_melee_max > 0)
ss << stats->dmg_melee_min + bonus << "-" << stats->dmg_melee_max + bonus;
else
ss << "-";
statList->append(ss.str(),"");
}
if (show_stat[9]) {
bonus = stats->get_offense() * stats->bonus_per_offense;
ss.str("");
ss << msg->get("Ranged Damage:") << " ";
if (stats->dmg_ranged_max > 0)
ss << stats->dmg_ranged_min + bonus << "-" << stats->dmg_ranged_max + bonus;
else
ss << "-";
statList->append(ss.str(),"");
}
if (show_stat[10]) {
bonus = stats->get_mental() * stats->bonus_per_mental;
ss.str("");
ss << msg->get("Mental Damage:") << " ";
if (stats->dmg_ment_max > 0)
ss << stats->dmg_ment_min + bonus << "-" << stats->dmg_ment_max + bonus;
else
ss << "-";
statList->append(ss.str(),"");
}
if (show_stat[11]) {
ss.str("");
ss << msg->get("Crit:") << " " << stats->crit << "%";
statList->append(ss.str(),"");
}
if (show_stat[12]) {
ss.str("");
ss << msg->get("Absorb:") << " ";
if (stats->absorb_min == stats->absorb_max)
ss << stats->absorb_min;
else
ss << stats->absorb_min << "-" << stats->absorb_max;
statList->append(ss.str(),"");
}
if (show_stat[13]) {
for (unsigned int j=0; j<stats->vulnerable.size(); j++) {
ss.str("");
ss << ELEMENTS[j].resist << ": " << (100 - stats->vulnerable[j]) << "%";
statList->append(ss.str(),"");
}
}
// update tool tips
cstat[CSTAT_NAME].tip.num_lines = 0;
cstat[CSTAT_NAME].tip.lines[cstat[CSTAT_NAME].tip.num_lines++] = msg->get(stats->character_class);
cstat[CSTAT_LEVEL].tip.num_lines = 0;
cstat[CSTAT_LEVEL].tip.lines[cstat[CSTAT_LEVEL].tip.num_lines++] = msg->get("XP: %d", stats->xp);
if (stats->level < MAX_CHARACTER_LEVEL) {
cstat[CSTAT_LEVEL].tip.lines[cstat[CSTAT_LEVEL].tip.num_lines++] = msg->get("Next: %d", stats->xp_table[stats->level]);
}
cstat[CSTAT_PHYSICAL].tip.num_lines = 0;
cstat[CSTAT_PHYSICAL].tip.lines[cstat[CSTAT_PHYSICAL].tip.num_lines++] = msg->get("Physical (P) increases melee weapon proficiency and total HP.");
cstat[CSTAT_PHYSICAL].tip.lines[cstat[CSTAT_PHYSICAL].tip.num_lines++] = msg->get("base (%d), bonus (%d)", stats->physical_character, stats->physical_additional);
cstat[CSTAT_MENTAL].tip.num_lines = 0;
cstat[CSTAT_MENTAL].tip.lines[cstat[CSTAT_MENTAL].tip.num_lines++] = msg->get("Mental (M) increases mental weapon proficiency and total MP.");
cstat[CSTAT_MENTAL].tip.lines[cstat[CSTAT_MENTAL].tip.num_lines++] = msg->get("base (%d), bonus (%d)", stats->mental_character, stats->mental_additional);
cstat[CSTAT_OFFENSE].tip.num_lines = 0;
cstat[CSTAT_OFFENSE].tip.lines[cstat[CSTAT_OFFENSE].tip.num_lines++] = msg->get("Offense (O) increases ranged weapon proficiency and accuracy.");
cstat[CSTAT_OFFENSE].tip.lines[cstat[CSTAT_OFFENSE].tip.num_lines++] = msg->get("base (%d), bonus (%d)", stats->offense_character, stats->offense_additional);
cstat[CSTAT_DEFENSE].tip.num_lines = 0;
cstat[CSTAT_DEFENSE].tip.lines[cstat[CSTAT_DEFENSE].tip.num_lines++] = msg->get("Defense (D) increases armor proficiency and avoidance.");
cstat[CSTAT_DEFENSE].tip.lines[cstat[CSTAT_DEFENSE].tip.num_lines++] = msg->get("base (%d), bonus (%d)", stats->defense_character, stats->defense_additional);
cstat[CSTAT_UNSPENT].tip.num_lines = 0;
if (skill_points) cstat[CSTAT_UNSPENT].tip.lines[cstat[CSTAT_UNSPENT].tip.num_lines++] = msg->get("Unspent attribute points");
}
/**
* Color-coding for positive/negative/no bonus
*/
SDL_Color MenuCharacter::bonusColor(int stat) {
if (stat > 0) return font->getColor("menu_bonus");
if (stat < 0) return font->getColor("menu_penalty");
return font->getColor("menu_label");
}
void MenuCharacter::logic() {
if (!visible) return;
if (closeButton->checkClick()) {
visible = false;
}
// upgrade buttons
for (int i=0; i<4; i++) {
upgradeButton[i]->enabled = false;
}
int spent = stats->physical_character + stats->mental_character + stats->offense_character + stats->defense_character -4;
skill_points = stats->level - spent;
if (spent < stats->level && spent < stats->max_spendable_stat_points) {
if (stats->physical_character < stats->max_points_per_stat && show_upgrade[0]) upgradeButton[0]->enabled = true;
if (stats->mental_character < stats->max_points_per_stat && show_upgrade[1]) upgradeButton[1]->enabled = true;
if (stats->offense_character < stats->max_points_per_stat && show_upgrade[2]) upgradeButton[2]->enabled = true;
if (stats->defense_character < stats->max_points_per_stat && show_upgrade[3]) upgradeButton[3]->enabled = true;
}
if (upgradeButton[0]->checkClick()) physical_up = true;
if (upgradeButton[1]->checkClick()) mental_up = true;
if (upgradeButton[2]->checkClick()) offense_up = true;
if (upgradeButton[3]->checkClick()) defense_up = true;
statList->checkClick();
// TODO: this doesn't need to be done every frame. Only call this when something has updated
refreshStats();
}
void MenuCharacter::render() {
if (!visible) return;
SDL_Rect src;
SDL_Rect dest;
// background
src.x = 0;
src.y = 0;
dest.x = window_area.x;
dest.y = window_area.y;
src.w = dest.w = 320;
src.h = dest.h = 416;
SDL_BlitSurface(background, &src, screen, &dest);
// close button
closeButton->render();
// title
labelCharacter->render();
// labels and values
for (int i=0; i<CSTAT_COUNT; i++) {
if (cstat[i].visible) {
cstat[i].label->render();
cstat[i].value->render();
}
}
// upgrade buttons
for (int i=0; i<4; i++) {
if (upgradeButton[i]->enabled) upgradeButton[i]->render();
}
statList->render();
}
/**
* Display various mouseovers tooltips depending on cursor location
*/
TooltipData MenuCharacter::checkTooltip() {
for (int i=0; i<CSTAT_COUNT; i++) {
if (isWithin(cstat[i].hover, inpt->mouse) && cstat[i].tip.num_lines > 0 && cstat[i].visible)
return cstat[i].tip;
}
TooltipData tip;
tip.num_lines = 0;
return tip;
}
/**
* User might click this menu to upgrade a stat. Check for this situation.
* Return true if a stat was upgraded.
*/
bool MenuCharacter::checkUpgrade() {
int spent = stats->physical_character + stats->mental_character + stats->offense_character + stats->defense_character -4;
skill_points = stats->level - spent;
// check to see if there are skill points available
if (spent < stats->level && spent < stats->max_spendable_stat_points) {
// physical
if (physical_up) {
stats->physical_character++;
stats->recalc(); // equipment applied by MenuManager
newPowerNotification = true; //TODO: Only show if a NEW power is unlocked...
physical_up = false;
return true;
}
// mental
else if (mental_up) {
stats->mental_character++;
stats->recalc(); // equipment applied by MenuManager
newPowerNotification = true;
mental_up = false;
return true;
}
// offense
else if (offense_up) {
stats->offense_character++;
stats->recalc(); // equipment applied by MenuManager
newPowerNotification = true;
offense_up = false;
return true;
}
// defense
else if (defense_up) {
stats->defense_character++;
stats->recalc(); // equipment applied by MenuManager
newPowerNotification = true;
defense_up = false;
return true;
}
}
return false;
}
MenuCharacter::~MenuCharacter() {
SDL_FreeSurface(background);
delete closeButton;
delete labelCharacter;
for (int i=0; i<CSTAT_COUNT; i++) {
delete cstat[i].label;
delete cstat[i].value;
}
for (int i=0; i<4; i++) {
delete upgradeButton[i];
}
delete statList;
}