MrxSubtitle
Module: mrxsubtitle.lua
Overview
The MrxSubtitle module manages the queueing and display of subtitles in the game. It provides functionality to add multiple subtitle messages with a callback for the final message, as well as clear pending messages from the buffer.
Inheritance
- Inherits from:
none β base/utility module - Imports:
none
Instance pattern
This is a stateless manager/utility module (no per-instance tables). The actual display goes through the engineβs Hud SubtitleBuffer object. Key fields:
_tMsgIds: A table to store message IDs of queued subtitles (soClearPendingcan remove them later)._knDisplayDuration=5: default on-screen seconds per subtitle message._knFadeDuration=0.5: default fade seconds per subtitle message.
Both durations are module globals with no setter β a mod changes subtitle timing by reassigning MrxSubtitle._knDisplayDuration / _knFadeDuration before calling Add.
Functions
Add(vMsgs, fCallback, tCallbackArgs)
Accepts a string or table of messages (type(vMsgs) branches on "string" vs "table"; any other type is a silent no-op β returns with no error and nothing queued). Builds one tConfig per message (sMessage, nDuration = _knDisplayDuration, nFadeTime = _knFadeDuration, bClearBuffer = true, bAllowsAppends = false) and pushes each to Hud.SubtitleBuffer:AddMessage(tConfig). Only the last message in the batch (i == nMsgs, via table.getn(tMsgs)) gets tConfig.fCallback/ tConfig.tCallbackData set from fCallback/tCallbackArgs β earlier messages in a multi-message call get no callback. Every message ID returned by AddMessage is appended to _tMsgIds.
ClearPending()
Removes pending messages from the buffer by calling Hud.SubtitleBuffer:RemovePendingMessage({tMessageIds = tMsgId}) for each stored message ID. Reassigns _tMsgIds to a fresh empty table after removal (source does _tMsgIds = nil immediately followed by _tMsgIds = {}, rather than clearing in place).
Events
No Event.* references anywhere in this file β this module is not event-driven. Add and ClearPending are plain functions called directly by whichever script wants to display or clear subtitles; there are no call sites for either inside this file, so triggering is entirely external (no call sites found in the decompiled corpus for either from this side).
Notes for modders
- Use
Addto queue multiple subtitle messages with a callback for the final message only β if you need a callback per-message, callAddonce per message instead of batching them. - Use
ClearPendingto remove any queued subtitle messages from the buffer before adding new ones. - Customize display and fade durations by modifying
_knDisplayDurationand_knFadeDuration. - Be aware that the module uses
Hud.SubtitleBufferfor managing subtitle messages, so ensure this buffer is available in your game environment. Addusestable.getn(tMsgs), a Lua 5.0-era API (removed in later Lua versions) rather than the#length operator β consistent with this codebaseβs older Lua runtime, not a bug.