Skip to content

Commit

Permalink
Added fillType Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Dec 24, 2023
1 parent 3b6e730 commit 1c9a782
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 131 deletions.
10 changes: 3 additions & 7 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,9 @@
<Text language="de"><![CDATA[CP: Silo laden]]></Text>
<Text language="en"><![CDATA[CP: Silo loading]]></Text>
</Translation>
<Translation name="CP_job_streetDriveTo">
<Text language="de"><![CDATA[CP: Drive to]]></Text>
<Text language="en"><![CDATA[CP: Drive to]]></Text>
</Translation>
<Translation name="CP_job_streetDeliver">
<Text language="de"><![CDATA[CP: Deliver]]></Text>
<Text language="en"><![CDATA[CP: Deliver]]></Text>
<Translation name="CP_job_street">
<Text language="de"><![CDATA[CP: Straße]]></Text>
<Text language="en"><![CDATA[CP: Street]]></Text>
</Translation>
<Translation name="CP_ai_page_generate_course">
<Text language="de"><![CDATA[CP: Feldkurs generieren]]></Text>
Expand Down
11 changes: 9 additions & 2 deletions config/gui/CourseGeneratorSettingsFrame.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<CourseGeneratorLayout>
<!-- MTO -->
<GuiElement type="cpOptionToggle" profile="ingameMenuAIParameterOption" id="createCpMultiOptionTemplate" onClick="onClickMultiTextOptionParameter" onClickCenter="onClickMultiTextOptionCenterParameter" >
<!-- MTO -->
<GuiElement type="cpOptionToggle" profile="ingameMenuAIParameterOption" id="createCpMultiOptionTemplate" onClick="onClickMultiTextOptionParameter" onClickCenter="onClickMultiTextOptionCenterParameter" >
<GuiElement type="button" profile="multiTextOptionLeft" />
<GuiElement type="button" profile="multiTextOptionRight" />
<GuiElement type="button" profile="cpMultiTextOptionText" />
<GuiElement type="bitmap" profile="multiTextOptionBg" />
<GuiElement type="bitmap" profile="ingameMenuAIParameterInvalid" name="invalid" />
</GuiElement>

<!-- VEHICLE -->
<GuiElement type="button" profile="ingameMenuAIParameterText" id="createCpTextTemplate" onClick="onClickMultiTextOptionCenterParameter">
<!-- <GuiElement type="bitmap" profile="ingameMenuAIParameterVehicleIcon" /> -->
<GuiElement type="text" profile="ingameMenuAIParameterTextTitle" name="title" text="My JD" />
<GuiElement type="bitmap" profile="ingameMenuAIParameterInvalid" name="invalid" />
</GuiElement>

