]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up HUD code:
authorterencehill <piuntn@gmail.com>
Thu, 8 Oct 2015 19:02:50 +0000 (21:02 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 8 Oct 2015 19:02:50 +0000 (21:02 +0200)
* vehicle crosshair code is now separated from vehicle HUD code and gets called right after the normal crosshair code
* the new function HUD_Draw() takes care of drawing HUD and crosshair, instead of UpdateCrosshair(!)

qcsrc/client/view.qc
qcsrc/common/vehicles/cl_vehicles.qc
qcsrc/common/vehicles/vehicle.qh
qcsrc/common/vehicles/vehicle/bumblebee.qc
qcsrc/common/vehicles/vehicle/racer.qc
qcsrc/common/vehicles/vehicle/raptor.qc
qcsrc/common/vehicles/vehicle/spiderbot.qc

index 3bb5585f35931ce09cd01f96c4be1741f725fd82..defec0708fb3d643f51162b0597c9bad04983233 100644 (file)
@@ -457,6 +457,31 @@ bool WantEventchase()
        return false;
 }
 
+void HUD_Vehicle()
+{
+       if(!hud || intermission)
+               return;
+
+       if(hud == HUD_BUMBLEBEE_GUN)
+               CSQC_BUMBLE_GUN_HUD();
+       else {
+               Vehicle info = get_vehicleinfo(hud);
+               info.vr_hud(info);
+       }
+}
+
+void HUD_Crosshair_Vehicle()
+{
+       if(!hud || intermission)
+               return;
+
+       if(hud != HUD_BUMBLEBEE_GUN)
+       {
+               Vehicle info = get_vehicleinfo(hud);
+               info.vr_crosshair(info);
+       }
+}
+
 vector damage_blurpostprocess, content_blurpostprocess;
 
 float unaccounted_damage = 0;
@@ -484,7 +509,7 @@ void UpdateDamage()
        spectatee_status_prev = spectatee_status;
 }
 
-void UpdateHitsound()
+void HitSound()
 {
        // varying sound pitch
 
@@ -533,34 +558,13 @@ void UpdateHitsound()
        }
 }
 
