Debian Codegraph @

prboom2/src/dsda/hud_components/message.c

raw
1 //
2 // Copyright(C) 2023 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 Message HUD Component
16 //
17
18 #include "base.h"
19
20 #include "message.h"
21
22 typedef struct {
23 dsda_text_t component;
24 dboolean center;
25 } local_component_t;
26
27 static local_component_t* local;
28
29 static void dsda_UpdateComponentText(char* str, size_t max_size) {
30 char* dsda_PlayerMessage(void);
31
32 char* message;
33
34 message = dsda_PlayerMessage();
35
36 if (message)
37 snprintf(
38 str,
39 max_size,
40 "%s%s",
41 dsda_TextColor(dsda_tc_hud_message),
42 message
43 );
44 else
45 str[0] = '\0';
46 }
47
48 void dsda_InitMessageHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
49 *data = Z_Calloc(1, sizeof(local_component_t));
50 local = *data;
51
52 local->center = arg_count > 0 ? !!args[0] : false;
53
54 dsda_InitBlockyHC(&local->component, x_offset, y_offset, vpt);
55 }
56
57 void dsda_UpdateMessageHC(void* data) {
58 local = data;
59
60 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
61 dsda_RefreshHudText(&local->component);
62
63 if (local->center)
64 HUlib_setTextXCenter(&local->component.text);
65 }
66
67 void dsda_DrawMessageHC(void* data) {
68 local = data;
69
70 dsda_DrawBasicText(&local->component);
71 }