LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

Dashboard

Description
Specialization for dashboards/instrument panels with various types (number, animation, rotation, visibility, ...)
Functions

defaultAnimationDashboardStateFunc

Description
Definition
defaultAnimationDashboardStateFunc()
Code
864function Dashboard:defaultAnimationDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
865 if dashboard.animName ~= nil then
866 if self:getAnimationExists(dashboard.animName) then
867 local normValue
868 if dashboard.minValueAnim ~= nil and dashboard.maxValueAnim ~= nil then
869 newValue = MathUtil.clamp(newValue, dashboard.minValueAnim, dashboard.maxValueAnim)
870 normValue = MathUtil.round((newValue - dashboard.minValueAnim) / (dashboard.maxValueAnim-dashboard.minValueAnim) , 3)
871 else
872 minValue = minValue or 0
873 maxValue = maxValue or 1
874 normValue = MathUtil.round((newValue-minValue)/(maxValue-minValue), 3)
875 end
876 self:setAnimationTime(dashboard.animName, normValue, true)
877 else
878 Logging.xmlWarning(self.xmlFile, "Unknown animation name '%s' for dashboard!", dashboard.animName)
879 dashboard.animName = nil
880 end
881 end
882end

defaultDashboardStateFunc

Description
Definition
defaultDashboardStateFunc()
Code
774function Dashboard:defaultDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
775 if dashboard.displayTypeIndex == Dashboard.TYPES.EMITTER then
776 Dashboard.defaultEmitterDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
777 elseif dashboard.displayTypeIndex == Dashboard.TYPES.NUMBER then
778 Dashboard.defaultNumberDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
779 elseif dashboard.displayTypeIndex == Dashboard.TYPES.ANIMATION then
780 Dashboard.defaultAnimationDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
781 elseif dashboard.displayTypeIndex == Dashboard.TYPES.ROT then
782 Dashboard.defaultRotationDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
783 elseif dashboard.displayTypeIndex == Dashboard.TYPES.VISIBILITY then
784 Dashboard.defaultVisibilityDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
785 elseif dashboard.displayTypeIndex == Dashboard.TYPES.TEXT then
786 Dashboard.defaultTextDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
787 elseif dashboard.displayTypeIndex == Dashboard.TYPES.SLIDER then
788 Dashboard.defaultSliderDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
789 elseif dashboard.displayTypeIndex == Dashboard.TYPES.MULTI_STATE then
790 Dashboard.defaultMultiStateDashboardStateFunc(self, dashboard, newValue, minValue, maxValue, isActive)
791 end
792end

defaultEmitterDashboardStateFunc

Description
Definition
defaultEmitterDashboardStateFunc()
Code
796function Dashboard:defaultEmitterDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
797 if type(newValue) == "number" then
798 newValue = newValue > 0.5 and true or false
799 end
800
801 if newValue == nil then
802 newValue = isActive
803 else
804 newValue = newValue and isActive
805 end
806
807 setShaderParameter(dashboard.node, "lightControl", newValue and dashboard.intensity or dashboard.idleValue, 0, 0, 0, false)
808end

defaultMultiStateDashboardStateFunc

Description
Definition
defaultMultiStateDashboardStateFunc()
Code
968function Dashboard:defaultMultiStateDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
969 if dashboard.node ~= nil then
970 local activeState = nil
971 if isActive then
972 for i=1, #dashboard.states do
973 local state = dashboard.states[i]
974 if type(newValue) == "table" then
975 for j=1, #state.values do
976 if newValue[state.values[j]] == true then
977 activeState = state
978 end
979 end
980 elseif type(newValue) == "number" then
981 for j=1, #state.values do
982 if state.values[j] == MathUtil.round(newValue) then
983 activeState = state
984 end
985 end
986 end
987 end
988 end
989
990 local rotation = dashboard.defaultRotation
991 local translation = dashboard.defaultTranslation
992 local scale = dashboard.defaultScale
993 local visibility = dashboard.defaultVisibility
994 if activeState ~= dashboard.lastState then
995 if activeState ~= nil then
996 rotation = activeState.rotation or rotation
997 translation = activeState.translation or translation
998 scale = activeState.scale or scale
999
1000 if activeState.visibility ~= nil then
1001 visibility = activeState.visibility
1002 end
1003 end
1004
1005 if dashboard.doInterpolation then
1006 if dashboard.interpolator ~= nil then
1007 dashboard.interpolator:update(9999999)
1008 end
1009
1010 local interpolator = ValueInterpolator.new(dashboard.node.."_dashboard", dashboard.get, dashboard.set, {translation[1], translation[2], translation[3],
1011 rotation[1], rotation[2], rotation[3],
1012 scale[1], scale[2], scale[3],
1013 visibility and 1 or 0},
1014 dashboard.multiStateInterpolationTime)
1015 if interpolator ~= nil then
1016 dashboard.interpolator = interpolator
1017 dashboard.interpolator:setDeleteListenerObject(self)
1018 dashboard.interpolator:setFinishedFunc(function(dash) dash.interpolator = nil end, dashboard)
1019 end
1020 else
1021 setRotation(dashboard.node, rotation[1], rotation[2], rotation[3])
1022 setTranslation(dashboard.node, translation[1], translation[2], translation[3])
1023 setScale(dashboard.node, scale[1], scale[2], scale[3])
1024 setVisibility(dashboard.node, visibility)
1025
1026 if self.setCharacterTargetNodeStateDirty ~= nil then
1027 self:setCharacterTargetNodeStateDirty(dashboard.node)
1028 end
1029
1030 if self.setMovingToolDirty ~= nil then
1031 self:setMovingToolDirty(dashboard.node)
1032 end
1033 end
1034
1035 dashboard.lastState = activeState
1036 end
1037 end
1038end

defaultNumberDashboardStateFunc

