]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/infomessages.qc
Dynamic HUD: Rework panel resizing/shifting in a cleaner way and implement proper...
[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 #define drawInfoMessage(s) MACRO_BEGIN {                                                                                                                                                        \
9         if(autocvar_hud_panel_infomessages_flip)                                                                                                                                                \
10                 o.x = pos.x + mySize.x - stringwidth(s, true, fontsize);                                                                                                        \
11         drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);                                                                                                               \
12         o.y += fontsize.y;                                                                                                                                                                                              \
13 } MACRO_END
14 void HUD_InfoMessages()
15 {
16         if(!autocvar__hud_configure)
17         {
18                 if(!autocvar_hud_panel_infomessages) return;
19         }
20
21         HUD_Panel_UpdateCvars();
22         vector pos, mySize;
23         pos = panel_pos;
24         mySize = panel_size;
25
26         HUD_Scale_Enable();
27         HUD_Panel_DrawBg(1);
28         if(panel_bg_padding)
29         {
30                 pos += '1 1 0' * panel_bg_padding;
31                 mySize -= '2 2 0' * panel_bg_padding;
32         }
33
34         // always force 5:1 aspect
35         vector newSize = '0 0 0';
36         if(mySize.x/mySize.y > 5)
37         {
38                 newSize.x = 5 * mySize.y;
39                 newSize.y = mySize.y;
40
41                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
42         }
43         else
44         {
45                 newSize.y = 1/5 * mySize.x;
46                 newSize.x = mySize.x;
47
48                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
49         }
50
51         mySize = newSize;
52         entity tm;
53         vector o;
54         o = pos;
55
56         vector fontsize;
57         fontsize = '0.20 0.20 0' * mySize.y;
58
59         float a;
60         a = panel_fg_alpha;
61
62         string s;
63         if(!autocvar__hud_configure)
64         {
65                 if(spectatee_status)
66                 {
67                         a = 1;
68                         if(spectatee_status == -1)
69                                 s = _("^1Observing");
70                         else
71                                 s = sprintf(_("^1Spectating: ^7%s"), entcs_GetName(current_player));
72                         drawInfoMessage(s);
73
74                         if(spectatee_status == -1)
75                                 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
76                         else
77                                 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
78                         drawInfoMessage(s);
79
80                         if(spectatee_status == -1)
81                                 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
82                         else
83                                 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
84                         drawInfoMessage(s);
85
86                         s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
87                         drawInfoMessage(s);
88
89                         if(gametype == MAPINFO_TYPE_LMS)
90                         {
91                                 entity sk;
92                                 sk = playerslots[player_localnum];
93                                 if(sk.(scores[ps_primary]) >= 666)
94                                         s = _("^1Match has already begun");
95                                 else if(sk.(scores[ps_primary]) > 0)
96                                         s = _("^1You have no more lives left");
97                                 else
98                                         s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
99                         }
100                         else
101                                 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
102                         drawInfoMessage(s);
103                 }
104
105                 if (time < STAT(GAMESTARTTIME))
106                 {
107                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
108                         float countdown = ceil(STAT(GAMESTARTTIME) - time);
109                         s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
110                         drawInfoMessage(s);
111                 }
112
113                 if(warmup_stage)
114                 {
115                         s = _("^2Currently in ^1warmup^2 stage!");
116                         drawInfoMessage(s);
117                 }
118
119                 string blinkcolor;
120                 if(time % 1 >= 0.5)
121                         blinkcolor = "^1";
122                 else
123                         blinkcolor = "^3";
124
125                 if(ready_waiting && !spectatee_status)
126                 {
127                         if(ready_waiting_for_me)
128                         {
129                                 if(warmup_stage)
130                                         s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
131                                 else
132                                         s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
133                         }
134                         else
135                         {
136                                 if(warmup_stage)
137                                         s = _("^2Waiting for others to ready up to end warmup...");
138                                 else
139                                         s = _("^2Waiting for others to ready up...");
140                         }
141                         drawInfoMessage(s);
142                 }
143                 else if(warmup_stage && !spectatee_status)
144                 {
145                         s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
146                         drawInfoMessage(s);
147                 }
148
149                 if(teamplay && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
150                 {
151                         float ts_min = 0, ts_max = 0;
152                         tm = teams.sort_next;
153                         if (tm)
154                         {
155                                 for (; tm.sort_next; tm = tm.sort_next)
156                                 {
157                                         if(!tm.team_size || tm.team == NUM_SPECTATOR)
158                                                 continue;
159                                         if(!ts_min) ts_min = tm.team_size;
160                                         else ts_min = min(ts_min, tm.team_size);
161                                         if(!ts_max) ts_max = tm.team_size;
162                                         else ts_max = max(ts_max, tm.team_size);
163                                 }
164                                 if ((ts_max - ts_min) > 1)
165                                 {
166                                         s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
167                                         tm = GetTeam(myteam, false);
168                                         if (tm)
169                                         if (tm.team != NUM_SPECTATOR)
170                                         if (tm.team_size == ts_max)
171                                                 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
172                                         drawInfoMessage(s);
173                                 }
174                         }
175                 }
176         }
177         else
178         {
179                 s = _("^7Press ^3ESC ^7to show HUD options.");
180                 drawInfoMessage(s);
181                 s = _("^3Doubleclick ^7a panel for panel-specific options.");
182                 drawInfoMessage(s);
183                 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
184                 drawInfoMessage(s);
185                 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
186                 drawInfoMessage(s);
187         }
188 }