Skip to content

cargo_react_util

Source: base/tealdef/gui/main/cargo_react_util.d.tl

Notes

React recipes and node builders for cargo: cargo icons, cargo lists of vehicles, lines and warehouses (count/capacity per cargo type with tendency, quality and loading state), the input/output arrow display of industries, and cargo class specialization badges. Load it with ug_require "/gui/main/cargo_react_util.tl". The data comes from CargoUtil.

CargoReactUtil

record global base/tealdef/gui/main/cargo_react_util.d.tl:3

global record CargoReactUtil

Load: local cargo_react_util = ug_require "/gui/main/cargo_react_util.tl"

Notes

Recipes and builders that show cargo icons and cargo lists.

Fields

Name Type Description
LineCargoInfo Recipe<LineCargoInfoParams> Shows the cargo of all vehicles of a line (count/capacity per cargo type, loading animation and unhappy/delayed indicators). used 1× in the base game
WarehouseCargoInfo Recipe<WarehouseCargoInfoParams> Shows the stock of a warehouse per cargo type (count/capacity, optional tendency, unhappy/delayed indicators). used 3× in the base game
CargoList Recipe<CargoListParams>
LocationCargoList Recipe<LocationCargoListParams> Lists the cargo types at a location, one entry per cargo type built by getCargoItemLayout.
CargoInputOutputIndicator Recipe<CargoInputOutputParams> Shows input cargo, an arrow and output cargo of a stock list, as used on industry HUD icons and in the cargo flow layer. used 13× in the base game
CargoIconLabelIndicator Recipe<CargoIconLabelIndicatorParams> Recipe version of makeCargoIconLabelIndicator. used 2× in the base game
CargoClassSpecialization Recipe<CargoSpecializationParams> Shows a badge per cargo class with the class name and a border in the class colour. used 2× in the base game

Functions

makeVehicleCargoInfo(VehicleCargoInfoParams) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:25

Call as cargo_react_util.makeVehicleCargoInfo

Notes

Builds a LocationCargoList that shows the cargo of a vehicle, sorted by capacity, in a flow layout.

Returns TreeNodeId: The list node, with shipping state Vehicle.

Used in the base game: 8 times in 5 files

base/content/gui/gui/layers/layer_public_transport.tl:142

