LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

VehicleHUDExtension

Description
Custom vehicle HUD drawing extension. This serves as the base class for custom specific drawing cases of vehicles in the HUD, e.g. MixerWagon fill levels. To create new HUD extensions for vehicle specializations: 1. sub-class this base class 2. source() the sub-class module after its corresponding specialization's table has been declared 3. call VehicleHUDExtension.registerHUDExtension([specialization], [HUDextension]) in sub-class module
Functions

addComponentForCleanup

Description
Add a display component for cleanup on delete(). Added components must support delete() themselves or they will be ignored.
Definition
addComponentForCleanup()
Code
59function VehicleHUDExtension:addComponentForCleanup(component)
60 if component.delete then
61 table.insert(self.displayComponents, component)
62 end
63end

canDraw

Description
Determine if this HUD extension is in a valid state for a call to draw() in the current frame. Override in sub-classes with custom logic.
Definition
canDraw()
Return Values
boolIftrue, the HUD extension should be drawn in the current frame.
Code
76function VehicleHUDExtension:canDraw()
77 return true
78end

createHUDExtensionForSpecialization

Description
HUD extension factory method, creates a HUD extension for a given vehicle specialization.
Definition
createHUDExtensionForSpecialization(table spec, table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tablespecSpecialization reference
tablevehicleVehicle which has the given specialization
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Return Values
tableHUDextension instance or nil of no extension has been registered for the given specialization
Code
111function VehicleHUDExtension.createHUDExtensionForSpecialization(spec, vehicle, uiScale, uiTextColor, uiTextSize)
112 local extType = registry[spec]
113 local extension = nil
114 if extType then
115 extension = extType.new(vehicle, uiScale, uiTextColor, uiTextSize)
116 end
117
118 return extension
119end

delete

Description
Delete this instance and clean up resources.
Definition
delete()
Code
49function VehicleHUDExtension:delete()
50 for k, component in pairs(self.displayComponents) do
51 component:delete()
52 self.displayComponents[k] = nil
53 end
54end

draw

Description
Draw HUD extension.
Definition
draw(float leftPosX, float rightPosX, float posY)
Arguments
floatleftPosXLeft input help panel column start position
floatrightPosXRight input help panel column start position
floatposYCurrent input help panel drawing vertical offset
Return Values
floatModifiedinput help panel drawing vertical offset
Code
86function VehicleHUDExtension:draw(leftPosX, rightPosX, posY)
87end

getDisplayHeight

Description
Get this HUD extension's display height. Override in subclasses.
Definition
getDisplayHeight()
Code
68function VehicleHUDExtension:getDisplayHeight()
69 return 0
70end

hasHUDExtensionForSpecialization

Description
Check if there is a HUD extension for a given specialization.
Definition
hasHUDExtensionForSpecialization()
Code
123function VehicleHUDExtension.hasHUDExtensionForSpecialization(spec)
124 return not not registry[spec]
125end

new

Description
Base constructor for vehicle HUD extensions.
Definition
new(table class_mt, table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tableclass_mtSub-class metatable
tablevehicleVehicle which has the specialization required by a sub-class
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Code
27function VehicleHUDExtension.new(class_mt, vehicle, uiScale, uiTextColor, uiTextSize)
28 if not class_mt or class_mt == VehicleHUDExtension then
29 class_mt = VehicleHUDExtension_mt
30 end
31
32 local self = setmetatable({}, class_mt)
33
34 -- vehicle specialization reference which provides the display data
35 self.vehicle = vehicle
36
37 self.uiTextColor = uiTextColor
38 self.uiTextSize = uiTextSize
39 self.uiScale = uiScale
40
41 -- array of created display components which need to be deleted
42 self.displayComponents = {}
43
44 return self
45end

registerHUDExtension

Description
Register a HUD extension for a specialization.
Definition
registerHUDExtension(table specializationType, table hudExtensionType)
Arguments
tablespecializationTypeVehicle specialization class type table
tablehudExtensionTypeHUD extension class type table corresponding to the given vehicle specialization
Code
99function VehicleHUDExtension.registerHUDExtension(spec, hudExtensionType)
100 registry[spec] = hudExtensionType
101end