Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Message

Classes

Class: Message

Extends Widget

Message

A Message widget displays messages, similar to a chat log or notification feed. Supports adding messages with optional visibility duration, scrolling, styling, and item link detection.

Dependencies:

Field: style

TextStyle

The default text style used for messages.

Method: ResetVisibleTime

(method) Message:ResetVisibleTime()

Resets the visibility duration for the Message.

Method: ScrollDown

(method) Message:ScrollDown()

Scrolls down by one line in the Message.

widget:SetHandler("OnWheelDown", function(self)
  self:ScrollDown()
end)

Method: ScrollToBottom

(method) Message:ScrollToBottom()

Scrolls to the bottom of the Message.

Method: RemoveLastMessage

(method) Message:RemoveLastMessage()
  -> remainingLines: number

Removes the last message and returns the remaining number of lines.

@return remainingLines — The number of remaining lines.

Method: PageDown

(method) Message:PageDown()

Scrolls down one page in the Message.

Method: PageUp

(method) Message:PageUp()

Scrolls up one page in the Message.

Method: GetPagePerMaxLines

(method) Message:GetPagePerMaxLines()
  -> maxLinesPerPage: number

Retrieves the maximum number of lines per page in the Message.

@return maxLinesPerPage — The maximum lines per page (the widgets height).

Method: ScrollToTop

(method) Message:ScrollToTop()

Scrolls to the top of the Message.

Method: SetFadeDuration

(method) Message:SetFadeDuration(seconds: number)

Sets the fade duration for the Message. Must be set before adding a message.

@param seconds — The fade duration in seconds.

Method: SetScrollPos

(method) Message:SetScrollPos(value: number)

Sets the scroll position for the Message.

@param value — The scroll position value.

Method: ScrollUp

(method) Message:ScrollUp()

Scrolls up by one line in the Message.

widget:SetHandler("OnWheelUp", function(self)
  self:ScrollUp()
end)

Method: SetMaxLines

(method) Message:SetMaxLines(count: number)

Sets the maximum number of lines for the Message. Uses widget:Clear() before setting the maximum line count.

@param count — The maximum line count.

Method: SetInset

(method) Message:SetInset(left: number, top: number, right: number, bottom: number)

Sets the inset for the Message.

@param left — The left inset.

@param top — The top inset.

@param right — The right inset.

@param bottom — The bottom inset.

Method: SetLineSpace

(method) Message:SetLineSpace(space: number)

Sets the line spacing for the Message.

@param space — The line spacing value.

Method: SetTimeVisible

(method) Message:SetTimeVisible(seconds: number)

Sets the visibility duration for the Message.

@param seconds — The duration in seconds the message remains visible. (default: 15)

Method: GetMessageLines

(method) Message:GetMessageLines()
  -> messageLineCount: number

Retrieves the number of message lines in the Message.

@return messageLineCount — The number of message lines.

Method: GetMaxLines

(method) Message:GetMaxLines()
  -> maxLines: number

Retrieves the maximum number of lines for the Message.

@return maxLines — The maximum number of lines. (default: 80)

Method: ChangeDefaultStyle

(method) Message:ChangeDefaultStyle()

Changes the default style for the Message.

Method: ChangeTextStyle

(method) Message:ChangeTextStyle()

Changes the text style of the Message from aligning to the bottom of the widget to the top of the widget.

Method: AddMessageRefresh

(method) Message:AddMessageRefresh(message: string)

Adds a message and refreshes the Message.

@param message — The message text to add.

Method: AddMessageEx

(method) Message:AddMessageEx(message: string, visibleTime: number)

Adds a message with a specified visibility duration to the Message.

@param message — The message text to add.

@param visibleTime — The visibility duration in milliseconds.

Method: AddMessageExRefresh

(method) Message:AddMessageExRefresh(message: string, visibleTime: number)

Adds a message with a specified visibility duration and refreshes the Message.

@param message — The message text to add.

@param visibleTime — The visibility duration in milliseconds.

Method: GetMessageByTimeStamp

(method) Message:GetMessageByTimeStamp(messageTimeStamp: number)
  -> message: string

Retrieves the message text for a given timestamp in the Message.

@param messageTimeStamp — The timestamp of the message.

@return message — The message text.

Method: Clear

(method) Message:Clear()

Clears all messages from the Message.

(method) Message:EnableItemLink(enable: boolean)

Enables or disables item link functionality (Message:GetLinkInfoOnCursor) for the Message.

@param enabletrue to enable item links, false to disable. (default: false)

Method: GetLinkInfoOnCursor

(method) Message:GetLinkInfoOnCursor()
  -> linkInfo: BaseLinkInfo

Retrieves link information for the item under the cursor in the Message. Requires Message:EnableItemLink(true).

@return linkInfo — The link information for the item.

widget:EnableItemLink(true)
widget:SetHandler("OnClick", function(self)
  local linkInfo = self:GetLinkInfoOnCursor()

  if linkInfo.linkType == "item" then
    @cast linkInfo ItemLinkInfo
    local itemInfo = X2Item:InfoFromLink(linkInfo.itemLinkText, tostring(linkInfo.linkKind))
  end
end)

Method: CopyTextToClipboard

(method) Message:CopyTextToClipboard()
  -> result: boolean

Checks if the text under the cursor was copied to the clipboard.

@return resulttrue if text was copied, false otherwise.

widget:SetHandler("OnClick", function(self, mouseButton)
  if mouseButton == "RightButton" then
    self:CopyTextToClipboard()
  end
end)

Method: GetLineSpace

(method) Message:GetLineSpace()
  -> lineSpace: number

Retrieves the line spacing for the Message.

@return lineSpace — The line spacing value. (default: 0)

Method: GetCurrentLine

(method) Message:GetCurrentLine()
  -> currentLine: number

Retrieves the current line index of the Message.

@return currentLine — The current line index.

Method: GetCurrentScroll

(method) Message:GetCurrentScroll()
  -> currentScroll: number

Retrieves the current scroll position of the Message.

@return currentScroll — The current scroll position (min: 0).

Method: AddMessage

(method) Message:AddMessage(message: string)

Adds a message to the Message. Must be used after defining the widgets dimensions.

@param message — The message text to add.