From 458b9e35ea41f20ba32b3f480928934e0dfd0edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=A4rtner?= Date: Mon, 8 Apr 2019 21:30:51 +0200 Subject: [PATCH] update: transfered all funtions, ready for polishing --- BaleLoaderAIDriver.lua | 6 ++ FillableFieldworkAIDriver.lua | 5 + hud.lua | 182 +++++++++++++++++----------------- register.lua | 1 + settings.lua | 12 +++ toolManager.lua | 12 +-- 6 files changed, 119 insertions(+), 99 deletions(-) diff --git a/BaleLoaderAIDriver.lua b/BaleLoaderAIDriver.lua index e1d18e263..86dc949a3 100644 --- a/BaleLoaderAIDriver.lua +++ b/BaleLoaderAIDriver.lua @@ -61,6 +61,12 @@ function BaleLoaderAIDriver:init(vehicle) self:debug('Initialized, bale loader: %s', self.baleLoader:getName()) end +function BaleLoaderAIDriver:setHudContent() + UnloadableFieldworkAIDriver.setHudContent(self) + courseplay.hud:setBaleLoaderAIDriverContent(self.vehicle) +end + + ---@return boolean true if unload took over the driving function BaleLoaderAIDriver:driveUnloadOrRefill(dt) self:updateOffset() diff --git a/FillableFieldworkAIDriver.lua b/FillableFieldworkAIDriver.lua index 986581272..c3bb668d3 100644 --- a/FillableFieldworkAIDriver.lua +++ b/FillableFieldworkAIDriver.lua @@ -39,6 +39,11 @@ function FillableFieldworkAIDriver:init(vehicle) self.refillState = self.states.TO_BE_REFILLED end +function FillableFieldworkAIDriver:setHudContent() + FieldworkAIDriver.setHudContent(self) + courseplay.hud:setFillableFieldworkAIDriverContent(self.vehicle) +end + function FillableFieldworkAIDriver:changeToUnloadOrRefill() self.refillState = self.states.TO_BE_REFILLED FieldworkAIDriver.changeToUnloadOrRefill(self) diff --git a/hud.lua b/hud.lua index df5efa1ae..9f705d4d5 100644 --- a/hud.lua +++ b/hud.lua @@ -726,18 +726,26 @@ function courseplay.hud:updatePageContent(vehicle, page) else self:disableButtonWithFunction(vehicle,page, 'setStopAtEnd') end + elseif entry.functionToCall == 'toggleAutomaticCoverHandling' then vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_COVER_HANDLING'); vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.automaticCoverHandling and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_DEACTIVATED'); + elseif entry.functionToCall == 'changeSiloFillType' then if vehicle.cp.canDrive then + self:enableButtonWithFunction(vehicle,page, 'changeSiloFillType') vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_FARM_SILO_FILL_TYPE'); vehicle.cp.hud.content.pages[page][line][2].text = g_fillTypeManager:getFillTypeByIndex(vehicle.cp.siloSelectedFillType).title + else + self:disableButtonWithFunction(vehicle,page, 'changeSiloFillType') end elseif entry.functionToCall == 'changeRunNumber' then if vehicle.cp.canDrive then + self:enableButtonWithFunction(vehicle,page, 'changeRunNumber') vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_NUMBER_OF_RUNS'); vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.runNumber < 11 and string.format("%d", vehicle.cp.runNumber) or courseplay:loc('COURSEPLAY_UNLIMITED'); + else + self:disableButtonWithFunction(vehicle,page, 'changeRunNumber') end elseif entry.functionToCall == 'switchDriverCopy' then if not vehicle.cp.canDrive and not vehicle.cp.isRecording and not vehicle.cp.recordingIsPaused then @@ -768,9 +776,7 @@ function courseplay.hud:updatePageContent(vehicle, page) else self:disableButtonWithFunction(vehicle,page, 'openAdvancedCourseGeneratorSettings') end - elseif entry.functionToCall == 'setIsLoaded' then - vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_DRIVE_NOW') - + elseif entry.functionToCall == 'changeTurnSpeed' then vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_SPEED_TURN'); vehicle.cp.hud.content.pages[page][line][2].text = string.format('%d %s', g_i18n:getSpeed(vehicle.cp.speeds.turn), courseplay:getSpeedMeasuringUnit()); @@ -1156,42 +1162,49 @@ function courseplay.hud:updatePageContent(vehicle, page) vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_REMOVEACTIVECOMBINEFROMTRACTOR'); end; + elseif entry.functionToCall == 'toggleOppositeTurnMode' then + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_OPPOSITE_TURN_DIRECTION'); + vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.oppositeTurnMode and courseplay:loc('COURSEPLAY_OPPOSITE_TURN_WHEN_POSSIBLE') or courseplay:loc('COURSEPLAY_OPPOSITE_TURN_AT_END'); + + elseif entry.functionToCall == 'toggleFertilizeOption' then + if vehicle.cp.hasFertilizerSowingMachine then + self:enableButtonWithFunction(vehicle,page, 'toggleFertilizeOption') + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_FERTILIZERFUNCTION'); + vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.fertilizerEnabled and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED'); + else + self:disableButtonWithFunction(vehicle,page, 'toggleFertilizeOption') + end + elseif entry.functionToCall == 'toggleRidgeMarkersAutomatic' then + if vehicle.cp.hasSowingMachine then + self:enableButtonWithFunction(vehicle,page, 'toggleRidgeMarkersAutomatic') + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_RIDGEMARKERS'); + vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.ridgeMarkersAutomatic and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_DEACTIVATED'); + else + self:disableButtonWithFunction(vehicle,page, 'toggleRidgeMarkersAutomatic') + end - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + elseif entry.functionToCall == 'changeRefillUntilPct' then + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_REFILL_UNTIL_PCT'); + vehicle.cp.hud.content.pages[page][line][2].text = ('%d%%'):format(vehicle.cp.refillUntilPct); + + elseif entry.functionToCall == 'toggleAutomaticUnloadingOnField' then + if not vehicle.cp.hasUnloadingRefillingCourse then + self:enableButtonWithFunction(vehicle,page, 'toggleAutomaticUnloadingOnField') + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_UNLOADING_ON_FIELD'); + vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.automaticUnloadingOnField and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_MANUAL'); + else + self:disableButtonWithFunction(vehicle,page, 'toggleAutomaticUnloadingOnField') + end + elseif entry.functionToCall == 'togglePlowFieldEdge' then + if vehicle.cp.hasPlow then + self:enableButtonWithFunction(vehicle,page, 'togglePlowFieldEdge') + vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_PLOW_FIELD_EDGE'); + vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.plowFieldEdge and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED'); + else + self:disableButtonWithFunction(vehicle,page, 'togglePlowFieldEdge') + end end end @@ -1237,8 +1250,11 @@ function courseplay.hud:updatePageContent(vehicle, page) --[[ + + --PAGE 1: COURSEPLAY CONTROL elseif page == self.PAGE_CP_CONTROL then + if vehicle.cp.canDrive then if not vehicle:getIsCourseplayDriving() then -- only 6 lines available, as the mode buttons are in lines 7 and 8! @@ -1250,58 +1266,17 @@ function courseplay.hud:updatePageContent(vehicle, page) vehicle.cp.hud.content.pages[1][4][2].text = courseplay:loc('UNKNOWN'); end end - - - if vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE and vehicle.cp.hasFertilizerSowingMachine then - vehicle.cp.hud.content.pages[1][5][1].text = courseplay:loc('COURSEPLAY_FERTILIZERFUNCTION'); - vehicle.cp.hud.content.pages[1][5][2].text = vehicle.cp.fertilizerEnabled and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED'); - end; - - else - - - if vehicle.cp.HUD1noWaitforFill then - vehicle.cp.hud.content.pages[1][3][1].text = courseplay:loc('COURSEPLAY_DRIVE_NOW') - end - - if vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE and vehicle.cp.hasSowingMachine then - vehicle.cp.hud.content.pages[1][5][1].text = courseplay:loc('COURSEPLAY_RIDGEMARKERS'); - vehicle.cp.hud.content.pages[1][5][2].text = vehicle.cp.ridgeMarkersAutomatic and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_DEACTIVATED'); - - elseif vehicle.cp.mode == courseplay.MODE_FIELDWORK and vehicle.cp.hasBaleLoader and not vehicle.cp.hasUnloadingRefillingCourse then - vehicle.cp.hud.content.pages[1][5][1].text = courseplay:loc('COURSEPLAY_UNLOADING_ON_FIELD'); - vehicle.cp.hud.content.pages[1][5][2].text = vehicle.cp.automaticUnloadingOnField and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_MANUAL'); - end; - - - - if vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK then - vehicle.cp.hud.content.pages[1][8][1].text = courseplay:loc('COURSEPLAY_OPPOSITE_TURN_DIRECTION'); - vehicle.cp.hud.content.pages[1][8][2].text = vehicle.cp.oppositeTurnMode and courseplay:loc('COURSEPLAY_OPPOSITE_TURN_WHEN_POSSIBLE') or courseplay:loc('COURSEPLAY_OPPOSITE_TURN_AT_END'); - end; - end - - - --PAGE 3: MODE 2 SETTINGS - elseif page == self.PAGE_COMBI_MODE then - - - if vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT then - vehicle.cp.hud.content.pages[3][6][1].text = courseplay:loc('COURSEPLAY_REFILL_UNTIL_PCT'); - vehicle.cp.hud.content.pages[3][6][2].text = ('%d%%'):format(vehicle.cp.refillUntilPct); - elseif vehicle.cp.lastValidTipDistance ~= nil then + + + if vehicle.cp.lastValidTipDistance ~= nil then vehicle.cp.hud.content.pages[3][6][1].text = courseplay:loc('COURSEPLAY_LAST_VAILD_TIP_DIST'); vehicle.cp.hud.content.pages[3][6][2].text = ('%.1fm'):format(vehicle.cp.lastValidTipDistance); end; - - if vehicle.cp.mode == courseplay.MODE_FIELDWORK and vehicle.cp.hasPlow then - vehicle.cp.hud.content.pages[3][7][1].text = courseplay:loc('COURSEPLAY_PLOW_FIELD_EDGE'); - vehicle.cp.hud.content.pages[3][7][2].text = vehicle.cp.plowFieldEdge and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED'); - end; - - + + --PAGE 3: MODE 2 SETTINGS + elseif page == self.PAGE_COMBI_MODE then - -- PAGE 8: COURSE GENERATION + -- PAGE 8: COURSE GENERATION elseif page == self.PAGE_COURSE_GENERATION then -- line 1 = field edge path vehicle.cp.hud.content.pages[8][1][1].text = courseplay:loc('COURSEPLAY_FIELD_EDGE_PATH'); @@ -2168,8 +2143,8 @@ function courseplay.hud:showCpModeButtons(vehicle, show) local fn, cpModeToCheck = button.functionToCall, button.parameter; if fn == 'setCpMode'then button:setShow(show); - button:setActive(cpModeToCheck == vehicle.cp.mode) button:setDisabled(not courseplay:getIsToolValidForCpMode(vehicle,cpModeToCheck)) + button:setActive(cpModeToCheck == vehicle.cp.mode) end end end @@ -2308,6 +2283,10 @@ function courseplay.hud:setGrainTransportAIDriverContent(vehicle) self:addSettingsRow(vehicle,'changeLoadUnloadOffsetX', 7, 5, 1 ) self:addSettingsRow(vehicle,'changeLoadUnloadOffsetZ', 7, 6, 1 ) + --page 8 + self:enablePageButton(vehicle, 8) + self:addSettingsRow(vehicle,'changeRefillUntilPct', 8, 1, 1 ) + self:setReloadPageOrder(vehicle, -1, true) end @@ -2340,11 +2319,12 @@ function courseplay.hud:setFieldWorkAIDriverContent(vehicle) self:addSettingsRowWithArrows(vehicle,'changeLaneOffset', 8, 1, 2 ) self:addRowButton(vehicle,'toggleSymmetricLaneChange', 8, 2, 1 ) self:addRowButton(vehicle,'toggleTurnOnField', 8, 3, 1 ) - self:addRowButton(vehicle,'toggleRealisticDriving', 8, 4, 1 ) + self:addSettingsRowWithArrows(vehicle,'changeToolOffsetX', 8, 5, 1 ) self:addSettingsRowWithArrows(vehicle,'changeToolOffsetZ', 8, 6, 1 ) + self:addRowButton(vehicle,'toggleOppositeTurnMode', 8, 7, 1 ) - + --togglePlowFieldEdge self:setReloadPageOrder(vehicle, -1, true) end @@ -2353,9 +2333,10 @@ function courseplay.hud:setUnloadableFieldworkAIDriverContent(vehicle) self:debug(vehicle,"setUnloadableFieldworkAIDriverContent") self:addRowButton(vehicle,'setDriveNow', 1, 2, 3 ) - --self:addSettingsRow(vehicle,'changeDriveOnAtFillLevel', 3, 5, 1 ) - + self:addSettingsRow(vehicle,'changeRefillUntilPct', 3, 5, 1 ) + + self:addRowButton(vehicle,'toggleRealisticDriving', 8, 4, 1 ) end function courseplay.hud:setCombineAIDriverContent(vehicle) @@ -2400,11 +2381,28 @@ function courseplay.hud:setCombineUnloadAIDriverContent(vehicle) self:addSettingsRowWithArrows(vehicle,'changeTipperOffset', 8, 2, 1 ) self:addSettingsRowWithArrows(vehicle,'changeDriveOnAtFillLevel', 8, 3, 1 ) self:addSettingsRowWithArrows(vehicle,'changeFollowAtFillLevel', 8, 4, 1 ) - self:addRowButton(vehicle,'toggleRealisticDriving', 8, 5, 1 ) + self:addRowButton(vehicle,'toggleRealisticDriving', 8, 4, 1 ) end +function courseplay.hud:setBaleLoaderAIDriverContent(vehicle) + self:debug(vehicle,"setBaleLoaderAIDriverContent") + self:addRowButton(vehicle,'toggleAutomaticUnloadingOnField', 3, 6, 1 ) + +end + +function courseplay.hud:setFillableFieldworkAIDriverContent(vehicle) + self:debug(vehicle,"setFillableFieldworkAIDriverContent") + self:addSettingsRow(vehicle,'changeRefillUntilPct', 3, 5, 1 ) + + self:addRowButton(vehicle,'toggleRealisticDriving', 8, 4, 1 ) +end + + + + + --different buttons to set function courseplay.hud:addRowButton(vehicle,funct, hudPage, line, column ) self:debug(vehicle," addRowButton: "..tostring(funct),true) @@ -2434,7 +2432,9 @@ function courseplay.hud:addSettingsRowWithArrows(vehicle,funct, hudPage, line, c end function courseplay.hud:debug(vehicle,printString,showManyPrints) - --print(printString) + if not showManyPrints then + print(printString) + end end -- do not remove this comment diff --git a/register.lua b/register.lua index ae35bc028..587fdc42f 100644 --- a/register.lua +++ b/register.lua @@ -16,6 +16,7 @@ function courseplay.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onLeaveVehicle", courseplay) SpecializationUtil.registerEventListener(vehicleType, "onDelete", courseplay) SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", courseplay) + SpecializationUtil.registerEventListener(vehicleType, "onPostDetachImplement", courseplay) end function courseplay:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) diff --git a/settings.lua b/settings.lua index 9edc8a408..1975c6e68 100644 --- a/settings.lua +++ b/settings.lua @@ -136,6 +136,14 @@ function courseplay:toggleFertilizeOption(self) self.cp.fertilizerEnabled = not self.cp.fertilizerEnabled end +function courseplay:toggleRidgeMarkersAutomatic(self) + self.cp.ridgeMarkersAutomatic = not self.cp.ridgeMarkersAutomatic +end + +function courseplay:toggleAutomaticUnloadingOnField(self) + self.cp.automaticUnloadingOnField = not self.cp.automaticUnloadingOnField; +end + function courseplay:toggleAutoRefuel(self) self.cp.allwaysSearchFuel = not self.cp.allwaysSearchFuel end @@ -169,6 +177,10 @@ function courseplay:toggleWantsCourseplayer(combine) combine.cp.wantsCourseplayer = not combine.cp.wantsCourseplayer; end; +function courseplay:toggleOppositeTurnMode(vehicle) + vehicle.cp.oppositeTurnMode = not vehicle.cp.oppositeTurnMode +end + function courseplay:startStop(vehicle) if vehicle.cp.canDrive then if not vehicle:getIsCourseplayDriving() then diff --git a/toolManager.lua b/toolManager.lua index b24275cb4..bb1f1f005 100644 --- a/toolManager.lua +++ b/toolManager.lua @@ -24,8 +24,6 @@ function courseplay:onPostDetachImplement(implementIndex) self.cp.attachedCombine = nil; end end; ---AttacherJoints.detachImplement = Utils.appendedFunction(AttacherJoints.detachImplement, courseplay.detachImplement); ---Tommi disabled it self is allways nil function courseplay:resetTools(vehicle) vehicle.cp.workTools = {} @@ -35,6 +33,9 @@ function courseplay:resetTools(vehicle) vehicle.cp.hasSugarCaneTrailer = false vehicle.cp.hasFertilizerSowingMachine = nil; vehicle.cp.workToolAttached = courseplay:updateWorkTools(vehicle, vehicle); + if not vehicle.cp.workToolAttached then + courseplay:setCpMode(vehicle, courseplay.MODE_TRANSPORT) + end -- Ryan prints fillTypeManager table. Nice cause it prints out all the fillTypes print_r(g_fillTypeManager) -- Reset fill type. --[[ @@ -53,9 +54,7 @@ function courseplay:resetTools(vehicle) vehicle.cp.siloSelectedEasyFillType = 0; courseplay:changeSiloFillType(vehicle, 1, vehicle.cp.siloSelectedFillType); - if vehicle.cp.hud.currentPage == 1 then - courseplay.hud:setReloadPageOrder(vehicle, 1, true); - end; + courseplay.hud:setReloadPageOrder(vehicle, -1, true); courseplay:calculateWorkWidth(vehicle, true); @@ -1902,9 +1901,6 @@ function courseplay:getIsToolValidForCpMode(vehicle,cpModeToCheck) end end end - if vehicle.cp.mode == cpModeToCheck and not modeValid then - courseplay:setCpMode(vehicle, 5) - end return modeValid end end \ No newline at end of file