Classes:BaseStatusBar

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


BaseStatusBar is the base class that all standard HUDs inherit from. Despite the name, it handles drawing both of statusbar HUDs and fullscreen HUDs. It does not handle GZDoom's Alternate HUD, however (see AltHUD for creating altHUD replacements). This class can be used to create your own custom HUDs from entirely within ZScript.

The statusbar global variable contains a pointer to the current HUD. As such, it's possible to use BaseStatusBar drawing functions from an event handler's RenderOverlay()/RenderUnderlay() events, and it's possible to interact with the HUD from play scope by using an event handler with an InterfaceProcess override.

Note, to see your HUD in the game, it MUST be added via the GameInfo block of the MAPINFO lump as follows:

GameInfo
{
  StatusBarClass = "MyCustomHUD" //replaces the base HUD
  AltHUDClass = "MyCustomAltHUD" //replaces the alternative HUD
}

See ZScript HUDs for details.

Constants

  • double XHAIRSHRINKSIZE = 1. / 18
  • double XHAIRPICKUPSIZE = 2 + XHAIRSHRINKSIZE
  • int POWERUPICONSIZE = 32

Fields

  • int RelTop
The height of the status bar in pixels. This is based off the resolution defined by HorizontalResolution and VerticalResolution and does not take GZDoom's status bar scaling into account.
  • int HorizontalResolution
Width of the virtual resolution in pixels. If 0 this is 320.
  • int VerticalResolution
Height of the virtual resolution in pixels. If 0 this is 200.
  • bool Centering
Unused
  • bool FixedOrigin
Unused
  • bool CompleteBorder
Controls how the background image is drawn when the view port is smaller than the window resolution. If set to true the image is drawn behind the status bar and not just around the edges.
  • double CrosshairSize
Scalar for the size of the player's crosshair. The CVar crosshairgrow must be true for this to scale.
  • double Displacement
The size difference (in pixels) between the scaled status bar and the unscaled status bar as a fraction of RelTop. The size difference is based off of HorizontalResolution and VerticalResolution. This value is scaled down by GZDoom's status bar scale.
  • Note: If hud_aspectscale is set to true GZDoom's status bar scale is multiplied by 1.2 for this calculation
  • PlayerInfo CPlayer
The PlayerInfo for the player currently being viewed through. Note that this can change if swapping player views in multiplayer.
  • bool ShowLog
Handles showing subtitles and log text (mainly used in Strife).
  • Vector2 defaultScale
The x and y scale for scaling a HorizontalResolution x VerticalResolution area to best fit the window resolution without any fractional steps.
  • int artiflashTick
Keeps track of drawing the flash sprite when using an item from the inventory bar (mainly used in Heretic and Hexen).
  • double itemFlashFade
Keeps track of the alpha of the flash when using an item (mainly used in Strife).
  • double Alpha
Controls the overall alpha of the HUD.
  • Vector2 drawOffset
X and y offsets for drawing HUD graphics. This is based off of HorizontalResolution and VerticalResolution and not the real window resolution. This is scaled by GZDoom's status bar scaling.
  • double drawClip[4]
Unused
  • bool fullscreenOffsets
If set to true, draws graphics based off the real window resolution instead of the virtual resolution defined by HorizontalResolution and VerticalResolution.

Methods

Virtual

Called when the status bar is first created. Can be used to set up additional functionality.
Called every tic. Can be used to track functionality that should be handled on a consistently timed basis.
  • void Draw(int state, double TicFrac)
Called every frame. Handles drawing functionality of the HUD.
Called whenever the screen size changes. Sets up the HUD to properly scale with the new resolution.
Called when a weapon is picked up for the first time. Signals the mug shot to grin.
  • Weapon weapn - The weapon that was picked up.
  • clearscope void SetMugShotState(String state_name, bool wait_till_done = false, bool reset = false)
Sets the current state of the mug shot.
  • clearscope void FlashItem(class<Inventory> itemtype)
Responsible for the flash that appears in the player's visible inventory when using an item (see: Heretic and Hexen).
  • class<Inventory> itemtype - The class type of the item that was used.
Attaches the HUD to the specified player.
  • PlayerInfo player - The PlayerInfo of the player that the HUD should attach to.