Description
Definition
defaultNumberDashboardStateFunc()
Code
812function Dashboard:defaultNumberDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
813 if type(newValue) == "number" then
814 local value = tonumber(string.format("%."..dashboard.precision.."f", newValue))
815 value = math.floor(value * 10 ^ dashboard.precision)
816
817 for i=1, #dashboard.numberNodes do
818 local numberNode = dashboard.numberNodes[i]
819
820 if value > 0 then
821 local curNumber = value - (math.floor(value / 10)*10)
822 value = (value - curNumber) / 10
823 dashboard.fontMaterial:setFontCharacter(numberNode, ("%d"):format(curNumber))
824 setVisibility(numberNode, true)
825 else
826 dashboard.fontMaterial:setFontCharacter(numberNode, "0")
827 if not (isActive and i - 1 <= dashboard.precision) then
828 setVisibility(numberNode, false)
829 end
830 end
831 end
832 elseif type(newValue) == "string" then
833 local length = newValue:len()
834
835 for i=1, #dashboard.numberNodes do
836 local numberNode = dashboard.numberNodes[i]
837
838 if i <= length then
839 local index = length - (i - 1)
840 dashboard.fontMaterial:setFontCharacter(numberNode, newValue:sub(index, index))
841 end
842
843 setVisibility(numberNode, isActive)
844 end
845 end
846end

defaultRotationDashboardStateFunc

Description
Definition
defaultRotationDashboardStateFunc()
Code
886function Dashboard:defaultRotationDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
887 local alpha
888 if type(newValue) == "boolean" then
889 alpha = newValue and 1 or 0
890 else
891 if dashboard.minValueRot ~= nil and dashboard.maxValueRot ~= nil then
892 newValue = MathUtil.clamp(newValue, dashboard.minValueRot, dashboard.maxValueRot)
893 alpha = MathUtil.round((newValue - dashboard.minValueRot) / (dashboard.maxValueRot-dashboard.minValueRot) , 3)
894 else
895 minValue = minValue or 0
896 maxValue = maxValue or 1
897 alpha = (newValue-minValue)/(maxValue-minValue)
898 end
899 end
900
901 if dashboard.rotAxis ~= nil then
902 local x, y, z = getRotation(dashboard.node)
903
904 local rot = MathUtil.lerp(dashboard.minRot, dashboard.maxRot, alpha)
905 if dashboard.rotAxis == 1 then
906 x = rot
907 elseif dashboard.rotAxis == 2 then
908 y = rot
909 else
910 z = rot
911 end
912
913 setRotation(dashboard.node, x, y, z)
914
915 if self.setCharacterTargetNodeStateDirty ~= nil then
916 self:setCharacterTargetNodeStateDirty(dashboard.node)
917 end
918
919 if self.setMovingToolDirty ~= nil then
920 self:setMovingToolDirty(dashboard.node)
921 end
922 else
923 local x, y, z = MathUtil.vector3ArrayLerp(dashboard.minRot, dashboard.maxRot, alpha)
924 setRotation(dashboard.node, x, y, z)
925
926 if self.setCharacterTargetNodeStateDirty ~= nil then
927 self:setCharacterTargetNodeStateDirty(dashboard.node)
928 end
929
930 if self.setMovingToolDirty ~= nil then
931 self:setMovingToolDirty(dashboard.node)
932 end
933 end
934end

defaultSliderDashboardStateFunc

Description
Definition
defaultSliderDashboardStateFunc()
Code
950function Dashboard:defaultSliderDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
951 if dashboard.node ~= nil then
952 local normValue
953 if dashboard.minValueSlider ~= nil and dashboard.maxValueSlider ~= nil then
954 newValue = MathUtil.clamp(newValue, dashboard.minValueSlider, dashboard.maxValueSlider)
955 normValue = MathUtil.round((newValue - dashboard.minValueSlider) / (dashboard.maxValueSlider-dashboard.minValueSlider) , 3)
956 else
957 minValue = minValue or 0
958 maxValue = maxValue or 1
959 normValue = MathUtil.round((newValue-minValue)/(maxValue-minValue), 3)
960 end
961
962 setShaderParameter(dashboard.node, "sliderPos", normValue, 0, 0, 0, false)
963 end
964end

defaultTextDashboardStateFunc

Description
Definition
defaultTextDashboardStateFunc()
Code
850function Dashboard:defaultTextDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
851 if type(newValue) == "number" then
852 local int, floatPart = math.modf(newValue)
853 local value = string.format(dashboard.textFormatStr, int, math.abs(math.floor((floatPart + 0.000001) * (10 ^ dashboard.textFormatPrecision))))
854 dashboard.fontMaterial:updateCharacterLine(dashboard.characterLine, value)
855 elseif type(newValue) == "string" then
856 dashboard.fontMaterial:updateCharacterLine(dashboard.characterLine, newValue)
857 end
858
859 setVisibility(dashboard.node, isActive)
860end

defaultVisibilityDashboardStateFunc

Description
Definition
defaultVisibilityDashboardStateFunc()
Code
938function Dashboard:defaultVisibilityDashboardStateFunc(dashboard, newValue, minValue, maxValue, isActive)
939 if newValue == nil then
940 newValue = isActive
941 else
942 newValue = newValue and isActive
943 end
944
945 setVisibility(dashboard.node, newValue)
946end

getDashboardColor

Description
Definition
getDashboardColor()
Code
1085function Dashboard:getDashboardColor(xmlFile, colorStr)
1086 if colorStr == nil then
1087 return nil
1088 end
1089
1090 if Dashboard.COLORS[colorStr:upper()] ~= nil then
1091 return Dashboard.COLORS[colorStr:upper()]
1092 end
1093
1094 local brandColor = g_brandColorManager:getBrandColorByName(colorStr)
1095 if brandColor ~= nil then
1096 return brandColor
1097 end
1098
1099 local vector = string.getVectorN(colorStr)
1100 if vector ~= nil and #vector >= 3 then
1101 if #vector == 3 then
1102 vector[4] = 1
1103 end
1104
1105 return vector
1106 end
1107
1108 Logging.xmlWarning(xmlFile, "Unable to resolve color '%s'", colorStr)
1109
1110 return nil
1111end

getDashboardGroupByName

Description
Definition
getDashboardGroupByName()
Code
315function Dashboard:getDashboardGroupByName(name)
316 return self.spec_dashboard.groups[name]
317end

getDashboardValue

Description
Definition
getDashboardValue()
Code
1066function Dashboard:getDashboardValue(valueObject, valueFunc, dashboard)
1067 if type(valueFunc) == "number" or type(valueFunc) == "boolean" then
1068 return valueFunc
1069 elseif type(valueFunc) == "function" then
1070 return valueFunc(valueObject, dashboard)
1071 end
1072
1073 local object = valueObject[valueFunc]
1074 if type(object) == "function" then
1075 return valueObject[valueFunc](valueObject, dashboard)
1076 elseif type(object) == "number" or type(object) == "boolean" then
1077 return object
1078 end
1079
1080 return nil
1081end

