Debian Codegraph @

prboom2/src/dsda/hud_components/health_text.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Health Text HUD Component
16 //
17
18 #include "base.h"
19
20 #include "health_text.h"
21
22 typedef struct {
23 dsda_text_t component;
24 } local_component_t;
25
26 static local_component_t* local;
27
28 static void dsda_UpdateComponentText(char* str, size_t max_size) {
29 player_t* player;
30
31 player = &players[displayplayer];
32
33 snprintf(
34 str,
35 max_size,
36 "%sHEL %3d%%",
37 player->health <= hud_health_red ? dsda_TextColor(dsda_tc_exhud_health_bad) :
38 player->health <= hud_health_yellow ? dsda_TextColor(dsda_tc_exhud_health_warning) :
39 player->health <= hud_health_green ? dsda_TextColor(dsda_tc_exhud_health_ok) :
40 dsda_TextColor(dsda_tc_exhud_health_super),
41 player->health
42 );
43 }
44
45 void dsda_InitHealthTextHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
46 *data = Z_Calloc(1, sizeof(local_component_t));
47 local = *data;
48
49 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
50 }
51
52 void dsda_UpdateHealthTextHC(void* data) {
53 local = data;
54
55 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
56 dsda_RefreshHudText(&local->component);
57 }
58
59 void dsda_DrawHealthTextHC(void* data) {
60 local = data;
61
62 dsda_DrawBasicText(&local->component);
63 }