<GuiElement type="empty" id="courseGeneratorFrame">
<GuiElement type="text" profile="cpDrawingCustomFieldHeader" id="drawingCustomFieldHeader"/>
<GuiElement type="bitmap" profile="cpCourseGeneratorBackground" position="30px -86px" id="courseGeneratorLayout">
Expand Down
49 changes: 49 additions & 0 deletions config/gui/FillTypeTargetFrame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<FillTypeTargetFrame>
<GuiElement type="empty" id="fillTypeSelectionTargetFrame">
<GuiElement type="bitmap" profile="cpCourseGeneratorBackground" position="30px -86px">
<GuiElement type="empty" position="0px -64px">
<GuiElement type="empty" profile="cpIngameMenuSettingsBox" position="10px -10px">
<GuiElement type="empty" profile="ingameMenuFrameHeaderPanel" position="0 70px">
<GuiElement type="text" profile="ingameMenuFrameHeaderText" id="fillTypeSelectionTargetHeader" text="Test parameter name"/>
</GuiElement>
<GuiElement type="bitmap" profile="topScrollClipper" name="topClipper"/>
<GuiElement type="bitmap" profile="bottomScrollClipper" name="bottomClipper"/>
<GuiElement type="text" profile="cpFillTypeTitle" id="fillTypeSelectionFillTypeTitle"/>
<GuiElement type="boxLayout" id="fillTypeSelectionTargetLayout" profile="cpFillTypeSelectionLayout">
<GuiElement type="smoothList" profile="cpFillTypeSelectionList"
focusChangeTop="nil" focusChangeBottom="nil"
selectedWithoutFocus="true" name="fillType">
<GuiElement type="listItem" profile="cpFillTypeSelectionListItem">
<GuiElement type="text" name="name" profile="ingameMenuPriceItemTitle" />
</GuiElement>
</GuiElement>
<GuiElement type="boxLayout" profile="cpFillTypeSelectionLayoutSide">
<GuiElement type="cpOptionToggle" name="counter" profile="cpFillTypeSelection" onClick="onClickFillTypeMultiTextOptionParameter" namedComponents="true">
<GuiElement type="text" name="label" profile="cpFillTypeMultiTextOptionTitle"/>
<GuiElement type="button" name="left" profile="cpFillTypeMultiTextOptionLeft" />
<GuiElement type="button" name="right" profile="cpFillTypeMultiTextOptionRight"/>
<GuiElement type="text" name="text" profile="cpFillTypeMultiTextOptionText" />
<GuiElement type="bitmap" name="gradient" profile="cpFillTypeMultiTextOptionBg" />
</GuiElement>
<GuiElement type="cpOptionToggle" name="maxFillLevel" profile="cpFillTypeSelection" onClick="onClickFillTypeMultiTextOptionParameter" namedComponents="true">
<GuiElement type="text" name="label" profile="cpFillTypeMultiTextOptionTitle"/>
<GuiElement type="button" name="left" profile="cpFillTypeMultiTextOptionLeft" />
<GuiElement type="button" name="right" profile="cpFillTypeMultiTextOptionRight"/>
<GuiElement type="text" name="text" profile="cpFillTypeMultiTextOptionText" />
<GuiElement type="bitmap" name="gradient" profile="cpFillTypeMultiTextOptionBg" />
</GuiElement>
<GuiElement type="cpOptionToggle" name="minFillLevel" profile="cpFillTypeSelection" onClick="onClickFillTypeMultiTextOptionParameter" namedComponents="true">
<GuiElement type="text" name="label" profile="cpFillTypeMultiTextOptionTitle"/>
<GuiElement type="button" name="left" profile="cpFillTypeMultiTextOptionLeft" />
<GuiElement type="button" name="right" profile="cpFillTypeMultiTextOptionRight"/>
<GuiElement type="text" name="text" profile="cpFillTypeMultiTextOptionText" />
<GuiElement type="bitmap" name="gradient" profile="cpFillTypeMultiTextOptionBg" />
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</FillTypeTargetFrame>
73 changes: 73 additions & 0 deletions config/gui/GUIProfiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,78 @@
<Value name="imageFocusedColor" value="$preset_colorFocusBackgroundGradient"/>
<Value name="imageSelectedColor" value="$preset_colorFocusBackgroundGradient"/>
</Profile>
<Profile name="cpFillTypeSelectionLayoutSide" extends="ingameMenuSettingsLayout" with="anchorTopLeft">
<!-- <Value name="flowDirection" value="vertical" />
<Value name="alignmentY" value="top"/>
<Value name="alignmentX" value="left" />
<Value name="wrapAround" value="true"/> -->
<!-- <Value name="lateralFlowSize" value="120px"/> -->
<Value name="autoValidateLayout" value="true"/>
<Value name="fitToElements" value="true"/>
<Value name="numFlows" value="3"/>
<Value name="alignmentY" value="top"/>
<Value name="alignmentX" value="left" />
<Value name="size" value="500px 700px"/>
<!-- <Value name="position" value="0 0"/> -->
<Value name="imageColor" value="0 0 0 0"/>
<Value name="margin" value="50px 0 0 0" />
</Profile>