getIsDashboardGroupActive

Description
Definition
getIsDashboardGroupActive()
Code
309function Dashboard:getIsDashboardGroupActive(group)
310 return true
311end

initSpecialization

Description
Definition
initSpecialization()
Code
51function Dashboard.initSpecialization()
52 local schema = Vehicle.xmlSchema
53 schema:setXMLSpecializationType("Dashboard")
54
55 Dashboard.registerDashboardXMLPaths(schema, "vehicle.dashboard.default")
56 schema:register(XMLValueType.STRING, Dashboard.GROUP_XML_KEY .. "#name", "Dashboard group name")
57
58 schema:register(XMLValueType.FLOAT, "vehicle.dashboard#maxUpdateDistance", "Max. distance to vehicle root to update connection hoses", Dashboard.DEFAULT_MAX_UPDATE_DISTANCE)
59 schema:register(XMLValueType.FLOAT, "vehicle.dashboard#maxUpdateDistanceCritical", "Max. distance to vehicle root to update critical connection hoses (All with type 'ROT')", Dashboard.DEFAULT_MAX_UPDATE_DISTANCE_CRITICAL)
60
61 schema:setXMLSpecializationType()
62end

loadAnimationDashboardFromXML

Description
Definition
loadAnimationDashboardFromXML()
Code
605function Dashboard:loadAnimationDashboardFromXML(xmlFile, key, dashboard)
606 dashboard.animName = xmlFile:getValue(key.."#animName")
607
608 if dashboard.animName ~= nil then
609 dashboard.minValueAnim = xmlFile:getValue(key.."#minValueAnim")
610 dashboard.maxValueAnim = xmlFile:getValue(key.."#maxValueAnim")
611 else
612 Logging.xmlWarning(self.xmlFile, "Missing animation for dashboard '%s'", key)
613 return false
614 end
615
616 return true
617end

loadDashboardFromXML

Description
Definition
loadDashboardFromXML()
Code
350function Dashboard:loadDashboardFromXML(xmlFile, key, dashboard, dashboardData)
351 local valueType = xmlFile:getValue(key .. "#valueType")
352 if valueType ~= nil then
353 if valueType ~= dashboardData.valueTypeToLoad then
354 return false
355 end
356 elseif dashboardData.valueTypeToLoad ~= nil then
357 Logging.xmlWarning(self.xmlFile, "Missing valueType for dashboard '%s'", key)
358 return false
359 end
360
361 local displayType = xmlFile:getValue(key .. "#displayType")
362 if displayType ~= nil then
363 local displayTypeIndex = Dashboard.TYPES[displayType:upper()]
364
365 if displayTypeIndex ~= nil then
366 dashboard.displayTypeIndex = displayTypeIndex
367 else
368 Logging.xmlWarning(self.xmlFile, "Unknown displayType '%s' for dashboard '%s'", displayType, key)
369 return false
370 end
371 else
372 Logging.xmlWarning(self.xmlFile, "Missing displayType for dashboard '%s'", key)
373 return false
374 end
375
376 dashboard.doInterpolation = xmlFile:getValue(key .. "#doInterpolation", false)
377 dashboard.interpolationSpeed = xmlFile:getValue(key .. "#interpolationSpeed", 0.005)
378 dashboard.idleValue = xmlFile:getValue(key .. "#idleValue", dashboardData.idleValue or 0)
379 dashboard.lastInterpolationValue = dashboard.idleValue
380
381 dashboard.groups = {}
382 local groupsStr = xmlFile:getValue(key .. "#groups")
383 local groups = string.split(groupsStr, " ")
384 for _, name in ipairs(groups) do
385 local group = self:getDashboardGroupByName(name)
386 if group ~= nil then
387 table.insert(dashboard.groups, group)
388 else
389 Logging.xmlWarning(self.xmlFile, "Unable to find dashboard group '%s' for dashboard '%s'", name, key)
390 end
391 end
392
393 if dashboard.displayTypeIndex == Dashboard.TYPES.EMITTER then
394 if not self:loadEmitterDashboardFromXML(xmlFile, key, dashboard) then
395 return false
396 end
397 elseif dashboard.displayTypeIndex == Dashboard.TYPES.NUMBER then
398 if not self:loadNumberDashboardFromXML(xmlFile, key, dashboard) then
399 return false
400 end
401 elseif dashboard.displayTypeIndex == Dashboard.TYPES.ANIMATION then
402 if not self:loadAnimationDashboardFromXML(xmlFile, key, dashboard) then
403 return false
404 end
405 elseif dashboard.displayTypeIndex == Dashboard.TYPES.ROT then
406 if not self:loadRotationDashboardFromXML(xmlFile, key, dashboard) then
407 return false
408 end
409 elseif dashboard.displayTypeIndex == Dashboard.TYPES.VISIBILITY then
410 if not self:loadVisibilityDashboardFromXML(xmlFile, key, dashboard) then
411 return false
412 end
413 elseif dashboard.displayTypeIndex == Dashboard.TYPES.TEXT then
414 if not self:loadTextDashboardFromXML(xmlFile, key, dashboard) then
415 return false
416 end
417 elseif dashboard.displayTypeIndex == Dashboard.TYPES.SLIDER then
418 if not self:loadSliderDashboardFromXML(xmlFile, key, dashboard) then
419 return false
420 end
421 elseif dashboard.displayTypeIndex == Dashboard.TYPES.MULTI_STATE then
422 if not self:loadMultiStateDashboardFromXML(xmlFile, key, dashboard) then
423 return false
424 end
425 end
426
427 if dashboardData.additionalAttributesFunc ~= nil then
428 if not dashboardData.additionalAttributesFunc(self, xmlFile, key, dashboard) then
429 return false
430 end
431 end
432
433 dashboard.valueObject = dashboardData.valueObject
434 dashboard.valueFunc = dashboardData.valueFunc
435 dashboard.valueCompare = dashboardData.valueCompare
436 dashboard.valueFactor = dashboardData.valueFactor
437 dashboard.minFunc = dashboardData.minFunc
438 dashboard.maxFunc = dashboardData.maxFunc
439 dashboard.centerFunc = dashboardData.centerFunc
440 dashboard.stateFunc = dashboardData.stateFunc or Dashboard.defaultDashboardStateFunc
441
442 dashboard.lastValue = dashboard.idleValue
443
444 return true
445end

