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