diff --git a/config/HudSettingsSetup.xml b/config/HudSettingsSetup.xml new file mode 100644 index 000000000..f0dcf2a20 --- /dev/null +++ b/config/HudSettingsSetup.xml @@ -0,0 +1,46 @@ + + + + + + + + + + 1 + 2 + 3 + + 4 + + 5 + + 6 + + 7 + 8 + + 9 + 10 + 11 + + + + fieldWork_nearest + fieldWork_first + fieldWork_last + baleFinder + bunkerSilo + siloLoader + unloader_harvester + unloader_loader + street_driveTo + street_unloadOrRefill + street_loadAndUnload + + + + \ No newline at end of file diff --git a/config/jobParameters/FieldWorkJobParameterSetup.xml b/config/jobParameters/FieldWorkJobParameterSetup.xml index c805e5252..7ac36f754 100644 --- a/config/jobParameters/FieldWorkJobParameterSetup.xml +++ b/config/jobParameters/FieldWorkJobParameterSetup.xml @@ -18,15 +18,17 @@ 1 2 3 - 4 - 5 + + + + nearest first last - bunkerSilo - siloLoader + diff --git a/scripts/gui/hud/CpBaleFinderHudPage.lua b/scripts/gui/hud/CpBaleFinderHudPage.lua index fc7e4ffe0..ccdf74af7 100644 --- a/scripts/gui/hud/CpBaleFinderHudPage.lua +++ b/scripts/gui/hud/CpBaleFinderHudPage.lua @@ -27,20 +27,6 @@ function CpBaleFinderHudPageElement:setupElements(baseHud, vehicle, lines, wMarg } self.baleFinderFillTypeBtn:setCallback(callback, callback) - --- Goal button. - local width, height = getNormalizedScreenValues(37, 37) - local goalOverlay = CpGuiUtil.createOverlay({width, height}, - {AITargetHotspot.FILENAME, CpBaseHud.uvs.goalSymbol}, - CpBaseHud.OFF_COLOR, - CpBaseHud.alignments.bottomRight) - - self.goalBtn = CpHudButtonElement.new(goalOverlay, self) - local x, y = unpack(lines[4].right) - self.goalBtn:setPosition(x, y + hMargin/2) - self.goalBtn:setCallback("onClickPrimary", vehicle, function (vehicle) - baseHud:openCourseGeneratorGui(vehicle) - end) - --- Bale progress of how much bales have bin worked on, similar to waypoint progress. self.balesProgressBtn = baseHud:addRightLineTextButton(self, 4, CpBaseHud.defaultFontSize, function(vehicle) diff --git a/scripts/gui/hud/CpBaseHud.lua b/scripts/gui/hud/CpBaseHud.lua index bfd22eaab..62b81a9c8 100644 --- a/scripts/gui/hud/CpBaseHud.lua +++ b/scripts/gui/hud/CpBaseHud.lua @@ -12,6 +12,7 @@ CpBaseHud.ON_COLOR = {0, 0.6, 0, 0.9} CpBaseHud.SEMI_ON_COLOR = {0.6, 0.6, 0, 0.9} CpBaseHud.WHITE_COLOR = {1, 1, 1, 0.9} CpBaseHud.BACKGROUND_COLOR = {0, 0, 0, 0.7} +CpBaseHud.DARK_BACKGROUND_COLOR = {0, 0, 0, 0.8} CpBaseHud.HEADER_COLOR = { 0, 0.4, 0.6, 1 @@ -80,7 +81,29 @@ CpBaseHud.uvs = { }, cpIcon = { {80, 26, 144, 144}, {256, 256} - } + }, + shovelSymbol = { + {128, 128, 128, 128} + }, + bunkerSymbol = { + {256, 128, 128, 128} + }, + fieldWorkSymbol = { + {7*128, 128, 128, 128} + }, + streetLoadAndUnloadSymbol = { + {0, 3*128, 128, 128} + }, + unloaderSymbol = { + {128, 3*128, 128, 128} + }, + streetDriveToSymbol = { + {5*128, 3*128, 128, 128} + }, + baleFinderSymbol = { + {7*128, 3*128, 128, 128} + }, + } --- Vertical + horizontal overlay alignment @@ -216,10 +239,10 @@ function CpBaseHud:init(vehicle) end) --- Starting point - self.startingPointBtn = self:addLeftLineTextButton(self.baseHud, 5, self.defaultFontSize, + self.startingPointBtn = self:addLeftLineTextButtonWithIcon(self.baseHud, 5, self.defaultFontSize, function (vehicle) self:executeStartingPointBtnCallback(vehicle) - end,self.vehicle) + end, self.vehicle, 24, 24, "img/ui_courseplay.dds") -------------------------------------- --- Right side @@ -319,6 +342,33 @@ function CpBaseHud:addLeftLineTextButton(parent, line, textSize, callbackFunc, c return element end +function CpBaseHud:addLeftLineTextButtonWithIcon(parent, line, textSize, callbackFunc, callbackClass, iconWidth, iconHeight, iconFilePath) + local x, y = unpack(self.lines[line].left) + local width, height = getNormalizedScreenValues(iconWidth, iconHeight) + + local element = CpTextHudElement.new(parent, x + width + self.wMargin/4, y, textSize) + element:setCallback("onClickPrimary", callbackClass, callbackFunc) + local overlay = CpGuiUtil.createOverlay({width, height}, + {Utils.getFilename(iconFilePath, Courseplay.BASE_DIRECTORY), GuiUtils.getUVs({0,0,0,0})}, + self.OFF_COLOR, + self.alignments.bottomLeft) + + local backgroundOverlay = CpGuiUtil.createOverlay({width, height}, + {g_baseUIFilename, g_colorBgUVs}, + self.DARK_BACKGROUND_COLOR, + self.alignments.bottomLeft) + local backgroundElement = CpHudElement.new(backgroundOverlay, element) + backgroundElement:setPosition(x, y - self.hMargin/8) + backgroundElement:setDimension(width, height) + + local iconElement = CpHudElement.new(overlay, backgroundElement) + iconElement:setPosition(x, y - self.hMargin/8) + iconElement:setDimension(width, height) + iconElement:setCallback("onClickPrimary", callbackClass, callbackFunc) + element.icon = iconElement + return element +end + function CpBaseHud:addRightLineTextButton(parent, line, textSize, callbackFunc, callbackClass) local x, y = unpack(self.lines[line].right) local element = CpTextHudElement.new(parent , x , y, @@ -419,17 +469,19 @@ function CpBaseHud:isMouseOverArea(posX, posY) end function CpBaseHud:getActiveHudPage(vehicle) - if vehicle:getCanStartCpCombineUnloader() then - return self.combineUnloaderLayout - elseif vehicle:getCanStartCpBaleFinder() and not vehicle:hasCpCourse() then + + if vehicle:cpIsHudFieldWorkJobSelected() then + return self.fieldworkLayout + elseif vehicle:cpIsHudBaleFinderJobSelected() then return self.baleFinderLayout - elseif vehicle:getCanStartCpSiloLoaderWorker() and (vehicle:getCpStartingPointSetting():getValue() == CpFieldWorkJobParameters.START_AT_SILO_LOADING - or AIUtil.hasChildVehicleWithSpecialization(vehicle, ConveyorBelt)) then - return self.siloLoaderWorkerLayout - elseif vehicle:getCanStartCpBunkerSiloWorker() and (vehicle:getCpStartingPointSetting():getValue() == CpFieldWorkJobParameters.START_AT_BUNKER_SILO or - (AIUtil.hasChildVehicleWithSpecialization(vehicle, Leveler) - and not AIUtil.hasChildVehicleWithSpecialization(vehicle, Shovel))) then + elseif vehicle:cpIsHudBunkerSiloJobSelected() then return self.bunkerSiloWorkerLayout + elseif vehicle:cpIsHudSiloLoaderJobSelected() then + return self.siloLoaderWorkerLayout + elseif vehicle:cpIsHudUnloaderJobSelected() then + return self.combineUnloaderLayout + elseif vehicle:cpIsHudDriveToJobSelected() then + return self.fieldworkLayout else return self.fieldworkLayout end @@ -495,18 +547,33 @@ function CpBaseHud:updateContent(vehicle, status) activeLayout:setDisabled(false) activeLayout:updateContent(vehicle, status) - self.startingPointBtn:setDisabled(true) - if activeLayout.isStartingPointBtnDisabled then - self.startingPointBtn:setDisabled(activeLayout:isStartingPointBtnDisabled(vehicle)) - end - self.startingPointBtn:setVisible(true) - if activeLayout.isStartingPointBtnVisible then - self.startingPointBtn:setVisible(activeLayout:isStartingPointBtnVisible(vehicle)) + local text, uvs = self:getStartingPointBtnTextAndIconUvs(vehicle) + if text ~= self.startingPointBtn:getText() then + self.startingPointBtn:setTextDetails(text) + self.startingPointBtn.icon:setUVs(uvs) end - self.startingPointBtn:setTextDetails(vehicle:getCpStartText()) - if activeLayout.getStartingPointBtnText then - self.startingPointBtn:setTextDetails(activeLayout:getStartingPointBtnText(vehicle)) +end + + +function CpBaseHud:getStartingPointBtnTextAndIconUvs(vehicle) + local setting = vehicle:cpGetHudStartingPointSetting() + local uvs = self.uvs.fieldWorkSymbol + if vehicle:cpIsHudFieldWorkJobSelected() then + uvs = self.uvs.fieldWorkSymbol + elseif vehicle:cpIsHudBaleFinderJobSelected() then + uvs = self.uvs.baleFinderSymbol + elseif vehicle:cpIsHudBunkerSiloJobSelected() then + uvs = self.uvs.bunkerSymbol + elseif vehicle:cpIsHudSiloLoaderJobSelected() then + uvs = self.uvs.shovelSymbol + elseif vehicle:cpIsHudUnloaderJobSelected() then + uvs = self.uvs.unloaderSymbol + elseif vehicle:cpIsHudDriveToJobSelected() then + uvs = self.uvs.streetDriveToSymbol + else + uvs = self.uvs.streetLoadAndUnloadSymbol end + return setting:getString(), GuiUtils.getUVs(unpack(uvs)) end function CpBaseHud:delete() @@ -538,12 +605,15 @@ function CpBaseHud:openGlobalSettingsGui(vehicle) end function CpBaseHud:executeStartingPointBtnCallback(vehicle) - local activeLayout = self:getActiveHudPage(vehicle) - if activeLayout and activeLayout.executeStartingPointBtnCallback then - activeLayout:executeStartingPointBtnCallback(vehicle) - else - vehicle:getCpStartingPointSetting():setNextItem() - end + local setting = vehicle:cpGetHudStartingPointSetting() + setting:setNextItem() + + -- local activeLayout = self:getActiveHudPage(vehicle) + -- if activeLayout and activeLayout.executeStartingPointBtnCallback then + -- activeLayout:executeStartingPointBtnCallback(vehicle) + -- else + -- vehicle:getCpStartingPointSetting():setNextItem() + -- end end --- Saves hud position. diff --git a/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua b/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua index af1cb27ab..3cc1fa697 100644 --- a/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua +++ b/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua @@ -43,20 +43,6 @@ function CpBunkerSiloWorkerHudPageElement:setupElements(baseHud, vehicle, lines, self.workWidthBtn = baseHud:addLineTextButton(self, 2, CpBaseHud.defaultFontSize, vehicle:getCpSettings().bunkerSiloWorkWidth) - --- Goal button. - local width, height = getNormalizedScreenValues(37, 37) - local goalOverlay = CpGuiUtil.createOverlay({width, height}, - {AITargetHotspot.FILENAME, CpBaseHud.uvs.goalSymbol}, - CpBaseHud.OFF_COLOR, - CpBaseHud.alignments.bottomRight) - - self.goalBtn = CpHudButtonElement.new(goalOverlay, self) - local x, y = unpack(lines[4].right) - self.goalBtn:setPosition(x, y + hMargin/2) - self.goalBtn:setCallback("onClickPrimary", vehicle, function (vehicle) - baseHud:openCourseGeneratorGui(vehicle) - end) - --- Bunker silo compaction percentage local x, y = unpack(lines[3].left) local xRight,_ = unpack(lines[3].right) @@ -108,15 +94,3 @@ function CpBunkerSiloWorkerHudPageElement:updateContent(vehicle, status) self.compactionPercentageBtn:setTextDetails(g_i18n:getText("CP_bunkerSilo_compactionPercentage"), compactionText) self.compactionPercentageBtn:setDisabled(stopWithCompactedSilo:getIsDisabled()) end - -function CpBunkerSiloWorkerHudPageElement:isStartingPointBtnDisabled(vehicle) - return AIUtil.hasChildVehicleWithSpecialization(vehicle, Leveler) - and not AIUtil.hasChildVehicleWithSpecialization(vehicle, Shovel) -end - -function CpBunkerSiloWorkerHudPageElement:getStartingPointBtnText(vehicle) - if self:isStartingPointBtnDisabled(vehicle) then - return vehicle:getCpStartText() - end - return vehicle:getCpStartingPointSetting():getString() -end \ No newline at end of file diff --git a/scripts/gui/hud/CpCombineUnloaderHudPage.lua b/scripts/gui/hud/CpCombineUnloaderHudPage.lua index ebb6e0ad7..526536b1c 100644 --- a/scripts/gui/hud/CpCombineUnloaderHudPage.lua +++ b/scripts/gui/hud/CpCombineUnloaderHudPage.lua @@ -30,19 +30,13 @@ function CpCombineUnloaderHudPageElement:setupElements(baseHud, vehicle, lines, vehicle:getCpSettings().fullThreshold) - --- Unloading combine or silo loader ? - self.unloadModeBtn = baseHud:addLeftLineTextButton(self, 6, CpBaseHud.defaultFontSize, - function (vehicle) - vehicle:getCpCombineUnloaderJobParameters().unloadTarget:setNextItem() - end, vehicle) - - --- Giants unloading station - local x, y = unpack(lines[5].left) - self.giantsUnloadStationText = CpTextHudElement.new(self , x , y, CpBaseHud.defaultFontSize) - self.giantsUnloadStationText:setCallback("onClickPrimary", vehicle, - function(vehicle) - vehicle:getCpCombineUnloaderJobParameters().unloadingStation:setNextItem() - end) + -- --- Giants unloading station + -- local x, y = unpack(lines[5].left) + -- self.giantsUnloadStationText = CpTextHudElement.new(self , x , y, CpBaseHud.defaultFontSize) + -- self.giantsUnloadStationText:setCallback("onClickPrimary", vehicle, + -- function(vehicle) + -- vehicle:getCpCombineUnloaderJobParameters().unloadingStation:setNextItem() + -- end) --- Drive now button local width, height = getNormalizedScreenValues(22, 22) @@ -76,20 +70,6 @@ function CpCombineUnloaderHudPageElement:setupElements(baseHud, vehicle, lines, vehicle:getCpCombineUnloaderJobParameters().useGiantsUnload:setNextItem() end) - --- Goal button. - local width, height = getNormalizedScreenValues(37, 37) - local goalOverlay = CpGuiUtil.createOverlay({width, height}, - {AITargetHotspot.FILENAME, CpBaseHud.uvs.goalSymbol}, - CpBaseHud.OFF_COLOR, - CpBaseHud.alignments.bottomRight) - - self.goalBtn = CpHudButtonElement.new(goalOverlay, self) - local x, y = unpack(lines[4].right) - self.goalBtn:setPosition(x, y + hMargin/2) - self.goalBtn:setCallback("onClickPrimary", vehicle, function (vehicle) - baseHud:openCourseGeneratorGui(vehicle) - end) - CpGuiUtil.addCopyAndPasteButtons(self, baseHud, vehicle, lines, wMargin, hMargin, 1) @@ -125,10 +105,6 @@ end function CpCombineUnloaderHudPageElement:updateContent(vehicle, status) - self.unloadModeBtn:setDisabled(vehicle:getIsCpActive()) - local text = vehicle:getCpCombineUnloaderJobParameters().unloadTarget:getString() - self.unloadModeBtn:setTextDetails(text) - local combineOffsetX = vehicle:getCpSettings().combineOffsetX self.combineOffsetXBtn:setTextDetails(combineOffsetX:getTitle(), combineOffsetX:getString()) self.combineOffsetXBtn:setDisabled(combineOffsetX:getIsDisabled()) @@ -141,15 +117,15 @@ function CpCombineUnloaderHudPageElement:updateContent(vehicle, status) self.fullThresholdBtn:setTextDetails(fullThreshold:getTitle(), fullThreshold:getString()) self.fullThresholdBtn:setDisabled(fullThreshold:getIsDisabled()) - local useGiantsUnload = vehicle:getCpCombineUnloaderJobParameters().useGiantsUnload - self.giantsUnloadStationText:setVisible(useGiantsUnload:getValue() and not useGiantsUnload:getIsDisabled()) - self.giantsUnloadStationText:setDisabled(not useGiantsUnload:getValue() or vehicle:getIsCpActive()) - local giantsUnloadStation = vehicle:getCpCombineUnloaderJobParameters().unloadingStation - self.giantsUnloadStationText:setTextDetails(giantsUnloadStation:getString()) + -- local useGiantsUnload = vehicle:getCpCombineUnloaderJobParameters().useGiantsUnload + -- self.giantsUnloadStationText:setVisible(useGiantsUnload:getValue() and not useGiantsUnload:getIsDisabled()) + -- self.giantsUnloadStationText:setDisabled(not useGiantsUnload:getValue() or vehicle:getIsCpActive()) + -- local giantsUnloadStation = vehicle:getCpCombineUnloaderJobParameters().unloadingStation + -- self.giantsUnloadStationText:setTextDetails(giantsUnloadStation:getString()) - self.activateGiantsUnloadBtn:setColor(useGiantsUnload:getValue() and unpack(CpBaseHud.ON_COLOR) or unpack(CpBaseHud.OFF_COLOR)) - self.activateGiantsUnloadBtn:setVisible(not useGiantsUnload:getIsDisabled()) - self.activateGiantsUnloadBtn:setDisabled(useGiantsUnload:getIsDisabled() or vehicle:getIsCpActive()) + -- self.activateGiantsUnloadBtn:setColor(useGiantsUnload:getValue() and unpack(CpBaseHud.ON_COLOR) or unpack(CpBaseHud.OFF_COLOR)) + -- self.activateGiantsUnloadBtn:setVisible(not useGiantsUnload:getIsDisabled()) + -- self.activateGiantsUnloadBtn:setDisabled(useGiantsUnload:getIsDisabled() or vehicle:getIsCpActive()) local fillLevelPercentage = FillLevelManager.getTotalTrailerFillLevelPercentage(vehicle) if fillLevelPercentage > 0.01 then diff --git a/scripts/gui/hud/CpSiloLoaderWorkerHudPage.lua b/scripts/gui/hud/CpSiloLoaderWorkerHudPage.lua index 4d5068109..e7d19c1a4 100644 --- a/scripts/gui/hud/CpSiloLoaderWorkerHudPage.lua +++ b/scripts/gui/hud/CpSiloLoaderWorkerHudPage.lua @@ -20,20 +20,6 @@ function CpSiloLoaderWorkerHudPageElement:setupElements(baseHud, vehicle, lines, self.workWidthBtn = baseHud:addLineTextButton(self, 3, CpBaseHud.defaultFontSize, vehicle:getCpSettings().bunkerSiloWorkWidth) - --- Goal button. - local width, height = getNormalizedScreenValues(37, 37) - local goalOverlay = CpGuiUtil.createOverlay({width, height}, - {AITargetHotspot.FILENAME, CpBaseHud.uvs.goalSymbol}, - CpBaseHud.OFF_COLOR, - CpBaseHud.alignments.bottomRight) - - self.goalBtn = CpHudButtonElement.new(goalOverlay, self) - local x, y = unpack(lines[4].right) - self.goalBtn:setPosition(x, y + hMargin/2) - self.goalBtn:setCallback("onClickPrimary", vehicle, function (vehicle) - baseHud:openCourseGeneratorGui(vehicle) - end) - --- Displays the fill level of current worked on heap. local x, y = unpack(lines[4].left) @@ -154,14 +140,3 @@ function CpSiloLoaderWorkerHudPageElement:arePositionEqual(parameters, otherPara end return true end - -function CpSiloLoaderWorkerHudPageElement:isStartingPointBtnDisabled(vehicle) - return AIUtil.hasChildVehicleWithSpecialization(vehicle, ConveyorBelt) or vehicle:getIsCpActive() -end - -function CpSiloLoaderWorkerHudPageElement:getStartingPointBtnText(vehicle) - if self:isStartingPointBtnDisabled(vehicle) then - return vehicle:getCpStartText() - end - return vehicle:getCpStartingPointSetting():getString() -end \ No newline at end of file diff --git a/scripts/gui/hud/HudElements.lua b/scripts/gui/hud/HudElements.lua index db2310b70..fec1bc54f 100644 --- a/scripts/gui/hud/HudElements.lua +++ b/scripts/gui/hud/HudElements.lua @@ -3,7 +3,7 @@ CpHudElement = {} local CpHudElement_mt = Class(CpHudElement, HUDElement) -function CpHudElement.new(overlay,parentHudElement,customMt) +function CpHudElement.new(overlay, parentHudElement, customMt) if customMt == nil then customMt = CpHudElement_mt end @@ -317,12 +317,17 @@ function CpTextHudElement:draw() setTextWrapWidth(0) setTextBold(false) setTextColor(1, 1, 1, 1) + CpTextHudElement:superClass().draw(self) end function CpTextHudElement:getScreenHeight() return self.screenTextSize end +function CpTextHudElement:getText() + return self.text +end + --- Moveable Hud element. ---@class CpHudMoveableElement : CpHudElement CpHudMoveableElement = { diff --git a/scripts/specializations/CpAIBaleFinder.lua b/scripts/specializations/CpAIBaleFinder.lua index d640f0e65..64d07f5e5 100644 --- a/scripts/specializations/CpAIBaleFinder.lua +++ b/scripts/specializations/CpAIBaleFinder.lua @@ -48,7 +48,6 @@ end function CpAIBaleFinder.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAIBaleFinder.getCanStartCp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAIBaleFinder.getCpStartableJob) - SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpAIBaleFinder.getCpStartText) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtFirstWp', CpAIBaleFinder.startCpAtFirstWp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtLastWp', CpAIBaleFinder.startCpAtLastWp) @@ -132,17 +131,14 @@ function CpAIBaleFinder:getCanStartCp(superFunc) end --- Only use the bale finder, if the cp field work job is not possible. -function CpAIBaleFinder:getCpStartableJob(superFunc, ...) +function CpAIBaleFinder:getCpStartableJob(superFunc, isStartedByHud) local spec = self.spec_cpAIBaleFinder - return superFunc(self, ...) or self:getCanStartCpBaleFinder() and spec.cpJob -end - -function CpAIBaleFinder:getCpStartText(superFunc) - local text = superFunc and superFunc(self) - return text~="" and text or self:getCanStartCpBaleFinder() and CpAIBaleFinder.startText + if isStartedByHud and self:cpIsHudBaleFinderJobSelected() then + return self:getCanStartCpBaleFinder() and spec.cpJob + end + return superFunc(self, isStartedByHud) or self:getCanStartCpBaleFinder() and spec.cpJob end - --- Starts the cp driver at the first waypoint. function CpAIBaleFinder:startCpAtFirstWp(superFunc) if not superFunc(self) then diff --git a/scripts/specializations/CpAIBunkerSiloWorker.lua b/scripts/specializations/CpAIBunkerSiloWorker.lua index fbea78db9..99fabefc3 100644 --- a/scripts/specializations/CpAIBunkerSiloWorker.lua +++ b/scripts/specializations/CpAIBunkerSiloWorker.lua @@ -46,7 +46,6 @@ end function CpAIBunkerSiloWorker.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAIBunkerSiloWorker.getCanStartCp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAIBunkerSiloWorker.getCpStartableJob) - SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpAIBunkerSiloWorker.getCpStartText) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtFirstWp', CpAIBunkerSiloWorker.startCpAtFirstWp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtLastWp', CpAIBunkerSiloWorker.startCpAtLastWp) end @@ -107,16 +106,10 @@ end function CpAIBunkerSiloWorker:getCpStartableJob(superFunc, isStartedByHud) local spec = self.spec_cpAIBunkerSiloWorker - local job = self:getCanStartCpBunkerSiloWorker() and spec.cpJob - if isStartedByHud and not AIUtil.hasChildVehicleWithSpecialization(self, Leveler) then - job = self:getCpStartingPointSetting():getValue() == CpFieldWorkJobParameters.START_AT_BUNKER_SILO and job + if isStartedByHud and self:cpIsHudBunkerSiloJobSelected() then + return self:getCanStartCpBunkerSiloWorker() and spec.cpJob end - return superFunc(self, isStartedByHud) or job -end - -function CpAIBunkerSiloWorker:getCpStartText(superFunc) - local text = superFunc and superFunc(self) - return text~="" and text or self:getCanStartCpBunkerSiloWorker() and CpAIBunkerSiloWorker.startText + return superFunc(self, isStartedByHud) or self:getCanStartCpBunkerSiloWorker() and spec.cpJob end function CpAIBunkerSiloWorker:getCpBunkerSiloWorkerJobParameters() diff --git a/scripts/specializations/CpAICombineUnloader.lua b/scripts/specializations/CpAICombineUnloader.lua index 3f13de130..b2ebd5a24 100644 --- a/scripts/specializations/CpAICombineUnloader.lua +++ b/scripts/specializations/CpAICombineUnloader.lua @@ -141,7 +141,6 @@ end function CpAICombineUnloader.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAICombineUnloader.getCanStartCp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAICombineUnloader.getCpStartableJob) - SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpAICombineUnloader.getCpStartText) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtFirstWp', CpAICombineUnloader.startCpAtFirstWp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtLastWp', CpAICombineUnloader.startCpAtLastWp) @@ -247,17 +246,14 @@ function CpAICombineUnloader:getCanStartCp(superFunc) return superFunc(self) or self:getCanStartCpCombineUnloader() and not self:getIsCpCourseRecorderActive() end -function CpAICombineUnloader:getCpStartableJob(superFunc, ...) +function CpAICombineUnloader:getCpStartableJob(superFunc, isStartedByHud) local spec = self.spec_cpAICombineUnloader - return superFunc(self, ...) or self:getCanStartCpCombineUnloader() and spec.cpJob -end - -function CpAICombineUnloader:getCpStartText(superFunc) - local text = superFunc and superFunc(self) - return text~="" and text or self:getCanStartCpCombineUnloader() and self:getCpCombineUnloaderJobParameters().unloadTarget:getString() + if isStartedByHud and self:cpIsHudUnloaderJobSelected() then + return self:getCanStartCpCombineUnloader() and spec.cpJob + end + return superFunc(self, isStartedByHud) or self:getCanStartCpCombineUnloader() and spec.cpJob end - --- Starts the cp driver at the first waypoint. function CpAICombineUnloader:startCpAtFirstWp(superFunc) if not superFunc(self) then diff --git a/scripts/specializations/CpAIFieldWorker.lua b/scripts/specializations/CpAIFieldWorker.lua index 6afc9033e..868d92906 100644 --- a/scripts/specializations/CpAIFieldWorker.lua +++ b/scripts/specializations/CpAIFieldWorker.lua @@ -68,7 +68,6 @@ end function CpAIFieldWorker.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAIFieldWorker.getCanStartCp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAIFieldWorker.getCpStartableJob) - SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpAIFieldWorker.getCpStartText) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpDriveStrategy', CpAIFieldWorker.getCpDriveStrategy) end @@ -294,14 +293,12 @@ function CpAIFieldWorker:getCanStartCp(superFunc) end --- Gets the field work job for the hud or start action event. -function CpAIFieldWorker:getCpStartableJob(superFunc, ...) +function CpAIFieldWorker:getCpStartableJob(superFunc, isStartedByHud) local spec = self.spec_cpAIFieldWorker - return self:getCanStartCpFieldWork() and self:hasCpCourse() and spec.cpJob or superFunc(self, ...) -end - -function CpAIFieldWorker:getCpStartText(superFunc) - local spec = self.spec_cpAIFieldWorker - return self:hasCpCourse() and spec.cpJob:getCpJobParameters().startAt:getString() or superFunc(self) + if isStartedByHud and self:cpIsHudFieldWorkJobSelected() then + return self:getCanStartCpFieldWork() and self:hasCpCourse() and spec.cpJob + end + return superFunc(self, isStartedByHud) or self:getCanStartCpFieldWork() and self:hasCpCourse() and spec.cpJob end --- Makes sure a callstack is printed, when an error appeared. diff --git a/scripts/specializations/CpAISiloLoaderWorker.lua b/scripts/specializations/CpAISiloLoaderWorker.lua index 43a7bec24..5374d5094 100644 --- a/scripts/specializations/CpAISiloLoaderWorker.lua +++ b/scripts/specializations/CpAISiloLoaderWorker.lua @@ -48,7 +48,6 @@ end function CpAISiloLoaderWorker.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAISiloLoaderWorker.getCanStartCp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAISiloLoaderWorker.getCpStartableJob) - SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpAISiloLoaderWorker.getCpStartText) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtFirstWp', CpAISiloLoaderWorker.startCpAtFirstWp) SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtLastWp', CpAISiloLoaderWorker.startCpAtLastWp) end @@ -104,16 +103,10 @@ end function CpAISiloLoaderWorker:getCpStartableJob(superFunc, isStartedByHud) local spec = self.spec_cpAISiloLoaderWorker - local job = self:getCanStartCpSiloLoaderWorker() and spec.cpJob - if isStartedByHud and not AIUtil.hasChildVehicleWithSpecialization(self, ConveyorBelt) then - job = self:getCpStartingPointSetting():getValue() == CpFieldWorkJobParameters.START_AT_SILO_LOADING and job + if isStartedByHud and self:cpIsHudSiloLoaderJobSelected() then + return self:getCanStartCpSiloLoaderWorker() and spec.cpJob end - return superFunc(self, isStartedByHud) or job -end - -function CpAISiloLoaderWorker:getCpStartText(superFunc) - local text = superFunc and superFunc(self) - return text~="" and text or self:getCanStartCpSiloLoaderWorker() and CpAISiloLoaderWorker.startText + return superFunc(self, isStartedByHud) or self:getCanStartCpSiloLoaderWorker() and spec.cpJob end function CpAISiloLoaderWorker:getCpSiloLoaderWorkerJobParameters() diff --git a/scripts/specializations/CpAIWorker.lua b/scripts/specializations/CpAIWorker.lua index 77f6d33d3..05b718516 100644 --- a/scripts/specializations/CpAIWorker.lua +++ b/scripts/specializations/CpAIWorker.lua @@ -182,9 +182,9 @@ function CpAIWorker:updateActionEvents() g_inputBinding:setActionEventActive(actionEvent.actionEventId, false) end actionEvent = spec.actionEvents[InputAction.CP_CHANGE_STARTING_POINT] - local startingPointSetting = self:getCpStartingPointSetting() + local startingPointSetting = self:cpGetHudStartingPointSetting() g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format("CP: %s %s", startingPointSetting:getTitle(), startingPointSetting:getString())) - g_inputBinding:setActionEventActive(actionEvent.actionEventId, self:getCanStartCpFieldWork()) + g_inputBinding:setActionEventActive(actionEvent.actionEventId, self:getCanStartCp()) actionEvent = spec.actionEvents[InputAction.CP_CHANGE_COURSE_VISIBILITY] local setting = self:getCpSettings().showCourse @@ -197,7 +197,7 @@ function CpAIWorker:updateActionEvents() end function CpAIWorker:changeStartingPoint() - local startingPointSetting = self:getCpStartingPointSetting() + local startingPointSetting = self:cpGetHudStartingPointSetting() startingPointSetting:setNextItem() end diff --git a/scripts/specializations/CpHud.lua b/scripts/specializations/CpHud.lua index d94ddafb7..36e653d7a 100644 --- a/scripts/specializations/CpHud.lua +++ b/scripts/specializations/CpHud.lua @@ -7,12 +7,18 @@ CpHud.MOD_NAME = g_currentModName CpHud.NAME = ".cpHud" CpHud.SPEC_NAME = CpHud.MOD_NAME .. CpHud.NAME -CpHud.KEY = "."..CpHud.MOD_NAME..CpHud.NAME .. "." +CpHud.KEY = "." .. CpHud.MOD_NAME .. CpHud.NAME +CpHud.SETTINGS_KEY = ".settings" CpHud.isHudActive = false CpHud.workWidthDisplayDelayMs = 5000 -- 5 seconds +CpHud.hudSettings = {} function CpHud.initSpecialization() local schema = Vehicle.xmlSchemaSavegame + CpSettingsUtil.registerXmlSchema(schema, + "vehicles.vehicle(?)" .. CpHud.KEY .. CpHud.SETTINGS_KEY .. "(?)") + local filePath = Utils.getFilename("config/HudSettingsSetup.xml", g_Courseplay.BASE_DIRECTORY) + CpSettingsUtil.loadSettingsFromSetup(CpHud.hudSettings, filePath) end function CpHud.prerequisitesPresent(specializations) @@ -44,6 +50,7 @@ function CpHud.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "cpUpdateMouseAction", CpHud) SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", CpHud) SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", CpHud) + SpecializationUtil.registerEventListener(vehicleType, "onStateChange", CpHud) end function CpHud.registerFunctions(vehicleType) @@ -57,13 +64,22 @@ function CpHud.registerFunctions(vehicleType) SpecializationUtil.registerFunction(vehicleType, 'showCpBunkerSiloWorkWidth', CpHud.showCpBunkerSiloWorkWidth) SpecializationUtil.registerFunction(vehicleType, 'showCpCombineUnloaderWorkWidth', CpHud.showCpCombineUnloaderWorkWidth) SpecializationUtil.registerFunction(vehicleType, 'showCpCourseWorkWidth', CpHud.showCpCourseWorkWidth) + SpecializationUtil.registerFunction(vehicleType, "cpGetHudStartingPointSetting", CpHud.cpGetHudStartingPointSetting) + + SpecializationUtil.registerFunction(vehicleType, "cpIsHudFieldWorkJobSelected", CpHud.cpIsHudFieldWorkJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudBaleFinderJobSelected", CpHud.cpIsHudBaleFinderJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudBunkerSiloJobSelected", CpHud.cpIsHudBunkerSiloJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudSiloLoaderJobSelected", CpHud.cpIsHudSiloLoaderJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudUnloaderJobSelected", CpHud.cpIsHudUnloaderJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudDriveToJobSelected", CpHud.cpIsHudDriveToJobSelected) + SpecializationUtil.registerFunction(vehicleType, "cpIsHudTransportJobSelected", CpHud.cpIsHudTransportJobSelected) end function CpHud.registerOverwrittenFunctions(vehicleType) if vehicleType.functions["enterVehicleRaycastClickToSwitch"] ~= nil then SpecializationUtil.registerOverwrittenFunction(vehicleType, "enterVehicleRaycastClickToSwitch", CpHud.enterVehicleRaycastClickToSwitch) end - + SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartText', CpHud.getCpStartText) end --- Disables the click to switch action, while the mouse is over the cp hud. @@ -178,7 +194,15 @@ function CpHud:onLoad(savegame) spec.lastShownWorkWidthTimeStamp = g_time spec.lastShownBaleCollectorOffsetTimeStamp = g_time spec.openCloseText = g_i18n:getText("input_CP_OPEN_CLOSE_HUD") - + spec.hudSettings = {} + --- Clones the generic settings to create different settings containers for each vehicle. + CpSettingsUtil.cloneSettingsTable(spec.hudSettings, CpHud.hudSettings.settings, self, CpHud) + for _, setting in ipairs(spec.hudSettings.settings) do + setting:refresh() + end + if savegame == nil or savegame.resetVehicles then return end + CpSettingsUtil.loadFromXmlFile(spec, savegame.xmlFile, + savegame.key .. CpHud.KEY .. CpHud.SETTINGS_KEY, self) end function CpHud:onWriteUpdateStream(streamId, connection, dirtyMask) @@ -202,7 +226,10 @@ function CpHud:onPostLoad(savegame) end function CpHud:saveToXMLFile(xmlFile, baseKey, usedModNames) - + --- Saves the settings. + local spec = self.spec_cpHud + CpSettingsUtil.saveToXmlFile(spec.settings, xmlFile, + baseKey .. CpHud.SETTINGS_KEY, self, nil) end function CpHud:onEnterVehicle(isControlling) @@ -222,6 +249,19 @@ function CpHud:onLeaveVehicle(wasEntered) end end +function CpHud:onStateChange(state, data) + local spec = self.spec_cpHud + if state == Vehicle.STATE_CHANGE_ATTACH then + for _, setting in ipairs(spec.hudSettings.settings) do + setting:refresh() + end + elseif state == Vehicle.STATE_CHANGE_DETACH then + for _, setting in ipairs(spec.hudSettings.settings) do + setting:refresh() + end + end +end + --- Enriches the status data for the hud here. function CpHud:onUpdate(dt) local spec = self.spec_cpHud @@ -290,3 +330,80 @@ end function CpHud:cpInit() self.spec_cpHud.hud = CpBaseHud(self) end + +-------------------------------------- +--- Hud Settings +-------------------------------------- + +function CpHud:isFieldWorkModeDisabled() + return not self:getCanStartCpFieldWork() +end + +function CpHud:isBaleFinderModeDisabled() + return not self:getCanStartCpBaleFinder() +end + +function CpHud:isSiloLoadingModeDisabled() + return not self:getCanStartCpSiloLoaderWorker() +end + +function CpHud:isUnloaderModeDisabled() + return not self:getCanStartCpCombineUnloader() +end + +function CpHud:isStreetModeDisabled() + return false +end + +function CpHud:cpIsHudFieldWorkJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value <= CpHud.hudSettings.START_AT_FIELDWORK_LAST_POINT +end + +function CpHud:cpIsHudBaleFinderJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value == CpHud.hudSettings.START_AT_BALE_FINDER +end + +function CpHud:cpIsHudBunkerSiloJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value == CpHud.hudSettings.START_AT_BUNKER_SILO +end + +function CpHud:cpIsHudSiloLoaderJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value == CpHud.hudSettings.START_AT_SILO_LOADING +end + +function CpHud:cpIsHudUnloaderJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value == CpHud.hudSettings.START_AT_UNLOADER_HARVESTER or + value == CpHud.hudSettings.START_AT_UNLOADER_LOADER +end + +function CpHud:cpIsHudDriveToJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value == CpHud.hudSettings.START_AT_STREET_DRIVE_TO +end + +function CpHud:cpIsHudTransportJobSelected() + local spec = self.spec_cpHud + local value = spec.hudSettings.hudStartAt:getValue() + return value > CpHud.hudSettings.START_AT_STREET_DRIVE_TO +end + +function CpHud:cpGetHudStartingPointSetting() + local spec = self.spec_cpHud + return spec.hudSettings.hudStartAt +end + +function CpHud:getCpStartText() + local spec = self.spec_cpHud + return spec.hudSettings.hudStartAt:getString() or "---" +end \ No newline at end of file