loadDashboardGroupFromXML

Description
Definition
loadDashboardGroupFromXML()
Code
290function Dashboard:loadDashboardGroupFromXML(xmlFile, key, group)
291 group.name = xmlFile:getValue(key .. "#name")
292 if group.name == nil then
293 Logging.xmlWarning(self.xmlFile, "Missing name for dashboard group '%s'", key)
294 return false
295 end
296
297 if self:getDashboardGroupByName(group.name) ~= nil then
298 Logging.xmlWarning(self.xmlFile, "Duplicated dashboard group name '%s' for group '%s'", group.name, key)
299 return false
300 end
301
302 group.isActive = false
303
304 return true
305end

loadDashboardsFromXML

Description
Definition
loadDashboardsFromXML()
Code
321function Dashboard:loadDashboardsFromXML(xmlFile, key, dashboardData)
322 if self.isClient then
323 local spec = self.spec_dashboard
324
325 local i = 0
326 while true do
327 local baseKey = string.format("%s.dashboard(%d)", key, i)
328 if not xmlFile:hasProperty(baseKey) then
329 break
330 end
331
332 local dashboard = {}
333 if self:loadDashboardFromXML(xmlFile, baseKey, dashboard, dashboardData) then
334 if dashboard.displayTypeIndex ~= Dashboard.TYPES.ROT then
335 table.insert(spec.dashboards, dashboard)
336 else
337 table.insert(spec.criticalDashboards, dashboard)
338 end
339 end
340
341 i = i + 1
342 end
343 end
344
345 return true
346end

loadEmitterDashboardFromXML

Description
Definition
loadEmitterDashboardFromXML()
Code
449function Dashboard:loadEmitterDashboardFromXML(xmlFile, key, dashboard)
450 local node = xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings)
451 if node ~= nil then
452 if getHasClassId(node, ClassIds.SHAPE) then
453 dashboard.node = node
454
455-- local materialId = getMaterial(node, 0)
456-- if getMaterialCustomShaderFilename(materialId):contains("glowShader.xml")
457-- and getMaterialCustomShaderVariation(materialId) == "staticLight" then
458-- if not getMaterialNormalMapFilename(materialId):contains("default_normal") then
459-- Logging.xmlWarning(self.xmlFile, "Glow shader mesh using different normal map than default! '%s' '%s' '%s'", getName(node), getMaterialNormalMapFilename(materialId), key)
460-- end
461-- end
462--
463-- if getMaterialCustomShaderFilename(materialId):contains("glowShader.xml")
464-- and getMaterialCustomShaderVariation(materialId) == "staticLight" then
465-- if not getMaterialGlossMapFilename(materialId):contains("default_vmask") and not getMaterialGlossMapFilename(materialId):contains("singleColorTexture") then
466-- Logging.xmlWarning(self.xmlFile, "Glow shader mesh using different specular map than default! '%s' '%s' '%s'", getName(node), getMaterialGlossMapFilename(materialId), key)
467-- end
468-- end
469
470 dashboard.baseColor = self:getDashboardColor(xmlFile, xmlFile:getValue(key .. "#baseColor"))
471 if dashboard.baseColor ~= nil then
472 setShaderParameter(dashboard.node, "baseColor", dashboard.baseColor[1], dashboard.baseColor[2], dashboard.baseColor[3], 1, false)
473 end
474
475 dashboard.emitColor = self:getDashboardColor(xmlFile, xmlFile:getValue(key .. "#emitColor"))
476 if dashboard.emitColor ~= nil then
477 setShaderParameter(dashboard.node, "emitColor", dashboard.emitColor[1], dashboard.emitColor[2], dashboard.emitColor[3], 1, false)
478 end
479
480 dashboard.intensity = xmlFile:getValue(key .. "#intensity", 1)
481 setShaderParameter(dashboard.node, "lightControl", dashboard.idleValue, 0, 0, 0, false)
482 else
483 Logging.xmlWarning(self.xmlFile, "Emitter Dashboard node is not a shape! '%s' in '%s'", getName(node), key)
484 return false
485 end
486 else
487 Logging.xmlWarning(self.xmlFile, "Missing node for emitter dashboard '%s'", key)
488 return false
489 end
490
491 return true
492end

loadMultiStateDashboardFromXML

Description
Definition
loadMultiStateDashboardFromXML()
Code
704function Dashboard:loadMultiStateDashboardFromXML(xmlFile, key, dashboard)
705 dashboard.node = xmlFile:getValue(key.."#node", nil, self.components, self.i3dMappings)
706 if dashboard.node == nil then
707 Logging.xmlWarning(self.xmlFile, "Missing 'node' for dashboard '%s'", key)
708 return false
709 end
710
711 dashboard.states = {}
712
713 self.xmlFile:iterate(key..".state", function(index, stateKey)
714 local state = {}
715 state.values = xmlFile:getValue(stateKey.."#value", nil, true)
716 if state.values ~= nil and #state.values > 0 then
717 state.rotation = xmlFile:getValue(stateKey.."#rotation", nil, true)
718 state.translation = xmlFile:getValue(stateKey.."#translation", nil, true)
719 state.scale = xmlFile:getValue(stateKey.."#scale", nil, true)
720 state.visibility = xmlFile:getValue(stateKey.."#visibility")
721
722 table.insert(dashboard.states, state)
723 end
724 end)
725
726 if #dashboard.states == 0 then
727 Logging.xmlWarning(self.xmlFile, "No states defined for dashboard '%s'", key)
728 return false
729 end
730
731 dashboard.multiStateInterpolationTime = 1 / dashboard.interpolationSpeed
732 dashboard.interpolationSpeed = 99999
733
734 dashboard.lastState = nil
735
736 dashboard.get = function()
737 local x, y, z = getTranslation(dashboard.node)
738 local rx, ry, rz = getRotation(dashboard.node)
739 local sx, sy, sz = getScale(dashboard.node)
740 local vis = getVisibility(dashboard.node) and 1 or 0
741
742 return x, y, z, rx, ry, rz, sx, sy, sz, vis
743 end
744
745 dashboard.set = function(x, y, z, rx, ry, rz, sx, sy, sz, vis)
746 setTranslation(dashboard.node, x, y, z)
747 setRotation(dashboard.node, rx, ry, rz)
748 setScale(dashboard.node, sx, sy, sz)
749 setVisibility(dashboard.node, vis >= 0.5)
750
751 if self.setCharacterTargetNodeStateDirty ~= nil then
752 self:setCharacterTargetNodeStateDirty(dashboard.node)
753 end
754
755 if self.setMovingToolDirty ~= nil then
756 self:setMovingToolDirty(dashboard.node)
757 end
758 end
759
760 dashboard.defaultRotation = {getRotation(dashboard.node)}
761 dashboard.defaultTranslation = {getTranslation(dashboard.node)}
762 dashboard.defaultScale = {getScale(dashboard.node)}
763 dashboard.defaultVisibility = getVisibility(dashboard.node)
764
765 return true
766end

