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