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