<Profile name="cpFillTypeSelectionLayout" extends="ingameMenuSettingsLayout" with="anchorTopLeft">
<Value name="flowMargin" value="0 20px 0 0"/>
<Value name="flowDirection" value="horizontal" />
<Value name="alignmentY" value="top"/>
<Value name="alignmentX" value="left" />
<!-- <Value name="wrapAround" value="true"/> -->
<!-- <Value name="lateralFlowSize" value="120px"/> -->
<!-- <Value name="autoValidateLayout" value="true"/> -->
<Value name="autoValidateLayout" value="true"/>
<Value name="fitToElements" value="true"/>
<Value name="numFlows" value="2"/>
<!-- <Value name="alignmentX" value="left" /> -->
<Value name="size" value="1200px 700px"/>
<Value name="imageColor" value="0 0 0 0"/>
</Profile>

<Profile name="cpFillTypeSelectionListItem" extends="ingameMenuPriceListItem" with="anchorTopLeft">
<Value name="size" value="600px 50px" />
<Value name="imageColor" value="$preset_colorListRowBackground"/>
<Value name="imageFocusedColor" value="$preset_colorFocusBackgroundGradient"/>
<Value name="imageSelectedColor" value="$preset_colorFocusBackgroundGradient"/>
</Profile>

<Profile name="cpFillTypeTitle" extends="cpFillTypeMultiTextOptionTitle" with="anchorTopLeft">
<Value name="position" value="50px -20px" />
</Profile>

<Profile name="cpFillTypeSelectionList" extends="ingameMenuPriceList" with="anchorTopLeft">
<Value name="margin" value="50px 0 0 0"/>
<Value name="isHorizontalList" value="false"/>
<Value name="size" value="550px 650px"/>
<Value name="fitToElements" value="true"/>
</Profile>

<Profile name="cpFillTypeSelection" extends="multiTextOption" with="anchorBottomLeft">
<Value name="margin" value="0 50px 0 0" />
<Value name="size" value="300px 100px"/>
<!-- <Value name="size" value=""/> -->
</Profile>
<Profile name="cpFillTypeMultiTextOptionLeft" extends="multiTextOptionLeft" with="anchorTopLeft">
<!-- <Value name="position" value="250px 0px" /> -->
</Profile>
<Profile name="cpFillTypeMultiTextOptionRight" extends="multiTextOptionRight" with="anchorTopRight">
<!-- <Value name="position" value="250px 0px" /> -->
</Profile>
<Profile name="cpFillTypeMultiTextOptionText" extends="multiTextOptionText" with="anchorTopCenter">
<!-- <Value name="position" value="250px 0px" /> -->
</Profile>
<Profile name="cpFillTypeMultiTextOptionTitle" extends="multiTextOptionSettingsTitle" with="anchorTopLeft">
<Value name="position" value="0 50px" />
<!-- <Value name="position" value="0 0 0 0"/> -->
</Profile>
<Profile name="cpFillTypeMultiTextOptionBg" extends="multiTextOptionBg" with="anchorTopLeft">
<Value name="size" value="252px 48px"/>
<!-- <Value name="position" value="250px 0px" /> -->
</Profile>

</GUIProfiles>
2 changes: 2 additions & 0 deletions config/jobParameters/FieldWorkJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
</SettingSubTitle>
<SettingSubTitle title="unloadRefillTargetPoint">
<Setting classType="CpAIParameterTargetPoint" name="unloadRefillTargetPoint" generateValuesFunction="generateAutoDriveMarkers" isDisabled="isUnloadRefillTargetDisabled" />
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection1" isDisabled="isUnloadRefillTargetDisabled"/>
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection2" isDisabled="isUnloadRefillTargetDisabled"/>
</SettingSubTitle>
<SettingSubTitle title="startAt">
<Setting classType="AIParameterSettingList" name="startAt" default="2" isCopyValueDisabled ="true">
Expand Down
12 changes: 12 additions & 0 deletions config/jobParameters/FillTypeSelectionParameterSetup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>