local cargoInfo = cargo_react_util.makeVehicleCargoInfo{
base/content/gui/gui/layers/layer_cargo.tl:112
local cargoInfo = cargo_react_util.makeVehicleCargoInfo({
base/content/gui/gui/main/hud_icon_toolbox.tl:312
children[#children + 1] = cargo_react_util.makeVehicleCargoInfo{
base/content/gui/gui/entity_window/entity_window_hud.tl:335
children[#children + 1] = cargo_react_util.makeVehicleCargoInfo{
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:865
content = cargo_react_util.makeVehicleCargoInfo{

makeIcon(class : string, icon : string, tooltip : string, forceFocusable? : boolean) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:29

Call as cargo_react_util.makeIcon

Notes

Builds a builtin.ImageView with the given style class, image path and tooltip.

Parameter Type Description
class string Style class.
icon string Image path.
tooltip string Tooltip text.
forceFocusable? boolean Passed to meta.forceFocusable.

Returns TreeNodeId

makeCargoIcon(CargoTypeId, ?string, ?string, withoutTooltip? : boolean, forceFocusable? : boolean, tooltipModifier? : function(string) : string) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:30

Call as cargo_react_util.makeCargoIcon

Notes

Builds the icon of a cargo type with its name as tooltip.

Parameter Type Description
#1 CargoTypeId Cargo type id.
#2 ?string Style class.
#3 ?string Image path to use instead of the cargo type's icon.
withoutTooltip? boolean If true, no tooltip is set.
forceFocusable? boolean Passed to meta.forceFocusable.
tooltipModifier? function(string) : string Called with the tooltip text (or nil); its result becomes the tooltip.

Returns TreeNodeId

Used in the base game: 15 times in 11 files

base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:709

passengerChild = cargo_react_util.makeCargoIcon(cargoDisplayState:old().passengerCargoTypeId, "cargo-icon-only")
base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:247
content = cargo_react_util.makeCargoIcon(cargoTypeId, nil, nil, true),
base/content/gui/gui/main/town_hud_react_util.tl:151
table.insert(content, cargo_react_util.makeCargoIcon(cargoTypeId))
base/content/gui/gui/statistics/statistic_warehouses.tl:100
children[#children + 1] = cargo_react_util.makeCargoIcon(cargoTypeId, "text-icon-size-hack, cargo-icon-only" .. ((#children == 0) and ", first" or ""))
base/content/gui/gui/statistics/statistic_lines.tl:74
children[#children + 1] = cargo_react_util.makeCargoIcon(cargoTypeId, "text-icon-size-hack, cargo-icon-only" .. ((#children == 0) and ", first" or ""))
base/content/gui/gui/statistics/statistic_industries.tl:97
children[#children + 1] = cargo_react_util.makeCargoIcon(cargoTypeId, "text-icon-size-hack, cargo-icon-only" .. ((#children == 0) and ", first" or ""))
… and 5 more files.

makeCargoClassIcon(CargoTypeId, ?string) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:31

Call as cargo_react_util.makeCargoClassIcon

Notes

Builds a horizontal row with the icons of all cargo classes of a cargo type, each with the class name as tooltip.

Parameter Type Description
#1 CargoTypeId Cargo type id.
#2 ?string Style class of the icons.

Returns TreeNodeId

makeTooltipStockCompatibility(Engine.Component.TransportVehicle.LoadSpeedModifiers) : string base/tealdef/gui/main/cargo_react_util.d.tl:33

Call as cargo_react_util.makeTooltipStockCompatibility

Notes

Builds the tooltip text "Specialized Warehouse" with the load speed boost from warehouse specialization.

Returns string

Used in the base game: 1 time in 1 file

base/content/gui/gui/entity_window/entity_window_util.tl:2233

tooltip = tooltip .. cargo_react_util.makeTooltipStockCompatibility(loadSpeedModifiers)

makeTooltipVehicleCompatibility(Engine.Component.TransportVehicle.LoadSpeedModifiers) : string base/tealdef/gui/main/cargo_react_util.d.tl:34

Call as cargo_react_util.makeTooltipVehicleCompatibility

Notes

Builds the tooltip lines that explain the terminal part of the load speed (specialized terminal, mismatched specialization, terminal too short).

Returns string: Translated lines joined with newlines.

Used in the base game: 1 time in 1 file

base/content/gui/gui/entity_window/entity_window_util.tl:2227

tooltip = tooltip .. cargo_react_util.makeTooltipVehicleCompatibility(loadSpeedModifiers)

makeCargoIconLabelIndicator(CargoIconLabelIndicatorParams) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:50

Call as cargo_react_util.makeCargoIconLabelIndicator

Notes

Builds an icon/label indicator for a cargo type with the cargo icon and name filled in.

Returns TreeNodeId

Details

Calls GuiReactUtil.makeContentLabelIndictator with the cargo icon(s) as iconPath and the cargo name(s) as iconTooltip.

Used in the base game: 5 times in 4 files

base/content/gui/gui/layers/layer_public_transport.tl:54

return cargo_react_util.makeCargoIconLabelIndicator{
base/content/gui/gui/entity_window/entity_window_util.tl:705
children[#children + 1] = cargo_react_util.makeCargoIconLabelIndicator{
base/content/gui/gui/entity_window/town_building/town_building.tl:129
cargo_react_util.makeCargoIconLabelIndicator{
base/content/game_mechanics/game_mechanics/towns/town_react_util.tl:150
cargo_react_util.makeCargoIconLabelIndicator{

makeCargoInputOutputDataForStorage(entity : Engine.Entity) : CargoReactUtil.CargoInputOutputData base/tealdef/gui/main/cargo_react_util.d.tl:99

Call as cargo_react_util.makeCargoInputOutputDataForStorage

Notes

Builds CargoInputOutputData for a storage, listing the accepted cargo types (or "any cargo") as inputs without counts.

Parameter Type Description
entity Engine.Entity Stock list entity.

Returns CargoReactUtil.CargoInputOutputData

Used in the base game: 1 time in 1 file

base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:934

stockList = cargo_react_util.makeCargoInputOutputDataForStorage(hudIconParam.entity),

makeCargoInputOutputDataForStocklist(entity : Engine.Entity, inputCount : boolean, inputMax : boolean, outputCount : boolean, outputMax : boolean) : CargoInputOutputData base/tealdef/gui/main/cargo_react_util.d.tl:100

Call as cargo_react_util.makeCargoInputOutputDataForStocklist

Notes

Builds CargoInputOutputData from the inputs and outputs of the rules of a stock list.

Parameter Type Description
entity Engine.Entity Stock list entity (e.g. Industry.stockList).
inputCount boolean If true, fills count of inputs with the consumption per year.
inputMax boolean If true, fills max of inputs with the maximum consumption per year.
outputCount boolean If true, fills count of outputs with the production per year.
outputMax boolean If true, fills max of outputs with the maximum production per year.

Returns CargoInputOutputData

Example

-- from layer_cargo_flow.tl
stockListData = cargo_react_util.makeCargoInputOutputDataForStocklist(param.entity, false, true, false, true)
Used in the base game: 8 times in 5 files

base/content/gui/gui/layers/layer_cargo_flow.tl:98

stockListData = cargo_react_util.makeCargoInputOutputDataForStocklist(param.entity, false, true, false, true)
base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:943
stockList = cargo_react_util.makeCargoInputOutputDataForStocklist(hudIconParam.entity, false, false, false, false),
base/content/gui/gui/construction/constructionHudIconMaster.tl:137
return cargo_react_util.makeCargoInputOutputDataForStocklist(param.entity, false, false, false, false)
base/content/gui/gui/statistics/statistics.tl:92
result.cargoData = cargo_react_util.makeCargoInputOutputDataForStocklist(params.entity,  false, true, false, true)
base/content/gui/gui/entity_window/entity_window_hud.tl:45
return cargo_react_util.makeCargoInputOutputDataForStocklist(industry.stockList, false, false, false, false)

makeCargoInputOutputDataForConstructionData(entity : Engine.Entity) : CargoInputOutputData base/tealdef/gui/main/cargo_react_util.d.tl:102

Call as cargo_react_util.makeCargoInputOutputDataForConstructionData

Notes

Builds CargoInputOutputData with the cargo requirements of a construction as inputs.

Parameter Type Description
entity Engine.Entity Construction entity.

Returns CargoInputOutputData

Details

Reads the requirements from the construction's persistent metadata. Inputs are only added while the construction is above level 0 and below its last level.

CargoReactUtil.VehicleCargoInfoParams

record base/tealdef/gui/main/cargo_react_util.d.tl:4

record VehicleCargoInfoParams

Notes

Parameters of makeVehicleCargoInfo.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:260

cargo_react_util.makeVehicleCargoInfo = function(params : CargoReactUtil.VehicleCargoInfoParams) : TreeNodeId

Fields

Name Type Description
vehicleEntity Engine.Entity Vehicle whose cargo is shown.
showEmpty boolean show with number 0 if empty
showLoadingIndicator boolean If true, shows the loading/unloading animation while the vehicle is at a terminal (not in EntityWindow mode).
mode GuiReactUtil.LabelMode Label mode of the entries. EntityWindow also groups unset capacities and adds the unhappy/delayed indicators.

Functions

cargoTypeFilter(CargoTypeId) : boolean base/tealdef/gui/main/cargo_react_util.d.tl:9

Notes

Function that returns true for cargo types to show.

Returns boolean

getEmptyItem() : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:11

use special recipe if empty

Returns TreeNodeId

CargoReactUtil.LineCargoInfoParams

record base/tealdef/gui/main/cargo_react_util.d.tl:13

record LineCargoInfoParams

Notes

Parameters of the LineCargoInfo recipe.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:280

cargo_react_util.LineCargoInfo = react.RegisterRecipe("LineCargoInfo", function(params : CargoReactUtil.LineCargoInfoParams) : TreeNodeId

Fields

Name Type Description
lineEntity Engine.Entity Line whose cargo is shown.
makeEmptyItem TreeNodeId Shown when the line carries nothing. If nil, empty cargo types are listed instead.
mode GuiReactUtil.LabelMode Label mode of the entries.

CargoReactUtil.WarehouseCargoInfoParams

record base/tealdef/gui/main/cargo_react_util.d.tl:18

record WarehouseCargoInfoParams

Notes

Parameters of the WarehouseCargoInfo recipe.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:303

cargo_react_util.WarehouseCargoInfo = react.RegisterRecipe("WarehouseCargoInfo", function(params : CargoReactUtil.WarehouseCargoInfoParams) : TreeNodeId

Fields

Name Type Description
warehouseEntity Engine.Entity Warehouse (or other stock list owner) whose stock is shown.
makeEmptyItem TreeNodeId Shown when the stock is empty. If nil, empty cargo types are listed instead (except in HudIconLayer mode).
showTendency boolean If true, shows tendency arrows (not in the HUD modes).
mode GuiReactUtil.LabelMode Label mode of the entries.

CargoReactUtil.CargoIconLabelIndicatorParams

record base/tealdef/gui/main/cargo_react_util.d.tl:36

record CargoIconLabelIndicatorParams

Notes

Parameters of makeCargoIconLabelIndicator and CargoIconLabelIndicator.

Fields

Name Type Description
cargoType CargoTypeId Cargo type whose icon is shown. Ignored when cargoTypes is set.
cargoTypes {CargoTypeId} Several cargo types; their icons are shown side by side, each with its name as tooltip.
iconStyle string
label string Text label, usually the count.
richLabel GuiReactUtil.RichLabel Label with text and icon; takes precedence over label.
labelFontColor GuiReactUtil.LabelFontColor Colour of the label.
labelMode GuiReactUtil.LabelMode Layout mode.
labelTooltip string Tooltip of the label.
indicatorIconPath string Image path of a small indicator icon next to the label, e.g. a tendency arrow.
iconOverride string
loadingIndicator TreeNodeId Node shown above the indicator, e.g. the loading animation.
shippingState GuiReactUtil.ShippingState Where the cargo is; adds the matching style class.

CargoReactUtil.CargoListParams

record base/tealdef/gui/main/cargo_react_util.d.tl:52

record CargoListParams

No description in the game files yet.

Fields

Name Type Description
gameCtx GameContext
cargoTypeLoadSpeed {{CargoTypeId, number}}
allCargo boolean

CargoReactUtil.LocationCargoListParams

record base/tealdef/gui/main/cargo_react_util.d.tl:59

record LocationCargoListParams

Notes

Parameters of the LocationCargoList recipe.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:390

cargo_react_util.LocationCargoList = react.RegisterRecipe("LocationCargoList", function(params : CargoReactUtil.LocationCargoListParams) : TreeNodeId

Fields

Name Type Description
locationParams CargoUtil.CargoLocationParams Where to collect the cargo (vehicle, stock list owner, line).
layout LocationCargoListLayout Arrangement of the entries. Anything other than FLOW or VERTICAL gives a horizontal box.
sortOrder CargoUtil.CargoListSortOrder Sort order of the cargo types.
groupIfAllEmpty boolean If true and the location is a vehicle with showEmpty, adds the vehicle's unset capacities (single-type capacities to their cargo type, multi-type capacities as extra entries).
shippingState GuiReactUtil.ShippingState Shipping state passed to the item layout functions.

Functions

cargoTypeFilter(CargoTypeId) : boolean base/tealdef/gui/main/cargo_react_util.d.tl:67

Notes

Passed to CargoUtil.getSortedProducedCargoTypes (see the note there on when it takes effect).

Returns boolean

getCargoItemLayout(CargoUtil.CargoTypeInfo, GuiReactUtil.ShippingState) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:71

Notes

Builds the node of one cargo type entry.

Returns TreeNodeId

getFrownyIconLayout(summary : UtilCargo.CargoQualityData, cargoIsPassengers : boolean, shippingState : GuiReactUtil.ShippingState) : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:72

Notes

If set, builds the indicator for unhappy passengers and spoiled cargo; called only when the location has such items.

Returns TreeNodeId

getEmptyItem() : TreeNodeId base/tealdef/gui/main/cargo_react_util.d.tl:73

Notes

Builds the node shown when the list has no entries.

Returns TreeNodeId

CargoReactUtil.LocationCargoListParams.LocationCargoListLayout

enum base/tealdef/gui/main/cargo_react_util.d.tl:60

enum LocationCargoListLayout

Notes

How the entries of a LocationCargoList are arranged.

Value Description
"VERTICAL" Vertical box layout.
"HORIZONTAL" Horizontal box layout.
"FLOW" Flow layout that wraps entries into rows.

CargoReactUtil.CargoInputOutputData

record base/tealdef/gui/main/cargo_react_util.d.tl:79

record CargoInputOutputData

Notes

Input and output cargo of a stock list for CargoInputOutputIndicator.

Used in the base game: 25 times in 7 files

base/content/gui/gui/layers/layer_react_util.tl:181

local data : CargoReactUtil.CargoInputOutputData = {
base/content/gui/gui/layers/layer_cargo_flow.tl:54
districtTownData : CargoReactUtil.CargoInputOutputData
base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:917
stockList : CargoReactUtil.CargoInputOutputData
base/content/gui/gui/construction/constructionHudIconMaster.tl:135
local generalCargoDataState = engine_react_util.useStepStateTimer(function() : CargoReactUtil.CargoInputOutputData
base/content/gui/gui/main/cargo_react_util.tl:618
cargo_react_util.makeCargoInputOutputDataForStorage = function(entity : Engine.Entity) : CargoReactUtil.CargoInputOutputData
base/content/gui/gui/statistics/statistics.tl:63
cargoData : CargoReactUtil.CargoInputOutputData
… and 1 more files.

Fields

Name Type Description
inputs {CargoData} Input cargo entries.
outputs {CargoData} Output cargo entries.

CargoReactUtil.CargoInputOutputData.CargoData

record base/tealdef/gui/main/cargo_react_util.d.tl:80

record CargoData

Notes

One cargo entry of CargoInputOutputData.

Used in the base game: 9 times in 4 files

base/content/gui/gui/layers/layer_cargo_flow.tl:83

local cargoData : CargoReactUtil.CargoInputOutputData.CargoData = {
base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:1042
local cargoData : CargoReactUtil.CargoInputOutputData.CargoData = {
base/content/gui/gui/construction/constructionHudIconMaster.tl:154
local cargoData : CargoReactUtil.CargoInputOutputData.CargoData = {
base/content/gui/gui/main/cargo_react_util.tl:486
local appendChildren = function(targetChildren : {TreeNodeId}, cargoData : CargoReactUtil.CargoInputOutputData.CargoData, tooltip : string)

Fields

Name Type Description
count integer Current amount, e.g. consumed or produced per year. nil if not shown.
max integer Maximum amount, e.g. maximum consumption or production per year. nil if not shown.
cargoType CargoTypeId Cargo type id.
allCargoType boolean true if the entry stands for any cargo; shown with the mixed cargo icon.

CargoReactUtil.CargoInputOutputParams

record base/tealdef/gui/main/cargo_react_util.d.tl:90

record CargoInputOutputParams

Notes

Parameters of the CargoInputOutputIndicator recipe.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:472

cargo_react_util.CargoInputOutputIndicator = react.RegisterRecipe("CargoInputOutputIndicator", function(params : CargoReactUtil.CargoInputOutputParams) : TreeNo

Fields

Name Type Description
data CargoInputOutputData Input and output cargo to show.
inputDistrict LandUseType optional, default is nil
outputDistrict LandUseType optional, default is nil
showPercentage boolean If true, entries with count and max show count / max as a percentage instead of count/max.

CargoReactUtil.CargoSpecializationParams

record base/tealdef/gui/main/cargo_react_util.d.tl:104

record CargoSpecializationParams

Notes

Parameters of the CargoClassSpecialization recipe.

Fields

Name Type Description
cargoClasses {string} Cargo class names, e.g. from CargoUtil.getSpecializationClasses. Duplicates are removed.
horizontalLayout boolean If true, the badges are placed side by side, otherwise below each other.