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