Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
ChatWindow
DescriptionHUD chat window. Displays chat messages.Parent
HUDDisplayElementFunctions
- createBackground
- draw
- getBackgroundPosition
- new
- onMenuVisibilityChange
- scrollChatMessages
- setChatMessages
- setScale
- setVisible
- storeScaledValues
- update
createBackground
DescriptionCreate the background overlay.Definition
createBackground()Code
191 | function ChatWindow.createBackground(hudAtlasPath) |
192 | local posX, posY = ChatWindow.getBackgroundPosition(1) |
193 | local width, height = getNormalizedScreenValues(unpack(ChatWindow.SIZE.SELF)) |
194 | |
195 | local overlay = Overlay:new(hudAtlasPath, posX, posY, width, height) |
196 | overlay:setUVs(getNormalizedUVs(ChatWindow.UV.BACKGROUND)) |
197 | overlay:setColor(unpack(ChatWindow.COLOR.BACKGROUND)) |
198 | overlay.visible = false -- initialize as invisible, important for first hide call and hide timer |
199 | return overlay |
200 | end |
draw
DescriptionDraw the chat window.Definition
draw()Code
111 | function ChatWindow:draw() |
112 | -- TODO: implement a non-hacky way of knowing when the chat dialog is open: |
113 | |
114 | if self:getVisible() and (not self.isMenuVisible or g_gui.currentGuiName == "ChatDialog") and #self.messages > 0 then |
115 | ChatWindow:superClass().draw(self) |
116 | |
117 | setTextWrapWidth(self:getWidth()) |
118 | setTextBold(false) |
119 | setTextAlignment(RenderText.ALIGN_LEFT) |
120 | local currentLine = 0 |
121 | |
122 | local baseX, baseY = self:getPosition() |
123 | local posX, posY = baseX + self.messageOffsetX, baseY + self.messageOffsetY |
124 | local lineHeight = self.textSize + self.lineOffset |
125 | |
126 | local maxLineShown = self.maxLines + self.chatMessagesShowOffset |
127 | for i = #self.messages, 1, -1 do |
128 | local text = self.messages[i].sender .. ": " .. self.messages[i].msg |
129 | local _, numLines = getTextHeight(self.textSize, text) |
130 | currentLine = currentLine + numLines |
131 | if currentLine > self.chatMessagesShowOffset then |
132 | local lineShowOffset = math.max(currentLine - maxLineShown, 0) |
133 | local numLinesShow = math.min(numLines, currentLine - self.chatMessagesShowOffset) |
134 | numLinesShow = numLinesShow - lineShowOffset |
135 | |
136 | setTextLineBounds(lineShowOffset, numLinesShow) |
137 | |
138 | -- render shadow |
139 | setTextColor(unpack(ChatWindow.COLOR.MESSAGE_SHADOW)) |
140 | renderText(posX + self.shadowOffset, posY + (currentLine - lineShowOffset - self.chatMessagesShowOffset - 1) * lineHeight - self.shadowOffset, self.textSize, text) |
141 | -- render text |
142 | setTextColor(unpack(ChatWindow.COLOR.MESSAGE)) |
143 | renderText(posX, posY + (currentLine - lineShowOffset - self.chatMessagesShowOffset - 1) * lineHeight, self.textSize, text) |
144 | setTextLineBounds(0, 0) |
145 | if lineShowOffset > 0 then |
146 | break |
147 | end |
148 | end |
149 | end |
150 | |
151 | setTextWrapWidth(0) |
152 | end |
153 | end |
getBackgroundPosition
DescriptionGet this element's base background position.Definition
getBackgroundPosition(float uiScale)Arguments
float | uiScale | Current UI scale factor |
169 | function ChatWindow.getBackgroundPosition(uiScale) |
170 | local offX, offY = getNormalizedScreenValues(unpack(ChatWindow.POSITION.SELF)) |
171 | return g_safeFrameOffsetX + offX, g_safeFrameOffsetY + offY |
172 | end |
new
DescriptionCreate a new ChatWindow.Definition
new(string hudAtlasPath, table speakerDisplay)Arguments
string | hudAtlasPath | Path to the HUD atlas texture. |
table | speakerDisplay | SpeakerDisplay reference which is notified when this window is visible |
table | ChatWindow | instance |
25 | function ChatWindow.new(hudAtlasPath, speakerDisplay) |
26 | local backgroundOverlay = ChatWindow.createBackground(hudAtlasPath) |
27 | local self = ChatWindow:superClass().new(ChatWindow_mt, backgroundOverlay, nil) |
28 | |
29 | self.speakerDisplay = speakerDisplay |
30 | |
31 | self.maxLines = ChatWindow.MAX_NUM_MESSAGES -- overrides parent class value |
32 | self.messages = {} -- reference to chat message history owned by mission object |
33 | |
34 | self.chatMessagesShowOffset = 0 |
35 | self.hideTime = 0 |
36 | |
37 | self.messageOffsetX, self.messageOffsetY = 0, 0 |
38 | self.textSize = 0 |
39 | self.textOffsetY = 0 |
40 | self.lineOffset = 0 |
41 | self.shadowOffset = 0 |
42 | |
43 | self:storeScaledValues() |
44 | |
45 | return self |
46 | end |
onMenuVisibilityChange
DescriptionHandle menu visibility state change.Definition
onMenuVisibilityChange()Code
83 | function ChatWindow:onMenuVisibilityChange(isMenuVisible) |
84 | self.isMenuVisible = isMenuVisible |
85 | end |
scrollChatMessages
DescriptionScroll chat messages by a given amount.Definition
scrollChatMessages(int delta, int numMessages)Arguments
int | delta | Number of lines (positive or negative) to scroll |
int | numMessages | Number of currently stored chat messages |
77 | function ChatWindow:scrollChatMessages(delta, numMessages) |
78 | self.chatMessagesShowOffset = MathUtil.clamp(self.chatMessagesShowOffset + delta, 0, numMessages - self.maxLines) |
79 | end |
setChatMessages
DescriptionSet the chat message history reference for displaying. The array is owned by the caller and must not be modified.Definition
setChatMessages(table messages)Arguments
table | messages | Messages array as {i={msg= |
52 | function ChatWindow:setChatMessages(messages) |
53 | self.messages = messages |
54 | end |
setScale
DescriptionSet this element's UI scale.Definition
setScale()Code
161 | function ChatWindow:setScale(uiScale) |
162 | ChatWindow:superClass().setScale(self, uiScale) |
163 | self:storeScaledValues() |
164 | end |
setVisible
DescriptionDefinitionsetVisible()Code
58 | function ChatWindow:setVisible(isVisible, animate) |
59 | if isVisible then |
60 | self.speakerDisplay:onChatVisibilityChange(true) |
61 | ChatWindow:superClass().setVisible(self, true, false) |
62 | |
63 | if animate then |
64 | self.hideTime = ChatWindow.DISPLAY_DURATION |
65 | else |
66 | self.hideTime = -1 |
67 | end |
68 | else |
69 | self.hideTime = self:getVisible() and ChatWindow.DISPLAY_DURATION or 0 |
70 | end |
71 | end |
storeScaledValues
DescriptionStore scaled positioning, size and offset values.Definition
storeScaledValues()Code
176 | function ChatWindow:storeScaledValues() |
177 | self.messageOffsetX, self.messageOffsetY = self:scalePixelToScreenVector(ChatWindow.POSITION.MESSAGE) |
178 | |
179 | self.textSize = self:scalePixelToScreenHeight(ChatWindow.TEXT_SIZE.MESSAGE) |
180 | self.textOffsetY = self.textSize * 0.15 |
181 | self.lineOffset = self.textSize * 0.3 |
182 | self.shadowOffset = ChatWindow.SHADOW_OFFSET_FACTOR * self.textSize |
183 | end |
update
DescriptionUpdate element state.Definition
update()Code
93 | function ChatWindow:update(dt) |
94 | ChatWindow:superClass().update(self, dt) |
95 | |
96 | if self.hideTime >= 0 then -- also update and hide if time has been set to 0, see test below |
97 | self.hideTime = self.hideTime - dt |
98 | if self.hideTime <= 0 then |
99 | self.speakerDisplay:onChatVisibilityChange(false) |
100 | ChatWindow:superClass().setVisible(self, false, false) |
101 | end |
102 | end |
103 | end |