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
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
69 | function InputGlyphElement:delete() |
70 | InputGlyphElement:superClass().delete(self) |
71 | |
72 | self.keyboardOverlay:delete() |
73 | self:deleteOverlayCopies() |
74 | end |
deleteOverlayCopies
DescriptionDelete any overlay copies.Definition
deleteOverlayCopies()Code
86 | function InputGlyphElement:deleteOverlayCopies() |
87 | for k, v in pairs(self.overlayCopies) do |
88 | v:delete() |
89 | self.overlayCopies[k] = nil |
90 | end |
91 | end |
draw
DescriptionDraw the input glyph(s).Definition
draw()Code
324 | function InputGlyphElement:draw() |
325 | if #self.actionNames == 0 or not self.overlay.visible then |
326 | return |
327 | end |
328 | |
329 | local posX, posY = self:getPosition() |
330 | |
331 | if next(self.buttonOverlays) then |
332 | for _, actionName in ipairs(self.actionNames) do |
333 | posX = self:drawControllerButtons(self.buttonOverlays[actionName], posX, posY) |
334 | end |
335 | elseif next(self.keyNames) then |
336 | for _, actionName in ipairs(self.actionNames) do |
337 | posX = self:drawKeyboardKeys(self.keyNames[actionName], posX, posY) |
338 | end |
339 | end |
340 | |
341 | if self.actionText ~= nil then |
342 | self:drawActionText(posX, posY) |
343 | end |
344 | 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 |
411 | function InputGlyphElement:drawActionText(posX, posY) |
412 | setTextAlignment(RenderText.ALIGN_LEFT) |
413 | setTextBold(self.bold) |
414 | setTextColor(unpack(self.color)) |
415 | |
416 | renderText(posX + self.textOffsetX, posY + self.actionTextSize * 0.5, self.actionTextSize, self.displayText) |
417 | 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 |
352 | function InputGlyphElement:drawControllerButtons(buttonOverlays, posX, posY) |
353 | local padding = 0 |
354 | for i, overlay in ipairs(buttonOverlays) do |
355 | if i > 1 then |
356 | local separatorType = self.separators[i - 1] |
357 | local separatorOverlay = self.orOverlay |
358 | local separatorWidth = 0 |
359 | local separatorHeight = 0 |
360 | if separatorType == InputHelpElement.SEPARATOR.COMBO_INPUT then |
361 | separatorOverlay = self.plusOverlay |
362 | separatorWidth, separatorHeight = self.plusIconSizeX, self.plusIconSizeY |
363 | elseif separatorType == InputHelpElement.SEPARATOR.ANY_INPUT then |
364 | separatorWidth, separatorHeight = self.orIconSizeX, self.orIconSizeY |
365 | end |
366 | |
367 | separatorOverlay:setColor(nil, nil, nil, self.buttonColor[4]) |
368 | separatorOverlay:setPosition(posX, posY + separatorHeight) |
369 | separatorOverlay:setDimension(separatorWidth, separatorHeight) |
370 | separatorOverlay:render() |
371 | |
372 | separatorOverlay:setColor(nil, nil, nil, 1) -- reset alpha |
373 | |
374 | separatorOverlay:resetDimensions() |
375 | posX = posX + separatorWidth + self.glyphOffsetX |
376 | end |
377 | |
378 | overlay:setPosition(posX, posY + self.iconSizeY * 0.5) -- controller symbols are vertically aligned to middle |
379 | overlay:setDimension(self.iconSizeX, self.iconSizeY) |
380 | overlay:render() |
381 | |
382 | overlay:resetDimensions() |
383 | |
384 | padding = i < #buttonOverlays and self.glyphOffsetX or 0 |
385 | posX = posX + self.iconSizeX + padding |
386 | end |
387 | |
388 | return posX |
389 | 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 |
397 | function InputGlyphElement:drawKeyboardKeys(keyNames, posX, posY) |
398 | local padding = 0 |
399 | for i, key in ipairs(keyNames) do |
400 | padding = i < #keyNames and self.glyphOffsetX or 0 |
401 | posX = posX + self.keyboardOverlay:renderButton(key, posX, posY, self.iconSizeY) + padding |
402 | end |
403 | |
404 | return posX |
405 | end |
getGlyphWidth
DescriptionGet the screen space width required by the glyphs used to display input in the current input context.Definition
getGlyphWidth()Code
287 | function InputGlyphElement:getGlyphWidth() |
288 | local width = 0 |
289 | if next(self.buttonOverlays) then |
290 | for _, actionName in ipairs(self.actionNames) do |
291 | for i, overlay in ipairs(self.buttonOverlays[actionName]) do |
292 | if i > 1 then |
293 | local separatorType = self.separators[i - 1] |
294 | local separatorOverlay = self.orOverlay |
295 | local separatorWidth = 0 |
296 | if separatorType == InputHelpElement.SEPARATOR.COMBO_INPUT then |
297 | separatorOverlay = self.plusOverlay |
298 | separatorWidth = self.plusIconSizeX |
299 | elseif separatorType == InputHelpElement.SEPARATOR.ANY_INPUT then |
300 | separatorWidth = self.orIconSizeX |
301 | end |
302 | |
303 | width = width + separatorWidth + self.glyphOffsetX |
304 | end |
305 | |
306 | local padding = i < #self.buttonOverlays[actionName] and self.glyphOffsetX or 0 |
307 | width = width + self.iconSizeX + padding |
308 | end |
309 | end |
310 | elseif next(self.keyNames) then |
311 | for _, actionName in ipairs(self.actionNames) do |
312 | for i, key in ipairs(self.keyNames[actionName]) do |
313 | local padding = i < #self.keyNames[actionName] and self.glyphOffsetX or 0 |
314 | width = width + self.keyboardOverlay:getButtonWidth(key, self.iconSizeY) + padding |
315 | end |
316 | end |
317 | end |
318 | |
319 | return width |
320 | 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(InputGlyphElement_mt, backgroundOverlay, nil) |
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.separators = {} -- {i=InputHelpElement.SEPARATOR} |
44 | self.keyNames = {} -- action name -> key names |
45 | |
46 | self.color = {1, 1, 1, 1} -- RGBA array |
47 | self.buttonColor = {1, 1, 1, 1} -- RGBA array |
48 | self.overlayCopies = {} -- contains overlay copies which need to be deleted |
49 | |
50 | self.baseWidth, self.baseHeight = baseWidth, baseHeight |
51 | |
52 | self.glyphOffsetX = 0 |
53 | self.textOffsetX = 0 |
54 | self.iconSizeX, self.iconSizeY = baseWidth, baseHeight |
55 | self.plusIconSizeX, self.plusIconSizeY = baseWidth * 0.5, baseHeight * 0.5 |
56 | self.orIconSizeX, self.orIconSizeY = baseWidth * 0.5, baseHeight * 0.5 |
57 | |
58 | self.alignX, self.alignY = 1, 1 |
59 | self.alignmentOffsetX, self.alignmentOffsetY = 0, 0 |
60 | self.lowerCase = false |
61 | self.upperCase = false |
62 | self.bold = false |
63 | |
64 | return self |
65 | 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, integer comboMask)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! |
integer | comboMask | [optional] If non-nil, will remove gamepad bindings that have not got the matching comboMask, and bindings which are not gamepad or panel (PS4 only - other platforms no effect) |
165 | function InputGlyphElement:setAction(actionName, actionText, actionTextSize, noModifiers, copyOverlays, comboMask) |
166 | -- use this instance's action names array instead of creating a new one each time this is called |
167 | clearTable(self.actionNames) |
168 | table.insert(self.actionNames, actionName) |
169 | self:setActions(self.actionNames, actionText, actionTextSize, noModifiers, copyOverlays, comboMask) |
170 | 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, integer comboMask)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! |
integer | comboMask | [optional] If non-nil, will remove gamepad bindings that have not got the matching comboMask, and bindings which are not gamepad or panel (PS4 only - other platforms no effect) |
183 | function InputGlyphElement:setActions(actionNames, actionText, actionTextSize, noModifiers, copyOverlays, comboMask) |
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 | clearTable(self.buttonOverlays) |
194 | clearTable(self.keyNames) |
195 | self:deleteOverlayCopies() |
196 | |
197 | local hasButtons = false |
198 | local hasKeys = false |
199 | local isDoubleAction = #actionNames == 2 |
200 | |
201 | for i, actionName in ipairs(actionNames) do |
202 | local actionName2 = nil |
203 | if isDoubleAction then |
204 | actionName2 = actionNames[i + 1] |
205 | end |
206 | |
207 | local helpElement = self.inputDisplayManager:getControllerSymbolOverlays(actionName, actionName2, "", noModifiers, comboMask) |
208 | local buttonOverlays = helpElement.buttons |
209 | self.separators = helpElement.separators |
210 | |
211 | if copyOverlays then |
212 | local originals = buttonOverlays |
213 | buttonOverlays = {} |
214 | |
215 | for _, overlay in ipairs(originals) do |
216 | -- TODO: make overlay:clone() function |
217 | local overlayCopy = Overlay:new(overlay.filename, overlay.x, overlay.y, overlay.defaultWidth, overlay.defaultHeight) |
218 | overlayCopy:setUVs(overlay.uvs) |
219 | overlayCopy:setAlignment(overlay.alignmentVertical, overlay.alignmentHorizontal) |
220 | |
221 | table.insert(self.overlayCopies, overlayCopy) |
222 | table.insert(buttonOverlays, overlayCopy) |
223 | end |
224 | end |
225 | |
226 | if #buttonOverlays > 0 then |
227 | self.buttonOverlays[actionName] = {} |
228 | for _, overlay in ipairs(buttonOverlays) do |
229 | table.insert(self.buttonOverlays[actionName], overlay) |
230 | end |
231 | |
232 | hasButtons = true |
233 | end |
234 | |
235 | if #helpElement.keys > 0 then |
236 | self.keyNames[actionName] = {} |
237 | for _, key in ipairs(helpElement.keys) do |
238 | table.insert(self.keyNames[actionName], key) |
239 | end |
240 | |
241 | hasKeys = true |
242 | end |
243 | |
244 | if isDoubleAction then |
245 | table.remove(self.actionNames, 2) |
246 | break -- should have resolved everything now |
247 | end |
248 | end |
249 | |
250 | if hasButtons then |
251 | for _, buttonOverlays in pairs(self.buttonOverlays) do |
252 | for i, overlay in ipairs(buttonOverlays) do |
253 | if i > 1 then -- TODO: use separator types to get width |
254 | width = width + self.plusIconSizeX + self.glyphOffsetX |
255 | end |
256 | |
257 | width = width + self.iconSizeX + (i < #buttonOverlays and self.glyphOffsetX or 0) |
258 | end |
259 | end |
260 | elseif hasKeys then |
261 | for _, keyNames in pairs(self.keyNames) do |
262 | for _, key in ipairs(keyNames) do |
263 | width = width + self.keyboardOverlay:getButtonWidth(key, height) |
264 | end |
265 | end |
266 | end |
267 | |
268 | -- adjust this element's size so other elements can correctly offset from this |
269 | self:setDimension(width, height) |
270 | end |
setBold
DescriptionSet the glyph text to be displayed in bold print or not.Definition
setBold()Code
128 | function InputGlyphElement:setBold(isBold) |
129 | self.bold = isBold |
130 | end |
setButtonGlyphColor
DescriptionSet the color for button glyphs.Definition
setButtonGlyphColor(table color)Arguments
table | color | Color as an RGBA array |
143 | function InputGlyphElement:setButtonGlyphColor(color) |
144 | self.buttonColor = color |
145 | |
146 | for _, actionName in ipairs(self.actionNames) do |
147 | local buttonOverlays = self.buttonOverlays[actionName] |
148 | if buttonOverlays ~= nil then -- safety-catch to avoid errors for invalid setups (will just not show icon) |
149 | for _, overlay in pairs(buttonOverlays) do |
150 | overlay:setColor(unpack(color)) |
151 | end |
152 | end |
153 | end |
154 | end |
setKeyboardGlyphColor
DescriptionSet the button frame color for the keyboard glyphs.Definition
setKeyboardGlyphColor(table color)Arguments
table | color | Color as an RGBA array |
135 | function InputGlyphElement:setKeyboardGlyphColor(color) |
136 | self.color = color |
137 | self.keyboardOverlay:setColor(unpack(color)) |
138 | 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
120 | function InputGlyphElement:setLowerCase(enableLowerCase) |
121 | self.lowerCase = enableLowerCase |
122 | self.upperCase = self.upperCase and not enableLowerCase |
123 | self:updateDisplayText() |
124 | 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 |
97 | function InputGlyphElement:setScale(widthScale, heightScale) |
98 | InputGlyphElement:superClass().setScale(self, widthScale, heightScale) |
99 | |
100 | self.glyphOffsetX = self:scalePixelToScreenWidth(InputGlyphElement.GLYPH_OFFSET_X) |
101 | self.textOffsetX = self:scalePixelToScreenWidth(InputGlyphElement.TEXT_OFFSET_X) |
102 | |
103 | self.iconSizeX, self.iconSizeY = self.baseWidth * widthScale, self.baseHeight * heightScale |
104 | self.plusIconSizeX, self.plusIconSizeY = self.iconSizeX * 0.5, self.iconSizeY * 0.5 |
105 | self.orIconSizeX, self.orIconSizeY = self.iconSizeX * 0.5, self.iconSizeY * 0.5 |
106 | 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
111 | function InputGlyphElement:setUpperCase(enableUpperCase) |
112 | self.upperCase = enableUpperCase |
113 | self.lowerCase = self.lowerCase and not enableUpperCase |
114 | self:updateDisplayText() |
115 | end |
updateDisplayText
DescriptionUpdate the display text from the set action text according to current casing settings.Definition
updateDisplayText()Code
274 | function InputGlyphElement:updateDisplayText() |
275 | if self.actionText ~= nil then |
276 | self.displayText = self.actionText |
277 | if self.upperCase then |
278 | self.displayText = utf8ToUpper(self.actionText) |
279 | elseif self.lowerCase then |
280 | self.displayText = utf8ToLower(self.actionText) |
281 | end |
282 | end |
283 | end |