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
TopNotification
DescriptionHUD top notification element. Displays notifications issued by other game components at the top of the screen.Parent
HUDDisplayElementFunctions
- createBackground
- createComponents
- createIconOverlays
- delete
- draw
- getBackgroundPosition
- getHidingTranslation
- new
- setNotification
- setScale
- storeScaledValues
- update
createBackground
DescriptionCreate the background overlay.Definition
createBackground()Code
244 | function TopNotification.createBackground(hudAtlasPath) |
245 | local width, height = getNormalizedScreenValues(unpack(TopNotification.SIZE.SELF)) |
246 | local posX, posY = TopNotification.getBackgroundPosition(1, width, height) |
247 | |
248 | local overlay = Overlay.new(g_baseUIFilename, posX, posY, width, height) |
249 | overlay:setUVs(g_colorBgUVs) |
250 | overlay:setColor(unpack(TopNotification.COLOR.BACKGROUND)) |
251 | |
252 | return overlay |
253 | end |
createComponents
DescriptionCreate required display components.Definition
createComponents()Code
257 | function TopNotification:createComponents(hudAtlasPath) |
258 | end |
createIconOverlays
DescriptionDefinitioncreateIconOverlays()Code
262 | function TopNotification:createIconOverlays() |
263 | local width, height = getNormalizedScreenValues(unpack(TopNotification.SIZE.ICON)) |
264 | |
265 | local iconOverlay = Overlay.new(g_iconsUIFilename, 0, 0, width, height) |
266 | iconOverlay:setUVs(GuiUtils.getUVs(TopNotification.UV.ICON_RADIO_STREAM)) |
267 | iconOverlay:setColor(unpack(TopNotification.COLOR.ICON)) |
268 | self.icons[TopNotification.ICON.RADIO] = iconOverlay |
269 | end |
delete
DescriptionDefinitiondelete()Code
59 | function TopNotification:delete() |
60 | for k, overlay in pairs(self.icons) do |
61 | overlay:delete() |
62 | self.icons[k] = nil |
63 | end |
64 | |
65 | if self.customIcon ~= nil then |
66 | self.customIcon:delete() |
67 | self.customIcon = nil |
68 | end |
69 | |
70 | TopNotification:superClass().delete(self) |
71 | end |
draw
DescriptionDraw notification.Definition
draw()Code
140 | function TopNotification:draw() |
141 | if self:getVisible() then |
142 | TopNotification:superClass().draw(self) -- background and frame |
143 | |
144 | local notification = self.currentNotification |
145 | local title = Utils.limitTextToWidth(notification.title, self.titleTextSize, self.maxTextWidth, false, "...") |
146 | local text = Utils.limitTextToWidth(notification.text, self.descTextSize, self.maxTextWidth, false, "...") |
147 | local info = Utils.limitTextToWidth(notification.info, self.infoTextSize, self.maxTextWidth, false, "...") |
148 | |
149 | local fadeAlpha = 1 |
150 | if self.notificationStartDuration - self.currentNotification.duration < TopNotification.FADE_DURATION then |
151 | fadeAlpha = (self.notificationStartDuration - self.currentNotification.duration) / TopNotification.FADE_DURATION |
152 | elseif self.currentNotification.duration < TopNotification.FADE_DURATION then |
153 | fadeAlpha = self.currentNotification.duration / TopNotification.FADE_DURATION |
154 | end |
155 | |
156 | local _, _, _, baseAlpha = self:getColor() |
157 | local baseX, baseY = self:getPosition() |
158 | local width, height = self:getWidth(), self:getHeight() |
159 | |
160 | local alpha = baseAlpha * fadeAlpha |
161 | |
162 | if notification.iconFilename ~= nil then |
163 | local icon = self.customIcon |
164 | icon:setColor(nil, nil, nil, alpha) |
165 | icon:setPosition(baseX + self.iconOffsetX, -- left |
166 | baseY + (height - notification.icon.height) * 0.5) -- middle |
167 | icon:render() |
168 | elseif notification.icon ~= nil then |
169 | local icon = notification.icon |
170 | icon:setColor(nil, nil, nil, alpha) |
171 | icon:setPosition(baseX + self.iconOffsetX, -- left |
172 | baseY + (height - notification.icon.height) * 0.5) -- middle |
173 | icon:render() |
174 | end |
175 | |
176 | local r, g, b, a = unpack(TopNotification.COLOR.TEXT_TITLE) |
177 | setTextColor(r, g, b, a * alpha) |
178 | setTextBold(false) |
179 | setTextAlignment(RenderText.ALIGN_CENTER) |
180 | |
181 | local centerX = baseX + width * 0.5 |
182 | renderText(centerX + self.titleOffsetX, baseY + self.titleOffsetY, self.titleTextSize, title) |
183 | |
184 | r, g, b, a = unpack(TopNotification.COLOR.TEXT_DESC) |
185 | setTextColor(r, g, b, a * alpha) |
186 | renderText(centerX + self.descOffsetX, baseY + self.descOffsetY, self.descTextSize, text) |
187 | |
188 | r, g, b, a = unpack(TopNotification.COLOR.TEXT_INFO) |
189 | setTextColor(r, g, b, a * alpha) |
190 | renderText(centerX + self.infoOffsetX, baseY + self.infoOffsetY, self.infoTextSize, info) |
191 | end |
192 | end |
getBackgroundPosition
DescriptionGet this element's base background position.Definition
getBackgroundPosition(float uiScale)Arguments
float | uiScale | Current UI scale factor |
201 | function TopNotification.getBackgroundPosition(uiScale, width, height) |
202 | local offX, offY = getNormalizedScreenValues(unpack(TopNotification.POSITION.SELF)) |
203 | return 0.5 - width * 0.5 + offX * uiScale, 1 - g_safeFrameOffsetY - height + offY * uiScale -- top center plus offset |
204 | end |
getHidingTranslation
DescriptionGet the screen space translation for hiding. Override in sub-classes if a different translation is required.Definition
getHidingTranslation()Return Values
float | Screen | space X translation |
float | Screen | space Y translation |
108 | function TopNotification:getHidingTranslation() |
109 | return 0, 0.5 -- hide half a screen height above the upper screen border |
110 | end |
new
DescriptionCreate a new TopNotification.Definition
new(string hudAtlasPath)Arguments
string | hudAtlasPath | Path to the HUD atlas texture. |
table | TopNotification | instance |
31 | function TopNotification.new(hudAtlasPath) |
32 | local backgroundOverlay = TopNotification.createBackground(hudAtlasPath) |
33 | local self = TopNotification:superClass().new(backgroundOverlay, nil, TopNotification_mt) |
34 | |
35 | self.currentNotification = TopNotification.NO_NOTIFICATION |
36 | self.icons = {} -- icon key -> Overlay |
37 | |
38 | self.titleTextSize = 0 |
39 | self.descTextSize = 0 |
40 | self.infoTextSize = 0 |
41 | self.maxTextWidth = 0 |
42 | |
43 | self.titleOffsetX, self.titleOffsetY = 0, 0 |
44 | self.descOffsetX, self.descOffsetY = 0, 0 |
45 | self.infoOffsetX, self.infoOffsetY = 0, 0 |
46 | self.iconOffsetX, self.iconOffsetY = 0, 0 |
47 | |
48 | self.notificationStartDuration = 0 |
49 | |
50 | self:storeScaledValues() |
51 | self:createComponents(hudAtlasPath) |
52 | self:createIconOverlays() |
53 | |
54 | return self |
55 | end |
setNotification
DescriptionSet a notification to be displayed in a frame at the top of the screen. If another notification is being displayed, it is immediately replaced by this new one.Definition
setNotification(string title, string text, string info, table iconKey, int duration)Arguments
string | title | Notification title |
string | text | Notification message text |
string | info | Additional info text |
table | iconKey | [optional] Icon key for a display icon, use a value from TopNotification.ICON |
int | duration | [optional] Display duration in milliseconds. Negative values or nil default to a long-ish standard duration. |
82 | function TopNotification:setNotification(title, text, info, iconKey, duration, iconFilename) |
83 | local icon = nil |
84 | if iconKey ~= nil and self.icons[iconKey] ~= nil then |
85 | icon = self.icons[iconKey] |
86 | end |
87 | |
88 | if duration == nil or duration < 0 then |
89 | duration = TopNotification.DEFAULT_DURATION |
90 | end |
91 | |
92 | local notification = {title=title, text=text, info=info, icon=icon, duration=duration, iconFilename=iconFilename} |
93 | self.notificationStartDuration = duration |
94 | self.currentNotification = notification |
95 | |
96 | if iconFilename ~= nil then |
97 | self.customIcon = self:createCustomIcon(iconFilename) |
98 | end |
99 | |
100 | self:setVisible(true, true) -- animate in |
101 | end |
setScale
DescriptionSet uniform UI scale.Definition
setScale()Code
208 | function TopNotification:setScale(uiScale) |
209 | TopNotification:superClass().setScale(self, uiScale) |
210 | self:storeScaledValues() |
211 | |
212 | -- set position again because we anchor from the top (scaling protrudes from bottom left) |
213 | local width, height = self:scalePixelToScreenVector(TopNotification.SIZE.SELF) |
214 | local posX, posY = TopNotification.getBackgroundPosition(uiScale, width, height) |
215 | self:setPosition(posX, posY) |
216 | end |
storeScaledValues
DescriptionStore scaled positioning, size and offset values.Definition
storeScaledValues()Code
220 | function TopNotification:storeScaledValues() |
221 | self.titleTextSize = self:scalePixelToScreenHeight(TopNotification.TEXT_SIZE.TITLE) |
222 | self.descTextSize = self:scalePixelToScreenHeight(TopNotification.TEXT_SIZE.TEXT) |
223 | self.infoTextSize = self:scalePixelToScreenHeight(TopNotification.TEXT_SIZE.INFO) |
224 | |
225 | self.maxTextWidth = self:scalePixelToScreenWidth(TopNotification.TEXT_SIZE.MAX_TEXT_WIDTH) |
226 | |
227 | self.titleOffsetX, self.titleOffsetY = self:scalePixelToScreenVector(TopNotification.POSITION.TITLE_OFFSET) |
228 | self.descOffsetX, self.descOffsetY = self:scalePixelToScreenVector(TopNotification.POSITION.TEXT_OFFSET) |
229 | self.infoOffsetX, self.infoOffsetY = self:scalePixelToScreenVector(TopNotification.POSITION.INFO_OFFSET) |
230 | |
231 | self.iconOffsetX, self.iconOffsetY = self:scalePixelToScreenVector(TopNotification.POSITION.ICON) |
232 | local iconWidth, iconHeight = self:scalePixelToScreenVector(TopNotification.SIZE.ICON) |
233 | for _, overlay in pairs(self.icons) do |
234 | overlay:setDimension(iconWidth, iconHeight) |
235 | end |
236 | end |
update
DescriptionUpdate notification state.Definition
update()Code
118 | function TopNotification:update(dt) |
119 | TopNotification:superClass().update(self, dt) |
120 | |
121 | if self:getVisible() and self.currentNotification ~= TopNotification.NO_NOTIFICATION then |
122 | if self.currentNotification.duration < TopNotification.FADE_DURATION and self.animation:getFinished() then |
123 | self:setVisible(false, true) -- animate out |
124 | end |
125 | |
126 | if self.currentNotification.duration <= 0 then |
127 | self.currentNotification = TopNotification.NO_NOTIFICATION |
128 | else |
129 | self.currentNotification.duration = self.currentNotification.duration - dt |
130 | end |
131 | end |
132 | end |