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