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
HUDElement
DescriptionLightweight HUD UI element. Wraps an Overlay instance to display and provides a transform hierarchy of child HUDElement instances.Functions
- addChild
- delete
- draw
- getAlpha
- getColor
- getHeight
- getPosition
- getRotationPivot
- getScale
- getVisible
- getWidth
- new
- normalizeUVPivot
- removeChild
- resetDimensions
- scalePixelToScreenHeight
- scalePixelToScreenVector
- scalePixelToScreenWidth
- setAlignment
- setAlpha
- setColor
- setDimension
- setImage
- setPosition
- setRotation
- setRotationPivot
- setScale
- setUVs
- setVisible
- update
addChild
DescriptionAdd a child HUD element to this element.Definition
addChild(table childHudElement)Arguments
table | childHudElement | HUDElement instance which is added as a child. |
72 | function HUDElement:addChild(childHudElement) |
73 | if childHudElement.parent == self then |
74 | return |
75 | end |
76 | |
77 | if childHudElement.parent ~= nil then |
78 | childHudElement.parent:removeChild(childHudElement) |
79 | end |
80 | |
81 | table.insert(self.children, childHudElement) |
82 | childHudElement.parent = self |
83 | end |
delete
DescriptionDelete this HUD element and all its children. This will also delete the overlay and thus release its engine handle.Definition
delete()Code
50 | function HUDElement:delete() |
51 | if self.overlay ~= nil then |
52 | self.overlay:delete() |
53 | self.overlay = nil |
54 | end |
55 | |
56 | if self.parent ~= nil then |
57 | self.parent:removeChild(self) |
58 | end |
59 | |
60 | self.parent = nil |
61 | |
62 | for k, v in pairs(self.children) do |
63 | v.parent = nil -- saves the call to removeChild() on delete(), see above |
64 | v:delete() |
65 | self.children[k] = nil |
66 | end |
67 | end |
draw
DescriptionDraw this HUD element and all of its children in order of addition.Definition
draw()Code
298 | function HUDElement:draw() |
299 | if self.overlay.visible then |
300 | self.overlay:render() |
301 | |
302 | for _, child in ipairs(self.children) do |
303 | child:draw() |
304 | end |
305 | end |
306 | end |
getAlpha
DescriptionGet this HUD element's color alpha value.Definition
getAlpha()Return Values
float | Alpha | value |
231 | function HUDElement:getAlpha() |
232 | return self.overlay.a |
233 | end |
getColor
DescriptionGet this HUD element's color.Definition
getColor()Return Values
float | Red | value |
float | Green | value |
float | Blue | value |
float | Alpha | value |
224 | function HUDElement:getColor() |
225 | return self.overlay.r, self.overlay.g, self.overlay.b, self.overlay.a |
226 | end |
getHeight
DescriptionGet this HUD element's height in screen space.Definition
getHeight()Code
243 | function HUDElement:getHeight() |
244 | return self.overlay.height |
245 | end |
getPosition
DescriptionGet this HUD element's position.Definition
getPosition()Return Values
float | X | position in screen space |
float | Y | position in screen space |
153 | function HUDElement:getPosition() |
154 | return self.overlay:getPosition() |
155 | end |
getRotationPivot
DescriptionGet this HUD element's rotation pivot point.Definition
getRotationPivot()Return Values
float | Pivot | x position offset from element position in screen space |
float | Pivot | y position offset from element position in screen space |
145 | function HUDElement:getRotationPivot() |
146 | return self.pivotX, self.pivotY |
147 | end |
getScale
DescriptionGet this HUD element's scale.Definition
getScale()Return Values
Width | scale | factor |
Height | scale | factor |
193 | function HUDElement:getScale() |
194 | return self.overlay:getScale() |
195 | end |
getVisible
DescriptionGet this HUD element's visibility.Definition
getVisible()Code
214 | function HUDElement:getVisible() |
215 | return self.overlay.visible |
216 | end |
getWidth
DescriptionGet this HUD element's width in screen space.Definition
getWidth()Code
237 | function HUDElement:getWidth() |
238 | return self.overlay.width |
239 | end |
new
DescriptionCreate a new HUD element.Definition
new(table subClass, table overlay, table parentHudElement)Arguments
table | subClass | Subclass metatable for inheritance |
table | overlay | Wrapped Overlay instance |
table | parentHudElement | [optional] Parent HUD element of the newly created HUD element |
table | HUDElement | instance |
21 | function HUDElement.new(subClass, overlay, parentHudElement) |
22 | if not subClass or subClass == HUDElement then |
23 | subClass = HUDElement_mt |
24 | end |
25 | |
26 | local self = setmetatable({}, subClass) |
27 | |
28 | self.overlay = overlay |
29 | self.children = {} |
30 | |
31 | self.pivotX = 0 |
32 | self.pivotY = 0 |
33 | self.defaultPivotX = 0 |
34 | self.defaultPivotY = 0 |
35 | |
36 | -- animation |
37 | self.animation = TweenSequence.NO_SEQUENCE |
38 | |
39 | self.parent = nil |
40 | if parentHudElement then |
41 | parentHudElement:addChild(self) |
42 | end |
43 | |
44 | return self |
45 | end |
normalizeUVPivot
DescriptionConvert a texture space pivot to an element-local pivot.Definition
normalizeUVPivot(table uvPivot, table uvs)Arguments
table | uvPivot | Array of two pixel pivot coordinates in texture space |
table | uvs | Array of UV coordinates as {x, y, width, height} |
338 | function HUDElement:normalizeUVPivot(uvPivot, size, uvs) |
339 | return self:scalePixelToScreenWidth(uvPivot[1] * size[1] / uvs[3]), |
340 | self:scalePixelToScreenHeight(uvPivot[2] * size[2] / uvs[4]) |
341 | end |
removeChild
DescriptionRemove a child HUD element from this element.Definition
removeChild(table childHudElement)Arguments
table | childHudElement | HUDElement instance which is removed as a child. |
88 | function HUDElement:removeChild(childHudElement) |
89 | if childHudElement.parent == self then |
90 | for i, child in ipairs(self.children) do |
91 | if child == childHudElement then |
92 | child.parent = nil |
93 | table.remove(self.children, i) |
94 | return |
95 | end |
96 | end |
97 | end |
98 | end |
resetDimensions
DescriptionReset this HUD element's dimensions to their default values. Resets width, height, scale and pivot.Definition
resetDimensions()Code
257 | function HUDElement:resetDimensions() |
258 | self.overlay:resetDimensions() |
259 | self.pivotX = self.defaultPivotX |
260 | self.pivotY = self.defaultPivotY |
261 | end |
scalePixelToScreenHeight
DescriptionConvert a vertical pixel value into scaled screen space value.Definition
scalePixelToScreenHeight(float height)Arguments
float | height | Vertical pixel value |
323 | function HUDElement:scalePixelToScreenHeight(height) |
324 | return height * self.overlay.scaleHeight * g_aspectScaleY / g_referenceScreenHeight |
325 | end |
scalePixelToScreenVector
DescriptionConvert a vector from pixel values into scaled screen space values.Definition
scalePixelToScreenVector(table vector2D)Arguments
table | vector2D | Array of two pixel values |
315 | function HUDElement:scalePixelToScreenVector(vector2D) |
316 | return vector2D[1] * self.overlay.scaleWidth * g_aspectScaleX / g_referenceScreenWidth, |
317 | vector2D[2] * self.overlay.scaleHeight * g_aspectScaleY / g_referenceScreenHeight |
318 | end |
scalePixelToScreenWidth
DescriptionConvert a horizontal pixel value into scaled screen space value.Definition
scalePixelToScreenWidth(float width)Arguments
float | width | Horizontal pixel value |
330 | function HUDElement:scalePixelToScreenWidth(width) |
331 | return width * self.overlay.scaleWidth * g_aspectScaleX / g_referenceScreenWidth |
332 | end |
setAlignment
DescriptionSet this HUD element's positional alignment. See Overlay:setAlignment for positioning logic.Definition
setAlignment(int vertical, int horizontal)Arguments
int | vertical | Vertical alignment value [Overlay.ALIGN_VERTICAL_BOTTOM | Overlay.ALIGN_VERTICAL_MIDDLE | Overlay.ALIGN_VERTICAL_TOP] |
int | horizontal | Horizontal alignment value [Overlay.ALIGN_HORIZONTAL_LEFT | Overlay.ALIGN_HORIZONTAL_CENTER | Overlay.ALIGN_HORIZONTAL_RIGHT] |
202 | function HUDElement:setAlignment(vertical, horizontal) |
203 | self.overlay:setAlignment(vertical, horizontal) |
204 | end |
setAlpha
DescriptionSet this HUD element overlay's color alpha value only.Definition
setAlpha()Code
272 | function HUDElement:setAlpha(alpha) |
273 | self.overlay:setColor(nil, nil, nil, alpha) |
274 | end |
setColor
DescriptionSet this HUD element overlay's color. Children are unaffected.Definition
setColor()Code
266 | function HUDElement:setColor(r, g, b, a) |
267 | self.overlay:setColor(r, g, b, a) |
268 | end |
setDimension
DescriptionSet this HUD element's width and height. Either value can be omitted (== nil) for no change.Definition
setDimension()Code
250 | function HUDElement:setDimension(width, height) |
251 | self.overlay:setDimension(width, height) |
252 | end |
setImage
DescriptionSet this HUD element overlay's image file.Definition
setImage()Code
278 | function HUDElement:setImage(imageFilename) |
279 | self.overlay:setImage(imageFilename) |
280 | end |
setPosition
DescriptionSet a HUD element's absolute screen space position. If the element has any children, they will be moved with this element.Definition
setPosition()Code
103 | function HUDElement:setPosition(x, y) |
104 | local prevX, prevY = self:getPosition() |
105 | |
106 | -- substitute omitted parameters with current values to mirror Overlay behavior: |
107 | x = x or prevX |
108 | y = y or prevY |
109 | |
110 | self.overlay:setPosition(x, y) |
111 | |
112 | if #self.children > 0 then -- move children with self |
113 | local moveX, moveY = x - prevX, y - prevY |
114 | |
115 | for _, child in pairs(self.children) do |
116 | local childX, childY = child:getPosition() |
117 | child:setPosition(childX + moveX, childY + moveY) |
118 | end |
119 | end |
120 | end |
setRotation
DescriptionSet this HUD element's rotation. Does not affect children. If no center position is given, the element's pivot values are used (default to 0)Definition
setRotation(float rotation, float centerX, float centerY)Arguments
float | rotation | Rotation in radians |
float | centerX | [optional] Rotation pivot X position offset from overlay position in screen space |
float | centerY | [optional] Rotation pivot Y position offset from overlay position in screen space |
128 | function HUDElement:setRotation(rotation, centerX, centerY) |
129 | self.overlay:setRotation(rotation, centerX or self.pivotX, centerY or self.pivotY) |
130 | end |
setRotationPivot
DescriptionSet this HUD element's rotation pivot point.Definition
setRotationPivot(float pivotX, float pivotY)Arguments
float | pivotX | Pivot x position offset from element position in screen space |
float | pivotY | Pivot y position offset from element position in screen space |
136 | function HUDElement:setRotationPivot(pivotX, pivotY) |
137 | self.pivotX, self.pivotY = pivotX or self.defaultPivotX, pivotY or self.defaultPivotY |
138 | self.defaultPivotX, self.defaultPivotY = pivotX or self.defaultPivotX, pivotY or self.defaultPivotY |
139 | end |
setScale
DescriptionSet this HUD element's scale. This will move and scale children proportionally.Definition
setScale(float scaleWidth, float scaleHeight)Arguments
float | scaleWidth | Width scale factor |
float | scaleHeight | Height scale factor |
162 | function HUDElement:setScale(scaleWidth, scaleHeight) |
163 | local prevSelfX, prevSelfY = self:getPosition() |
164 | local prevScaleWidth, prevScaleHeight = self:getScale() |
165 | self.overlay:setScale(scaleWidth, scaleHeight) |
166 | local selfX, selfY = self:getPosition() |
167 | |
168 | if #self.children > 0 then |
169 | local changeFactorX, changeFactorY = scaleWidth / prevScaleWidth, scaleHeight / prevScaleHeight |
170 | |
171 | for _, child in pairs(self.children) do |
172 | local childScaleWidth, childScaleHeight = child:getScale() |
173 | |
174 | local childPrevX, childPrevY = child:getPosition() |
175 | local offX = childPrevX - prevSelfX |
176 | local offY = childPrevY - prevSelfY |
177 | local posX = selfX + offX * changeFactorX |
178 | local posY = selfY + offY * changeFactorY |
179 | |
180 | child:setPosition(posX, posY) |
181 | child:setScale(childScaleWidth * changeFactorX, childScaleHeight * changeFactorY) |
182 | end |
183 | end |
184 | |
185 | self.pivotX = self.defaultPivotX * scaleWidth |
186 | self.pivotY = self.defaultPivotY * scaleHeight |
187 | end |
setUVs
DescriptionSet this HUD element overlay's UV coordinates.Definition
setUVs()Code
284 | function HUDElement:setUVs(uvs) |
285 | self.overlay:setUVs(uvs) |
286 | end |
setVisible
DescriptionSet this HUD element's visibility.Definition
setVisible()Code
208 | function HUDElement:setVisible(isVisible) |
209 | self.overlay.visible = isVisible |
210 | end |
update
DescriptionUpdate this HUD element's state.Definition
update()Code
290 | function HUDElement:update(dt) |
291 | if not self.animation:getFinished() then |
292 | self.animation:update(dt) |
293 | end |
294 | end |