|
Custom HUDs
Mod Code : ^Soul^
Mod Text : ^Soul^
24 November 1998
/* Ok, heres a better explanation on the hud, between this and c0mpi1es you should be come a hud master in no time, its fairly easy, you can tell, becuase what i'm about to impart on you is the sum of an hours worth of working with it. Ok this is basicly a modified version of c0mpi1es and its purpose is to expand upon that knowledge. clipX and clipY is located in canavas.uc they are you unreal resolution, 0,0 is thel upper left corner, if your res is 640 x 480 then your lower right corner would be 640,480. which makes your lower left corner 640,0 and upper right 0,480.
you following so far? Ok CurX and CurY are your drawing location so to draw at a specific location they must equal something, like to draw in the exact center of your screen you would do
CurX = 320; and CurY = 240; thats taking into account your res is 640 x 480, also if your doing a value for your icon, i.e health or somthing then i would use drawicon value, not drawtext even though drawicon value uses drawtext it aligns things better. From here on out, you should be good to go.
*/
class ModifyingtheHud expands UnrealHUD;
/* Function HUDSetup, sets up the defaults for the hud, including
the font, you can also set any of the other Canvas defaults from
here.
*/
simulated function HUDSetup(canvas canvas)
{
// Setup the way we want to draw all HUD elements
Canvas.Reset();
Canvas.SpaceX=0;
Canvas.bNoSmooth = True;
Canvas.DrawColor.r = 255;
Canvas.DrawColor.g = 255;
Canvas.DrawColor.b = 255;
// set the font
Canvas.Font = Canvas.LargeFont;
}
/*
Function PostRender, does the actual rendering of the hud on the
screen. For every new icon or text you want drawn on the screen, you
need to tell post render to either draw it or call another function
that will do the work. PostRender is called every tick.
*/
simulated function PostRender( canvas Canvas )
{
//sets the defaults up for the canvas
HUDSetup(canvas);
//if the owner of this player exists do the bracketed stuff
if ( PlayerPawn(Owner) != None )
{
//if you have pressed escape then show the menu
if ( PlayerPawn(Owner).bShowMenu )
{
if ( MainMenu == None )
CreateMenu();
if ( MainMenu != None )
MainMenu.DrawMenu(Canvas);
return;
}
//self explanatory show the score
if ( PlayerPawn(Owner).bShowScores )
{
if ((PlayerPawn(Owner).Scoring == None) && (PlayerPawn(Owner).ScoringType != None) )
PlayerPawn(Owner).Scoring = Spawn(PlayerPawn(Owner).ScoringType, PlayerPawn(Owner));
if ( PlayerPawn(Owner).Scoring != None )
{
PlayerPawn(Owner).Scoring.ShowScores(Canvas);
return;
}
}
//draw the crosshair if the player has a weapon
else if ( (PlayerPawn(Owner).Weapon != None) && (Level.LevelAction == LEVACT_None) )
DrawCrossHair(Canvas, 0.5 * Canvas.ClipX - 8, 0.5 * Canvas.ClipY - 8);
if ( PlayerPawn(Owner).ProgressTimeOut > Level.TimeSeconds )
DisplayProgressMessage(Canvas);
}
// here's where the fun really begins :). The rest of the code
// basically says depending on the hud mode then draw this (armor,
// ammo, health) on the screen at different positions, base it off
// of the Clip to make sure it looks right at no matter what the
// resolution of the screen
// To totally remake the HUD then erase all this and use the code
// here as an example, I'll show you how to do the drawing to the
// screen in a couple of paragraphs.
if (HudMode==5)
{
DrawInventory(Canvas, Canvas.ClipX-96, 0,False);
Return;
}
if (Canvas.ClipX<320) HudMode = 4;
// Draw Armor
if (HudMode<2) DrawArmor(Canvas, 0, 0,False);
else if (HudMode==3 || HudMode==2) DrawArmor(Canvas, 0, Canvas.ClipY-32,False);
else if (HudMode==4) DrawArmor(Canvas, Canvas.ClipX-64, Canvas.ClipY-64,True);
if (HudMode!=4) DrawAmmo(Canvas, Canvas.ClipX-48-64, Canvas.ClipY-32);
else DrawAmmo(Canvas, Canvas.ClipX-48, Canvas.ClipY-32);
// Draw Health
if (HudMode<2) DrawHealth(Canvas, 0, Canvas.ClipY-32);
else if (HudMode==3||HudMode==2) DrawHealth(Canvas, Canvas.ClipX-128, Canvas.ClipY-32);
else if (HudMode==4) DrawHealth(Canvas, Canvas.ClipX-64, Canvas.ClipY-32);
//Display Inventory
if (HudMode<2) DrawInventory(Canvas, Canvas.ClipX-96, 0,False);
else if (HudMode==3) DrawInventory(Canvas, Canvas.ClipX-96, Canvas.ClipY-64,False);
else if (HudMode==4) DrawInventory(Canvas, Canvas.ClipX-64, Canvas.ClipY-64,True);
else if (HudMode==2) DrawInventory(Canvas, Canvas.ClipX/2-64, Canvas.ClipY-32,False);
//Display Frag count
if ( (Level.Game == None) || Level.Game.IsA('DeathMatchGame') )
{
if (HudMode<3) DrawFragCount(Canvas, Canvas.ClipX-32,Canvas.ClipY-64);
else if (HudMode==3) DrawFragCount(Canvas, 0,Canvas.ClipY-64);
else if (HudMode==4) DrawFragCount(Canvas, 0,Canvas.ClipY-32);
}
}
//as an example lets look at DrawHealth, you can use this as a base for
//one of your functions.
simulated function DrawHealth(Canvas Canvas, int X, int Y)
{
//set the current canvas position to what you had wanted in
//PostRender
Canvas.CurY = Y;
Canvas.CurX = X;
//set the Font to large
Canvas.Font = Canvas.LargeFont;
//if your health is less then 25 then use the red font
if (Pawn(Owner).Health<25) Canvas.Font = Font'LargeRedFont';
//call drawicon to draw the health icon and use the drawscale of
//one
Canvas.DrawIcon(Texture'IconHealth', 1.0);
//then set the cursor to draw the health ammount
Canvas.CurY += 29;
//draw icon value draws the number inside the icon
DrawIconValue(Canvas, Max(0,Pawn(Owner).Health));
Canvas.CurY -= 29;
if (HudMode==0) Canvas.DrawText(Max(0,Pawn(Owner).Health),False);
//ever wonder how they did that health bar effect? pretty easy,
//draw the bar as a tile, and tile in respect to the health
//that's left
Canvas.CurY = Y+29;
Canvas.CurX = X+2;
if (HudMode!=1 && HudMode!=2 && HudMode!=4)
Canvas.DrawTile(Texture'HudLine',FMin(27.0*(float(Pawn(Owner).Health)/float(Pawn(Owner).Default.Health)),27),2.0,0,0,32.0,2.0);
}
Opinions on this article, love it, hate it? - feedback
|