Life as an unresolved external symbol.
HTHUD: Part 1 – Building The Base Class + Displaying Ammo
Video Version
Subject: HTHUD: Part 1 – Building The Base Class + Displaying Ammo
Skill Level: Beginner
Run-Time: 1 Hour and 30 Minutes
Author: Michael Allar
Notes: Creating a new HUD class and having it display our current weapons ammo.
Download: Low-Res (236MB) Hi-Res (337MB)
Video Update 3/25/2010
Run-Time: 2 Minutes
Notes: Fixes chat messages not displaying.
Streaming: 720×480
Download: Low-Res (7MB)
Written Version
Subject: HTHUD: Part 1 – Building The Base Class + Displaying Ammo
Skill Level: Beginner
Author: Michael Allar
Notes: Creating a new HUD class and having it display our current weapons ammo.
See video for an in-depth explanation. Sorry about the indentation, it seems like my indentation will not survive copy paste… D: I will create a written tutorial soon.
HTHUD
/*******************************************************************************
HTHUD
Creation date: 09/03/2010 05:04
Copyright (c) 2010, Allar
*******************************************************************************/
class HTHUD extends UDKHUD;
/** The Pawn that is currently owning this hud */
var Pawn PawnOwner;
/** Points to the UT Pawn. Will be resolved if in a vehicle */
var HTPawn HTPawnOwner;
/** Cached reference to the another hud texture */
var const Texture2D HudTexture;
var linearcolor HudTint;
var bool bShowAmmo;
var vector2d AmmoPosition;
var TextureCoordinates AmmoBGCoords;
/** Resolution dependent HUD scaling factor */
var float HUDScaleX, HUDScaleY;
/** Holds the scaling factor given the current resolution. This is calculated in PostRender() */
var float ResolutionScale, ResolutionScaleX;
/** The percentage of the view that should be considered safe */
var float SafeRegionPct;
/** Holds the full width and height of the viewport */
var float FullWidth, FullHeight;
/**
* Perform any value precaching, and set up various safe regions
*
* NOTE: NO DRAWING should ever occur in PostRender. Put all drawing code in DrawHud().
*/
event PostRender()
{
PawnOwner = Pawn(PlayerOwner.ViewTarget);
if ( PawnOwner == None )
{
PawnOwner = PlayerOwner.Pawn;
}
HTPawnOwner = HTPawn(PawnOwner);
// draw any debug text in real-time
PlayerOwner.DrawDebugTextList(Canvas,RenderDelta);
HUDScaleX = Canvas.ClipX/1280;
HUDScaleY = Canvas.ClipX/1280;
ResolutionScaleX = Canvas.ClipX/1024;
ResolutionScale = Canvas.ClipY/768;
FullWidth = Canvas.ClipX;
FullHeight = Canvas.ClipY;
if ( bShowHud )
{
DrawHud();
}
// let iphone draw any always present overlays
DrawInputOverlays();
}
/**
* This is the main drawing pump. It will determine which hud we need to draw (Game or PostGame). Any drawing that should occur
* regardless of the game state should go here.
*/
function DrawHUD()
{
local float x,y,w,h;
// Create the safe region
w = FullWidth * SafeRegionPct;
X = Canvas.OrgX + (Canvas.ClipX - w) * 0.5;
// We have some extra logic for figuring out how things should be displayed
// in split screen.
h = FullHeight * SafeRegionPct;
Y = Canvas.OrgY + (Canvas.ClipY - h) * 0.5;
Canvas.OrgX = X;
Canvas.OrgY = Y;
Canvas.ClipX = w;
Canvas.ClipY = h;
Canvas.Reset(true);
// Set up delta time
RenderDelta = WorldInfo.TimeSeconds - LastHUDRenderTime;
LastHUDRenderTime = WorldInfo.TimeSeconds;
PlayerOwner.DrawHud( Self );
if (bShowGameHUD)
{
DrawGameHud();
}
}
function DrawGameHud()
{
DisplayLocalMessages();
<div id="_mcePaste"> DisplayConsoleMessages();</div>
<div id="_mcePaste"></div>
DrawLivingHud();
}
/**
* Anything drawn in this function will be displayed ONLY when the player is living.
*/
function DrawLivingHud()
{
local HTWeapon Weapon;
// Manage the weapon. NOTE: Vehicle weapons are managed by the vehicle
// since they are integrated in to the vehicle health bar
if( PawnOwner != none )
{
if ( bShowAmmo )
{
Weapon = HTWeapon(PawnOwner.Weapon);
if ( Weapon != none )
{
DisplayAmmo(Weapon);
}
}
}
}
function DisplayAmmo(HTWeapon Weapon)
{
local vector2d POS;
local string Amount;
local int AmmoCount;
// Resolve the position
POS = ResolveHudPosition(AmmoPosition,AmmoBGCoords.UL,AmmoBGCoords.VL);
// Figure out if we should be pulsing
AmmoCount = Weapon.GetAmmoCount();
// Draw the background
Canvas.SetPos(POS.X,POS.Y);// - (AmmoBarOffsetY * ResolutionScale));
Canvas.DrawColorizedTile(HudTexture, AmmoBGCoords.UL * ResolutionScale, AmmoBGCoords.VL * ResolutionScale, AmmoBGCoords.U, AmmoBGCoords.V, AmmoBGCoords.UL, AmmoBGCoords.VL, HudTint);
// Draw the amount
Amount = ""$AmmoCount;
Canvas.DrawColor = WhiteColor;
Canvas.DrawText(Amount,,3.0f,3.0f);
}
/**
* Given a default screen position (at 1024x768) this will return the hud position at the current resolution.
* NOTE: If the default position value is < 0.0f then it will attempt to place the right/bottom face of
* the "widget" at that offset from the ClipX/Y.
*
* @Param Position The default position (in 1024x768 space)
* @Param Width How wide is this "widget" at 1024x768
* @Param Height How tall is this "widget" at 1024x768
*
* @returns the hud position
*/
function Vector2D ResolveHUDPosition(vector2D Position, float Width, float Height)
{
local vector2D FinalPos;
FinalPos.X = (Position.X < 0) ? Canvas.ClipX - (Position.X * ResolutionScale) - (Width * ResolutionScale) : Position.X * ResolutionScale;
FinalPos.Y = (Position.Y < 0) ? Canvas.ClipY - (Position.Y * ResolutionScale) - (Height * ResolutionScale) : Position.Y * ResolutionScale;
return FinalPos;
}
defaultproperties
{
HudTexture=Texture2D'HTUI.Textures.T_UI_HUD_BaseA'
HudTint=(R=1.0f,G=1.0f,B=1.0f,A=1.0f)
AmmoPosition=(X=0,Y=-1)
AmmoBGCoords=(U=0,UL=76,V=0,VL=126)
SafeRegionPct = 1.0f
bShowAmmo=true
}
UDKGame
Update your defaultproperties as shown:
defaultproperties
{
DefaultPawnClass=class'UDKGame.HTPawn'
PlayerControllerClass=class'UDKGame.HTPlayerController'
HUDType=class'UDKGame.HTHUD'
DefaultMapPrefixes(0)=(Prefix="HT",GameType="UDKGame.TheHuntGame")
}
T_UI_HUD_BaseA.psd
Compressed into a .zip file.
April 7, 2010 - 1:39 pm
How would some one go about making different ammo display textures for each weapon? With this it seems that every weapon I will create will display the same Cannon ball texture which was obviously made for the Cannon. Will there be any thing on this is the future cause its seems to continue with the tutorials would make it harder later on to change this.
April 7, 2010 - 1:42 pm
This would be fairly easy to implement. You would put these different textures onto the same texture sheet, but you would check for the weapon type and then draw coordinates based on weapon type instead of the default variable.
Or a more object-oriented approach might be to create a DrawAmmo in the weapon class itself similar to how we draw our crosshairs, and then in the weapon code itself change how the ammo is drawn on a per-weapon basis, then call this function inside the HUD’s DisplayAmmo function.
April 7, 2010 - 2:33 pm
The first one makes the most sense to me since i havn’t gotten to drawcrosshair tutorial yet, but i’m completly stumped on what I would have code to check for different weapon types.
April 7, 2010 - 2:37 pm
If (HTWP_DeathBeam(self) != None)
{
//This code will run if we have a death beam.
}
In theory.
May 8, 2010 - 6:19 am
Hi …
Thanks for all your help. Currently i have, the next problem whe compilin in the HUD class
I am using the UDK-2010-04 please helpme with this problem is very importarnt form me. Thanks
*************
Canvas.DrawColorizedTile
Error, Unrecognized member ‘DrawColorizedTile’, in class Canvas.
May 8, 2010 - 10:05 am
This series uses the March build.
In the April build, DrawColorizedTile was removed and now you have to use DrawTile, works exactly the same way though.