I'm not the first to do it, and I'm also not completely satisfied with my current implementation, but it works (even though it can only be called from play scope).
All documentation is at the repository. The hudmessage relies on an event handler (you can implement the event and the array into your own event handler if you're using them) and a class that handles the drawing. There's only one function that can be used as a combination of HUDMSG_TYPEON and HUDMSG_FADEINOUT HudMessage styles.
If you plan to use this in your project, I recommend using Find & Replace to replace "JGP_" with your own prefix.
To draw the hud message, call JGP_HudMessage.Create from anywhere in play context. Currently cannot be called in UI scope.
Code: Select all
static JGP_HudMessage Create(string text, uint id = 0, name fontname = 'NewSmallFont', int fontColor = Font.CR_Red, vector2 pos = (160, 50), int alignment = ALIGN_LEFT, uint fadeInTime = 0, uint typeTime = 0, uint holdTime = 35, uint fadeOutTime = 0, vector2 scale = (1,1), PlayerInfo viewer = null)
- text — the string of text to print. LANGUAGE references are supported.
- id (default: 0) — the ID of the message. If non-zero, new messages will override older messages with the same ID.
- fontname (default: 'NewSmallFont') — the name of the font to be used.
- fontcolor (default: Font.CR_Red) — the color of the font (as defined in the Font struct).
- pos (default: (160, 50)) — the position of the message in a virtual 320x200 grid. Note, this is virtual resolution, so (0, 0) corresponds to top left corner of the screen.
- alignment (default: ALIGN_LEFT) — the alignment of the text relative to the pos.
— JGP_HudMessage.ALIGN_CENTER — center alignment
— JGP_HudMessage.ALIGN_LEFT — left alignment (default)
— JGP_HudMessage.ALIGN_RIGHT — right alignment - fadeInTime (default: 0) — the time in tics it takes the message to fade in. If non-zero, holdTime will begin the countdown after the message fully faded in.
- typeTime (default: 0) — if non-zero, each character will take this amount of time in tics to type out each character in the string. If fadeInTime is non-zero, typing and fade-in will overlap, and holdTime will begin counting after whatever took longer (fade-in or type-out) has finished.
- holdTime (default: 35) — the time in tics the message will stay on the screen (fade-in, fade-out and type-out are added on top of this).
- fadeOutTime (default: 0) — the time in tics the message will take to fade out before disappearing.
- scale (default: (1, 1)) — the scale of the text.
- viewer (default: null) — a PlayerInfo pointer. If non-null, the message will only be visibled to the specified player. Otherwise it'll be visible to everyone.