Skip to content

Commit

Permalink
Merge pull request #27 from VertexFloat/additionalUnits-support
Browse files Browse the repository at this point in the history
added AdditionalUnits mod support
  • Loading branch information
Achimobil authored Apr 6, 2024
2 parents 1cf4169 + 8423e35 commit bac7dae
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
67 changes: 42 additions & 25 deletions InfoDisplayExtension.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ InfoDisplayExtension.metadata = {
};
InfoDisplayExtension.modDir = g_currentModDirectory;

function InfoDisplayExtension:formatVolume(liters, precision, unit)
if unit == "" then
unit = nil;
end

local g_additionalUnits = nil

function InfoDisplayExtension:formatVolume(liters, precision, unit, fillTypeName)
unit = unit == "" and nil or (unit == false and "" or unit)

if g_additionalUnits ~= nil and fillTypeName ~= nil then
local formattedLiters, formattedUnit = g_additionalUnits:formatFillLevel(liters, fillTypeName)

if unit ~= "" then
unit = formattedUnit.shortName or unit
end

liters = formattedLiters
end

return g_i18n:formatVolume(liters, precision, unit)
end

function InfoDisplayExtension:formatCapacity(liters, capacity, precision, unit)
if unit == "" then
unit = nil;
end

return g_i18n:formatVolume(liters, precision, "") .. " / " .. g_i18n:formatVolume(capacity, precision, unit);
function InfoDisplayExtension:formatCapacity(liters, capacity, precision, unit, fillTypeName)
return self:formatVolume(liters, precision, false, fillTypeName) .. " / " .. self:formatVolume(capacity, precision, unit, fillTypeName);
end

function InfoDisplayExtension:storeScaledValues(superFunc)
Expand Down Expand Up @@ -124,12 +130,12 @@ function InfoDisplayExtension:updateInfo(_, superFunc, infoTable)
if fillTypeAndLevel.capacity == nil then
table.insert(infoTable, {
title = fillType.title,
text = InfoDisplayExtension:formatVolume(fillTypeAndLevel.fillLevel, 0, fillType.unitShort)
text = InfoDisplayExtension:formatVolume(fillTypeAndLevel.fillLevel, 0, fillType.unitShort, fillType.name)
})
else
table.insert(infoTable, {
title = fillType.title,
text = InfoDisplayExtension:formatCapacity(fillTypeAndLevel.fillLevel, fillTypeAndLevel.capacity, 0, fillType.unitShort)
text = InfoDisplayExtension:formatCapacity(fillTypeAndLevel.fillLevel, fillTypeAndLevel.capacity, 0, fillType.unitShort, fillType.name)
})
end
end
Expand Down Expand Up @@ -232,7 +238,7 @@ function InfoDisplayExtension:updateInfoProductionPoint(superFunc, infoTable)
if isOutput then
table.insert(inputOutputTypeInfo, {
title = fillType.title,
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort)
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort, fillType.name)
})
else
if not titleAdded then
Expand All @@ -244,7 +250,7 @@ function InfoDisplayExtension:updateInfoProductionPoint(superFunc, infoTable)
end
table.insert(infoTable, {
title = fillType.title,
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort)
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort, fillType.name)
})
end
end
Expand Down Expand Up @@ -284,7 +290,7 @@ function InfoDisplayExtension:updateInfoProductionPoint(superFunc, infoTable)

table.insert(infoTable, {
title = fillType.title,
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort)
text = InfoDisplayExtension:formatCapacity(fillLevel, fillLevelCapacity, 0, fillType.unitShort, fillType.name)
})
end
end
Expand Down Expand Up @@ -342,10 +348,9 @@ function InfoDisplayExtension:populateCellForItemInSection(superFunc, list, sect

-- für große breiten rechts ausrichten
cell:getAttribute("fillLevel").textAlignment = RenderText.ALIGN_RIGHT

cell:getAttribute("icon"):setImageFilename(fillTypeDesc.hudOverlayFilename)
cell:getAttribute("fillType"):setText(fillTypeDesc.title)
cell:getAttribute("fillLevel"):setText(InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, fillTypeDesc.unitShort));
cell:getAttribute("fillLevel"):setText(InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, fillTypeDesc.unitShort, fillTypeDesc.name));

if not isInput then
local outputMode = productionPoint:getOutputDistributionMode(fillType)
Expand Down Expand Up @@ -686,7 +691,8 @@ function InfoDisplayExtension:updateInfoPlaceableHusbandryMilk(_, superFunc, inf

local fillLevel = self:getHusbandryFillLevel(spec.fillType)
local capacity = self:getHusbandryCapacity(spec.fillType)
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);

spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, g_fillTypeManager:getFillTypeNameByIndex(spec.fillType));

