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