<Settings prefixText="CP_streetJobParameters_">
<SettingSubTitle title="ai_parameterGroupTitlePosition">
<!--Field Speed-->
<Setting classType="AIParameterSettingList" name="fillType" generateValuesFunction="generateFillTypes"/>
<Setting classType="AIParameterSettingList" name="maxFillLevel" min="20" max="100" default="100" unit="6"/>
<Setting classType="AIParameterSettingList" name="minFillLevel" min="0" max="100" default="0" unit="6"/>
<Setting classType="AIParameterSettingList" name="counter" min="1" max="25" default="15"/>
</SettingSubTitle>
</Settings>
11 changes: 8 additions & 3 deletions config/jobParameters/StreetJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
<SettingSubTitle title="loadTargetPoint" >
<Setting classType="CpAIParameterTargetPoint" name="loadTargetPoint" isDisabled="isLoadTargetPointDisabled" generateValuesFunction="generateAutoDriveMarkers" onChangeCallback="onChangeTargetPoints"/>
</SettingSubTitle>

<SettingSubTitle title="counter" >
<Setting classType="AIParameterSettingList" name="counter" min="1" max="99" isDisabled="isLoadTargetPointDisabled"/>
<SettingSubTitle title="loadingMultipleFruitTypesAllowed" >
<Setting classType="AIParameterBooleanSetting" name="loadingMultipleFruitTypesAllowed" isDisabled="isLoadTargetPointDisabled"/>
</SettingSubTitle>
<SettingSubTitle title="fillTypes">
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection1" isDisabled="isLoadTargetPointDisabled"/>
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection2" isDisabled="isLoadTargetPointDisabled"/>
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection3" isDisabled="isLoadTargetPointDisabled"/>
<Setting classType="CpAIParameterFillTypeSetting" name="fillTypeSelection4" isDisabled="isLoadTargetPointDisabled"/>
</SettingSubTitle>
</Settings>
1 change: 1 addition & 0 deletions modDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ Changelog 7.1.0.0:
<sourceFile filename="scripts/ai/parameters/CpAIParameterUnloadingStation.lua"/>
<sourceFile filename="scripts/ai/parameters/CpAIParameterPositionAngle.lua"/>
<sourceFile filename="scripts/ai/parameters/CpAIParameterTargetPoint.lua"/>
<sourceFile filename="scripts/ai/parameters/CpAIParameterFillTypeSelection.lua"/>

<sourceFile filename="scripts/ai/jobs/CpJobParameters.lua"/>
<sourceFile filename="scripts/ai/jobs/CpAIJob.lua"/>
Expand Down
12 changes: 11 additions & 1 deletion scripts/CpSettingsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,22 @@ function CpSettingsUtil.raiseEventForSettings(settings, eventName, ...)
end
end

function CpSettingsUtil.registerXmlSchema(schema, key)
function CpSettingsUtil.registerXmlSchemaForSetting(schema, key)
schema:register(XMLValueType.INT, key.."#value", "Old setting save format.")
schema:register(XMLValueType.STRING, key.."#currentValue", "Setting value")
schema:register(XMLValueType.STRING, key.."#name", "Setting name")
end

function CpSettingsUtil.registerXmlSchema(schema, key)
CpSettingsUtil.registerXmlSchemaForSetting(schema, key)

--- Fill type setting
CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).fillType")
CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).maxFillLevel")
CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).minFillLevel")
CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).counter")
end

--- Loads setting values from an xml file.
---@param dataTable table
---@param xmlFile table
Expand Down
20 changes: 20 additions & 0 deletions scripts/ai/AIUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,23 @@ function AIUtil.isOtherVehicleAhead(vehicle, otherVehicle)
local _, _, dz = localToLocal(otherVehicle.rootNode, vehicle:getAIDirectionNode(), 0, 0, 0)
return dz > (frontMarkerOffset + backMarkerOffset) / 2
end

