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