Skip to main content

Scrollablechatqueue

Based on game build 714014 | Last updated: 2026-03-08

Overview

ScrollableChatQueue is a UI widget responsible for displaying the most recent chat messages in a scrollable view. It integrates with ChatHistory to fetch and render messages, supports multiline chat text via a temporary text widget, and manages automatic scrolling when new messages arrive or the user scrolls up/down. It inherits from Widget and uses ChatScrollList for scrolling logic and ChatLine for individual message rendering.

Usage example

local ScrollableChatQueue = require "widgets/redux/scrollablechatqueue"
local inst = CreateEntity()
inst:AddWidget("scrollablechatqueue", ScrollableChatQueue())
inst:ListenForEvent("on_player_log_in", function()
inst.components.scrollablechatqueue:PushMessage()
end)

Dependencies & tags

Components used: Widget, ChatHistory (via ChatHistory:AddChatHistoryListener, ChatHistory:GetChatMessageAtIndex, etc.)
Tags: None identified.

Properties

PropertyTypeDefault ValueDescription
widget_rowstable{}Array of ChatLine widgets used to render each chat line.
chat_fontstring"TALKINGFONT"Font identifier for chat text.
chat_sizenumber30Font size for chat text.
user_widthnumber160Width constraint for sender name rendering.
user_max_charsnumber28Maximum characters for sender name.
message_widthnumber850Width constraint for message content rendering.
message_max_charsnumber150Maximum characters per message line.
chat_listenerfunctionnilListener callback added to ChatHistory to respond to new messages.

Main functions

GetChatLinesForMessage(history_index)

  • Description: Returns the number of rendered lines (as an integer) required to display the chat message at the given index in ChatHistory. The result is cached in message_data.chatqueue_chatlines to avoid repeated splits. If the index points beyond the current history (e.g., for the last deleted message), it retrieves that special case.
  • Parameters: history_index (number) — The 1-based index into ChatHistory, or ChatHistory.MAX_CHAT_HISTORY + 1 to retrieve the last deleted message.
  • Returns: number — Number of lines needed to render the message; nil if no message data exists for the index.
  • Error states: Returns nil if ChatHistory does not contain a message for the given index.

MakeChatScrollList()

  • Description: Initializes the internal ChatScrollList, creates and configures the ChatLine widgets in self.widget_rows, and sets up the data generation, rendering, and scrolling logic for the chat queue.
  • Parameters: None.
  • Returns: Nothing.
  • Error states: Does nothing if self.chat_scroll_list already exists.

PushMessage()

  • Description: Adjusts the scroll position when a new chat message is added. If the view was fully scrolled down (max_scroll is true) and a deleted message is present (e.g., chat limit exceeded), scroll up by the difference in line counts. Otherwise, scroll up by the number of lines in the new message to keep the newest messages visible.
  • Parameters: None.
  • Returns: Nothing.

CalculateChatAlpha(history_index)

  • Description: Returns the alpha (opacity) value for a chat line based on its age in history. Currently hardcoded to return 1.0 for valid messages and 0.0 for invalid/empty entries.
  • Parameters: history_index (number?) — Index of the message in ChatHistory, or nil for invalid.
  • Returns: number — Alpha value (0.0 or 1.0).

RefreshWidgets(force_update)

  • Description: Triggers a full refresh of all widgets in the scroll list. Sets a history_updated flag to bypass caching during updates.
  • Parameters: force_update (boolean) — Whether to force a refresh even if internal state suggests it’s unnecessary.
  • Returns: Nothing.

OnChatControl(control, down)

  • Description: Passes chat-related input events (e.g., up/down arrow, page up/down) to the underlying ChatScrollList.
  • Parameters:
    • control (string) — The control identifier (e.g., "up", "down").
    • down (boolean) — Whether the control key was pressed.
  • Returns: boolean — Return value from ChatScrollList:OnChatControl.

IsChatOpen()

  • Description: Returns the current open state of the chat UI.
  • Parameters: None.
  • Returns: booleanself.chat_open.

Kill()

  • Description: Cleans up the component by removing the chat listener from ChatHistory and calling the parent Kill method.
  • Parameters: None.
  • Returns: Nothing.

Events & listeners

  • Listens to: ChatHistory events via AddChatHistoryListener — triggers PushMessage() on new chat entries.
  • Pushes: None identified.