Skip to content

Commit

Permalink
Changed shield height offset range
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Oct 18, 2023
1 parent cec93bf commit f43252e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/VehicleSettingsSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Setting classType="AIParameterSettingList" name="loadingShovelHeightOffset" min="-1" max="1" incremental="0.1" default="0" unit="2"
isVisible="isLoadingShovelOffsetSettingVisible" isDisabled="isLoadingShovelOffsetSettingDisabled"
onChangeCallback="onCpLoadingShovelOffsetSettingChanged" vehicleConfiguration="loadingShovelOffset"/>
<Setting classType="AIParameterSettingList" name="levelerHeightOffset" min="0" max="1" incremental="0.1" default="0" unit="2"
<Setting classType="AIParameterSettingList" name="levelerHeightOffset" min="0" max="0.5" incremental="0.05" default="0" unit="2" precision="3"
isVisible="isLevelerHeightOffsetSettingVisible" isDisabled="isLevelerHeightOffsetSettingDisabled" />
</SettingSubTitle>

Expand Down
11 changes: 7 additions & 4 deletions scripts/CpSettingsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ CpSettingsUtil = {}
- isExpertModeOnly(bool): is the setting visible in the expert version?, default = false
- generateValuesFunction(string): dynamically adds value, when the setting is created.
- min (int): min value
- max (int): max value
- min (float): min value
- max (float): max value
- incremental (float): increment (optional), default "1"
- precision (float): optional rounding precision
- text(string): string to format the setting value with in the gui element.
- unit (int) : 1 == km/h, 2 == meters, 3 == ha (optional), 4 = percent (%), 5 = degrees (°)
Expand Down Expand Up @@ -89,9 +90,10 @@ function CpSettingsUtil.init()
schema:register(XMLValueType.BOOL, key.."#isExpertModeOnly", "Is enabled in simple mode?", false) -- optional

schema:register(XMLValueType.STRING, key .. "#generateValuesFunction", "Function to generate values.")
schema:register(XMLValueType.INT, key.."#min", "Setting min value")
schema:register(XMLValueType.INT, key.."#max", "Setting max value")
schema:register(XMLValueType.FLOAT, key.."#min", "Setting min value")
schema:register(XMLValueType.FLOAT, key.."#max", "Setting max value")
schema:register(XMLValueType.FLOAT, key.."#incremental", "Setting incremental", 1) -- optional
schema:register(XMLValueType.FLOAT, key.."#precision", "Setting precision", 2) -- optional
schema:register(XMLValueType.STRING, key.."#text", "Setting text") -- optional
schema:register(XMLValueType.INT, key .. "#unit", "Setting value unit (km/h, m ...)") --optional

Expand Down Expand Up @@ -205,6 +207,7 @@ function CpSettingsUtil.loadSettingsFromSetup(class, filePath)
settingParameters.min = xmlFile:getValue(baseKey.."#min")
settingParameters.max = xmlFile:getValue(baseKey.."#max")
settingParameters.incremental = MathUtil.round(xmlFile:getValue(baseKey.."#incremental"), 3)
settingParameters.precision = xmlFile:getValue(baseKey.."#precision", 2)
settingParameters.textStr = xmlFile:getValue(baseKey.."#text")
settingParameters.unit = xmlFile:getValue(baseKey.."#unit")

Expand Down
28 changes: 16 additions & 12 deletions scripts/ai/parameters/AIParameterSettingList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function AIParameterSettingList:init(data, vehicle, class)
--- so we generate a series of float values and texts here.
self.data.values = {}
self.data.texts = {}
AIParameterSettingList.generateValues(self, self.data.values, self.data.texts, data.min, data.max, data.incremental, data.unit)
AIParameterSettingList.generateValues(self, self.data.values, self.data.texts,
data.min, data.max, data.incremental, data.unit, data.precision)
--- Same as above, make sure the values are copied.
self.values = table.copy(self.data.values)
if self.data.texts ~= nil then
Expand Down Expand Up @@ -73,27 +74,28 @@ function AIParameterSettingList:init(data, vehicle, class)

end

function AIParameterSettingList.getSpeedText(value)
function AIParameterSettingList.getSpeedText(value, precision)
return string.format("%.1f %s", g_i18n:getSpeed(value), g_i18n:getSpeedMeasuringUnit())
end

function AIParameterSettingList.getDistanceText(value)
function AIParameterSettingList.getDistanceText(value, precision)
precision = precision or 1
if g_Courseplay.globalSettings and g_Courseplay.globalSettings.distanceUnit:getValue() == g_Courseplay.globalSettings.IMPERIAL_UNIT then
return string.format("%.1f %s", value*AIParameterSettingList.FOOT_FACTOR, g_i18n:getText("CP_unit_foot"))
end
return string.format("%.1f %s", value, g_i18n:getText("CP_unit_meter"))
return string.format("%.".. tostring(precision) .. "f %s", value, g_i18n:getText("CP_unit_meter"))
end

function AIParameterSettingList.getAreaText(value)
function AIParameterSettingList.getAreaText(value, precision)
return g_i18n:formatArea(value, 1, true)
end

AIParameterSettingList.UNITS_TEXTS = {
AIParameterSettingList.getSpeedText, --- km/h
AIParameterSettingList.getDistanceText, --- m
AIParameterSettingList.getAreaText, --- ha/arcs
function (value) return string.format("%d", value) .. "%" end, --- percent
function (value) return string.format("%d", value) .. "°" end --- degrees
function (value, precision) return string.format("%d", value) .. "%" end, --- percent
function (value, precision) return string.format("%d", value) .. "°" end --- degrees
}

AIParameterSettingList.UNITS_CONVERSION = {
Expand All @@ -113,12 +115,13 @@ AIParameterSettingList.INPUT_VALUE_THRESHOLD = 2
---@param max number
---@param inc number
---@param unit number
function AIParameterSettingList:generateValues(values, texts, min, max, inc, unit)
function AIParameterSettingList:generateValues(values, texts, min, max, inc, unit, precision)
inc = inc or 1
precision = precision or 2
for i=min, max, inc do
table.insert(values, i)
local value = MathUtil.round(i, 2)
local text = unit and AIParameterSettingList.UNITS_TEXTS[unit] and AIParameterSettingList.UNITS_TEXTS[unit](value) or tostring(value)
local value = MathUtil.round(i, precision)
local text = unit and AIParameterSettingList.UNITS_TEXTS[unit] and AIParameterSettingList.UNITS_TEXTS[unit](value, precision - 1) or tostring(value)
table.insert(texts, text)
end
end
Expand Down Expand Up @@ -233,12 +236,13 @@ end
--- For all units that are not an SI unit ...
function AIParameterSettingList:validateTexts()
local unit = self.data.unit
local precision = self.data.precision or 2
if unit then
local unitStrFunc = AIParameterSettingList.UNITS_TEXTS[unit]
local fixedTexts = {}
for ix, value in ipairs(self.values) do
local value = MathUtil.round(value, 2)
local text = unitStrFunc(value)
local value = MathUtil.round(value, precision)
local text = unitStrFunc(value, precision - 1)
fixedTexts[ix] = text
end
self.texts = fixedTexts
Expand Down

0 comments on commit f43252e

Please sign in to comment.