Responsible for the crosshair size change that can be set when picking up items.
Called whenever a new game is started. Does not include loading a saved game.
Draws a popup box like the character portraits when talking to someone in Strife.
  • int popnum - The index of the popup to show.
Checks to see if a log instead of a popup should be drawn. Returning true tells the game to draw the log.
  • state - The current state of the HUD.
Called when the console receives a notification. If true is returned then the console will not print the notification.
Called when the console notifications are cleared.
Called when the console wants to print a HUD message. If true is returned then the console will not automatically create the HUD message.
  • Font fnt - The font type to print the message with.
  • String msg - The message to be printed.
  • bool bold - If true, uses the font's bold text.
(Need more info)
Called when a chat message is to be printed. If true is returned then the game will not execute the default logic for chat printing.
  • String txt - The current message to be printed.
Called when calculating the height of the status bar when drawing the level name in the auto map. Useful for graphics that extend higher than the status bar itself. Returns the additional height to add to the top of the status bar relative to the resolution of the HUD.
  • double scaleratio - The current width ratio of the last line of text to draw of the level name to the width of the HUD.
Called every frame the idmypos cheat is on. Handles drawing the player's current position on the screen.
Called every frame the automap is active. Handles drawing text based information that's printed while the auto map is open.
  • double ticfrac - The percentage of the way to the next tic that the current frame is at. Ranges from 0 to 1.
Called every frame. Handles drawing power up icons if they have one.

Static

Non-static

Returns the scale of the HUD relative to the current resolution.
  • void BeginStatusBar(bool forceScaled = false, int resW = -1, int resH = -1, int rel = -1)
Creates a virtual canvas for the HUD with the provided size that covers the designated area on the screen (usually used by statusbar-styled HUDs).
  • void BeginHUD(double Alpha = 1., bool forcescaled = false, int resW = -1, int resH = -1)
Creates a virtual canvas for the HUD with the provided size that covers the whole screen (used by fullscreen HUDs).
  • void UpdateScreenGeometry()
  • TextureID GetMugShot(int accuracy, int stateflags = MugShot.STANDARD, String default_face = "STF")
  • void DrawTexture(TextureID texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1), ERenderStyle style = STYLE_Translucent, Color col = 0xffffffff, int translation = 0, double clipwidth = -1)
Draws a graphic on the HUD. Takes a TextureID.
  • void DrawImage(String texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1), ERenderStyle style = STYLE_Translucent, Color col = 0xffffffff, int translation = 0, double clipwidth = -1)
Draws a graphic on the HUD. Takes the name of the image (or full path to the image file).
  • void DrawImageRotated(String texid, Vector2 pos, int flags, double angle, double alpha = 1, Vector2 scale = (1, 1), ERenderStyle style = STYLE_Translucent, Color col = 0xffffffff, int translation = 0)
Draws a graphic that can be rotated.
  • void DrawInventoryIcon(Inventory item, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.))
Draws the Icon of the given Inventory item.
  • void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1))
Draws a text string using the given HUDFont.
  • void DrawHexenArmor(int armortype, String image, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.))
Draws Hexen-specific armor.
  • void DrawShader(int which, Vector2 pos, Vector2 size, int flags = 0, double alpha = 1.)
  • Vector2, int AdjustPosition(Vector2 position, int flags, double width, double height)
  • void DrawGem(String chain, String gem, int displayvalue, int maxrange, Vector2 pos, int leftpadding, int rightpadding, int chainmod, int flags = 0)
  • void DrawBar(String ongfx, String offgfx, double curval, double maxval, Vector2 position, int border, int vertical, int flags = 0, double alpha 1.0)
Draws a horizontal bar.
  • void DrawInventoryBar(InventoryBarState parms, Vector2 position, int numfields, int flags = 0, double bgalpha = 1.)
Draws an inventory bar, using the data pulled from the InventoryBarState class.
  • double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0)
  • void Fill(Color col, double x, double y, double w, double h, int flags = 0)
Fills a rectangle of the given width/height at the given area with a solid color.
Creates a rectangular mask area. Everything drawn afterwards will only be drawn within that area.
Clears the previously defined clipping rectangle.
Checks that the player has a valid Inventory item selected in their inventory bar.
Gets the ammo pointers and and ammo amounts for the player's current weapon.
  • TextureID, Vector2 GetIcon(Inventory item, int flags, bool showdepleted = true)
Gets the icon for the given Inventory item.