table.insert(infoTable, spec.info)
end
Expand All @@ -698,7 +704,7 @@ function InfoDisplayExtension:updateInfoPlaceableHusbandryLiquidManure(_, superF
local spec = self.spec_husbandryLiquidManure;
local fillLevel = self:getHusbandryFillLevel(spec.fillType);
local capacity = self:getHusbandryCapacity(spec.fillType);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, g_fillTypeManager:getFillTypeNameByIndex(spec.fillType));

table.insert(infoTable, spec.info)
end
Expand All @@ -710,7 +716,7 @@ function InfoDisplayExtension:updateInfoPlaceableHusbandryStraw(_, superFunc, in
local spec = self.spec_husbandryStraw;
local fillLevel = self:getHusbandryFillLevel(spec.inputFillType);
local capacity = self:getHusbandryCapacity(spec.inputFillType);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, g_fillTypeManager:getFillTypeNameByIndex(spec.inputFillType));

table.insert(infoTable, spec.info)
end
Expand All @@ -724,7 +730,7 @@ function InfoDisplayExtension:updateInfoPlaceableHusbandryWater(_, superFunc, in
if not spec.automaticWaterSupply then
local fillLevel = self:getHusbandryFillLevel(spec.fillType);
local capacity = self:getHusbandryCapacity(spec.fillType);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);
spec.info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, g_fillTypeManager:getFillTypeNameByIndex(spec.fillType));

table.insert(infoTable, spec.info)
end
Expand All @@ -742,7 +748,7 @@ function InfoDisplayExtension:updateInfoPlaceableManureHeap(_, superFunc, infoTa

local fillLevel = spec.manureHeap:getFillLevel(spec.manureHeap.fillTypeIndex);
local capacity = spec.manureHeap:getCapacity(spec.manureHeap.fillTypeIndex);
spec.infoFillLevel.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);
spec.infoFillLevel.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, g_fillTypeManager:getFillTypeNameByIndex(spec.manureHeap.fillTypeIndex));

table.insert(infoTable, spec.infoFillLevel)

Expand Down Expand Up @@ -770,6 +776,11 @@ function InfoDisplayExtension:updateInfoFeedingRobot(_, infoTable)
for _, info in ipairs(self.infos) do
local fillLevel = 0
local capacity = 0
local fillTypeName = "UNKNOWN"

for _, fillType in ipairs(info.fillTypes) do
fillTypeName = g_fillTypeManager:getFillTypeNameByIndex(fillType)
end

-- nur den ersten filltype abfragen, da die anderen da schon drin sind
fillLevel = self:getFillLevel(info.fillTypes[1]);
Expand All @@ -778,7 +789,7 @@ function InfoDisplayExtension:updateInfoFeedingRobot(_, infoTable)
capacity = spot.capacity;
end

info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0);
info.text = InfoDisplayExtension:formatCapacity(fillLevel, capacity, 0, nil, fillTypeName);

table.insert(infoTable, info)
end
Expand Down Expand Up @@ -1146,4 +1157,10 @@ function InfoDisplayExtension:loadMap(name)
end
end

addModEventListener(InfoDisplayExtension)
if g_modIsLoaded["FS22_AdditionalUnits"] then
local modEnv = FS22_AdditionalUnits

g_additionalUnits = modEnv.g_additionalUnits
end

addModEventListener(InfoDisplayExtension)
10 changes: 8 additions & 2 deletions modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="79">
<author>Achimobil</author>
<version>1.7.1.0</version>
<version>1.7.1.1</version>
<title>
<de>Info Display Erweiterung</de>
<en>Info Display Extension</en>
<pl>Rozszerzone informacje</pl>
<pl>Rozszerzone Informacje</pl>
<ru>Дополнительная Информация</ru>
</title>
<description>
Expand All @@ -31,6 +31,9 @@ Das Verändern oder erneutes hochladen, ob ganz oder in Teilen, ist nicht gestat
Fehler und Anregungen gerne auf <a href="https://github.com/Achimobil/FS22_InfoDisplayExtension">GitHub</a>
Changelog
1.7.1.1
- Mod-Unterstützung für „Zusätzliche Einheiten“ hinzugefügt
1.7.1.0
- Anzeige des Food Buffer wenn Animal Grazing Mod verwendet wird. (Nur Singleplayer)
- Bei Produktionen werden die Filltypes jetzt gesplittet angezeigt nach nur Eingang oder Ausgang oder beides
Expand Down Expand Up @@ -88,6 +91,9 @@ Modifying and re-uploading in whole or in part is not allowed!
Bugs and suggestions welcome on <a href="https://github.com/Achimobil/FS22_InfoDisplayExtension">GitHub</a>.
Changelog
1.7.1.1
- added 'Additional Units' mod support
1.7.0.0
- When loading animals, the available quantity is now displayed for the own animals
- Display of the purchased working width for implements added
Expand Down

0 comments on commit bac7dae

Please sign in to comment.