function AIUtil.getAllValidFillTypes(vehicle, lambda, ...)
local fillTypes, fillTypesByIndex = {}, {}
for _, v in pairs(vehicle:getChildVehicles()) do
if v.getFillUnits then
for ix, _ in pairs(v:getFillUnits()) do
for fillType, state in pairs(v:getFillUnitSupportedFillTypes(ix)) do
if state then
if not fillTypesByIndex[fillType] and
(lambda == nil or lambda(fillType, ...)) then
fillTypesByIndex[fillType] = true
table.insert(fillTypes, fillType)
end
end
end
end
end
end
return fillTypes, fillTypesByIndex
end
17 changes: 17 additions & 0 deletions scripts/ai/jobs/CpJobParameters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,23 @@ function CpStreetJobParameters:isLoadTargetPointDisabled()
return self:hasNoValidTrailerAttached() or self.loadUnloadTargetMode:getValue() ~= CpStreetJobParameters.LOAD_AND_UNLOAD
end

function CpStreetJobParameters:generateFillTypes()
local fillTypes = {}
local texts = {}
local vehicle = self.job:getVehicle()
if vehicle then
fillTypes = AIUtil.getAllValidFillTypes(vehicle, function()
return true
end)
for _, f in pairs(fillTypes) do
table.insert(texts, g_fillTypeManager:getFillTypeTitleByIndex(f))
end
end
table.insert(fillTypes, 1, -1)
table.insert(texts, 1, "---")
return fillTypes, texts, fillTypes[1]
end

---@param setting CpAIParameterTargetPoint
function CpStreetJobParameters:onChangeTargetPoints(setting)
if setting:getIsDisabled() then
Expand Down
25 changes: 21 additions & 4 deletions scripts/ai/parameters/AIParameterSetting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
---@class AIParameterSetting : AIParameterSettingInterface
AIParameterSetting = CpObject(AIParameterSettingInterface)

function AIParameterSetting:init(name)
function AIParameterSetting:init(data, vehicle, class)
AIParameterSettingInterface.init(self)
self.data = nil
self.vehicle = nil
self.class = nil
self.vehicle = vehicle
self.class = class

self.name = name
self.name = ""
self.title = ""
self.tooltip = ""

Expand Down Expand Up @@ -63,6 +63,9 @@ function AIParameterSetting:getIsDisabled()
if self:hasCallback(self.data.isDisabledFunc) then
return self:getCallback(self.data.isDisabledFunc)
end
if self.parent and self.parent:getIsDisabled() then
return true
end
return false
end

Expand All @@ -79,11 +82,17 @@ function AIParameterSetting:getIsVisible()
if self:hasCallback(self.data.isVisibleFunc) then
return self:getCallback(self.data.isVisibleFunc)
end
if self.parent and not self.parent:getIsVisible() then
return false
end
return true
end

--- Is the setting specific for a player and is not synchronized?
function AIParameterSetting:getIsUserSetting()
if self.data == nil then
CpUtil.error("data is nil for %s!", self.name)
end
return self.data.isUserSetting
end

Expand All @@ -92,6 +101,14 @@ function AIParameterSetting:getIsExpertModeSetting()
return self.data.isExpertModeOnly
end

function AIParameterSetting:setParent(parent)
self.parent = parent
end

function AIParameterSetting:setClass(class)
self.class = class
end

--- Raises an event and sends the callback string to the Settings controller class.
function AIParameterSetting:raiseCallback(callbackStr, ...)
if self.class ~= nil and self.class.raiseCallback and callbackStr then
Expand Down
8 changes: 8 additions & 0 deletions scripts/ai/parameters/AIParameterSettingInterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,12 @@ end

function AIParameterSettingInterface:getDebugString()

end

function AIParameterSettingInterface:setParent(parent)

end

function AIParameterSettingInterface:setClass(class)

end
Loading

0 comments on commit 1c9a782

Please sign in to comment.