-void UpdateCrosshair()
+void HUD_Crosshair()
 {SELFPARAM();
        static float rainbow_last_flicker;
     static vector rainbow_prev_color;
        entity e = self;
        float f, i, j;
        vector v;
-       if(getstati(STAT_FROZEN))
-               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, ((getstatf(STAT_REVIVE_PROGRESS)) ? ('0.25 0.90 1' + ('1 0 0' * getstatf(STAT_REVIVE_PROGRESS)) + ('0 1 1' * getstatf(STAT_REVIVE_PROGRESS) * -1)) : '0.25 0.90 1'), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-       else if (getstatf(STAT_HEALING_ORB)>time)
-               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, NADE_TYPE_HEAL.m_color, autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
-       if(!intermission)
-       if(getstatf(STAT_NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
-       {
-               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_NADE_TIMER), '0.25 0.90 1' + ('1 0 0' * getstatf(STAT_NADE_TIMER)) - ('0 1 1' * getstatf(STAT_NADE_TIMER)), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-               drawstring_aspect(eY * 0.64 * vid_conheight, ((autocvar_cl_nade_timer == 2) ? _("Nade timer") : ""), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
-       }
-       else if(getstatf(STAT_REVIVE_PROGRESS))
-       {
-               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_REVIVE_PROGRESS), '0.25 0.90 1', autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
-               drawstring_aspect(eY * 0.64 * vid_conheight, _("Revival progress"), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
-       }
-
-       if(autocvar_r_letterbox == 0)
-               if(autocvar_viewsize < 120)
-                       CSQC_common_hud();
-
-       // crosshair goes VERY LAST
        if(!scoreboard_active && !camera_active && intermission != 2 &&
                spectatee_status != -1 && hud == HUD_NORMAL && !csqcplayer.viewloc &&
                !HUD_MinigameMenu_IsOpened() )
@@ -1007,6 +1011,35 @@ void UpdateCrosshair()
        }
 }
 
+void HUD_Draw()
+{
+       if(getstati(STAT_FROZEN))
+               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, ((getstatf(STAT_REVIVE_PROGRESS)) ? ('0.25 0.90 1' + ('1 0 0' * getstatf(STAT_REVIVE_PROGRESS)) + ('0 1 1' * getstatf(STAT_REVIVE_PROGRESS) * -1)) : '0.25 0.90 1'), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
+       else if (getstatf(STAT_HEALING_ORB)>time)
+               drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, NADE_TYPE_HEAL.m_color, autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
+       if(!intermission)
+       if(getstatf(STAT_NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
+       {
+               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_NADE_TIMER), '0.25 0.90 1' + ('1 0 0' * getstatf(STAT_NADE_TIMER)) - ('0 1 1' * getstatf(STAT_NADE_TIMER)), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
+               drawstring_aspect(eY * 0.64 * vid_conheight, ((autocvar_cl_nade_timer == 2) ? _("Nade timer") : ""), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
+       }
+       else if(getstatf(STAT_REVIVE_PROGRESS))
+       {
+               DrawCircleClippedPic(eX * 0.5 * vid_conwidth + eY * 0.6 * vid_conheight, 0.1 * vid_conheight, "gfx/crosshair_ring.tga", getstatf(STAT_REVIVE_PROGRESS), '0.25 0.90 1', autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
+               drawstring_aspect(eY * 0.64 * vid_conheight, _("Revival progress"), eX * vid_conwidth + eY * 0.025 * vid_conheight, '1 1 1', 1, DRAWFLAG_NORMAL);
+       }
+
+       if(autocvar_r_letterbox == 0)
+               if(autocvar_viewsize < 120)
+                       CSQC_common_hud();
+
+       // crosshair goes VERY LAST
+       UpdateDamage();
+       HUD_Crosshair();
+       HUD_Crosshair_Vehicle();
+       HitSound();
+}
+
 bool ov_enabled;
 float oldr_nearclip;
 float oldr_farclip_base;
@@ -1810,9 +1843,7 @@ void CSQC_UpdateView(float w, float h)
 
        scoreboard_active = HUD_WouldDrawScoreboard();
 
-       UpdateDamage();
-       UpdateCrosshair();
-       UpdateHitsound();
+       HUD_Draw();
 
        if(NextFrameCommand)
        {
@@ -1856,14 +1887,6 @@ void CSQC_UpdateView(float w, float h)
        else
                HUD_Radar_Mouse();
 
-    if(hud && !intermission)
-    if(hud == HUD_BUMBLEBEE_GUN)
-       CSQC_BUMBLE_GUN_HUD();
-    else {
-       Vehicle info = get_vehicleinfo(hud);
-               info.vr_hud(info);
-       }
-
        cl_notice_run();
 
        // let's reset the view back to normal for the end
@@ -1871,13 +1894,13 @@ void CSQC_UpdateView(float w, float h)
        setproperty(VF_SIZE, '1 0 0' * w + '0 1 0' * h);
 }
 
-
 void CSQC_common_hud(void)
 {
        if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
                Accuracy_LoadLevels();
 
        HUD_Main(); // always run these functions for alpha checks
+       HUD_Vehicle();
        HUD_DrawScoreboard();
 
        // scoreboard/accuracy, map/gametype voting screen
index 3472a7f1c7e7e76747e0b056ef22c31d12c589ca..07a3cc9fdc7f20f68b4751e9ed28bca56181b61e 100644 (file)
@@ -119,12 +119,9 @@ void Vehicles_drawHUD(
        string iconAmmo1,
        vector colorAmmo1,
        string iconAmmo2,
-       vector colorAmmo2,
-       string crosshair)
-{SELFPARAM();
-       if(autocvar_r_letterbox)
-               return;
-
+       vector colorAmmo2)
+{
+       SELFPARAM();
        if(scoreboard_showscores)
                return;
 
@@ -314,6 +311,13 @@ void Vehicles_drawHUD(
                        drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
                }
        }
+}
+
+void Vehicles_drawCrosshair(string crosshair)
+{
+       SELFPARAM();
+       vector tmpSize = '0 0 0';
+       vector tmpPos  = '0 0 0';
 
        // Raptor bomb crosshair
        if(hud == VEH_RAPTOR.vehicleid && weapon2mode != RSM_FLARE)
@@ -327,6 +331,7 @@ void Vehicles_drawHUD(
                        dropmark.gravity = 1;
                }
 
+               float reload2 = getstati(STAT_VEHICLESTAT_RELOAD2) * 0.01;
                if(reload2 == 1)
                {
                        setorigin(dropmark, pmove_org);
index 80787b4ae619eb8acda9abb09e101c698be384d3..58a2b7330eb517c282cc0662f6d8493a01eb2f0e 100644 (file)
@@ -48,6 +48,8 @@ CLASS(Vehicle, Object)
     METHOD(Vehicle, vr_impact, void(Vehicle)) { }
     /** (CLIENT) logic to run every frame */
     METHOD(Vehicle, vr_hud, void(Vehicle)) { }
+    /** (CLIENT) logic to run every frame */
+    METHOD(Vehicle, vr_crosshair, void(Vehicle)) { }
 ENDCLASS(Vehicle)
 
 // vehicle spawn flags (need them here for common registrations)
index b64ac0203171753c8c1e2a2e6944716d2ebadbc1..7f5bfea3a40a5f3f559e48daa1ab8d1ea3fd0266 100644 (file)
@@ -953,16 +953,18 @@ void CSQC_BUMBLE_GUN_HUD()
 {
        Vehicles_drawHUD("vehicle_gunner", "vehicle_gunner_weapon1", string_null,
                                         "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                        string_null, '0 0 0',
-                                        string_null);
+                                        string_null, '0 0 0');
 }
 
                METHOD(Bumblebee, vr_hud, void(Bumblebee thisveh))
                {
                        Vehicles_drawHUD(VEH_BUMBLEBEE.m_icon, "vehicle_bumble_weapon1", "vehicle_bumble_weapon2",
                                                         "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                                        vCROSS_HEAL);
+                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color);
+               }
+               METHOD(Bumblebee, vr_crosshair, void(Bumblebee thisveh))
+               {
+                       Vehicles_drawCrosshair(vCROSS_HEAL);
                }
                METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh))
                {
index 2b5950a259e8e780c6ae3a12fec2c654105a464e..38c6844d49415a1e7ded8d85823baf13c432cbfc 100644 (file)
@@ -655,8 +655,11 @@ void racer_draw()
                {
                        Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
                                                         "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
-                                                        vCROSS_GUIDE);
+                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
+               }
+               METHOD(Racer, vr_crosshair, void(Racer thisveh))
+               {
+                       Vehicles_drawCrosshair(vCROSS_GUIDE);
                }
 #endif
                METHOD(Racer, vr_setup, void(Racer thisveh))
index 1f623379e55d1c1d50224bb0e66278e655caadea..b170dd557de43e9eb802e085570fec75396231e5 100644 (file)
@@ -773,6 +773,12 @@ spawnfunc(vehicle_raptor)
 #ifdef CSQC
 
                METHOD(Raptor, vr_hud, void(Raptor thisveh))
+               {
+                       Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
+                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
+                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
+               }
+               METHOD(Raptor, vr_crosshair, void(Raptor thisveh))
                {
                        string crosshair;
 
@@ -783,10 +789,7 @@ spawnfunc(vehicle_raptor)
                                default:        crosshair = vCROSS_BURST;
                        }
 
-                       Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
-                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
-                                                        crosshair);
+                       Vehicles_drawCrosshair(crosshair);
                }
                METHOD(Raptor, vr_setup, void(Raptor thisveh))
                {
index ee79966ef3ae81cd0ea5b0aabd7cd839226440c9..7971cfb7937559f28cc3ebba8c5b63655846494e 100644 (file)
@@ -645,6 +645,12 @@ float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6;
 float autocvar_cl_vehicle_spiderbot_cross_size = 1;
 
                METHOD(Spiderbot, vr_hud, void(Spiderbot thisveh))
+               {
+                       Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2",
+                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
+                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
+               }
+               METHOD(Spiderbot, vr_crosshair, void(Spiderbot thisveh))
                {
                        string crosshair;
 
@@ -656,10 +662,7 @@ float autocvar_cl_vehicle_spiderbot_cross_size = 1;
                                default:             crosshair = vCROSS_BURST;
                        }
 
-                       Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2",
-                                                        "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
-                                                        "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
-                                                        crosshair);
+                       Vehicles_drawCrosshair(crosshair);
                }
                METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh))
                {