loadNumberDashboardFromXML

Description
Definition
loadNumberDashboardFromXML()
Code
496function Dashboard:loadNumberDashboardFromXML(xmlFile, key, dashboard)
497 dashboard.numbers = xmlFile:getValue(key.."#numbers", nil, self.components, self.i3dMappings)
498
499 dashboard.numberColor = self:getDashboardColor(xmlFile, xmlFile:getValue(key.."#numberColor"))
500 if dashboard.numberColor == nil then
501 dashboard.numberColor = {0.9, 0.9, 0.9, 1}
502 end
503
504 if dashboard.numbers ~= nil then
505 dashboard.precision = xmlFile:getValue(key.."#precision", 1)
506 dashboard.numChilds = getNumOfChildren(dashboard.numbers)
507
508 dashboard.fontMaterialName = xmlFile:getValue(key.."#font", "DIGIT")
509 dashboard.hasNormalMap = xmlFile:getValue(key.."#hasNormalMap", false)
510 dashboard.emissiveScale = xmlFile:getValue(key.."#emissiveScale", 0.2)
511
512 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#hiddenAlpha") --FS19 to FS22
513
514 dashboard.fontMaterial = g_materialManager:getFontMaterial(dashboard.fontMaterialName, self.customEnvironment)
515 if dashboard.fontMaterial ~= nil then
516 dashboard.numberNodes = {}
517 if dashboard.numChilds-dashboard.precision <= 0 then
518 Logging.xmlWarning(self.xmlFile, "Not enough number meshes for vehicle hud '%s'", key)
519 return false
520 else
521 for i=1,dashboard.numChilds do
522 local numberNode = getChildAt(dashboard.numbers, i - 1)
523 if numberNode ~= nil then
524 dashboard.fontMaterial:assignFontMaterialToNode(numberNode, dashboard.hasNormalMap)
525 if dashboard.numberColor ~= nil then
526 dashboard.fontMaterial:setFontCharacterColor(numberNode, dashboard.numberColor[1], dashboard.numberColor[2], dashboard.numberColor[3], 1, dashboard.emissiveScale)
527 end
528 setVisibility(numberNode, false)
529
530 table.insert(dashboard.numberNodes, numberNode)
531 end
532 end
533 end
534 else
535 Logging.xmlWarning(self.xmlFile, "Unknown font '%s' in '%s'", dashboard.fontMaterialName, key)
536 return false
537 end
538
539 dashboard.maxValue = (10 ^ (dashboard.numChilds)) - 1/(10^dashboard.precision) -- e.g. max with 2 childs and 1 float -> 10^2 - 1/10 -> 99.9 -> makes sure that display doesn't show 00.0 if value is 100
540 else
541 Logging.xmlWarning(self.xmlFile, "Missing numbers node for dashboard '%s'", key)
542 return false
543 end
544
545 return true
546end

loadRotationDashboardFromXML

Description
Definition
loadRotationDashboardFromXML()
Code
621function Dashboard:loadRotationDashboardFromXML(xmlFile, key, dashboard)
622 dashboard.node = xmlFile:getValue(key.."#node", nil, self.components, self.i3dMappings)
623 if dashboard.node == nil then
624 Logging.xmlWarning(self.xmlFile, "Missing 'node' for dashboard '%s'", key)
625 return false
626 end
627
628 dashboard.rotAxis = xmlFile:getValue(key.."#rotAxis")
629
630 local minRotStr = xmlFile:getValue(key.."#minRot")
631 if minRotStr ~= nil then
632 if dashboard.rotAxis ~= nil then
633 dashboard.minRot = math.rad(tonumber(minRotStr))
634 else
635 dashboard.minRot = minRotStr:getRadians(3)
636 end
637 else
638 Logging.xmlWarning(self.xmlFile, "Missing 'minRot' attribute for dashboard '%s'", key)
639 return false
640 end
641
642 local maxRotStr = xmlFile:getValue(key.."#maxRot")
643 if maxRotStr ~= nil then
644 if dashboard.rotAxis ~= nil then
645 dashboard.maxRot = math.rad(tonumber(maxRotStr))
646 else
647 dashboard.maxRot = maxRotStr:getRadians(3)
648 end
649 else
650 Logging.xmlWarning(self.xmlFile, "Missing 'maxRot' attribute for dashboard '%s'", key)
651 return false
652 end
653
654 dashboard.minValueRot = xmlFile:getValue(key.."#minValueRot")
655 dashboard.maxValueRot = xmlFile:getValue(key.."#maxValueRot")
656
657 return true
658end

loadSliderDashboardFromXML

Description
Definition
loadSliderDashboardFromXML()
Code
677function Dashboard:loadSliderDashboardFromXML(xmlFile, key, dashboard)
678 dashboard.node = xmlFile:getValue(key.."#node", nil, self.components, self.i3dMappings)
679 if dashboard.node == nil then
680 Logging.xmlWarning(self.xmlFile, "Missing 'node' for dashboard '%s'", key)
681 return false
682 end
683
684 if not getHasClassId(dashboard.node, ClassIds.SHAPE) then
685 Logging.xmlWarning(self.xmlFile, "Slider Dashboard node is not a shape! '%s' in '%s'", getName(dashboard.node), key)
686 return false
687 end
688
689 if getHasShaderParameter(dashboard.node, "sliderPos") then
690 setShaderParameter(dashboard.node, "sliderPos", 0, 0, 0, 0, false)
691
692 dashboard.minValueSlider = xmlFile:getValue(key.."#minValueSlider")
693 dashboard.maxValueSlider = xmlFile:getValue(key.."#maxValueSlider")
694 else
695 Logging.xmlWarning(self.xmlFile, "Node '%s' does not have a 'sliderPos' shader parameter for dashboard '%s'", getName(dashboard.node), key)
696 return false
697 end
698
699 return true
700end

