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