1
0
KF2-Dev-Scripts/KFGame/Classes/KFGFxHUD_PlayerBackpack.uc

292 lines
9.7 KiB
Ucode
Raw Normal View History

2020-12-13 15:01:13 +00:00
//=============================================================================
// KFGFxInGameHUD_PlayerBackpack
//=============================================================================
// HUD container that stores information about the player's Weapon & Equipment, dosh, etc.
//=============================================================================
// Killing Floor 2
// Copyright (C) 2015 Tripwire Interactive LLC
// - Alex Quick 5/15/2014
//=============================================================================
class KFGFxHUD_PlayerBackpack extends GFxObject;
/** Cached KFPlayerController */
var KFPlayerController MyKFPC;
// Player's dosh amount as of the last tick
var int LastDosh;
// Number of bullets in the current magazine
var int LastSpareAmmo;
var int LastMagazineAmmo;
var bool bUsesAmmo;
// string used for alternate display in ammo section
var string LastSpecialAmmo;
//
var int LastFlashlightBattery;
//
var int LastGrenades;
var int LastSavedBuild;
var int LastMaxWeight;
var int LastWeight;
// Amount of secondary ammo
var byte LastSecondaryAmmo;
var bool bWasUsingAltFireMode;
var bool bUsesSecondaryAmmo;
2020-12-13 15:09:05 +00:00
var bool bUsesGrenadesAsSecondaryAmmo;
2020-12-13 15:01:13 +00:00
var class<KFPerk> LastPerkClass;
var KFWeapon LastWeapon;
var KFInventoryManager MyKFInvManager;
2020-12-13 15:09:05 +00:00
var ASColorTransform DefaultColor;
var ASColorTransform RedColor;
var name OldState;
2020-12-13 15:01:13 +00:00
function InitializeHUD()
{
MyKFPC = KFPlayerController(GetPC());
if( MyKFPC.Pawn != none && MyKFPC.Pawn.InvManager != none )
{
MyKFInvManager = KFInventoryManager(MyKFPC.Pawn.InvManager);
}
2020-12-13 15:09:05 +00:00
DefaultColor = GetObject("secondaryAmmoContainer").GetColorTransform();
RedColor = GetObject("FlashlightContainer").GetColorTransform();
2020-12-13 15:01:13 +00:00
}
function TickHud(float DeltaTime)
{
UpdateDosh();
UpdateGrenades();
UpdateWeapon();
UpdateFlashlight();
UpdateWeight();
}
function UpdateWeight()
{
if( MyKFPC.Pawn != none && MyKFPC.Pawn.InvManager != none )
{
MyKFInvManager = KFInventoryManager(MyKFPC.Pawn.InvManager);
if(MyKFInvManager != none && (LastMaxWeight != MyKFInvManager.MaxCarryBlocks || LastWeight != MyKFInvManager.CurrentCarryBlocks))
{
SetString("WeightText", MyKFInvManager.CurrentCarryBlocks$"/"$MyKFInvManager.MaxCarryBlocks);
LastMaxWeight = MyKFInvManager.MaxCarryBlocks;
LastWeight = MyKFInvManager.CurrentCarryBlocks;
}
}
}
function UpdateDosh()
{
local int CurrentDosh;
local int DeltaDosh;
if (MyKFPC.PlayerReplicationInfo != none)
{
CurrentDosh = MyKFPC.PlayerReplicationInfo.Score;
// Update the dosh
if (CurrentDosh != LastDosh )
{
DeltaDosh = CurrentDosh - LastDosh;
SetInt("backpackDosh" ,DeltaDosh);
LastDosh = CurrentDosh;
}
}
}
function UpdateGrenades()
{
local int CurrentGrenades;
if(MyKFPC == None)
{
return;
}
if(MyKFInvManager != none)
{
CurrentGrenades = MyKFInvManager.GrenadeCount;
}
//Update the icon the for grenade type.
if(MyKFPC.CurrentPerk != none)
{
if( LastPerkClass != MyKFPC.CurrentPerk.Class ||
LastSavedBuild != MyKFPC.CurrentPerk.GetSavedBuild() )
{
SetString("backpackGrenadeType", "img://" $ MyKFPC.CurrentPerk.GetGrenadeImagePath());
LastPerkClass = MyKFPC.CurrentPerk.Class;
LastSavedBuild = MyKFPC.CurrentPerk.GetSavedBuild();
}
}
// Update the grenades count value
if(CurrentGrenades != LastGrenades)
{
SetInt("backpackGrenades" , CurrentGrenades);
LastGrenades = CurrentGrenades;
}
}
function UpdateWeapon()
{
local int CurrentSpareAmmo;
local int CurrentMagazineAmmo;
local byte CurrentSecondaryAmmo;
local string CurrentSpecialAmmo;
local KFWeapon CurrentWeapon;
2020-12-13 15:09:05 +00:00
local ASColorTransform ColorChange;
local name StateName;
local bool ForceSecondaryWeaponIconUpdate;
2020-12-13 15:01:13 +00:00
if(MyKFPC != none && MyKFPC.Pawn != none && MyKFPC.Pawn.Weapon != none )
{
CurrentWeapon = KFWeapon(MyKFPC.Pawn.Weapon);
if(CurrentWeapon != none)
{
// If we changed weapons
if( LastWeapon == none || LastWeapon != CurrentWeapon )
{
LastWeapon = CurrentWeapon;
RefreshWeapon(CurrentWeapon);
2020-12-13 15:09:05 +00:00
ForceSecondaryWeaponIconUpdate = true;
2020-12-13 15:01:13 +00:00
}
else if( bWasUsingAltFireMode != CurrentWeapon.bUseAltFireMode )
{
UpdateFireModeIcon(CurrentWeapon);
}
if (bUsesAmmo)
{
// Update the ammo in the weapon's magazine
CurrentMagazineAmmo = CurrentWeapon.AmmoCount[0];
if ( CurrentMagazineAmmo != LastMagazineAmmo )
{
SetInt("weaponMagazineAmmo" , CurrentMagazineAmmo);
LastMagazineAmmo = CurrentMagazineAmmo;
}
// Update the spare ammo (whatever is not in the magazine)
CurrentSpareAmmo = CurrentWeapon.GetSpareAmmoForHUD();
if ( CurrentSpareAmmo != LastSpareAmmo )
{
SetInt("backpackStoredAmmo" , CurrentSpareAmmo);
LastSpareAmmo = CurrentSpareAmmo;
}
}
else
{
// if the weapon doesn't use ammo, let them display a special string in that section
CurrentSpecialAmmo = CurrentWeapon.GetSpecialAmmoForHUD();
if (CurrentSpecialAmmo != LastSpecialAmmo)
{
SetString("specialAmmoString", CurrentSpecialAmmo);
}
}
// always reset the last special ammo since setting a new string turns the default "---" off
LastSpecialAmmo = CurrentSpecialAmmo;
2020-12-13 15:09:05 +00:00
StateName = CurrentWeapon.GetStateName();
2020-12-13 15:01:13 +00:00
if (bUsesSecondaryAmmo)
{
CurrentSecondaryAmmo = CurrentWeapon.GetSecondaryAmmoForHUD();
2020-12-13 15:09:05 +00:00
// Update the amount of ammo
if (CurrentSecondaryAmmo != LastSecondaryAmmo)
2020-12-13 15:01:13 +00:00
{
SetInt("secondaryAmmo" , CurrentSecondaryAmmo);
LastSecondaryAmmo = CurrentSecondaryAmmo;
2020-12-13 15:09:05 +00:00
}
// Force the color of the background if we detect a weapon change and the weapon doesn't use secondary ammo
if( !bUsesGrenadesAsSecondaryAmmo && ForceSecondaryWeaponIconUpdate )
{
GetObject("secondaryAmmoContainer").SetColorTransform(DefaultColor);
}
// Update the aspect of the icon
if ( bUsesGrenadesAsSecondaryAmmo && StateName != OldState)
{
OldState = StateName;
if(CurrentWeapon.HasToReloadSecondaryAmmoForHUD())
{
ColorChange.Add = MakeLinearColor(0.65f,0.23f,0.00f,0.2f);
GetObject("secondaryAmmoContainer").SetColorTransform(ColorChange);
SetString("secondaryIcon", "img://"$CurrentWeapon.SecondaryAmmoTexture.GetPackageName()$".UI_FireModeSelect_BulletSingleProhibited");
}
else
{
SetString("secondaryIcon", "img://"$CurrentWeapon.SecondaryAmmoTexture.GetPackageName()$"."$CurrentWeapon.SecondaryAmmoTexture);
GetObject("secondaryAmmoContainer").SetColorTransform(DefaultColor);
}
2020-12-13 15:01:13 +00:00
}
}
}
}
}
function UpdateFireModeIcon( KFWeapon CurrentWeapon )
{
local byte NewFireModeIndex;
NewFireModeIndex = CurrentWeapon.bUseAltFireMode ? CurrentWeapon.ALTFIRE_FIREMODE : CurrentWeapon.DEFAULT_FIREMODE;
// Update Fire Mode Icons
if( Len(CurrentWeapon.FireModeIconPaths[NewFireModeIndex]) > 0)
{
SetString("firemodeIcon", "img://"$CurrentWeapon.FireModeIconPaths[NewFireModeIndex].GetPackageName()$"."$CurrentWeapon.FireModeIconPaths[NewFireModeIndex]);
}
bWasUsingAltFireMode = CurrentWeapon.bUseAltFireMode;
}
function RefreshWeapon(KFWeapon CurrentWeapon)
{
bUsesAmmo = CurrentWeapon.UsesAmmo();
SetBool("bUsesAmmo", bUsesAmmo);
bUsesSecondaryAmmo = CurrentWeapon.UsesSecondaryAmmo();
2020-12-13 15:09:05 +00:00
bUsesGrenadesAsSecondaryAmmo = CurrentWeapon.UsesGrenadesAsSecondaryAmmo();
2020-12-13 15:01:13 +00:00
SetBool("bUsesSecondaryAmmo", bUsesSecondaryAmmo);
if( bUsesSecondaryAmmo )
{
SetString("secondaryIcon", "img://"$CurrentWeapon.SecondaryAmmoTexture.GetPackageName()$"."$CurrentWeapon.SecondaryAmmoTexture);
}
UpdateFireModeIcon(CurrentWeapon);
}
function UpdateFlashlight()
{
local KFPawn_Human MyKFP;
local int CurrentFlashlightBattery;
if(MyKFPC != none && MyKFPC.Pawn != none)
{
MyKFP = KFPawn_Human(MyKFPC.Pawn);
if ( MyKFP != none )
{
CurrentFlashlightBattery = MyKFP.BatteryCharge;
if ( CurrentFlashlightBattery != LastFlashlightBattery )
{
SetFlashlightBattery(CurrentFlashlightBattery, MyKFP.bFlashlightOn);
LastFlashlightBattery = CurrentFlashlightBattery;
}
}
}
}
function SetFlashlightBattery( int BatteryCharge, bool bIsOn )
{
ActionscriptVoid( "setFlashlightBattery" );
}
DefaultProperties
{
LastMaxWeight=-1
LastWeight=-1
}