loadTextDashboardFromXML

Description
Definition
loadTextDashboardFromXML()
Code
550function Dashboard:loadTextDashboardFromXML(xmlFile, key, dashboard)
551 dashboard.node = xmlFile:getValue(key.."#node", nil, self.components, self.i3dMappings)
552
553 dashboard.textColor = self:getDashboardColor(xmlFile, xmlFile:getValue(key.."#textColor"))
554 if dashboard.textColor == nil then
555 dashboard.textColor = {0.9, 0.9, 0.9, 1}
556 end
557
558 dashboard.hiddenColor = self:getDashboardColor(xmlFile, xmlFile:getValue(key.."#hiddenColor"))
559
560 if dashboard.node ~= nil then
561 local textAlignmentStr = xmlFile:getValue(key.."#textAlignment", "RIGHT")
562 dashboard.textAlignment = RenderText["ALIGN_" .. textAlignmentStr:upper()] or RenderText.ALIGN_RIGHT
563
564 dashboard.textSize = xmlFile:getValue(key.."#textSize", 0.03)
565 dashboard.textScaleX = xmlFile:getValue(key.."#textScaleX", 1)
566 dashboard.textScaleY = xmlFile:getValue(key.."#textScaleY", 1)
567 dashboard.textMask = xmlFile:getValue(key.."#textMask", "00.0")
568 dashboard.textFormatStr, dashboard.textFormatPrecision = string.maskToFormat(dashboard.textMask)
569
570 dashboard.fontName = xmlFile:getValue(key.."#font", "DIGIT"):upper()
571 dashboard.fontThickness = xmlFile:getValue(key.."#fontThickness", 1)
572 dashboard.emissiveScale = xmlFile:getValue(key.."#emissiveScale", 0.2)
573
574 dashboard.fontMaterial = g_materialManager:getFontMaterial(dashboard.fontName, self.customEnvironment)
575 if dashboard.fontMaterial ~= nil then
576 dashboard.characterLine = dashboard.fontMaterial:createCharacterLine(dashboard.node,
577 dashboard.textMask:len(),
578 dashboard.textSize,
579 dashboard.textColor,
580 dashboard.hiddenColor,
581 dashboard.emissiveScale,
582 dashboard.textScaleX,
583 dashboard.textScaleY,
584 dashboard.textAlignment,
585 nil,
586 dashboard.fontThickness)
587
588 dashboard.fontMaterial:updateCharacterLine(dashboard.characterLine, dashboard.textMask)
589 else
590 Logging.xmlWarning(self.xmlFile, "Unknown font '%s' in '%s'", dashboard.fontName, key)
591 return false
592 end
593
594 setVisibility(dashboard.node, false)
595 else
596 Logging.xmlWarning(self.xmlFile, "Missing node for dashboard '%s'", key)
597 return false
598 end
599
600 return true
601end

loadVisibilityDashboardFromXML

Description
Definition
loadVisibilityDashboardFromXML()
Code
662function Dashboard:loadVisibilityDashboardFromXML(xmlFile, key, dashboard)
663 dashboard.node = xmlFile:getValue(key.."#node", nil, self.components, self.i3dMappings)
664 if dashboard.node == nil then
665 Logging.xmlWarning(self.xmlFile, "Missing 'node' for dashboard '%s'", key)
666 return false
667 end
668
669 setVisibility(dashboard.node, false)
670
671 return true
672end

onLoad

Description
Definition
onLoad()
Code
98function Dashboard:onLoad(savegame)
99 local spec = self.spec_dashboard
100
101 spec.dashboards = {}
102 spec.criticalDashboards = {}
103 spec.groups = {}
104 spec.sortedGroups = {}
105 spec.groupUpdateIndex = 1
106 spec.hasGroups = false
107
108 local i = 0
109 while true do
110 local baseKey = string.format("%s.groups.group(%d)", "vehicle.dashboard", i)
111 if not self.xmlFile:hasProperty(baseKey) then
112 break
113 end
114
115 local group = {}
116 if self:loadDashboardGroupFromXML(self.xmlFile, baseKey, group) then
117 spec.groups[group.name] = group
118 table.insert(spec.sortedGroups, group)
119 spec.hasGroups = true
120 end
121
122 i = i + 1
123 end
124
125 spec.isDirty = false
126 spec.isDirtyTick = false
127
128 self:loadDashboardsFromXML(self.xmlFile, "vehicle.dashboard.default", {})
129
130 spec.maxUpdateDistance = self.xmlFile:getValue("vehicle.dashboard#maxUpdateDistance", Dashboard.DEFAULT_MAX_UPDATE_DISTANCE)
131 spec.maxUpdateDistanceCritical = self.xmlFile:getValue("vehicle.dashboard#maxUpdateDistanceCritical", Dashboard.DEFAULT_MAX_UPDATE_DISTANCE_CRITICAL)
132end

onPostLoad

