Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
SideNotification
DescriptionHUD side notification element. Displays notifications issued by other game components at the side of the screen.Parent
HUDDisplayElementFunctions
- addNotification
- createBackground
- createComponents
- draw
- getBackgroundPosition
- new
- setScale
- storeScaledValues
- update
- updateSizeAndPositions
addNotification
DescriptionAdd a notification message to display.Definition
addNotification(string text, table color, int displayDuration)Arguments
string | text | Display message text |
table | color | Color array as {r, g, b, a} |
int | displayDuration | Display duration of message in milliseconds |
43 | function SideNotification:addNotification(text, color, displayDuration) |
44 | local notification = {text=text, color=color, duration=displayDuration, startDuration=displayDuration} |
45 | table.insert(self.notificationQueue, notification) |
46 | |
47 | self:updateSizeAndPositions() |
48 | end |
createBackground
DescriptionCreate the background overlay.Definition
createBackground()Code
169 | function SideNotification:createBackground(hudAtlasPath) |
170 | local posX, posY = SideNotification.getBackgroundPosition(1) |
171 | local width, height = getNormalizedScreenValues(unpack(SideNotification.SIZE.SELF)) |
172 | |
173 | local overlay = Overlay.new(hudAtlasPath, posX - width, posY - height, width, height) |
174 | overlay:setUVs(GuiUtils.getUVs(SideNotification.UV.DEFAULT_BACKGROUND)) |
175 | overlay:setColor(unpack(SideNotification.COLOR.DEFAULT_BACKGROUND)) |
176 | return overlay |
177 | end |
createComponents
DescriptionCreate required display components.Definition
createComponents()Code
181 | function SideNotification:createComponents(hudAtlasPath) |
182 | end |
draw
DescriptionDraw the notifications.Definition
draw()Code
79 | function SideNotification:draw() |
80 | if self:getVisible() and #self.notificationQueue > 0 then |
81 | SideNotification:superClass().draw(self) |
82 | |
83 | local baseX, baseY = self:getPosition() |
84 | local width, height = self:getWidth(), self:getHeight() |
85 | |
86 | local offsetX = 1 / g_screenWidth |
87 | local offsetY = 1 / g_screenHeight |
88 | local notificationX = baseX + width - self.notificationMarginX |
89 | local notificationY = baseY + height - self.textSize - self.notificationMarginY |
90 | |
91 | local _, _, _, alpha = self:getColor() |
92 | for i = 1, math.min(#self.notificationQueue, SideNotification.MAX_NOTIFICATIONS) do |
93 | local notification = self.notificationQueue[i] |
94 | |
95 | local fadeAlpha = 1 |
96 | if notification.startDuration - notification.duration < SideNotification.FADE_DURATION then |
97 | fadeAlpha = (notification.startDuration - notification.duration) / SideNotification.FADE_DURATION |
98 | elseif notification.duration < SideNotification.FADE_DURATION then |
99 | fadeAlpha = notification.duration / SideNotification.FADE_DURATION |
100 | end |
101 | |
102 | setTextBold(false) |
103 | setTextAlignment(RenderText.ALIGN_RIGHT) |
104 | -- render shadow |
105 | setTextColor(0, 0, 0, alpha * fadeAlpha) |
106 | renderText(notificationX + offsetX, notificationY - offsetY + self.textOffsetY, self.textSize, notification.text) |
107 | -- render text |
108 | setTextColor(notification.color[1], notification.color[2], notification.color[3], notification.color[4] * alpha * fadeAlpha) |
109 | renderText(notificationX, notificationY + self.textOffsetY, self.textSize, notification.text) |
110 | |
111 | notificationY = notificationY - self.textSize - self.lineOffset |
112 | end |
113 | -- reset color to prevent following texts from being colored |
114 | setTextColor(1, 1, 1, 1) |
115 | end |
116 | end |
getBackgroundPosition
DescriptionGet this element's base background position.Definition
getBackgroundPosition(float uiScale)Arguments
float | uiScale | Current UI scale factor |
126 | function SideNotification.getBackgroundPosition(uiScale) |
127 | local offX, offY = getNormalizedScreenValues(unpack(SideNotification.POSITION.SELF)) |
128 | return 1 - g_safeFrameOffsetX + offX * uiScale, 1 - g_safeFrameOffsetY + offY * uiScale -- top right corner plus offset |
129 | end |
new
DescriptionCreate a new SideNotification.Definition
new(string hudAtlasPath)Arguments
string | hudAtlasPath | Path to the HUD atlas texture |
table | SideNotification | instance |
24 | function SideNotification.new(customMt, hudAtlasPath) |
25 | local self = SideNotification:superClass().new(nil, nil, customMt or SideNotification_mt) |
26 | self.overlay = self:createBackground(hudAtlasPath) |
27 | |
28 | self.notificationQueue = {} -- i={text=<text>, color={r,g,b,a}, duration=<time in ms>} |
29 | |
30 | self.textSize = 0 |
31 | self.textOffsetY = 0 -- vertical alignment compensation offset |
32 | self.lineOffset = 0 |
33 | self.notificationMarginX, self.notificationMarginY = 0, 0 |
34 | |
35 | return self |
36 | end |
setScale
DescriptionSet uniform UI scale.Definition
setScale()Code
133 | function SideNotification:setScale(uiScale) |
134 | SideNotification:superClass().setScale(self, uiScale) |
135 | self:updateSizeAndPositions() |
136 | end |
storeScaledValues
DescriptionStore scaled positioning, size and offset values.Definition
storeScaledValues()Code
156 | function SideNotification:storeScaledValues() |
157 | self.textSize = self:scalePixelToScreenHeight(SideNotification.TEXT_SIZE.DEFAULT_NOTIFICATION) |
158 | self.textOffsetY = self.textSize * 0.15 |
159 | self.lineOffset = self.textSize * 0.3 |
160 | self.notificationMarginX, self.notificationMarginY = self:scalePixelToScreenVector(SideNotification.SIZE.NOTIFICATION_MARGIN) |
161 | end |
update
DescriptionUpdate notifications state.Definition
update()Code
56 | function SideNotification:update(dt) |
57 | local hasRemoval = false |
58 | for i = math.min(#self.notificationQueue, SideNotification.MAX_NOTIFICATIONS), 1, -1 do |
59 | local notification = self.notificationQueue[i] |
60 | if notification.duration <= 0 then |
61 | table.remove(self.notificationQueue, i) |
62 | hasRemoval = true |
63 | else |
64 | notification.duration = math.max(0, notification.duration - dt) -- limit to zero for alpha calculations |
65 | end |
66 | end |
67 | |
68 | if hasRemoval then |
69 | self:updateSizeAndPositions() |
70 | end |
71 | end |
updateSizeAndPositions
DescriptionUpdate sizes and positions of this elements and its children.Definition
updateSizeAndPositions()Code
140 | function SideNotification:updateSizeAndPositions() |
141 | local numLines = math.min(#self.notificationQueue, SideNotification.MAX_NOTIFICATIONS) |
142 | |
143 | local height = numLines * self.textSize + (numLines - 1) * self.lineOffset + self.notificationMarginY * 2 |
144 | local width = self:getWidth() |
145 | self:setDimension(width, height) |
146 | |
147 | local topRightX, topRightY = SideNotification.getBackgroundPosition(self:getScale()) |
148 | local bottomY = topRightY - self:getHeight() |
149 | self:setPosition(topRightX - width, bottomY) |
150 | |
151 | self:storeScaledValues() |
152 | end |