GetIcon

From ZDoom Wiki
Jump to navigation Jump to search

BaseStatusBar

TextureID, Vector2 GetIcon(Inventory item, int flags, bool showdepleted = true)

Usage

Can be used in a ZScript HUD to obtain a TextureID of the specified item's icon. It functions as a more convenient wrapper for GetInventoryIcon.

By default the function will try obtaining a suitable graphic according to the following flow:

  • Get the item's Icon
  • If not available, get the item's AltIcon
  • If not available, get the item's Spawn state sprite
  • If not available and the item is a weapon, get its Ready state sprite

By default the texture will be scaled according to the item's scale property.

This function is internally used by DrawInventoryIcon.

Parameters

  • Inventory item
A pointer to an instance of an Inventory class (for example, obtained via FindInventory).
  • int flags
Possible flags:
  • DI_SKIPICON - don't check for Icon
  • DI_SKIPALTICON - don't check for AltIcon
  • DI_SKIPSPAWN - don't check for Spawn state sprite
  • DI_SKIPREADY - don't check for Ready state sprite
  • DI_ALTICONFIRST - look for AltIcon first; only if not availble look for Icon
  • DI_FORCESCALE - don't apply scale to the icon (Verification needed)
  • bool showdepleted
If this is false, the function will return a null icon. (Verification needed)

Return values

The function has 2 return values:

  • TextureID - the textureID of the icon
  • vector2 - the scale of the icon. The icon will be multiplied by the item's scale property, unless DI_FORCESCALED was passed.

Examples

This obtains the icon of the player's currently equipped weapon an draws it at the bottom left corner of the screen:

TextureID icon = GetIcon(CPlayer.readyWeapon, 0);
if (icon.isValid())
{
    DrawTexture(icon, (0,0), DI_SCREEN_LEFT_BOTTOM|DI_ITEM_LEFT_BOTTOM);
}

Note: this example is for educational purposes only. In practice it's not useful because it copies the functionality of DrawInventoryIcon.