Description
Definition
onPostLoad()
Code
136function Dashboard:onPostLoad(savegame)
137 local spec = self.spec_dashboard
138 if not self.isClient or (#spec.criticalDashboards == 0 and #spec.dashboards == 0) then
139 SpecializationUtil.removeEventListener(self, "onUpdate", Dashboard)
140 SpecializationUtil.removeEventListener(self, "onUpdateTick", Dashboard)
141 end
142end

onUpdate

Description
Definition
onUpdate()
Code
146function Dashboard:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
147 if self.isClient then
148 local spec = self.spec_dashboard
149
150 if spec.hasGroups then
151 local group = spec.sortedGroups[spec.groupUpdateIndex]
152 if self:getIsDashboardGroupActive(group) ~= group.isActive then
153 group.isActive = not group.isActive
154
155 -- force update of all dashboards
156 self:updateDashboards(spec.dashboards, dt, true)
157 self:updateDashboards(spec.criticalDashboards, dt, true)
158 end
159
160 spec.groupUpdateIndex = spec.groupUpdateIndex + 1
161 if spec.groupUpdateIndex > #spec.sortedGroups then
162 spec.groupUpdateIndex = 1
163 end
164 end
165
166 if self.currentUpdateDistance < spec.maxUpdateDistanceCritical or spec.isDirty then
167 self:updateDashboards(spec.criticalDashboards, dt)
168
169 spec.isDirty = false
170 end
171
172 if spec.isDirtyTick then
173 self:raiseActive()
174 end
175 end
176end

onUpdateEnd

Description
Definition
onUpdateEnd()
Code
193function Dashboard:onUpdateEnd(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
194 if self.isClient then
195 local spec = self.spec_dashboard
196 self:updateDashboards(spec.dashboards, dt, true)
197 self:updateDashboards(spec.criticalDashboards, dt, true)
198 end
199end

onUpdateTick

Description
Definition
onUpdateTick()
Code
180function Dashboard:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
181 if self.isClient then
182 local spec = self.spec_dashboard
183 if self.currentUpdateDistance < spec.maxUpdateDistance or spec.isDirtyTick then
184 self:updateDashboards(spec.dashboards, dt)
185
186 spec.isDirtyTick = false
187 end
188 end
189end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
45function Dashboard.prerequisitesPresent(specializations)
46 return true
47end

registerDashboardWarningXMLPaths

Description
Definition
registerDashboardWarningXMLPaths()
Code
1167function Dashboard.registerDashboardWarningXMLPaths(schema, basePath)
1168 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#warningThresholdMin", "(WARNING) Threshold min.")
1169 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#warningThresholdMax", "(WARNING) Threshold max.")
1170end

registerDashboardXMLPaths

Description
Definition
registerDashboardXMLPaths()
Code
1115function Dashboard.registerDashboardXMLPaths(schema, basePath, availableValueTypes)
1116 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#valueType", string.format("Value type name (Available: %s)", availableValueTypes or "no valueTypes available here"))
1117 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#displayType", "Display type name")
1118 schema:register(XMLValueType.BOOL, basePath .. ".dashboard(?)#doInterpolation", "Do interpolation", false)
1119 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#interpolationSpeed", "Interpolation speed", 0.005)
1120 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#idleValue", "Idle value", 0)
1121
1122 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#groups", "List of groups")
1123
1124 schema:register(XMLValueType.NODE_INDEX, basePath .. ".dashboard(?)#node", "(EMITTER | ROT | VISIBILITY) Node")
1125 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#baseColor", "(EMITTER) Base color (DashboardColor OR BrandColor OR r g b a)")
1126 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#emitColor", "(EMITTER) Emit color (DashboardColor OR BrandColor OR r g b a)")
1127 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#intensity", "(EMITTER) Intensity", 1)
1128
1129 schema:register(XMLValueType.NODE_INDEX, basePath .. ".dashboard(?)#numbers", "(NUMBER) Numbers node")
1130 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#numberColor", "(NUMBER) Numbers color (DashboardColor OR BrandColor OR r g b a)")
1131 schema:register(XMLValueType.INT, basePath .. ".dashboard(?)#precision", "(NUMBER) Precision", 1)
1132 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#font", "(NUMBER) Name of font to apply to mesh", "DIGIT")
1133 schema:register(XMLValueType.BOOL, basePath .. ".dashboard(?)#hasNormalMap", "(NUMBER) Normal map will be applied to number decals", false)
1134 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#emissiveScale", "(NUMBER) Scale of emissive map", 0.2)
1135
1136 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#textColor", "(TEXT) Font color (DashboardColor OR BrandColor OR r g b a)")
1137 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#hiddenColor", "(TEXT) Color of hidden character (if defined a '0' in this color is display instead of nothing)")
1138 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#textAlignment", "(TEXT) Alignment of text (LEFT | RIGHT | CENTER)", "RIGHT")
1139 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#textSize", "(TEXT) Size of font in meter", 0.03)
1140 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#fontThickness", "(TEXT) Thickness factor for font characters", 1.0)
1141 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#textScaleX", "(TEXT) Global X scale of text", 1)
1142 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#textScaleY", "(TEXT) Global Y scale of text", 1)
1143 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#textMask", "(TEXT) Font Mask", "00.0")
1144
1145 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#animName", "(ANIMATION) Animation name")
1146 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#minValueAnim", "(ANIMATION) Min. reference value for animation")
1147 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#maxValueAnim", "(ANIMATION) Max. reference value for animation")
1148
1149 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#rotAxis", "(ROT) Rotation axis")
1150 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#minRot", "(ROT) Min. rotation (Rotation value if rotAxis is given | Rotation Vector of rotAxis is not given)")
1151 schema:register(XMLValueType.STRING, basePath .. ".dashboard(?)#maxRot", "(ROT) Min. rotation (Rotation value if rotAxis is given | Rotation Vector of rotAxis is not given)")
1152 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#minValueRot", "(ROT) Min. reference value for rotation")
1153 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#maxValueRot", "(ROT) Max. reference value for rotation")
1154
1155 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#minValueSlider", "(SLIDER) Min. reference value for slider")
1156 schema:register(XMLValueType.FLOAT, basePath .. ".dashboard(?)#maxValueSlider", "(SLIDER) Max. reference value for slider")
1157
1158 schema:register(XMLValueType.VECTOR_N, basePath .. ".dashboard(?).state(?)#value", "(MULTI_STATE) One or multiple values separated by space to activate the state")
1159 schema:register(XMLValueType.VECTOR_ROT, basePath .. ".dashboard(?).state(?)#rotation", "(MULTI_STATE) Rotation while state is active")
1160 schema:register(XMLValueType.VECTOR_TRANS, basePath .. ".dashboard(?).state(?)#translation", "(MULTI_STATE) Translation while state is active")
1161 schema:register(XMLValueType.VECTOR_SCALE, basePath .. ".dashboard(?).state(?)#scale", "(MULTI_STATE) Scale while state is active")
1162 schema:register(XMLValueType.BOOL, basePath .. ".dashboard(?).state(?)#visibility", "(MULTI_STATE) Visibility while state is active")
1163end

registerEventListeners

Description
Definition
registerEventListeners()
Code
88function Dashboard.registerEventListeners(vehicleType)
89 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Dashboard)
90 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Dashboard)
91 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Dashboard)
92 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Dashboard)
93 SpecializationUtil.registerEventListener(vehicleType, "onUpdateEnd", Dashboard)
94end

