3 #include "strafehud.qh"
5 #include <client/autocvars.qh>
6 #include <client/miscfunctions.qh>
7 #include <common/animdecide.qh>
8 #include <common/ent_cs.qh>
9 #include <common/mapinfo.qh>
10 #include <common/physics/movetypes/movetypes.qh>
11 #include <common/physics/player.qh>
12 #include <lib/csqcmodel/cl_player.qh>
16 void HUD_StrafeHUD_Export(int fh)
18 // allow saving cvars that aesthetically change the panel into hud skin files
23 float demo_angle = -37;
24 float demo_direction = 1;
26 bool state_onground = false;
27 float state_onground_time = 0;
28 bool state_strafekeys = false;
29 float state_strafekeys_time = 0;
33 bool state_fwd = true;
34 bool state_fwd_prev = true;
35 float state_fwd_time = 0;
37 // provide basic panel cvars to old clients
38 // TODO remove them after a future release (0.8.2+)
39 noref string autocvar_hud_panel_strafehud_pos = "0.320000 0.570000";
40 noref string autocvar_hud_panel_strafehud_size = "0.360000 0.020000";
41 noref string autocvar_hud_panel_strafehud_bg = "0";
42 noref string autocvar_hud_panel_strafehud_bg_color = "";
43 noref string autocvar_hud_panel_strafehud_bg_color_team = "";
44 noref string autocvar_hud_panel_strafehud_bg_alpha = "0.7";
45 noref string autocvar_hud_panel_strafehud_bg_border = "";
46 noref string autocvar_hud_panel_strafehud_bg_padding = "";
53 // generic hud routines
54 if(!autocvar__hud_configure)
56 if(!autocvar_hud_panel_strafehud ||
57 (spectatee_status == -1 && (autocvar_hud_panel_strafehud == 1 || autocvar_hud_panel_strafehud == 3)) ||
58 (autocvar_hud_panel_strafehud == 3 && !(ISGAMETYPE(RACE) || ISGAMETYPE(CTS)))) return;
61 HUD_Panel_LoadCvars();
63 if(autocvar_hud_panel_strafehud_dynamichud)
76 panel_pos += '1 1 0' * panel_bg_padding;
77 panel_size -= '2 2 0' * panel_bg_padding;
80 // find out whether the local csqcmodel entity is valid
81 if(spectatee_status > 0 || isdemo())
84 strafeplayer = CSQCModel_server2csqc(player_localentnum - 1);
89 strafeplayer = csqcplayer;
93 if(csqcplayer && strafeplayer)
96 bool onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
98 bool swimming = strafeplayer.waterlevel >= WATERLEVEL_SWIMMING;
99 float speed = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337; // use local csqcmodel entity for this even when spectating, flickers too much otherwise
100 float maxspeed_crouch_mod = IS_DUCKED(strafeplayer) && !swimming ? .5 : 1;
101 float maxspeed_water_mod = swimming ? .7 : 1; // very simplified water physics, the hud will not work well (and is not supposed to) while swimming
102 float maxspeed_phys = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer);
103 float maxspeed = !autocvar__hud_configure ? maxspeed_phys * maxspeed_crouch_mod * maxspeed_water_mod : 320;
104 float vel_angle = vectoangles(strafeplayer.velocity).y;
105 float view_angle = PHYS_INPUT_ANGLES(strafeplayer).y + 180;
107 vector movement = PHYS_INPUT_MOVEVALUES(strafeplayer);
108 int keys = STAT(PRESSED_KEYS);
113 int mode = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0;
114 float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
115 float antiflicker_speed = max(0, autocvar_hud_panel_strafehud_antiflicker_speed);
117 float shift_offset = 0;
118 bool straight_overturn = false;
119 bool immobile = speed <= (swimming ? antiflicker_speed : 0);
121 float neutral_offset;
123 vector currentangle_color = autocvar_hud_panel_strafehud_angle_neutral_color;
124 float currentangle_offset;
125 vector currentangle_size = '0 0 0';
128 bool bestangle_anywhere = false;
129 float bestangle_offset;
130 float switch_bestangle_offset;
131 bool odd_angles = false;
132 float odd_bestangle_offset = 0;
133 float switch_odd_bestangle_offset = 0;
134 float bestangle_width;
135 float accelzone_left_offset;
136 float accelzone_right_offset;
137 float accelzone_width;
138 float overturn_offset;
139 float overturn_width;
140 float slickdetector_height;
141 vector direction_size_vertical = '0 0 0';
142 vector direction_size_horizontal = '0 0 0';
143 float range_minangle;
145 // determine whether the player is pressing forwards or backwards keys
146 if(islocal) // if entity is local player
152 else if(movement.x < 0)
161 else // alternatively determine direction by querying pressed keys
163 if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD))
167 else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD))
177 // determine player wishdir
178 if(islocal) // if entity is local player
186 else if(movement.y > 0)
203 wishangle = RAD2DEG * atan2(movement.y, movement.x);
204 // wrap the wish angle if it exceeds ±90°
205 if(fabs(wishangle) > 90)
207 if(wishangle < 0) wishangle += 180;
208 else wishangle -= 180;
209 wishangle = -wishangle;
214 else // alternatively calculate wishdir by querying pressed keys
216 if(keys & KEY_FORWARD || keys & KEY_BACKWARD)
228 else if(!(keys & KEY_RIGHT))
230 wishangle = 0; // wraps at 180°
234 strafekeys = fabs(wishangle) == 90;
236 // determine minimum required angle to display full strafe range
237 range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree
238 if(range_minangle > 45) // minimum angle range is 45
240 range_minangle = 45 - fabs(wishangle) % 45;
242 range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45
243 range_minangle *= 2; // multiply to accommodate for both sides of the hud
245 if(autocvar_hud_panel_strafehud_range == 0)
247 if(autocvar__hud_configure)
253 hudangle = range_minangle; // use minimum angle required if dynamically setting hud angle
258 hudangle = bound(0, fabs(autocvar_hud_panel_strafehud_range), 360); // limit HUD range to 360 degrees, higher values don't make sense
261 // detect air strafe turning
262 if(onground != state_onground)
264 state_onground_time = time;
266 state_onground = onground;
268 if(strafekeys != state_strafekeys)
270 state_strafekeys_time = time;
272 state_strafekeys = strafekeys;
274 if((keys & KEY_FORWARD) || (keys & KEY_BACKWARD) || swimming || autocvar__hud_configure)
280 if((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_ground) // timeout for strafe jumping in general
285 else // air strafe only
289 if(((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_air) || (keys & KEY_JUMP)) // timeout for slick ramps
291 turn = true; // CPMA turning
292 turnangle = wishangle;
295 else if((time - state_strafekeys_time) >= autocvar_hud_panel_strafehud_timeout_turn) // timeout for jumping with strafe keys only
302 maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no modifiers here because they don't affect air strafing
303 wishangle = turnangle;
306 minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? maxspeed + antiflicker_speed : autocvar_hud_panel_strafehud_switch_minspeed;
308 // get current strafing angle ranging from -180° to +180°
309 if(!autocvar__hud_configure)
313 // calculate view angle relative to the players current velocity direction
314 angle = vel_angle - view_angle;
316 // if the angle goes above 180° or below -180° wrap it to the opposite side
317 if (angle > 180) angle -= 360;
318 else if(angle < -180) angle += 360;
320 // shift the strafe angle by 180° for hud calculations
321 if(angle < 0) angle += 180;
324 // determine whether the player is strafing forwards or backwards
325 // if the player isn't strafe turning use forwards/backwards keys to determine direction
332 else if(keys_fwd < 0)
338 state_fwd = fabs(angle) <= 90;
341 // otherwise determine by examining the strafe angle
344 if(wishangle < 0) // detect direction using wishangle since the direction is not yet set
346 state_fwd = angle <= -wishangle;
350 state_fwd = angle >= -wishangle;
354 if(state_fwd_prev != state_fwd)
356 state_fwd_time = time;
358 state_fwd_prev = state_fwd;
360 if((time - state_fwd_time) >= autocvar_hud_panel_strafehud_timeout_direction || speed < maxspeed || (strafekeys && mode == 0)) // timeout when changing between forwards and backwards movement
365 // shift the strafe angle by 180° when strafing backwards
368 if(angle < 0) angle += 180;
372 // don't make the angle indicator switch side too much at ±180° if anti flicker is turned on
373 if(angle > (180 - antiflicker_angle) || angle < (-180 + antiflicker_angle))
375 straight_overturn = true;
383 else // simulate turning for HUD setup
386 if(autocvar__hud_panel_strafehud_demo && ((time - demo_time) >= .025))
389 demo_angle += demo_direction;
390 if(fabs(demo_angle) >= 55)
392 demo_direction = -demo_direction;
396 wishangle = 45 * (demo_angle > 0 ? 1 : -1);
399 // invert the wish angle when strafing backwards
402 wishangle = -wishangle;
405 // flip angles if v_flipped is enabled
406 if(autocvar_v_flipped)
409 wishangle = -wishangle;
412 // determine whether the player is strafing left or right
415 direction = wishangle > 0 ? 1 : -1;
419 direction = (angle > antiflicker_angle && angle < (180 - antiflicker_angle)) ? 1 : (angle < -antiflicker_angle && angle > (-180 + antiflicker_angle)) ? -1 : 0;
422 // best angle to strafe at
423 bestangle = (speed > maxspeed ? acos(maxspeed / speed) : 0) * RAD2DEG * (direction < 0 ? -1 : 1);
424 odd_bestangle = -bestangle - wishangle;
425 bestangle -= wishangle;
427 // various offsets and size calculations of hud indicator elements
428 // how much is hidden by the current hud angle
429 hidden_width = (360 - hudangle) / hudangle * panel_size.x;
431 currentangle_size.x = max(panel_size.x * autocvar_hud_panel_strafehud_angle_width, 1);
434 currentangle_offset = angle/hudangle * panel_size.x;
438 currentangle_offset = bound(-hudangle/2, angle, hudangle/2)/hudangle * panel_size.x + panel_size.x/2;
440 currentangle_size.y = max(panel_size.y * min(autocvar_hud_panel_strafehud_angle_height, 2), 1);
441 // best strafe acceleration angle
442 bestangle_offset = bestangle/hudangle * panel_size.x + panel_size.x/2;
443 switch_bestangle_offset = -bestangle/hudangle * panel_size.x + panel_size.x/2;
444 bestangle_width = max(panel_size.x * autocvar_hud_panel_strafehud_switch_width, 1);
446 if(((angle > -wishangle && direction < 0) || (angle < -wishangle && direction > 0)) && (direction != 0))
449 odd_bestangle_offset = odd_bestangle/hudangle * panel_size.x + panel_size.x/2;
450 switch_odd_bestangle_offset = (odd_bestangle+bestangle*2)/hudangle * panel_size.x + panel_size.x/2;
452 // direction indicator
453 direction_size_vertical.x = max(panel_size.y * min(autocvar_hud_panel_strafehud_direction_width, .5), 1);
454 direction_size_vertical.y = panel_size.y;
455 direction_size_horizontal.x = max(panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5), direction_size_vertical.x);
456 direction_size_horizontal.y = direction_size_vertical.x;
458 overturn_width = 180/hudangle * panel_size.x;
460 // the neutral zone fills the whole strafe bar
464 if(panel_size.x > 0 && panel_size.y > 0 && autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha > 0)
466 switch(autocvar_hud_panel_strafehud_style)
470 drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
474 HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
480 // calculate various zones of the strafe-o-meter
481 accelzone_width = overturn_offset = (90 - fabs(bestangle + wishangle))/hudangle * panel_size.x;
482 accelzone_right_offset = 0;
483 accelzone_left_offset = overturn_offset + overturn_width;
484 neutral_width = 360/hudangle * panel_size.x - accelzone_width*2 - overturn_width;
485 neutral_offset = direction < 0 ? accelzone_left_offset + accelzone_width : -neutral_width;
487 // remove switch indicator width from offset
490 bestangle_offset -= bestangle_width;
491 switch_odd_bestangle_offset -= bestangle_width;
495 switch_bestangle_offset -= bestangle_width;
496 odd_bestangle_offset -= bestangle_width;
499 // shift hud if operating in view angle centered mode
502 shift_offset = -currentangle_offset;
503 bestangle_offset += shift_offset;
504 switch_bestangle_offset += shift_offset;
505 odd_bestangle_offset += shift_offset;
506 switch_odd_bestangle_offset += shift_offset;
508 if(direction < 0) shift_offset += -360/hudangle * panel_size.x;
509 // calculate how far off-center the strafe zones currently are
510 shift_offset += (panel_size.x + neutral_width)/2 - wishangle/hudangle * panel_size.x;
511 // shift strafe zones into correct place
512 neutral_offset += shift_offset;
513 accelzone_left_offset += shift_offset;
514 accelzone_right_offset += shift_offset;
515 overturn_offset += shift_offset;
517 // draw left acceleration zone
518 HUD_Panel_DrawStrafeHUD(accelzone_left_offset, accelzone_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, 1);
520 // draw right acceleration zone
521 HUD_Panel_DrawStrafeHUD(accelzone_right_offset, accelzone_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, 2);
523 // draw overturn zone
524 HUD_Panel_DrawStrafeHUD(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_bar_overturn_color, autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, 3);
527 HUD_Panel_DrawStrafeHUD(neutral_offset, neutral_width, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, 0);
529 if(direction != 0 && direction_size_vertical.x > 0 && autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha > 0)
531 bool indicator_direction = direction < 0;
532 // invert left/right when strafing backwards or when strafing towards the opposite side indicated by the direction variable
533 // if both conditions are true then it's inverted twice hence not inverted at all
534 if(!fwd != odd_angles)
536 indicator_direction = !indicator_direction;
538 // draw the direction indicator caps at the sides of the hud
540 if(direction_size_vertical.y > 0) drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x), direction_size_vertical, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
541 // top horizontal line
542 drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) - eY * direction_size_horizontal.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
543 // bottom horizontal line
544 drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) + eY * panel_size.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
547 if(speed >= minspeed) // only draw indicators if minspeed is reached
549 // draw best angles for acceleration
550 float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset;
551 float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset;
552 // both indicators are inactive if no direction can be determined
553 vector switch_color = direction != 0 ? autocvar_hud_panel_strafehud_switch_active_color : autocvar_hud_panel_strafehud_switch_inactive_color;
554 float switch_alpha = direction != 0 ? autocvar_hud_panel_strafehud_switch_active_alpha : autocvar_hud_panel_strafehud_switch_inactive_alpha;
555 // draw the switch indicators
556 HUD_Panel_DrawStrafeHUD(switch_offset, bestangle_width, autocvar_hud_panel_strafehud_switch_inactive_color, autocvar_hud_panel_strafehud_switch_inactive_alpha * panel_fg_alpha, 0, 0);
557 HUD_Panel_DrawStrafeHUD(offset, bestangle_width, switch_color, switch_alpha * panel_fg_alpha, 0, 0);
561 slickdetector_height = panel_size.y * bound(0, autocvar_hud_panel_strafehud_slickdetector_height, 0.5);
562 if(autocvar_hud_panel_strafehud_slickdetector_range > 0 && autocvar_hud_panel_strafehud_slickdetector_alpha > 0 && slickdetector_height > 0 && panel_size.x > 0) // dunno if slick detection works in spectate
564 float slicksteps = 90 / pow(2, bound(0, autocvar_hud_panel_strafehud_slickdetector_granularity, 4));
565 bool slickdetected = false;
567 slickdetected = IS_ONSLICK(strafeplayer); // don't need to traceline if already touching slick
569 // traceline into every direction
570 trace_dphitq3surfaceflags = 0;
571 for(float i = 0; i < 360 && !slickdetected; i += slicksteps)
575 slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
576 slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
577 if(i != 0 && i != 180)
579 for(float j = 0; j < 180 && !slickdetected; j += slicksteps)
581 slickoffset.x = sin(j * DEG2RAD) * slickrotate;
582 slickoffset.y = cos(j * DEG2RAD) * slickrotate;
584 traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL);
585 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
590 slickoffset.x = slickoffset.y = 0;
591 traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL);
592 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
596 // if a traceline hit a slick surface
599 vector slickdetector_size = panel_size;
600 slickdetector_size.y = slickdetector_height;
601 // top horizontal line
602 drawfill(panel_pos - eY * slickdetector_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
603 // bottom horizontal line
604 drawfill(panel_pos + eY * panel_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
608 if(speed < (maxspeed + antiflicker_speed) && !immobile)
610 bestangle_anywhere = true; // moving forward should suffice to gain speed
613 // draw the actual strafe angle
614 if(!bestangle_anywhere && !immobile) // player gains speed with strafing
616 if((direction > 0 && (angle >= bestangle || angle <= -(bestangle + wishangle*2))) ||
617 (direction < 0 && (angle <= bestangle || angle >= -(bestangle + wishangle*2))))
618 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
621 if(fabs(angle + wishangle) > 90) // player is overturning
623 currentangle_color = autocvar_hud_panel_strafehud_angle_overturn_color;
625 else if(bestangle_anywhere) // player gains speed without strafing
627 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
630 if(mode == 0 || straight_overturn)
632 currentangle_offset = panel_size.x/2;
635 if(autocvar_hud_panel_strafehud_style == 2 && !immobile)
637 float moveangle = angle + wishangle;
638 float strafeangle = (bestangle + wishangle) * (direction < 0 ? -1 : 1);
639 float strafe_ratio = 0;
640 if(fabs(moveangle) > 90)
642 strafe_ratio = -((fabs(moveangle) - 90) / 90);
643 if(strafe_ratio < -1) strafe_ratio = -2 - strafe_ratio;
647 if(moveangle >= strafeangle)
649 strafe_ratio = 1 - (moveangle - strafeangle) / (90 - strafeangle);
651 else if(moveangle <= -strafeangle)
653 strafe_ratio = 1 - (moveangle + strafeangle) / (-90 + strafeangle);
658 currentangle_color = StrafeHUD_mixColors(autocvar_hud_panel_strafehud_angle_neutral_color, autocvar_hud_panel_strafehud_angle_overturn_color, -strafe_ratio);
662 currentangle_color = StrafeHUD_mixColors(autocvar_hud_panel_strafehud_angle_neutral_color, autocvar_hud_panel_strafehud_angle_accel_color, strafe_ratio);
666 if(currentangle_size.x > 0 && currentangle_size.y > 0 && autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0)
668 drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
673 // functions to make hud elements align perfectly in the hud area
674 void HUD_Panel_DrawStrafeHUD(float offset, float width, vector color, float alpha, int type, int gradientType)
676 float mirror_offset, mirror_width;
677 vector size = panel_size;
678 vector mirror_size = panel_size;
680 float original_width = width;
681 float hiddencolor_width;
683 if(alpha <= 0 && type != 2 || width <= 0) return;
685 if(type == 2 && gradientType == 0) type = 0;
689 mirror_width = min(fabs(offset), width);
690 mirror_offset = panel_size.x + hidden_width - fabs(offset);
696 mirror_width = min(offset + width - panel_size.x - hidden_width, width);
697 mirror_offset = max(offset - panel_size.x - hidden_width, 0);
699 if((offset + width) > panel_size.x)
701 width = panel_size.x - offset;
703 if(mirror_offset < 0)
705 mirror_width += mirror_offset;
708 if((mirror_offset + mirror_width) > panel_size.x)
710 mirror_width = panel_size.x - mirror_offset;
713 if(width < 0) width = 0;
714 if(mirror_width < 0) mirror_width = 0;
715 hiddencolor_width = original_width - width - mirror_width;
717 if(direction < 0) // swap mirror and non-mirror values if direction points left
719 offset += mirror_offset;
720 mirror_offset = offset - mirror_offset;
721 offset -= mirror_offset;
723 width += mirror_width;
724 mirror_width = width - mirror_width;
725 width -= mirror_width;
729 mirror_size.x = mirror_width;
734 case 0: // no styling (drawfill)
735 if(mirror_size.x > 0 && mirror_size.y > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha, DRAWFLAG_NORMAL);
736 if(size.x > 0 && size.y > 0) drawfill(panel_pos + eX * offset, size, color, alpha, DRAWFLAG_NORMAL);
739 case 1: // progress bar style
740 if(mirror_size.x > 0 && mirror_size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * mirror_offset, mirror_size, "progressbar", 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
741 if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
744 case 2: // gradient style (types: 1 = left, 2 = right, 3 = both)
745 StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, mirror_size, original_width, mirror_offset, alpha, width + (mirror_offset == 0 ? hiddencolor_width : 0), gradientType);
746 StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, size, original_width, offset, alpha, (offset == 0 ? hiddencolor_width : 0), gradientType);
750 vector StrafeHUD_mixColors(vector color1, vector color2, float ratio)
753 if(ratio <= 0) return color1;
754 if(ratio >= 1) return color2;
755 mixedColor.x = color1.x + (color2.x - color1.x) * ratio;
756 mixedColor.y = color1.y + (color2.y - color1.y) * ratio;
757 mixedColor.z = color1.z + (color2.z - color1.z) * ratio;
761 void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradientOffset, int gradientType)
763 float color_ratio, alpha1, alpha2;
764 vector gradient_size = size;
765 alpha1 = bound(0, alpha, 1);
766 alpha2 = bound(0, autocvar_hud_panel_strafehud_bar_neutral_alpha, 1);
767 if((alpha1+alpha2) == 0) return;
768 color_ratio = alpha1/(alpha1+alpha2);
769 for(int i = 0; i < size.x; ++i)
771 float ratio, alpha_ratio, combine_ratio1, combine_ratio2;
772 gradient_size.x = size.x - i < 1 ? size.x - i : 1;
773 ratio = (i + gradientOffset) / original_width * (gradientType == 3 ? 2 : 1);
774 if(ratio > 1) ratio = 2 - ratio;
775 if(gradientType != 2) ratio = 1 - ratio;
776 alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio;
777 combine_ratio1 = ratio*(1-color_ratio);
778 combine_ratio2 = (1-ratio)*color_ratio;
779 ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1/(combine_ratio1 + combine_ratio2);
780 if(alpha_ratio > 0) drawfill(panel_pos + eX * (offset + i), gradient_size, StrafeHUD_mixColors(color1, color2, ratio), alpha_ratio, DRAWFLAG_NORMAL);