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

370 lines
12 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;
2021-06-02 20:06:18 +00:00
var int LastSecondarySpareAmmo;
2020-12-13 15:01:13 +00:00
var bool bWasUsingAltFireMode;
var bool bUsesSecondaryAmmo;
2020-12-13 15:09:05 +00:00
var bool bUsesGrenadesAsSecondaryAmmo;
2021-06-02 20:06:18 +00:00
var bool bUsesSecondaryAmmoAltHUD;
2020-12-13 15:01:13 +00:00
2022-05-11 15:13:25 +00:00
var transient bool bLastDoshVisibility;
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;
2022-05-11 15:13:25 +00:00
var transient byte LastGrenadeIndex;
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;
2022-05-11 15:13:25 +00:00
local bool bCanUseDosh;
bCanUseDosh = MyKFPC.CanUseDosh();
if (bCanUseDosh != bLastDoshVisibility)
{
UpdateDoshVisibility(bCanUseDosh);
bLastDoshVisibility = bCanUseDosh;
}
if (!bCanUseDosh)
{
return;
}
2020-12-13 15:01:13 +00:00
if (MyKFPC.PlayerReplicationInfo != none)
{
CurrentDosh = MyKFPC.PlayerReplicationInfo.Score;
// Update the dosh
if (CurrentDosh != LastDosh )
{
DeltaDosh = CurrentDosh - LastDosh;
SetInt("backpackDosh" ,DeltaDosh);
LastDosh = CurrentDosh;
}
2022-05-11 15:13:25 +00:00
}
}
function UpdateDoshVisibility(bool visible)
{
if (visible)
{
SetBool("DoshSetVisibility", true);
}
else
{
SetBool("DoshSetVisibility", false);
2020-12-13 15:01:13 +00:00
}
}
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();
2022-05-11 15:13:25 +00:00
LastGrenadeIndex = MyKFPC.CurrentPerk.GetGrenadeSelectedIndex();
}
else if (MyKFPC.CurrentPerk.GetGrenadeSelectedIndex() != LastGrenadeIndex)
{
SetString("backpackGrenadeType", "img://" $ MyKFPC.CurrentPerk.GetGrenadeImagePath());
LastGrenadeIndex = MyKFPC.CurrentPerk.GetGrenadeSelectedIndex();
}
2020-12-13 15:01:13 +00:00
}
// Update the grenades count value
if(CurrentGrenades != LastGrenades)
{
SetInt("backpackGrenades" , CurrentGrenades);
LastGrenades = CurrentGrenades;
}
}
function UpdateWeapon()
{
local int CurrentSpareAmmo;
local int CurrentMagazineAmmo;
local byte CurrentSecondaryAmmo;
2021-06-02 20:06:18 +00:00
local int CurrentSecondarySpareAmmo;
2020-12-13 15:01:13 +00:00
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;
}
2021-11-16 17:03:42 +00:00
/**
Reusing this variable for showing the dosh icon for doshinegun.
Only FAMAS uses bUsesSecondaryAmmoAltHUD and for it bUsesSecondaryAmmo is true
*/
if (!bUsesSecondaryAmmo && CurrentWeapon.bUsesSecondaryAmmoAltHUD)
{
SetBool("doshAmmoIcon", true);
}
2020-12-13 15:01:13 +00:00
}
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
2021-06-02 20:06:18 +00:00
if (!bUsesSecondaryAmmoAltHUD)
2020-12-13 15:01:13 +00:00
{
2021-06-02 20:06:18 +00:00
if (CurrentSecondaryAmmo != LastSecondaryAmmo)
{
SetInt("secondaryAmmo" , CurrentSecondaryAmmo);
LastSecondaryAmmo = CurrentSecondaryAmmo;
}
}
else
{
if (CurrentSecondaryAmmo != LastSecondaryAmmo)
{
SetInt("secondaryAltAmmo" , CurrentSecondaryAmmo);
LastSecondaryAmmo = CurrentSecondaryAmmo;
}
CurrentSecondarySpareAmmo = CurrentWeapon.GetSecondarySpareAmmoForHUD();
if (CurrentSecondarySpareAmmo != LastSecondarySpareAmmo)
{
SetInt("secondaryAltSpareAmmo", CurrentSecondarySpareAmmo);
LastSecondarySpareAmmo = CurrentSecondarySpareAmmo;
}
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();
2021-06-02 20:06:18 +00:00
bUsesSecondaryAmmoAltHUD = bUsesSecondaryAmmo && CurrentWeapon.bUsesSecondaryAmmoAltHUD;
2020-12-13 15:09:05 +00:00
bUsesGrenadesAsSecondaryAmmo = CurrentWeapon.UsesGrenadesAsSecondaryAmmo();
2021-06-02 20:06:18 +00:00
if (bUsesSecondaryAmmoAltHUD)
{
SetBool("bUsesSecondaryAmmoAlt", bUsesSecondaryAmmoAltHUD);
}
else
{
SetBool("bUsesSecondaryAmmo", bUsesSecondaryAmmo);
}
2020-12-13 15:01:13 +00:00
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
2022-05-11 15:13:25 +00:00
bLastDoshVisibility=true
LastGrenadeIndex=0
2020-12-13 15:01:13 +00:00
}