registerFunctions

Description
Definition
registerFunctions()
Code
66function Dashboard.registerFunctions(vehicleType)
67 SpecializationUtil.registerFunction(vehicleType, "updateDashboards", Dashboard.updateDashboards)
68 SpecializationUtil.registerFunction(vehicleType, "loadDashboardGroupFromXML", Dashboard.loadDashboardGroupFromXML)
69 SpecializationUtil.registerFunction(vehicleType, "getIsDashboardGroupActive", Dashboard.getIsDashboardGroupActive)
70 SpecializationUtil.registerFunction(vehicleType, "getDashboardGroupByName", Dashboard.getDashboardGroupByName)
71 SpecializationUtil.registerFunction(vehicleType, "loadDashboardsFromXML", Dashboard.loadDashboardsFromXML)
72 SpecializationUtil.registerFunction(vehicleType, "loadDashboardFromXML", Dashboard.loadDashboardFromXML)
73 SpecializationUtil.registerFunction(vehicleType, "loadEmitterDashboardFromXML", Dashboard.loadEmitterDashboardFromXML)
74 SpecializationUtil.registerFunction(vehicleType, "loadNumberDashboardFromXML", Dashboard.loadNumberDashboardFromXML)
75 SpecializationUtil.registerFunction(vehicleType, "loadTextDashboardFromXML", Dashboard.loadTextDashboardFromXML)
76 SpecializationUtil.registerFunction(vehicleType, "loadAnimationDashboardFromXML", Dashboard.loadAnimationDashboardFromXML)
77 SpecializationUtil.registerFunction(vehicleType, "loadRotationDashboardFromXML", Dashboard.loadRotationDashboardFromXML)
78 SpecializationUtil.registerFunction(vehicleType, "loadVisibilityDashboardFromXML", Dashboard.loadVisibilityDashboardFromXML)
79 SpecializationUtil.registerFunction(vehicleType, "loadSliderDashboardFromXML", Dashboard.loadSliderDashboardFromXML)
80 SpecializationUtil.registerFunction(vehicleType, "loadMultiStateDashboardFromXML", Dashboard.loadMultiStateDashboardFromXML)
81 SpecializationUtil.registerFunction(vehicleType, "setDashboardsDirty", Dashboard.setDashboardsDirty)
82 SpecializationUtil.registerFunction(vehicleType, "getDashboardValue", Dashboard.getDashboardValue)
83 SpecializationUtil.registerFunction(vehicleType, "getDashboardColor", Dashboard.getDashboardColor)
84end

setDashboardsDirty

Description
Definition
setDashboardsDirty()
Code
1057function Dashboard:setDashboardsDirty()
1058 self.spec_dashboard.isDirty = true
1059 self.spec_dashboard.isDirtyTick = true
1060
1061 self:raiseActive()
1062end

updateDashboards

Description
Definition
updateDashboards()
Code
203function Dashboard:updateDashboards(dashboards, dt, force)
204 for i=1, #dashboards do
205 local dashboard = dashboards[i]
206 local isActive = true
207 for j=1, #dashboard.groups do
208 if not dashboard.groups[j].isActive then
209 isActive = false
210 break
211 end
212 end
213
214 if dashboard.valueObject ~= nil and dashboard.valueFunc ~= nil then
215 local value = self:getDashboardValue(dashboard.valueObject, dashboard.valueFunc, dashboard)
216
217 if dashboard.valueFactor ~= nil and type(value) == "number" then
218 value = value * dashboard.valueFactor
219 end
220
221 if not isActive then
222 value = dashboard.idleValue
223 end
224
225 if dashboard.doInterpolation and type(value) == "number" and value ~= dashboard.lastInterpolationValue then
226 local dir = MathUtil.sign(value - dashboard.lastInterpolationValue)
227 local limitFunc = math.min
228 if dir < 0 then
229 limitFunc = math.max
230 end
231
232 value = limitFunc(dashboard.lastInterpolationValue + dashboard.interpolationSpeed * dir * dt, value)
233 dashboard.lastInterpolationValue = value
234 end
235
236 if value ~= dashboard.lastValue or force then
237 dashboard.lastValue = value
238
239 local min, max
240 if type(value) == "number" then
241 -- for idle values while not active we ignore the limits
242 min = self:getDashboardValue(dashboard.valueObject, dashboard.minFunc, dashboard)
243 if min ~= nil and isActive then
244 value = math.max(min, value)
245 end
246
247 max = self:getDashboardValue(dashboard.valueObject, dashboard.maxFunc, dashboard)
248 if max ~= nil and isActive then
249 value = math.min(max, value)
250 end
251
252 local center = self:getDashboardValue(dashboard.valueObject, dashboard.centerFunc, dashboard)
253 if center ~= nil then
254 local maxValue = math.max(math.abs(min), math.abs(max))
255 if value < center then
256 value = -value / min * maxValue
257 elseif value > center then
258 value = value / max * maxValue
259 end
260
261 max = maxValue
262 min = -maxValue
263 end
264 end
265
266 if dashboard.valueCompare ~= nil then
267 if type(dashboard.valueCompare) == "table" then
268 local oldValue = value
269 value = false
270 for _, compareValue in ipairs(dashboard.valueCompare) do
271 if oldValue == compareValue then
272 value = true
273 end
274 end
275 else
276 value = value == dashboard.valueCompare
277 end
278 end
279
280 dashboard.stateFunc(self, dashboard, value, min, max, isActive)
281 end
282 elseif force then
283 dashboard.stateFunc(self, dashboard, true, nil, nil, isActive)
284 end
285 end
286end

warningAttributes

Description
Definition
warningAttributes()
Code
1042function Dashboard:warningAttributes(xmlFile, key, dashboard, isActive)
1043 dashboard.warningThresholdMin = xmlFile:getValue(key .. "#warningThresholdMin", -math.huge)
1044 dashboard.warningThresholdMax = xmlFile:getValue(key .. "#warningThresholdMax", math.huge)
1045
1046 return true
1047end

warningState

Description
Definition
warningState()
Code
1051function Dashboard:warningState(dashboard, newValue, minValue, maxValue, isActive)
1052 Dashboard.defaultDashboardStateFunc(self, dashboard, newValue > dashboard.warningThresholdMin and newValue < dashboard.warningThresholdMax, minValue, maxValue, isActive)
1053end