-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#81 - added HUD display for remaining meters to headland trigger
- Loading branch information
Showing
2 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,14 @@ | |
-- | ||
-- Author: Majo76 | ||
-- email: [email protected] | ||
-- @Date: 23.01.2022 | ||
-- @Date: 24.01.2022 | ||
-- @Version: 1.2.0.0 | ||
|
||
--[[ | ||
CHANGELOG | ||
2022-01-23 - V1.2.0.0 | ||
2022-01-24 - V1.2.0.0 | ||
+ added a display for the remaining distance to the headland trigger | ||
+ added config XML option to specify sfx volume | ||
* ATTENTION: Way of "how it works" changed: | ||
- Press RShift+Home to switch throught operating modes: "snap to direction" or "snap to track" | ||
|
@@ -607,7 +608,7 @@ function FS22_EnhancedVehicle:onPostLoad(savegame) | |
self.vData.opMode = 0 | ||
self.vData.triggerCalculate = false | ||
self.vData.impl = { isCalculated = false } | ||
self.vData.track = { isCalculated = false, deltaTrack = 1, headlandMode = 1, headlandDistance = 9999, isOnField = 0 } | ||
self.vData.track = { isCalculated = false, deltaTrack = 1, headlandMode = 1, headlandDistance = 9999, isOnField = 0, eofDistance = 0, eofNext = 0 } | ||
|
||
-- (server) set some defaults | ||
if self.isServer then | ||
|
@@ -669,10 +670,12 @@ end | |
function FS22_EnhancedVehicle:saveToXMLFile(xmlFile, key) | ||
if debug > 1 then print("-> " .. myName .. ": saveToXMLFile" .. mySelf(self)) end | ||
|
||
setXMLBool(xmlFile.handle, key.."#frontDiffIsOn", self.vData.is[1]) | ||
setXMLBool(xmlFile.handle, key.."#backDiffIsOn", self.vData.is[2]) | ||
setXMLInt(xmlFile.handle, key.."#driveMode", self.vData.is[3]) | ||
setXMLBool(xmlFile.handle, key.."#parkingBrakeIsOn", self.vData.is[13]) | ||
if self.vData.is[3] ~= -1 then | ||
setXMLBool(xmlFile.handle, key.."#frontDiffIsOn", self.vData.is[1]) | ||
setXMLBool(xmlFile.handle, key.."#backDiffIsOn", self.vData.is[2]) | ||
setXMLInt(xmlFile.handle, key.."#driveMode", self.vData.is[3]) | ||
setXMLBool(xmlFile.handle, key.."#parkingBrakeIsOn", self.vData.is[13]) | ||
end | ||
end | ||
|
||
-- ############################################################################# | ||
|
@@ -793,6 +796,12 @@ function FS22_EnhancedVehicle:onUpdate(dt) | |
end | ||
end | ||
|
||
-- get distance to end-of-field each second | ||
if self.vData.track.eofNext < g_currentMission.time then | ||
FS22_EnhancedVehicle:getHeadlandDistance(self) | ||
self.vData.track.eofNext = g_currentMission.time + 1000 | ||
end | ||
|
||
-- headland management | ||
if self.vData.is[5] and self.vData.is[6] then | ||
local isOnField = FS22_EnhancedVehicle:getHeadlandInfo(self) | ||
|
@@ -817,10 +826,6 @@ function FS22_EnhancedVehicle:onUpdate(dt) | |
if self.spec_drivable ~= nil and self.spec_drivable.cruiseControl ~= nil then | ||
if self.spec_drivable.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_OFF then | ||
self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF) | ||
-- update server/clients | ||
-- if not self.isServer then | ||
-- g_client:getServerConnection():sendEvent(SetCruiseControlStateEvent.new(self, Drivable.CRUISECONTROL_STATE_OFF)) | ||
-- end | ||
end | ||
end | ||
end | ||
|
@@ -1873,6 +1878,42 @@ function FS22_EnhancedVehicle:getHeadlandInfo(self) | |
return(isOnField) | ||
end | ||
|
||
-- ############################################################################# | ||
|
||
function FS22_EnhancedVehicle:getHeadlandDistance(self) | ||
local distance = self.vData.track.headlandDistance | ||
if distance == 9999 and self.vData.track.workWidth ~= nil then | ||
distance = self.vData.track.workWidth | ||
end | ||
local x = self.vData.px + (self.vData.dirX * distance) | ||
local z = self.vData.pz + (self.vData.dirZ * distance) | ||
local _x = x | ||
local _z = z | ||
|
||
local isOnField = true | ||
local _dist = 0.0 | ||
local _delta = 0.5 | ||
|
||
while(_dist < 100) do | ||
local y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 1, z) | ||
local groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels = g_currentMission.fieldGroundSystem:getDensityMapData(FieldDensityMap.GROUND_TYPE) | ||
local _density = getDensityAtWorldPos(groundTypeMapId, x, y, z) | ||
local _densityType = bitAND(bitShiftRight(_density, groundTypeFirstChannel), 2^groundTypeNumChannels - 1) | ||
isOnField = isOnField and (_densityType ~= g_currentMission.grassValue and _densityType ~= 0) | ||
|
||
if not isOnField then | ||
self.vData.track.eofDistance = MathUtil.vector2Length(_x - x, _z - z) | ||
_dist = 100 | ||
end | ||
|
||
x = x + (self.vData.dirX * _delta) | ||
z = z + (self.vData.dirZ * _delta) | ||
_dist = _dist + _delta | ||
end | ||
|
||
if _dist == 100 then self.vData.track.eofDistance = -1 end | ||
end | ||
|
||
-- ############################################################################# | ||
-- # this function updates the track layout | ||
-- # updateAngle true -> update track direction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
-- | ||
-- Author: Majo76 | ||
-- email: [email protected] | ||
-- @Date: 22.01.2022 | ||
-- @Date: 24.01.2022 | ||
-- @Version: 1.2.0.0 | ||
|
||
-- Thanks to Wopster for the inspiration to implement a HUD in this way | ||
|
@@ -54,10 +54,11 @@ FS22_EnhancedVehicle_HUD.POSITION = { | |
TRACK = { 55, 13 }, | ||
WORKWIDTH = { 245, 13 }, | ||
HLDISTANCE = { 245, 40 }, | ||
HLEOF = { 287, 39 }, | ||
ICON_SNAP = { 55-10-18, 29 }, | ||
ICON_TRACK = { 55+10, 29 }, | ||
ICON_HLMODE = { 245-24-18, 29 }, | ||
ICON_HLDIR = { 245+24, 29 }, | ||
ICON_HLDIR = { 245+18, 29 }, | ||
ICON_DIFF = { 0, 0 }, | ||
ICON_PARK = { 0, 0 }, | ||
DMG = { -15, 5 }, | ||
|
@@ -77,6 +78,7 @@ FS22_EnhancedVehicle_HUD.TEXT_SIZE = { | |
TRACK = 12, | ||
WORKWIDTH = 12, | ||
HLDISTANCE = 12, | ||
HLEOF = 9, | ||
DMG = 12, | ||
FUEL = 12, | ||
MISC = 13, | ||
|
@@ -106,6 +108,7 @@ function FS22_EnhancedVehicle_HUD:new(speedMeterDisplay, gameInfoDisplay, modDir | |
self.snapText2 = {} | ||
self.trackText = {} | ||
self.headlandText = {} | ||
self.headlandEOFText = {} | ||
self.workWidthText = {} | ||
self.headlandDistanceText = {} | ||
self.dmgText = {} | ||
|
@@ -480,6 +483,12 @@ function FS22_EnhancedVehicle_HUD:storeScaledValues(_move) | |
self.headlandDistanceText.posY = boxPosY + textY | ||
self.headlandDistanceText.size = self.speedMeterDisplay:scalePixelToScreenHeight(FS22_EnhancedVehicle_HUD.TEXT_SIZE.HLDISTANCE) | ||
|
||
-- headland eof text | ||
local textX, textY = self.speedMeterDisplay:scalePixelToScreenVector(FS22_EnhancedVehicle_HUD.POSITION.HLEOF) | ||
self.headlandEOFText.posX = boxPosX + textX | ||
self.headlandEOFText.posY = boxPosY + textY | ||
self.headlandEOFText.size = self.speedMeterDisplay:scalePixelToScreenHeight(FS22_EnhancedVehicle_HUD.TEXT_SIZE.HLEOF) | ||
|
||
-- for dmg and fuel display | ||
local addPosX = boxPosX + boxWidth / 2 | ||
local addPosY = boxPosY | ||
|
@@ -733,6 +742,7 @@ function FS22_EnhancedVehicle_HUD:drawHUD() | |
-- prepare text | ||
local track_txt = self.default_track_txt | ||
local headland_txt = self.default_headland_txt | ||
local headland_txt2 = "" | ||
local workwidth_txt = self.default_workwidth_txt | ||
|
||
if self.vehicle.vData.track.isCalculated then | ||
|
@@ -745,6 +755,7 @@ function FS22_EnhancedVehicle_HUD:drawHUD() | |
local _tmp = self.vehicle.vData.track.headlandDistance | ||
if _tmp == 9999 then _tmp = Round(self.vehicle.vData.track.workWidth, 1) end | ||
headland_txt = string.format("%.1fm", math.abs(_tmp)) | ||
headland_txt2 = self.vehicle.vData.track.eofDistance ~= -1 and string.format("%.1f", self.vehicle.vData.track.eofDistance) or "err" | ||
end | ||
if self.vehicle.vData.opMode == 1 and self.vehicle.vData.impl.isCalculated and self.vehicle.vData.impl.workWidth > 0 then | ||
workwidth_txt = string.format("|← %.1fm →|", Round(self.vehicle.vData.impl.workWidth, 1)) | ||
|
@@ -770,6 +781,18 @@ function FS22_EnhancedVehicle_HUD:drawHUD() | |
|
||
-- headland distance | ||
renderText(self.headlandDistanceText.posX, self.headlandDistanceText.posY, self.headlandDistanceText.size, headland_txt) | ||
|
||
if self.vehicle.vData.track.headlandMode >= 2 then | ||
if self.vehicle.vData.track.eofDistance > 30 then | ||
color = FS22_EnhancedVehicle_HUD.COLOR.ACTIVE | ||
elseif self.vehicle.vData.track.eofDistance > 10 then | ||
color = FS22_EnhancedVehicle_HUD.COLOR.STANDBY | ||
else | ||
color = { 1, 0, 0, 1 } | ||
end | ||
setTextColor(unpack(color)) | ||
end | ||
renderText(self.headlandEOFText.posX, self.headlandEOFText.posY, self.headlandEOFText.size, headland_txt2) | ||
end -- <- end of draw track box | ||
|
||
-- draw our diff HUD | ||
|