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
InputGlyphElement
DescriptionInput glyph display element. Displays a key or button glyph for an input.Parent
HUDElementFunctions
- delete
- deleteOverlayCopies
- draw
- drawActionText
- drawControllerButtons
- drawKeyboardKeys
- getGlyphWidth
- new
- setAction
- setActions
- setBold
- setButtonGlyphColor
- setKeyboardGlyphColor
- setLowerCase
- setScale
- setUpperCase
- updateDisplayText
delete
DescriptionDelete this element and release its resources.Definition
delete()Code
71 | function InputGlyphElement:delete() |
72 | InputGlyphElement:superClass().delete(self) |
73 | |
74 | self.keyboardOverlay:delete() |
75 | self:deleteOverlayCopies() |
76 | end |
deleteOverlayCopies
DescriptionDelete any overlay copies.Definition
deleteOverlayCopies()Code
88 | function InputGlyphElement:deleteOverlayCopies() |
89 | for k, v in pairs(self.overlayCopies) do |
90 | v:delete() |
91 | self.overlayCopies[k] = nil |
92 | end |
93 | end |
draw
DescriptionDraw the input glyph(s).Definition
draw()Code
332 | function InputGlyphElement:draw(clipX1, clipY1, clipX2, clipY2) |
333 | if #self.actionNames == 0 or not self.overlay.visible then |
334 | return |
335 | end |
336 | |
337 | local posX, posY = self:getPosition() |
338 | |
339 | if self.hasButtonOverlays then |
340 | for _, actionName in ipairs(self.actionNames) do |
341 | posX = self:drawControllerButtons(self.buttonOverlays[actionName], posX, posY, clipX1, clipY1, clipX2, clipY2) |
342 | end |
343 | elseif self.hasKeyNames then |
344 | for _, actionName in ipairs(self.actionNames) do |
345 | posX = self:drawKeyboardKeys(self.keyNames[actionName], posX, posY, clipX1, clipY1, clipX2, clipY2) |
346 | end |
347 | end |
348 | |
349 | if self.actionText ~= nil then |
350 | self:drawActionText(posX, posY, clipX1, clipY1, clipX2, clipY2) |
351 | end |
352 | end |
drawActionText
DescriptionDraw the action text after the input glyphs.Definition
drawActionText(float posX, float posY)Arguments
float | posX | Drawing X position in screen space |
float | posY | Drawing Y position in screen space |
418 | function InputGlyphElement:drawActionText(posX, posY, clipX1, clipY1, clipX2, clipY2) |
419 | setTextAlignment(RenderText.ALIGN_LEFT) |
420 | setTextBold(self.bold) |
421 | setTextColor(unpack(self.color)) |
422 | |
423 | if clipX1 ~= nil then |
424 | setTextClipArea(clipX1, clipY1, clipX2, clipY2) |
425 | end |
426 | |
427 | renderText(posX + self.textOffsetX, posY + self.actionTextSize * 0.5, self.actionTextSize, self.displayText) |
428 | |
429 | if clipX1 ~= nil then |
430 | setTextClipArea(0, 0, 1, 1) |
431 | end |
432 | end |
drawControllerButtons
DescriptionDraw controller button glyphs.Definition
drawControllerButtons(table Array, float posX, float posY)Arguments
table | Array | of controller button glyph overlays |
float | posX | Initial drawing X position in screen space |
float | posY | Initial drawing Y position in screen space |
float | X | position in screen space after the last glyph |
360 | function InputGlyphElement:drawControllerButtons(buttonOverlays, posX, posY, clipX1, clipY1, clipX2, clipY2) |
361 | for i, overlay in ipairs(buttonOverlays) do |
362 | if i > 1 then |
363 | local separatorType = self.separators[i - 1] |
364 | local separatorOverlay = self.orOverlay |
365 | local separatorWidth = 0 |
366 | local separatorHeight = 0 |
367 | if separatorType == InputHelpElement.SEPARATOR.COMBO_INPUT then |
368 | separatorOverlay = self.plusOverlay |
369 | separatorWidth, separatorHeight = self.plusIconSizeX, self.plusIconSizeY |
370 | elseif separatorType == InputHelpElement.SEPARATOR.ANY_INPUT then |
371 | separatorWidth, separatorHeight = self.orIconSizeX, self.orIconSizeY |
372 | end |
373 | |
374 | separatorOverlay:setColor(nil, nil, nil, self.buttonColor[4]) |
375 | separatorOverlay:setPosition(posX, posY + separatorHeight) |
376 | separatorOverlay:setDimension(separatorWidth, separatorHeight) |
377 | separatorOverlay:render(clipX1, clipY1, clipX2, clipY2) |
378 | |
379 | separatorOverlay:setColor(nil, nil, nil, 1) -- reset alpha |
380 | |
381 | separatorOverlay:resetDimensions() |
382 | posX = posX + separatorWidth + self.glyphOffsetX |
383 | end |
384 | |
385 | overlay:setPosition(posX, posY + self.iconSizeY * 0.5) -- controller symbols are vertically aligned to middle |
386 | overlay:setDimension(self.iconSizeX, self.iconSizeY) |
387 | overlay:setColor(unpack(self.buttonColor)) |
388 | overlay:render(clipX1, clipY1, clipX2, clipY2) |
389 | |
390 | overlay:resetDimensions() |
391 | |
392 | local padding = i < #buttonOverlays and self.glyphOffsetX or 0 |
393 | posX = posX + self.iconSizeX + padding |
394 | end |
395 | |
396 | return posX |
397 | end |
drawKeyboardKeys
DescriptionDraw keyboard key glyphs.Definition
drawKeyboardKeys(table Array, float posX, float posY)Arguments
table | Array | of keyboard key names |
float | posX | Initial drawing X position in screen space |
float | posY | Initial drawing Y position in screen space |
float | X | position in screen space after the last glyph |
405 | function InputGlyphElement:drawKeyboardKeys(keyNames, posX, posY, clipX1, clipY1, clipX2, clipY2) |
406 | for i, key in ipairs(keyNames) do |
407 | local padding = i < #keyNames and self.glyphOffsetX or 0 |
408 | posX = posX + self.keyboardOverlay:renderButton(key, posX, posY, self.iconSizeY, nil, true, clipX1, clipY1, clipX2, clipY2) + padding |
409 | end |
410 | |
411 | return posX |
412 | end |
getGlyphWidth
DescriptionGet the screen space width required by the glyphs used to display input in the current input context.Definition
getGlyphWidth()Code
297 | function InputGlyphElement:getGlyphWidth() |
298 | local width = 0 |
299 | if self.hasButtonOverlays then |
300 | for _, actionName in ipairs(self.actionNames) do |
301 | for i, _ in ipairs(self.buttonOverlays[actionName]) do |
302 | if i > 1 then |
303 | local separatorType = self.separators[i - 1] |
304 | local separatorWidth = 0 |
305 | if separatorType == InputHelpElement.SEPARATOR.COMBO_INPUT then |
306 | separatorWidth = self.plusIconSizeX |
307 | elseif separatorType == InputHelpElement.SEPARATOR.ANY_INPUT then |
308 | separatorWidth = self.orIconSizeX |
309 | end |
310 | |
311 | width = width + separatorWidth + self.glyphOffsetX |
312 | end |
313 | |
314 | local padding = i < #self.buttonOverlays[actionName] and self.glyphOffsetX or 0 |
315 | width = width + self.iconSizeX + padding |
316 | end |
317 | end |
318 | elseif self.hasKeyNames then |
319 | for _, actionName in ipairs(self.actionNames) do |
320 | for i, key in ipairs(self.keyNames[actionName]) do |
321 | local padding = i < #self.keyNames[actionName] and self.glyphOffsetX or 0 |
322 | width = width + self.keyboardOverlay:getButtonWidth(key, self.iconSizeY) + padding |
323 | end |
324 | end |
325 | end |
326 | |
327 | return width |
328 | end |
new
DescriptionCreate a new instance of InputGlyphElement.Definition
new(table inputDisplayManager, float baseWidth, float baseHeight)Arguments
table | inputDisplayManager | InputDisplayManager reference |
float | baseWidth | Default width of this element in screen space |
float | baseHeight | Default height of this element in screen space |
27 | function InputGlyphElement.new(inputDisplayManager, baseWidth, baseHeight) |
28 | local backgroundOverlay = Overlay.new(nil, 0, 0, baseWidth, baseHeight) |
29 | local self = InputGlyphElement:superClass().new(backgroundOverlay, nil, InputGlyphElement_mt) |
30 | |
31 | self.inputDisplayManager = inputDisplayManager |
32 | self.plusOverlay = inputDisplayManager:getPlusOverlay() |
33 | self.orOverlay = inputDisplayManager:getOrOverlay() |
34 | self.keyboardOverlay = ButtonOverlay.new() |
35 | |
36 | self.actionNames = {} |
37 | self.actionText = nil -- optional action text to display next to the glyph |
38 | self.displayText = nil -- lower or upper cased version of actionText for rendering |
39 | self.actionTextSize = InputGlyphElement.DEFAULT_TEXT_SIZE |
40 | self.inputHelpElement = nil |
41 | |
42 | self.buttonOverlays = {} -- action name -> overlays |
43 | self.hasButtonOverlays = false |
44 | self.separators = {} -- {i=InputHelpElement.SEPARATOR} |
45 | self.keyNames = {} -- action name -> key names |
46 | self.hasKeyNames = false |
47 | |
48 | self.color = {1, 1, 1, 1} -- RGBA array |
49 | self.buttonColor = {1, 1, 1, 1} -- RGBA array |
50 | self.overlayCopies = {} -- contains overlay copies which need to be deleted |
51 | |
52 | self.baseWidth, self.baseHeight = baseWidth, baseHeight |
53 | |
54 | self.glyphOffsetX = 0 |
55 | self.textOffsetX = 0 |
56 | self.iconSizeX, self.iconSizeY = baseWidth, baseHeight |
57 | self.plusIconSizeX, self.plusIconSizeY = baseWidth * 0.5, baseHeight * 0.5 |
58 | self.orIconSizeX, self.orIconSizeY = baseWidth * 0.5, baseHeight * 0.5 |
59 | |
60 | self.alignX, self.alignY = 1, 1 |
61 | self.alignmentOffsetX, self.alignmentOffsetY = 0, 0 |
62 | self.lowerCase = false |
63 | self.upperCase = false |
64 | self.bold = false |
65 | |
66 | return self |
67 | end |
setAction
DescriptionSet the action whose input glyphs need to be displayed by this element.Definition
setAction(string actionName, string actionText, float actionTextSize, bool noModifiers, bool copyOverlays)Arguments
string | actionName | InputAction name |
string | actionText | [optional] Additional action text to display after the glyph |
float | actionTextSize | [optional] Additional action text size in screen space |
bool | noModifiers | [optional] If true, will only show the input glyph of the last unmodified input binding axis |
bool | copyOverlays | [optional] If true, will create and handle a separate copy of an input glyph. Do not use this when updating the action each frame! |
166 | function InputGlyphElement:setAction(actionName, actionText, actionTextSize, noModifiers, copyOverlays) |
167 | -- use this instance's action names array instead of creating a new one each time this is called |
168 | clearTable(self.actionNames) |
169 | table.insert(self.actionNames, actionName) |
170 | self:setActions(self.actionNames, actionText, actionTextSize, noModifiers, copyOverlays) |
171 | end |
setActions
DescriptionSet multiple actions whose input glyphs need to be displayed by this element. If exactly two actions are passed in, they will be interpreted as belonging to the same axis and the system tries to resolved the actions to a combined glyph. Otherwise, the glyphs will just be displayed in order of the actions.Definition
setActions(table actionNames, string actionText, float actionTextSize, bool noModifiers, bool copyOverlays)Arguments
table | actionNames | InputAction names array |
string | actionText | [optional] Additional action text to display after the glyph |
float | actionTextSize | [optional] Additional action text size in screen space |
bool | noModifiers | [optional] If true, will only show the input glyph of the last unmodified input binding axis |
bool | copyOverlays | [optional] If true, will create and handle a separate copy of an input glyph. Do not use this when updating the action each frame! |
183 | function InputGlyphElement:setActions(actionNames, actionText, actionTextSize, noModifiers, copyOverlays) |
184 | self.actionNames = actionNames |
185 | self.actionText = actionText |
186 | self.actionTextSize = actionTextSize or InputGlyphElement.DEFAULT_TEXT_SIZE |
187 | |
188 | self:updateDisplayText() -- apply lower / upper case if necessary |
189 | |
190 | local height = self:getHeight() |
191 | local width = 0 |
192 | |
193 | self:deleteOverlayCopies() |
194 | |
195 | local isDoubleAction = #actionNames == 2 |
196 | |
197 | for i, actionName in ipairs(actionNames) do |
198 | local actionName2 = nil |
199 | if isDoubleAction then |
200 | actionName2 = actionNames[i + 1] |
201 | end |
202 | |
203 | local helpElement = self.inputDisplayManager:getControllerSymbolOverlays(actionName, actionName2, "", noModifiers) |
204 | local buttonOverlays = helpElement.buttons |
205 | self.separators = helpElement.separators |
206 | |
207 | if copyOverlays then |
208 | local originals = buttonOverlays |
209 | buttonOverlays = {} |
210 | |
211 | for _, overlay in ipairs(originals) do |
212 | -- TODO: make overlay:clone() function |
213 | local overlayCopy = Overlay.new(overlay.filename, overlay.x, overlay.y, overlay.defaultWidth, overlay.defaultHeight) |
214 | overlayCopy:setUVs(overlay.uvs) |
215 | overlayCopy:setAlignment(overlay.alignmentVertical, overlay.alignmentHorizontal) |
216 | |
217 | table.insert(self.overlayCopies, overlayCopy) |
218 | table.insert(buttonOverlays, overlayCopy) |
219 | end |
220 | end |
221 | |
222 | if self.buttonOverlays[actionName] == nil then |
223 | self.buttonOverlays[actionName] = {} |
224 | else |
225 | for j=1, #self.buttonOverlays[actionName] do |
226 | self.buttonOverlays[actionName][j] = nil |
227 | end |
228 | end |
229 | self.hasButtonOverlays = false |
230 | |
231 | if #buttonOverlays > 0 then |
232 | for _, overlay in ipairs(buttonOverlays) do |
233 | table.insert(self.buttonOverlays[actionName], overlay) |
234 | self.hasButtonOverlays = true |
235 | end |
236 | end |
237 | |
238 | if self.keyNames[actionName] == nil then |
239 | self.keyNames[actionName] = {} |
240 | else |
241 | for j=1, #self.keyNames[actionName] do |
242 | self.keyNames[actionName][j] = nil |
243 | end |
244 | end |
245 | self.hasKeyNames = false |
246 | |
247 | if #helpElement.keys > 0 then |
248 | for _, key in ipairs(helpElement.keys) do |
249 | table.insert(self.keyNames[actionName], key) |
250 | self.hasKeyNames = true |
251 | end |
252 | end |
253 | |
254 | if isDoubleAction then |
255 | table.remove(self.actionNames, 2) |
256 | break -- should have resolved everything now |
257 | end |
258 | end |
259 | |
260 | if self.hasButtonOverlays then |
261 | for _, buttonOverlays in pairs(self.buttonOverlays) do |
262 | for i, _ in ipairs(buttonOverlays) do |
263 | if i > 1 then -- TODO: use separator types to get width |
264 | width = width + self.plusIconSizeX + self.glyphOffsetX |
265 | end |
266 | |
267 | width = width + self.iconSizeX + (i < #buttonOverlays and self.glyphOffsetX or 0) |
268 | end |
269 | end |
270 | elseif self.hasKeyNames then |
271 | for _, keyNames in pairs(self.keyNames) do |
272 | for _, key in ipairs(keyNames) do |
273 | width = width + self.keyboardOverlay:getButtonWidth(key, height) |
274 | end |
275 | end |
276 | end |
277 | |
278 | -- adjust this element's size so other elements can correctly offset from this |
279 | self:setDimension(width, height) |
280 | end |
setBold
DescriptionSet the glyph text to be displayed in bold print or not.Definition
setBold()Code
130 | function InputGlyphElement:setBold(isBold) |
131 | self.bold = isBold |
132 | end |
setButtonGlyphColor
DescriptionSet the color for button glyphs.Definition
setButtonGlyphColor(table color)Arguments
table | color | Color as an RGBA array |
145 | function InputGlyphElement:setButtonGlyphColor(color) |
146 | self.buttonColor = color |
147 | |
148 | for _, actionName in ipairs(self.actionNames) do |
149 | local buttonOverlays = self.buttonOverlays[actionName] |
150 | if buttonOverlays ~= nil then -- safety-catch to avoid errors for invalid setups (will just not show icon) |
151 | for _, overlay in pairs(buttonOverlays) do |
152 | overlay:setColor(unpack(color)) |
153 | end |
154 | end |
155 | end |
156 | end |
setKeyboardGlyphColor
DescriptionSet the button frame color for the keyboard glyphs.Definition
setKeyboardGlyphColor(table color)Arguments
table | color | Color as an RGBA array |
137 | function InputGlyphElement:setKeyboardGlyphColor(color) |
138 | self.color = color |
139 | self.keyboardOverlay:setColor(unpack(color)) |
140 | end |
setLowerCase
DescriptionSet the glyph text to be displayed in all lower case or not. This resets the upper case setting if lower case is enabled.Definition
setLowerCase()Code
122 | function InputGlyphElement:setLowerCase(enableLowerCase) |
123 | self.lowerCase = enableLowerCase |
124 | self.upperCase = self.upperCase and not enableLowerCase |
125 | self:updateDisplayText() |
126 | end |
setScale
DescriptionSet the scale of this element.Definition
setScale(float widthScale, float heightScale)Arguments
float | widthScale | Width scale factor |
float | heightScale | Height scale factor |
99 | function InputGlyphElement:setScale(widthScale, heightScale) |
100 | InputGlyphElement:superClass().setScale(self, widthScale, heightScale) |
101 | |
102 | self.glyphOffsetX = self:scalePixelToScreenWidth(InputGlyphElement.GLYPH_OFFSET_X) |
103 | self.textOffsetX = self:scalePixelToScreenWidth(InputGlyphElement.TEXT_OFFSET_X) |
104 | |
105 | self.iconSizeX, self.iconSizeY = self.baseWidth * widthScale, self.baseHeight * heightScale |
106 | self.plusIconSizeX, self.plusIconSizeY = self.iconSizeX * 0.5, self.iconSizeY * 0.5 |
107 | self.orIconSizeX, self.orIconSizeY = self.iconSizeX * 0.5, self.iconSizeY * 0.5 |
108 | end |
setUpperCase
DescriptionSet the glyph text to be displayed in all upper case or not. This resets the lower case setting if upper case is enabled.Definition
setUpperCase()Code
113 | function InputGlyphElement:setUpperCase(enableUpperCase) |
114 | self.upperCase = enableUpperCase |
115 | self.lowerCase = self.lowerCase and not enableUpperCase |
116 | self:updateDisplayText() |
117 | end |
updateDisplayText
DescriptionUpdate the display text from the set action text according to current casing settings.Definition
updateDisplayText()Code
284 | function InputGlyphElement:updateDisplayText() |
285 | if self.actionText ~= nil then |
286 | self.displayText = self.actionText |
287 | if self.upperCase then |
288 | self.displayText = utf8ToUpper(self.actionText) |
289 | elseif self.lowerCase then |
290 | self.displayText = utf8ToLower(self.actionText) |
291 | end |
292 | end |
293 | end |