Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
6.03.00053 Many fixes
Browse files Browse the repository at this point in the history
*  Mode 6 re-enabled for Kuhn Discolander, fixes #7023

    The fix for #6912 screwed this up. Instead of enabling all foldables
    for mode 6 and disabling sprayers/sowing machines, just enable
    tension belts, that should cover auto bale loader trailers.

*   Working width setting by 0.1 increments fixes #5997

    Working width can be set by 0.1 increments over 10 m when holding
    down the left Alt key.

 * MapHotspot improvements

    - moved setting to global settings
    - simplified setting
    - improved start/stop CP multiplayer code

*  Fixes a click to switch bug.
    Where the player farm ID after entering a vehicle was not set correctly in SP.

*  Check for exact fill nodes before using them (#7060)
    Fixes #7006

*  Reverse for AD courses #7026 (#7061)

    Trying to figure out where should the course be driven in reverse,
    based on the angle difference between two subsequent waypoints,
    similar to what AD does internally.

    Quite a fragile process, not really happy with it.

*   Fix AD compatibility (#7066)

    - Added explicit interface functions to stop/start the CP driver
    - When stopping/starting just check if CP is driving, don't worry about getIsAIActive()
    as that can be anything, especially when other mods setting it.

*  Salford Plow:
    Removed 'noReverse' as it tourned out it can be pushed backwards in 90 and 180 degree turns very easy.

*   Making the cotton harvesters work (#7077)
    - Some of them won't lower the cutter, for those, just lower manually before starting the CP driver.

*  Mode 2 fix for trucks #7074 (#7078)
    - check truck's own fill level, not just trailer

* Action event rework

- created new ActionEventConfig.xml file.

* small pr improvements

* fixes MP bug, when autodrive starts a CP driver.

Co-authored-by: Tensuko <[email protected]>
  • Loading branch information
schwiti6190 and Tensuko authored Apr 18, 2021
1 parent 7c2e146 commit 28fb7f3
Show file tree
Hide file tree
Showing 28 changed files with 1,489 additions and 904 deletions.
446 changes: 446 additions & 0 deletions ActionEventsLoader.lua

Large diffs are not rendered by default.

138 changes: 92 additions & 46 deletions CpManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function CpManager:loadMap(name)
if g_server ~= nil then
self:loadXmlSettings();
g_vehicleConfigurations:loadFromXml()
g_ActionEventsLoader:loadFromXml()
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- SETUP (continued)
Expand Down Expand Up @@ -285,19 +286,6 @@ function CpManager:update(dt)
self.realTime5SecsTimerThrough = true;
end;

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- HELP MENU
if g_gui.currentGui == nil and g_currentMission.controlledVehicle == nil and not g_currentMission.player.currentTool then
if self.playerOnFootMouseEnabled then
-- TODO: Fix this when rewriting to the new Input Info box
-- Throws an error -> CpManager.lua:296: attempt to call method 'addHelpTextFunction' (a nil value)
-- wasn't able to find smth similiar in the FS19 doc, hence disable it for now
--g_currentMission:addHelpTextFunction(self.drawMouseButtonHelp, self, self.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_HIDE'));
--Tommi elseif self.globalInfoText.hasContent then
--Tommi g_currentMission:addHelpTextFunction(self.drawMouseButtonHelp, self, self.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_SHOW'));
end;
end;

if not courseplay.fields.modifier then
courseplay.fields.modifier = DensityMapModifier:new(g_currentMission.terrainDetailId, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels) -- terrain type modifier
courseplay.fields.filter = DensityMapFilter:new(courseplay.fields.modifier) -- filter on terrain type
Expand Down Expand Up @@ -363,43 +351,14 @@ function CpManager:mouseEvent(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- LEFT CLICK to click the button shown in globalInfoText
if (isDown or isUp) and mouseKey == courseplay.inputBindings.mouse.primaryButtonId and courseplay:mouseIsInArea(posX, posY, area.x1, area.x2, area.y1, area.y2) then
if self.globalInfoText.hasContent then
for i,button in pairs(self.globalInfoText.buttons) do
if button.show and button:getHasMouse(posX, posY) then
button:setClicked(isDown);
if isUp then
local sourceVehicle = g_currentMission.controlledVehicle or button.parameter;
button:handleMouseClick(sourceVehicle);
end;
break;
end;
end;
end;

self:onPrimaryMouseClick(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- RIGHT CLICK to activate the mouse cursor when I'm not in a vehicle and a globalInfoText is shown
elseif isUp and mouseKey == courseplay.inputBindings.mouse.secondaryButtonId and g_currentMission.controlledVehicle == nil then
if self.globalInfoText.hasContent and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool then
self.playerOnFootMouseEnabled = true;
self.wasPlayerFrozen = g_currentMission.isPlayerFrozen;
g_currentMission.isPlayerFrozen = true;
elseif self.playerOnFootMouseEnabled then
self.playerOnFootMouseEnabled = false;
if self.globalInfoText.hasContent then --if a button was hovered when deactivating the cursor, deactivate hover state
for _,button in pairs(self.globalInfoText.buttons) do
button:setClicked(false);
button:setHovered(false);
end;
end;
if not self.wasPlayerFrozen then
g_currentMission.isPlayerFrozen = false;
end;
end;
g_inputBinding:setShowMouseCursor(self.playerOnFootMouseEnabled);

self:onSecondaryMouseClick(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- HOVER
elseif not isDown and not isUp and self.globalInfoText.hasContent then
elseif not isDown and not isUp and self:getHasGlobalInfoText() then
for _,button in pairs(self.globalInfoText.buttons) do
button:setClicked(false);
if button.show and not button.isHidden then
Expand All @@ -410,12 +369,88 @@ function CpManager:mouseEvent(posX, posY, isDown, isUp, mouseKey)
g_devHelper:mouseEvent(posX, posY, isDown, isUp, mouseKey)
end;

---Secondary mouse button pressed
---@param float posX, mouse x position
---@param float posY, mouse y position
---@param boolean isDown, is the mouse button down ?
---@param boolean isUp, is the mouse button up ?
---@param int mouseKey, which mouse button was pressed ?
function CpManager:onSecondaryMouseClick(posX, posY, isDown, isUp, mouseKey)
if self:getHasGlobalInfoText() and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool then
self.playerOnFootMouseEnabled = true
self.wasPlayerFrozen = g_currentMission.isPlayerFrozen
g_currentMission.isPlayerFrozen = true
elseif self.playerOnFootMouseEnabled then
self.playerOnFootMouseEnabled = false
if self:getHasGlobalInfoText() then --if a button was hovered when deactivating the cursor, deactivate hover state
self:resetGlobalInfoTextButtons()
end;
if not self.wasPlayerFrozen then
g_currentMission.isPlayerFrozen = false
end;
end;
g_inputBinding:setShowMouseCursor(self.playerOnFootMouseEnabled)
CpManager:updateMouseInputText()
end

---Primary mouse button pressed
---@param float posX, mouse x position
---@param float posY, mouse y position
---@param boolean isDown, is the mouse button down ?
---@param boolean isUp, is the mouse button up ?
---@param int mouseKey, which mouse button was pressed ?
function CpManager:onPrimaryMouseClick(posX, posY, isDown, isUp, mouseKey)
if self:getHasGlobalInfoText() then
for i,button in pairs(self.globalInfoText.buttons) do
if button.show and button:getHasMouse(posX, posY) then
button:setClicked(isDown)
if isUp then
local sourceVehicle = g_currentMission.controlledVehicle or button.parameter
button:handleMouseClick(sourceVehicle)
end
break
end
end
CpManager:updateMouseInputText()
end
end

---Is the second mouse button allowed, when the player isn't in a vehicle ?
---@return boolean allowed?
function CpManager:isSecondaryMouseClickAllowed()
return self.playerOnFootMouseEnabled or self:getHasGlobalInfoText() and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool
end

---Is the first mouse button allowed, when the player isn't in a vehicle ?
---@return boolean allowed?
function CpManager:isPrimaryMouseClickAllowed()
return self:getHasGlobalInfoText() and self.playerOnFootMouseEnabled
end

---Updates mouse input texts
---@param boolean forceText should the texts forced to display?
function CpManager:updateMouseInputText()
-- HELP MENU
---TODO: For now always display the mouse action text,
--- as this one would probably be broken in MP,
--- should probably rework global info texts.

-- if g_gui.currentGui == nil and not g_currentMission.player.currentTool then
-- g_currentMission.hud.inputHelp:clearCustomEntries()
-- if self:isPrimaryMouseClickAllowed() or g_currentMission.controlledVehicle ~= nil then
-- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_MOUSEACTION_PRIMARY', '', courseplay:loc("input_COURSEPLAY_MOUSEACTION_PRIMARY"), false)
-- end
-- if self:isSecondaryMouseClickAllowed() or g_currentMission.controlledVehicle ~= nil then
-- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_MOUSEACTION_SECONDARY', '', courseplay:loc("input_COURSEPLAY_MOUSEACTION_SECONDARY"), false)
-- end
-- end
end

function CpManager:keyEvent(unicode, sym, modifier, isDown)
courseplay:onKeyEvent(unicode, sym, modifier, isDown)
g_devHelper:keyEvent(unicode, sym, modifier, isDown)
end;


-- ####################################################################################################
function CpManager.saveXmlSettings(self)
if g_server == nil and g_dedicatedServerInfo == nil then return end;
Expand Down Expand Up @@ -1113,6 +1148,17 @@ function CpManager:renderGlobalInfoTexts(basePosY)
return line;
end;

function CpManager:resetGlobalInfoTextButtons()
for _,button in pairs(self.globalInfoText.buttons) do
button:setClicked(false);
button:setHovered(false);
end;
end

function CpManager:getHasGlobalInfoText()
return self.globalInfoText.hasContent
end

-- ####################################################################################################
-- 2D COURSE DRAW SETUP
function CpManager:setup2dCourseData(createOverlays)
Expand Down
96 changes: 11 additions & 85 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ function courseplay:onLeaveVehicle()
courseplay:setMouseCursor(self, false);
courseEditor:reset()
end

---Update mouse action event texts
CpManager:updateMouseInputText()
--hide visual i3D waypoint signs when not in vehicle
courseplay.signs:setSignsVisibility(self, true);
end
Expand All @@ -423,7 +424,8 @@ function courseplay:onEnterVehicle()
if self.cp.mouseCursorActive then
courseplay:setMouseCursor(self, true);
end;

---Update mouse action event texts
CpManager:updateMouseInputText()
--show visual i3D waypoint signs only when in vehicle
courseplay.signs:setSignsVisibility(self);
end
Expand Down Expand Up @@ -464,88 +466,8 @@ function courseplay:onDraw()
end
local nx,ny,nz = getWorldTranslation(self.cp.directionNode);
cpDebug:drawPoint(nx, ny+4, nz, 0.6196, 0.3490 , 0);
end;


-- HELP BUTTON TEXTS
--renderText(0.2, 0.5, 0.02, string.format("InputBinding.wrapMousePositionEnabled(%s),g_currentMission.isPlayerFrozen(%s) self:getIsActive(%s) and Enterable.getIsEntered(self)(%s) then"
--,tostring(InputBinding.wrapMousePositionEnabled),tostring(g_currentMission.isPlayerFrozen),tostring(self:getIsActive()),tostring(Enterable.getIsEntered(self))));
--print(string.format("if self:getIsActive(%s) and self.isEntered(%s) then",tostring(self:getIsActive()),tostring(Enterable.getIsEntered(self))))
end;


if self:getIsActive() and self:getIsEntered() then
local modifierPressed = courseplay.inputModifierIsPressed;
--missing hud.openWithMouse ?
if self.cp.canDrive and not modifierPressed then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_FUNCTIONS'), InputBinding.COURSEPLAY_MODIFIER, nil, GS_PRIO_HIGH);
end;

--[[if self.cp.hud.show then
if self.cp.mouseCursorActive then
g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_HIDE'));
else
g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_SHOW'));
end;
end;]]
if modifierPressed then
if not self.cp.hud.show then
--g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_HUD'], true)
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_OPEN'), InputBinding.COURSEPLAY_HUD, nil, GS_PRIO_HIGH);
else
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_CLOSE'), InputBinding.COURSEPLAY_HUD, nil, GS_PRIO_HIGH);
end;
end;

if modifierPressed then
if self.cp.canDrive then
if isDriving then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_STOP_COURSE'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
--g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_START_STOP'], true)
if self.cp.HUD1wait or (self.cp.driver and self.cp.driver:isWaiting()) then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_CONTINUE'), InputBinding.COURSEPLAY_CANCELWAIT, nil, GS_PRIO_HIGH);
end;
if self.cp.HUD1noWaitforFill then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_DRIVE_NOW'), InputBinding.COURSEPLAY_DRIVENOW, nil, GS_PRIO_HIGH);
end;
else
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_START_COURSE'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
--g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_START_STOP'], true)

--new ShovelPositions still need info text!

-- if self.cp.hasShovelStatePositions[2] and InputBinding.COURSEPLAY_SHOVELPOSITION_LOAD ~= nil then
-- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_LOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_LOAD, nil, GS_PRIO_HIGH);
-- end;
-- if self.cp.hasShovelStatePositions[3] and InputBinding.COURSEPLAY_SHOVELPOSITION_TRANSPORT ~= nil then
-- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_TRANSPORT'). InputBinding.COURSEPLAY_SHOVELPOSITION_TRANSPORT, nil, GS_PRIO_HIGH);
-- end;
-- if self.cp.hasShovelStatePositions[4] and InputBinding.COURSEPLAY_SHOVELPOSITION_PREUNLOAD ~= nil then
-- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_PREUNLOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_PREUNLOAD, nil, GS_PRIO_HIGH);
-- end;
-- if self.cp.hasShovelStatePositions[5] and InputBinding.COURSEPLAY_SHOVELPOSITION_UNLOAD ~= nil then
-- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_UNLOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_UNLOAD, nil, GS_PRIO_HIGH);
-- end;
--end;
end;
else
if not self.cp.isRecording and not self.cp.recordingIsPaused and self.cp.numWaypoints == 0 then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_START'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
elseif self.cp.isRecording and not self.cp.recordingIsPaused and not self.cp.isRecordingTurnManeuver then
g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_STOP'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
end;
end;

if self.cp.canSwitchMode then
if self.cp.nextMode then
g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_NEXTMODE'), InputBinding.COURSEPLAY_NEXTMODE, nil, GS_PRIO_HIGH);
end;
if self.cp.prevMode then
g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_PREVMODE'), InputBinding.COURSEPLAY_PREVMODE, nil, GS_PRIO_HIGH);
end;
end;
end;
end;

if self:getIsActive() then
if self.cp.hud.show then
courseplay.hud:setContent(self);
Expand Down Expand Up @@ -1387,8 +1309,12 @@ function courseplay.onStartCpAIDriver(vehicle,helperIndex,noEventSend, startedFa
spec.currentHelper = g_helperManager:getRandomHelper()
end
g_helperManager:useHelper(spec.currentHelper)
spec.startedFarmId = startedFarmId
if g_server ~= nil then
---Make sure the farmId is never: 0 == spectator farm id,
---which could be the case when autodrive starts a CP driver.
if startedFarmId ~= 0 then
spec.startedFarmId = startedFarmId
end
if g_server ~= nil then
g_farmManager:updateFarmStats(startedFarmId, "workersHired", 1)
end
if noEventSend == nil or noEventSend == false then
Expand Down
3 changes: 3 additions & 0 deletions button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ function courseplay.button:getHasMouse(mouseX, mouseY)
return courseplay:mouseIsInArea(mouseX, mouseY, self.x, self.x2, self.y, self.y2);
end;

function courseplay.button:getIsDisabled()
return self.isDisabled
end


-- #################################################################
Expand Down
Loading

0 comments on commit 28fb7f3

Please sign in to comment.