]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/infomessages.qc
Remove redundant brackets from MACRO_BEGIN / MACRO_END calls
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / infomessages.qc
1 #include "infomessages.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/miscfunctions.qh>
5
6 #include <common/ent_cs.qh>
7 #include <common/mapinfo.qh>
8
9 // Info messages (#14)
10
11 float autocvar_hud_panel_infomessages_group0 = 1;
12 float autocvar_hud_panel_infomessages_group_fadetime = 0.4;
13 float autocvar_hud_panel_infomessages_group_time = 6;
14 const int IMG_COUNT = 1; // number of InfoMessage Groups
15 float img_fade[IMG_COUNT];
16 int img_cur_msg[IMG_COUNT];
17 float img_time[IMG_COUNT];
18
19 int img_select(int group_id)
20 {
21         float fadetime = max(0.001, autocvar_hud_panel_infomessages_group_fadetime);
22         if(time > img_time[group_id])
23         {
24                 img_fade[group_id] = max(0, img_fade[group_id] - frametime / fadetime);
25                 if(!img_fade[group_id])
26                 {
27                         ++img_cur_msg[group_id];
28                         img_time[group_id] = floor(time) + autocvar_hud_panel_infomessages_group_time;
29                 }
30         }
31         else
32                 img_fade[group_id] = min(1, img_fade[group_id] + frametime / fadetime);
33         return img_cur_msg[group_id];
34 }
35
36 vector InfoMessages_drawstring(string s, vector pos, vector sz, float a, vector fontsize)
37 {
38         getWrappedLine_remaining = s;
39         float offset = 0;
40         while(getWrappedLine_remaining)
41         {
42                 s = getWrappedLine(sz.x - offset, fontsize, stringwidth_colors);
43                 if(autocvar_hud_panel_infomessages_flip)
44                         offset = sz.x - stringwidth_colors(s, fontsize) - offset;
45                 drawcolorcodedstring(pos + eX * offset, s, fontsize, a, DRAWFLAG_NORMAL);
46                 pos.y += fontsize.y;
47                 offset = fontsize.x;
48         }
49         pos.y += fontsize.y * 0.25;
50         return pos;
51 }
52
53 #define InfoMessage(s) MACRO_BEGIN \
54         pos = InfoMessages_drawstring(s, pos, mySize, ((img_curr_group >= 0) ? panel_fg_alpha * img_fade[img_curr_group] : panel_fg_alpha), fontsize); \
55         img_curr_group = -1; \
56 MACRO_END
57
58 void HUD_InfoMessages()
59 {
60         if(!autocvar__hud_configure)
61         {
62                 if(!autocvar_hud_panel_infomessages) return;
63         }
64
65         HUD_Panel_LoadCvars();
66         vector pos, mySize;
67         pos = panel_pos;
68         mySize = panel_size;
69
70         if (autocvar_hud_panel_infomessages_dynamichud)
71                 HUD_Scale_Enable();
72         else
73                 HUD_Scale_Disable();
74         HUD_Panel_DrawBg();
75         if(panel_bg_padding)
76         {
77                 pos += '1 1 0' * panel_bg_padding;
78                 mySize -= '2 2 0' * panel_bg_padding;
79         }
80
81         vector fontsize = '0.2 0.2 0' * mySize.y;
82         string s;
83         int img_curr_group = -1;
84         if(!autocvar__hud_configure)
85         {
86                 if(spectatee_status)
87                 {
88                         if(spectatee_status == -1)
89                                 s = _("^1Observing");
90                         else
91                                 s = sprintf(_("^1Spectating: ^7%s"), entcs_GetName(current_player));
92                         InfoMessage(s);
93
94                         if(autocvar_hud_panel_infomessages_group0)
95                         {
96                                 img_curr_group = 0;
97                                 switch(img_select(img_curr_group) % 3)
98                                 {
99                                         default:
100                                         case 0:
101                                                 if(spectatee_status == -1)
102                                                         s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey(_("primary fire"), "+fire"));
103                                                 else
104                                                         s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey(_("next weapon"), "weapnext"), getcommandkey(_("previous weapon"), "weapprev"));
105                                                 break;
106                                         case 1:
107                                                 if(spectatee_status == -1)
108                                                         s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey(_("next weapon"), "weapnext"), getcommandkey(_("previous weapon"), "weapprev"));
109                                                 else
110                                                         s = sprintf(_("^1Press ^3%s^1 to observe, ^3%s^1 to change camera mode"), getcommandkey(_("secondary fire"), "+fire2"), getcommandkey(_("drop weapon"), "dropweapon"));
111                                                 break;
112                                         case 2:
113                                                 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey(_("server info"), "+show_info"));
114                                                 break;
115                                 }
116                                 InfoMessage(s);
117                         }
118
119                         MUTATOR_CALLHOOK(DrawInfoMessages, pos, mySize);
120
121                         if(!warmup_stage && ISGAMETYPE(LMS))
122                         {
123                                 entity sk;
124                                 sk = playerslots[player_localnum];
125                                 if(sk.(scores(ps_primary)) >= 666)
126                                         s = _("^1Match has already begun");
127                                 else if(sk.(scores(ps_primary)) > 0)
128                                         s = _("^1You have no more lives left");
129                                 else
130                                         s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey(_("jump"), "+jump"));
131                         }
132                         else
133                                 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey(_("jump"), "+jump"));
134                         InfoMessage(s);
135                 }
136
137                 if (time < STAT(GAMESTARTTIME))
138                 {
139                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
140                         float countdown = ceil(STAT(GAMESTARTTIME) - time);
141                         s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
142                         InfoMessage(s);
143                 }
144
145                 if(warmup_stage)
146                 {
147                         s = _("^2Currently in ^1warmup^2 stage!");
148                         InfoMessage(s);
149                 }
150
151                 string blinkcolor;
152                 if(time % 1 >= 0.5)
153                         blinkcolor = "^1";
154                 else
155                         blinkcolor = "^3";
156
157                 if(ready_waiting && !spectatee_status)
158                 {
159                         if(ready_waiting_for_me)
160                         {
161                                 if(warmup_stage)
162                                         s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey(_("ready"), "ready"), blinkcolor);
163                                 else
164                                         s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey(_("ready"), "ready"), blinkcolor);
165                         }
166                         else
167                         {
168                                 if(warmup_stage)
169                                         s = _("^2Waiting for others to ready up to end warmup...");
170                                 else
171                                         s = _("^2Waiting for others to ready up...");
172                         }
173                         InfoMessage(s);
174                 }
175                 else if(warmup_stage && !spectatee_status)
176                 {
177                         s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey(_("ready"), "ready"));
178                         InfoMessage(s);
179                 }
180
181                 if(teamplay && !spectatee_status && teamnagger)
182                 {
183                         float ts_min = 0, ts_max = 0;
184                         entity tm = teams.sort_next;
185                         if (tm)
186                         {
187                                 for (; tm.sort_next; tm = tm.sort_next)
188                                 {
189                                         if(!tm.team_size || tm.team == NUM_SPECTATOR)
190                                                 continue;
191                                         if(!ts_min) ts_min = tm.team_size;
192                                         else ts_min = min(ts_min, tm.team_size);
193                                         if(!ts_max) ts_max = tm.team_size;
194                                         else ts_max = max(ts_max, tm.team_size);
195                                 }
196                                 if ((ts_max - ts_min) > 1)
197                                 {
198                                         s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
199                                         tm = GetTeam(myteam, false);
200                                         if (tm && tm.team != NUM_SPECTATOR && tm.team_size == ts_max)
201                                                 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey(_("team menu"), "menu_showteamselect"), blinkcolor));
202                                         InfoMessage(s);
203                                 }
204                         }
205                 }
206
207                 if(autocvar_cl_showspectators)
208                 if(num_spectators)
209                 //if(spectatee_status != -1)
210                 {
211                         s = ((spectatee_status) ? _("^1Spectating this player:") : _("^1Spectating you:"));
212                         // InfoMessage(s)
213                         int limit = min(num_spectators, MAX_SPECTATORS);
214                         for(int i = 0; i < limit; ++i)
215                         {
216                                 float slot = spectatorlist[i];
217                                 if(i == 0)
218                                         s = strcat(s, " ^7", entcs_GetName(slot));
219                                 else
220                                         s = strcat("^7", entcs_GetName(slot));
221                                 InfoMessage(s);
222                         }
223                 }
224         }
225         else
226         {
227                 InfoMessage(_("^7Press ^3ESC ^7to show HUD options."));
228                 InfoMessage(_("^3Doubleclick ^7a panel for panel-specific options."));
229                 InfoMessage(_("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and"));
230                 InfoMessage(_("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments."));
231         }
232 }