Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Radix_HUD : BaseStatusBar
- {
- HUDFont mHUDFont;
- Font numFont;
- int defwidth, defheight;
- int xhair_lock;
- int seconds_timer;
- float fade;
- bool dofadeout;
- bool draw_penergy;
- bool draw_pshield;
- bool draw_pjets;
- bool draw_pinvul;
- Array<Int> timers;
- float HUDAlpha;
- string TmpHUDText; // Used for displaying things like "weapon" selected stuff.
- float TmpTextTimer; // TTT :P
- bool Blink(int tics, bool onoff, int tselect=0)
- {
- int dotime;
- dotime = timers[tselect];
- if(onoff)
- {
- dotime++;
- if(dotime == tics) onoff = false;
- }
- else
- {
- dotime--;
- if(dotime == 0) onoff = true;
- }
- timers[tselect] = dotime;
- return onoff;
- }
- // References:
- // DrawImage(image, pos, flags, alpha, boxsize, scale);
- // DrawString(mHUDFont, str, pos, flags, translation, HUDAlpha, wrap, spacing);
- // All H_ function auto adjust to the screen resolution based on 1080p coords.
- void H_DrawImage(Name img, vector2 pos, uint flags=0, vector2 scale=(1,1), vector2 bsize = (-1,-1))
- {
- vector2 hscale = GetHUDScale();
- hscale = ( int(hscale.x), int(hscale.x) ); // Force even scalar.
- float rwidth = (Screen.getWidth() / float(defwidth)) / hscale.x;
- float rheight = Screen.getHeight() / float(defheight) / hscale.y;
- vector2 rscale = (scale.x * rwidth, scale.y * rheight);
- vector2 rpos = ( pos.x*rwidth, pos.y*rheight );
- DrawImage(img, rpos, flags, HUDAlpha, bsize, rscale);
- }
- void H_SetClipRect(int x, int y, int width, int height)
- {
- vector2 hscale = GetHUDScale();
- hscale = ( int(hscale.x), int(hscale.x) ); // Force even scalar.
- float rwidth = (Screen.getWidth() / float(defwidth)) / hscale.x;
- float rheight = Screen.getHeight() / float(defheight) / hscale.y;
- vector2 rpos = ( x*rwidth, y*rheight );
- SetClipRect( rpos.x, rpos.y, width*rwidth, height*rheight );
- }
- void H_DrawString(String str, vector2 pos, uint flags = 0, int translation = Font.CR_UNTRANSLATED)
- {
- vector2 hscale = GetHUDScale();
- hscale = ( int(hscale.x), int(hscale.x) ); // Force even scalar.
- float rwidth = (Screen.getWidth() / float(defwidth)) / hscale.x;
- float rheight = Screen.getHeight() / float(defheight) / hscale.y;
- vector2 rpos = ( pos.x*rwidth, pos.y*rheight );
- DrawString(mHUDFont, str, rpos, flags, translation, HUDAlpha);
- }
- void H_DrawNumbers(String strnums, vector2 pos, vector2 scale=(1,1), int spacing=1, bool transp=false)
- {
- // Due to the way the scaling is done this needs to be completely custom done.
- String lmp = "HNUMS";
- if(transp) lmp = "TNUMS";
- for(int i = 0; i < strnums.Length(); i++)
- {
- String lmp_num = lmp..strnums.CharAt(i);
- H_DrawImage(lmp_num,pos,0,scale);
- pos.x += (numFont.GetCharWidth("0")+spacing)*scale.x;
- }
- }
- override void Init()
- {
- Super.Init();
- SetSize(32, 320, 200);
- defwidth = 1920;
- defheight = 1080;
- HUDAlpha = 1.0;
- timers.Resize(4); // Setup powerup blink timers.
- // Create the font used for the fullscreen HUD
- Font fnt = "dbigfont";
- mHUDFont = HUDFont.Create(fnt);
- numFont = "RADIXNUMFONT";
- }
- override void Draw (int state, double TicFrac)
- {
- Super.Draw (state, TicFrac);
- if (state == HUD_StatusBar)
- {
- BeginStatusBar();
- DrawMainBar (TicFrac);
- DrawGlobalHUD();
- }
- else if (state == HUD_Fullscreen)
- {
- BeginHUD();
- DrawFullScreenStuff ();
- DrawGlobalHUD();
- }
- }
- override void Tick()
- {
- //console.printf("%d",seconds_timer);
- // Easy way to detect whenever another map is started.
- if(Level.maptime == 0) seconds_timer = 0;
- let plr = RadixShip(CPlayer.mo);
- if(plr)
- {
- if(Level.maptime%35 == 0 && plr.health > 0) seconds_timer++;
- if( TmpHUDText != plr.hVars.TextMsg )
- {
- TmpTextTimer = 35*5;
- TmpHUDText = plr.hVars.TextMsg;
- }
- // Clear HUD text so we are able to print the same thing later.
- if(TmpTextTimer <= 0 && TmpHUDText != "")
- {
- TmpHUDText = "";
- plr.ClearHUDText();
- }
- } // We don't simply return here because super.tick.
- if(TmpTextTimer > 0) TmpTextTimer --;
- Super.tick();
- }
- void Draw_Weapons()
- {
- let plr = RadixShip(CPlayer.mo);
- if(!plr) return;
- // Draw ammo counts.
- H_DrawNumbers(""..plr.countinv("RadixShells"),(198,810),(6.0,4.6));
- H_DrawNumbers(""..plr.countinv("RadixMissiles"),(456,810),(6.01,4.6));
- H_DrawNumbers(""..plr.countinv("RadixTorpedos"),(198,860),(6.0,4.6));
- H_DrawNumbers(""..plr.countinv("RadixNukes"),(456,860),(6.01,4.6));
- // Display got weapons and selected weapon/weapon ammo use.
- for( let w = plr.Inv; w != null; w = w.Inv )
- {
- let weap = RadixWeapon(w);
- if(!weap) continue;
- int slotnum = weap.SlotNumber;
- int selnum = plr.currentWeaponID;
- int xspacing = (slotnum-1)*50;
- if(slotnum != selnum)
- {
- H_DrawImage("WEAPGOT"..slotnum,(175+xspacing,769),0,(6.0,4.5));
- }
- else
- {
- H_DrawImage("WEAPSEL"..slotnum,(175+xspacing,769),0,(6.0,4.5));
- if(weap.AmmoType1)
- {
- String wammo = getDefaultByType(weap.AmmoType1).GetClassName();
- if(wammo == "RadixShells")
- {
- H_DrawImage("AMMOSEL",(192,824),0,(6.0,4.5));
- }
- if(wammo == "RadixMissiles")
- {
- H_DrawImage("AMMOSEL",(450,824),0,(6.0,4.5));
- }
- if(wammo == "RadixTorpedos")
- {
- H_DrawImage("AMMOSEL",(192,873),0,(6.0,4.5));
- }
- if(wammo == "RadixNukes")
- {
- H_DrawImage("AMMOSEL",(450,873),0,(6.0,4.5));
- }
- if(wammo == "GravityWaves")
- {
- int num = plr.countinv("GravityWaves");
- String formatnum = num < 10 ? "0"..num : ""..num;
- H_DrawNumbers(formatnum,(442,719),(6.0,4.6),1,true);
- }
- }
- }
- }
- }
- void Draw_Radar()
- {
- if(CPlayer && CPlayer.mo)
- {
- float scale = 10;
- let plr = RadixShip(CPlayer.mo);
- if(!plr) return;
- ThinkerIterator act_it = ThinkerIterator.Create("Actor");
- Actor obj;
- // Draw player on radar.
- H_DrawImage("RADARPLR",(981,773),0,(3.0,3.0));
- while(obj = Actor(act_it.Next()))
- {
- int dis = ExtendedMaths.point_distance(obj,Actor(CPlayer.mo),scale);
- if( dis < 70 )
- {
- int x = plr.x - obj.x;
- int y = plr.y - obj.y;
- int dx = ( y * cos((plr.angle) )) - ( x * sin((plr.angle)) );
- int dy = ( y * sin((plr.angle) )) + ( x * cos((plr.angle)) );
- dx /= scale;
- dy /= scale;
- // If we're not the player.
- let nplr = RadixShip(obj);
- if( nplr != plr )
- {
- if(obj.bSHOOTABLE) H_DrawImage("RADARIND",(dx-940,dy-124),0,(3.0,3.0));
- }
- }
- }
- }
- }
- void DrawKeys()
- {
- if(!CPlayer) return;
- bool locks[6];
- String image;
- for(int i = 0; i < 6; i++) locks[i] = CPlayer.mo.CheckKeys(i + 1, false, true);
- // key 1
- if (locks[1] && locks[4]) image = "STKEYS6";
- else if (locks[1]) image = "STKEYS0";
- else if (locks[4]) image = "STKEYS3";
- H_DrawImage(image, (32, 48+32),0,(6.0,4.6));
- // key 2
- if (locks[2] && locks[5]) image = "STKEYS7";
- else if (locks[2]) image = "STKEYS1";
- else if (locks[5]) image = "STKEYS4";
- else image = "";
- H_DrawImage(image, (32, 96+32),0,(6.0,4.6));
- // key 3
- if (locks[0] && locks[3]) image = "STKEYS8";
- else if (locks[0]) image = "STKEYS2";
- else if (locks[3]) image = "STKEYS5";
- else image = "";
- H_DrawImage(image, (32, 144+32),0,(6.0,4.6));
- }
- // Drawn on Both statusbar AND Fullscreen HUD.
- void DrawGlobalHUD()
- {
- if(TmpTextTimer > 0)
- {
- H_DrawString(TmpHUDText,(16,16),0,Font.CR_ORANGE);
- }
- }
- void DrawMainBar (double TicFrac)
- {
- }
- void DrawFullScreenStuff ()
- {
- let plr = RadixShip(CPlayer.mo);
- if(!plr) return;
- // Scalar for energy bar.
- float energyFactor = plr.energy > 0 ? plr.energy / plr.maxenergy : 0;
- int energyScalar = (325*energyFactor);
- // Scalar for armor.
- float armorFactor = plr.shields > 0 ? plr.shields / plr.maxShields : 0;
- float armorScalar = 325*armorFactor;
- // Scalar for health.
- float healthFactor = (plr.health > 0 && plr.MaxHealth > 0) ? float(plr.health) / plr.MaxHealth : 0;
- float healthScalar = 325*healthFactor;
- // Scalar for throttle
- float throttlemod = plr.boosting ? 1.0 : plr.IsMoving() ? plr.throttle : plr.cruise;
- float throttleFactor = throttlemod > 0 ? (throttlemod*100) / 100 : 0;
- float throttleScalar = 174*throttleFactor;
- Name wgraphic = plr.weapGraphic;
- xhair_lock = clamp(int(plr.locktimer*10)+1, 1, 7);
- int threat = plr.Threat ? 1 : 0;
- // Draw background
- H_DrawImage( "CPITBG", (960,900), 0, (6.0, 4.5) );
- // Cockpit
- H_DrawImage( "COCKPIT", (960,900), 0, (6.0, 4.5) );
- // Threat
- H_DrawImage( "THREAT" .. threat, (960,140), 0, (6.0, 5.3) );
- // Radar
- H_DrawImage( "RADAR", (978,842), 0, (6.0, 4.6) );
- // Make sure we're not in the middle of a kewl powerup animation thingy.
- if(plr.powerup) return;
- Draw_Radar();
- // Crosshair
- H_DrawImage( "CRSHAIR" .. xhair_lock, (960,480), 0, (5.0, 3.5) );
- // Select Weapon Graphic
- H_DrawImage(wgraphic, (327,729), 0, (6.0,4.6));
- Draw_Weapons();
- // Throttle
- H_SetClipRect(648, 666, throttleScalar,32);
- String thrott = "THROTTLE";
- if(plr.countinv("Power_Jets") && plr.boosting) thrott = "THRTBOST";
- H_DrawImage( thrott, (735,699), 0, (6.0,4.85));
- // Armor bar
- H_SetClipRect(1212, 702, healthScalar,30);
- H_DrawImage( "ARMRBAR", (1376,720), 0, (6.05,3.5));
- // Sheild bar
- H_SetClipRect(1212, 769, armorScalar,30);
- H_DrawImage( "SHLDBAR", (1376,788), 0, (6.05,3.6));
- // Energy bar
- H_SetClipRect(1398, 837, energyScalar,30);
- H_DrawImage( "ENRGBAR", (1562,855), 0, (6.05,3.6));
- ClearClipRect(); // Clear all clip rects.
- // Draw PlasmaBombs (Use transparent nums)
- H_DrawImage( "PBOMBX", (1725,60), 0, (6.05,3.6));
- int numbombs = plr.countinv("RadixBombs");
- string strbombs = numbombs < 10 ? "0"..numbombs : ""..numbombs;
- H_DrawNumbers(strbombs,(1777,50),(6.0,4.6),1,true);
- // Draw level time.
- int lvlmins = clamp(seconds_timer/60, 0, 99); // 99 mins maximum time.
- int lvlsecs = seconds_timer - (lvlmins*60);
- String secs = (lvlsecs < 10 ? "0" .. lvlsecs : ""..lvlsecs);
- String mins = (lvlmins < 10 ? "0" .. lvlmins : ""..lvlmins);
- H_DrawNumbers(secs,(738,851),(6.0,4.6));
- H_DrawNumbers(mins,(654,851),(6.0,4.6));
- // Draw enemy count
- int kills = Level.killed_monsters;
- int enemies = Level.total_monsters;
- String kprefix = "";
- String eprefix = "";
- if(kills < 10){
- kprefix = "00";
- } else if(kills < 100){
- kprefix = "0";
- }
- if(enemies < 10){
- eprefix = "00";
- } else if(enemies < 100){
- eprefix = "0";
- }
- String formatkills = kprefix .. kills;
- String formatenemies = eprefix .. enemies;
- H_DrawNumbers(formatkills.."",(875,662),(6.1,4.6));
- H_DrawNumbers(formatenemies.."",(1020,662),(6.01,4.6));
- let penergy = Power_EnergyRegen(plr.FindInventory("Power_EnergyRegen"));
- let pshield = Power_ShieldRegen(plr.FindInventory("Power_ShieldRegen"));
- let pjets = Power_Jets(plr.FindInventory("Power_Jets"));
- let pinvuln = Power_UltraShields(plr.FindInventory("Power_UltraShields"));
- if(!penergy) timers[0] = 0;
- if(!pshield) timers[1] = 0;
- if(!pjets ) timers[2] = 0;
- if(!pinvuln) timers[3] = 0;
- // Energy regen.
- if( penergy && penergy.EffectTics <= 35*5 )
- draw_penergy = Blink(15,draw_penergy,0);
- else if(penergy)
- draw_penergy = true;
- else
- draw_penergy = false;
- // Shield regens
- if( pshield && pshield.EffectTics <= 35*5 )
- draw_pshield = Blink(15,draw_pshield,1);
- else if(pshield)
- draw_pshield = true;
- else
- draw_pshield = false;
- // Jets.
- if( pjets && pjets.EffectTics <= 35*5 )
- draw_pjets = Blink(15,draw_pjets,2);
- else if(pjets)
- draw_pjets = true;
- else
- draw_pjets = false;
- // Invulnurability (Ultrashields).
- if( pinvuln && pinvuln.EffectTics <= 35*5 )
- draw_pinvul = Blink(15,draw_pinvul,3);
- else if(pinvuln)
- draw_pinvul = true;
- else
- draw_pinvul = false;
- if(plr.countinv("Effect_PBombFlash"))
- {
- Screen.Dim(Color(255,255,255,255), fade, 0, 0, Screen.GetWidth(), Screen.GetHeight());
- fade += 0.06;
- dofadeout = true;
- }
- else if(dofadeout)
- {
- if(fade <= 0) dofadeout = false;
- Screen.Dim(Color(255,255,255,255), fade, 0, 0, Screen.GetWidth(), Screen.GetHeight());
- fade -= 0.06;
- }
- // Draw powerups
- if(draw_pshield)H_DrawImage( "POWSHLD", (1792,146), 0, (6.0, 4.6) );
- if(draw_penergy)H_DrawImage( "POWENRG", (1792,238), 0, (6.0, 4.6) );
- if( draw_pjets )H_DrawImage( "POWJETS", (1792,338), 0, (6.0, 4.6) );
- if( draw_pinvul)H_DrawImage( "POWUSLD", (1792,438), 0, (6.0, 4.6) );
- //Draw doom keys
- DrawKeys();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement