Debian Codegraph @

prboom2/src/dsda/hud_components/weapon_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 Weapon Text HUD Component
16 //
17
18 #include "base.h"
19
20 #include "weapon_text.h"
21
22 typedef struct {
23 dsda_text_t component;
24 dboolean grid;
25 const char* label_w;
26 const char* label_p;
27 const char* label_n;
28 const char* label_wpn;
29 } local_component_t;
30
31 static local_component_t* local;
32
33 static void dsda_UpdateComponentText(char* str, size_t max_size) {
34 player_t* player;
35
36 player = &players[displayplayer];
37
38 if (local->grid)
39 snprintf(
40 str,
41 max_size,
42 "%s%s%s%c %s%c %c\n"
43 "%s%s%s%c %c %c\n"
44 "%s%s%s%c %c %c",
45 dsda_TextColor(dsda_tc_exhud_weapon_label),
46 local->label_w,
47 player->powers[pw_strength] ? dsda_TextColor(dsda_tc_exhud_weapon_berserk) :
48 dsda_TextColor(dsda_tc_exhud_weapon_owned),
49 player->weaponowned[0] ? '1' : ' ',
50 dsda_TextColor(dsda_tc_exhud_weapon_owned),
51 player->weaponowned[1] ? '2' : ' ',
52 player->weaponowned[2] ? '3' : ' ',
53 dsda_TextColor(dsda_tc_exhud_weapon_label),
54 local->label_p,
55 dsda_TextColor(dsda_tc_exhud_weapon_owned),
56 player->weaponowned[3] ? '4' : ' ',
57 player->weaponowned[4] ? '5' : ' ',
58 player->weaponowned[5] ? '6' : ' ',
59 dsda_TextColor(dsda_tc_exhud_weapon_label),
60 local->label_n,
61 dsda_TextColor(dsda_tc_exhud_weapon_owned),
62 player->weaponowned[6] ? '7' : ' ',
63 player->weaponowned[7] ? '8' : ' ',
64 player->weaponowned[8] ? '9' : ' '
65 );
66 else
67 snprintf(
68 str,
69 max_size,
70 "%s%s%s%c %s%c %c %c %c %c %c %c %c",
71 dsda_TextColor(dsda_tc_exhud_weapon_label),
72 local->label_wpn,
73 player->powers[pw_strength] ? dsda_TextColor(dsda_tc_exhud_weapon_berserk) :
74 dsda_TextColor(dsda_tc_exhud_weapon_owned),
75 player->weaponowned[0] ? '1' : ' ',
76 dsda_TextColor(dsda_tc_exhud_weapon_owned),
77 player->weaponowned[1] ? '2' : ' ',
78 player->weaponowned[2] ? '3' : ' ',
79 player->weaponowned[3] ? '4' : ' ',
80 player->weaponowned[4] ? '5' : ' ',
81 player->weaponowned[5] ? '6' : ' ',
82 player->weaponowned[6] ? '7' : ' ',
83 player->weaponowned[7] ? '8' : ' ',
84 player->weaponowned[8] ? '9' : ' '
85 );
86 }
87
88 void dsda_InitWeaponTextHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
89 *data = Z_Calloc(1, sizeof(local_component_t));
90 local = *data;
91
92 local->grid = args[0];
93
94 if (arg_count < 2 || args[1]) {
95 local->label_w = "W ";
96 local->label_p = "P ";
97 local->label_n = "N ";
98 local->label_wpn = "WPN ";
99 }
100 else {
101 local->label_w = "";
102 local->label_p = "";
103 local->label_n = "";
104 local->label_wpn = "";
105 }
106
107 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
108 }
109
110 void dsda_UpdateWeaponTextHC(void* data) {
111 local = data;
112
113 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
114 dsda_RefreshHudText(&local->component);
115 }
116
117 void dsda_DrawWeaponTextHC(void* data) {
118 local = data;
119
120 dsda_DrawBasicText(&local->component);
121 }