Skip to content

Commit

Permalink
WIP Hud Starting Point changes
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Apr 5, 2024
1 parent e581ad0 commit 9c43bf1
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 190 deletions.
46 changes: 46 additions & 0 deletions config/HudSettingsSetup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
All the global settings can be setup here.
For documentation look up the CpSettingUtil.lua.
-->

<Settings prefixText="CP_hud_settings_">
<SettingSubTitle title="basic">
<Setting classType="AIParameterSettingList" name="hudStartAt">
<Values>
<!-- Fieldwork -->
<Value name="START_AT_FIELDWORK_NEAREST_POINT" isDisabled="isFieldWorkModeDisabled">1</Value>
<Value name="START_AT_FIELDWORK_FIRST_POINT" isDisabled="isFieldWorkModeDisabled">2</Value>
<Value name="START_AT_FIELDWORK_LAST_POINT" isDisabled="isFieldWorkModeDisabled">3</Value>
<!-- Bale Finder -->
<Value name="START_AT_BALE_FINDER" isDisabled="isBaleFinderModeDisabled">4</Value>
<!-- Bunker Silo -->
<Value name="START_AT_BUNKER_SILO" isDisabled="isBunkerSiloModeDisabled">5</Value>
<!-- Silo Loader -->
<Value name="START_AT_SILO_LOADING" isDisabled="isSiloLoadingModeDisabled">6</Value>
<!-- Combine Unloader -->
<Value name="START_AT_UNLOADER_HARVESTER" isDisabled="isUnloaderModeDisabled">7</Value>
<Value name="START_AT_UNLOADER_LOADER" isDisabled="isUnloaderModeDisabled">8</Value>
<!-- Street Driver -->
<Value name="START_AT_STREET_DRIVE_TO" isDisabled="isStreetModeDisabled">9</Value>
<Value name="START_AT_STREET_UNLOAD_OR_REFILL" isDisabled="isStreetModeDisabled">10</Value>
<Value name="START_AT_STREET_LOAD_AND_UNLOAD" isDisabled="isStreetModeDisabled">11</Value>

</Values>
<Texts>
<Text>fieldWork_nearest</Text>
<Text>fieldWork_first</Text>
<Text>fieldWork_last</Text>
<Text>baleFinder</Text>
<Text>bunkerSilo</Text>
<Text>siloLoader</Text>
<Text>unloader_harvester</Text>
<Text>unloader_loader</Text>
<Text>street_driveTo</Text>
<Text>street_unloadOrRefill</Text>
<Text>street_loadAndUnload</Text>
</Texts>
</Setting>
</SettingSubTitle>
</Settings>
10 changes: 6 additions & 4 deletions config/jobParameters/FieldWorkJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
<Value name="START_AT_NEAREST_POINT" isDisabled="isFieldWorkHudModeDisabled">1</Value>
<Value name="START_AT_FIRST_POINT" isDisabled="isFieldWorkHudModeDisabled">2</Value>
<Value name="START_AT_LAST_POINT" isDisabled="isFieldWorkHudModeDisabled">3</Value>
<Value name="START_AT_BUNKER_SILO" isDisabled="isBunkerSiloHudModeDisabled">4</Value> <!-- Only for bunker silo mode in the hud!-->
<Value name="START_AT_SILO_LOADING" isDisabled="isSiloLoadingHudModeDisabled">5</Value> <!-- Only for shovel silo loadings mode in the hud!-->
<!-- <Value name="START_AT_BUNKER_SILO" isDisabled="isBunkerSiloHudModeDisabled">4</Value> -->
<!-- Only for bunker silo mode in the hud!-->
<!-- <Value name="START_AT_SILO_LOADING" isDisabled="isSiloLoadingHudModeDisabled">5</Value> -->
<!-- Only for shovel silo loadings mode in the hud!-->
</Values>
<Texts>
<Text>nearest</Text>
<Text>first</Text>
<Text>last</Text>
<Text>bunkerSilo</Text>
<Text>siloLoader</Text>
<!-- <Text>bunkerSilo</Text>
<Text>siloLoader</Text> -->
</Texts>
</Setting>
</SettingSubTitle>
Expand Down
14 changes: 0 additions & 14 deletions scripts/gui/hud/CpBaleFinderHudPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
126 changes: 98 additions & 28 deletions scripts/gui/hud/CpBaseHud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 0 additions & 26 deletions scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
54 changes: 15 additions & 39 deletions scripts/gui/hud/CpCombineUnloaderHudPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down
Loading

0 comments on commit 9c43bf1

Please sign in to comment.