Skip to content

layer_react_util

Source: base/tealdef/gui/layers/layer_react_util.d.tl

Notes

Shared building blocks of the map layers: gradient legend colors, town rating and demand HUD icons, filtered entity tooltips, legend containers and fallback colors for a LayerConfig.

LayerReactUtil

record global base/tealdef/gui/layers/layer_react_util.d.tl:3

global record LayerReactUtil

Load: local layer_react_util = ug_require "/gui/layers/layer_react_util.tl"

Notes

Shared helpers of the map layers.

Fields

Name Type Description
TownRatingHudIcon Recipe2<string, Engine.Entity> HUD icon recipe that shows a town's name and a rating bar for one rating; parameters are the rating key and the town entity.
TownDemandsHudIcon Recipe<Engine.Entity> HUD icon recipe that shows a town's name and its residential, industrial and commercial cargo supply against demand.
LayerLegendWrapper Recipe<LayerLegendWrapperParam> Box layout around a layer's legend or window content; all layer recipes wrap their content with it.
LayerLegendFakeWindow Recipe<LayerLegendFakeWindowParam> Shows a layer legend styled like a window (class fake-builtin-window) without being a window; the town window uses it for its layer views. used 1× in the base game
ColorIndicator Recipe<string> Small color swatch (style class color-indicator-inner) for legends; the pollution legend uses it with classes odd and event.

Functions

makeGradientColorsOf2(GradientColorsOf2) : {GradientColor} base/tealdef/gui/layers/layer_react_util.d.tl:34

Call as layer_react_util.makeGradientColorsOf2

Notes

Interpolates numberOfLevels colors from colorA to colorB for a builtin.GradientLegend.

Returns {GradientColor}: List of colors with labels; only the first and last step are labelled unless iterativeLabels is set.

Example

-- from gui/layers/layer_noise.tl
builtin.GradientLegend{
    colors = layer_react_util.makeGradientColorsOf2{
        colorA = averageColors[1],
        colorB = emissionMinMaxColor[2],
        numberOfLevels = emission_config.pollutionNumSteps,
        labelLeft = pGetText("layer-rating-label", "Low"),
        labelRight = pGetText("layer-rating-label", "High"),
    },
    horizontal = true,
    discrete = true,
    internalLabels = false,
},
Used in the base game: 3 times in 1 file

base/content/gui/gui/entity_window/town/town.tl:96

colors = layer_react_util.makeGradientColorsOf2({

makeGradientColorsOfN(GradientColorsOfN) : {GradientColor} base/tealdef/gui/layers/layer_react_util.d.tl:35

Call as layer_react_util.makeGradientColorsOfN

Notes

Interpolates colors through all entries of colors for a builtin.GradientLegend.

Returns {GradientColor}: List of colors with labels; the list ends with the last color exactly.

buildMouseEmissionInfo(Engine.Component.EmissionGrid.Type) : TreeNodeId base/tealdef/gui/layers/layer_react_util.d.tl:36

Call as layer_react_util.buildMouseEmissionInfo

Notes

Builds a "Mouse Position Info" checkbox that, when ticked, shows the current and average emission at the mouse position, raw and in dB.

Returns TreeNodeId

Details

Must be called inside a recipe function (uses React state and onStep).

makeFilteredSelectorTooltips(selectedEntityRef : ReactRefT<Engine.Entity>, preFilter : {Engine.ComponentType}) : TreeNodeId base/tealdef/gui/layers/layer_react_util.d.tl:40

Call as layer_react_util.makeFilteredSelectorTooltips

Notes

Creates an action tooltip with the default entity tooltip, limited to entities with one of the given component types.

Parameter Type Description
selectedEntityRef ReactRefT<Engine.Entity> Reference that holds the hovered or selected entity.
preFilter {Engine.ComponentType} Component types to show tooltips for, usually the layer's getHudIconPreFilter().

Returns TreeNodeId

createDefaultFallbackColor(surface : GResColor, details : GResColor, overwriteMapSurface? : boolean, overwriteMapDetails? : boolean) : LayerConfig.ColorPassFn.FallbackColor base/tealdef/gui/layers/layer_react_util.d.tl:53

Call as layer_react_util.createDefaultFallbackColor

Notes

Creates the fallback color of a layer's color pass, used for everything that no specific painter colors.

Parameter Type Description
surface GResColor Color for terrain, water and other surfaces.
details GResColor Color for edges, nodes and parallel strips.
overwriteMapSurface? boolean Passed to BaseColor.fromColor for the surface color.
overwriteMapDetails? boolean Passed to BaseColor.fromColor for the details color.

Returns LayerConfig.ColorPassFn.FallbackColor: A new LayerConfig.ColorPassFn.FallbackColor.

Example

colorPassFn.fallbackColor = layer_react_util.createDefaultFallbackColor(layerColors.Noise.Fallback.Surface, layerColors.Noise.Fallback.Details)
Used in the base game: 8 times in 6 files

base/content/gui/gui/line_vehicle_mgmt/line_util.tl:1059

colorPassFn.fallbackColor = layer_react_util.createDefaultFallbackColor(layerColors.Terrain.Fallback.Surface, layerColors.Terrain.Fallback.Details, true, true)
base/content/gui/gui/construction/construction_react_util.tl:610
colorPassFn.fallbackColor = layer_react_util.createDefaultFallbackColor(layerColors.Construction.Fallback.Surface, layerColors.Construction.Fallback.Details)
base/content/gui/gui/statistics/statistics.tl:461
fallbackColor = layer_react_util.createDefaultFallbackColor(hudGuiConfig.colors.FallbackVehicle, hudGuiConfig.colors.FallbackVehicle, true, true),
base/content/gui/gui/entity_window/maintenance_station/maintenance_station.tl:164
fallbackColor = layer_react_util.createDefaultFallbackColor(hudGuiConfig.colors.FallbackVehicle, hudGuiConfig.colors.FallbackVehicle, true, true),
base/content/gui/gui/entity_window/vehicle/vehicle.tl:581
fallbackColor = layer_react_util.createDefaultFallbackColor(hudGuiConfig.colors.FallbackVehicle, hudGuiConfig.colors.FallbackVehicle, true, true),
base/content/gui/gui/entity_window/town/town.tl:63
colorPassFn.fallbackColor = layer_react_util.createDefaultFallbackColor(layerColors.CargoFlow.Fallback.Surface, layerColors.CargoFlow.Fallback.Details)

LayerReactUtil.GradientColorsOf2

record base/tealdef/gui/layers/layer_react_util.d.tl:4

record GradientColorsOf2

Notes

Input of makeGradientColorsOf2, a gradient between two colors.

Used in the base game: 1 time in 1 file

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

function layer_react_util.makeGradientColorsOf2(params : LayerReactUtil.GradientColorsOf2) : {LayerReactUtil.GradientColor}

Fields

Name Type Description
colorA Vec4f Color of the first step.
colorB Vec4f Color of the last step.
numberOfLevels integer Number of steps.
labelLeft string Label of the first step (default "Low").
labelRight string Label of the last step (default "High").
iterativeLabels boolean If true, every step is labelled with its number instead of using labelLeft and labelRight.

LayerReactUtil.GradientColorsOf3

record base/tealdef/gui/layers/layer_react_util.d.tl:13

record GradientColorsOf3

Notes

Gradient definition with three colors; no function in the base game takes it.

Fields

Name Type Description
colorA Vec4f
colorB Vec4f
colorC Vec4f
numberOfLevels integer
labelLeft string
labelRight string
iterativeLabels boolean

LayerReactUtil.GradientColorsOfN

record base/tealdef/gui/layers/layer_react_util.d.tl:23

record GradientColorsOfN

Notes

Input of makeGradientColorsOfN, a gradient through several colors.

Used in the base game: 1 time in 1 file

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

function layer_react_util.makeGradientColorsOfN(params : LayerReactUtil.GradientColorsOfN) : {LayerReactUtil.GradientColor}

Fields

Name Type Description
colors {Vec4f} Colors to interpolate between, in order.
numberOfLevels integer Total number of steps; split evenly between each pair of neighbouring colors.
labels {string} Optional labels, one per color, placed on the step where that color starts.

LayerReactUtil.GradientColor

record base/tealdef/gui/layers/layer_react_util.d.tl:29

record GradientColor

Notes

One step of a legend gradient.

Used in the base game: 4 times in 1 file

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

function layer_react_util.makeGradientColorsOf2(params : LayerReactUtil.GradientColorsOf2) : {LayerReactUtil.GradientColor}

Fields

Name Type Description
color Vec4f Color of the step.
label string Label of the step (may be empty).

LayerReactUtil.LayerLegendWrapperParam

record base/tealdef/gui/layers/layer_react_util.d.tl:42

record LayerLegendWrapperParam

Notes

Parameter of LayerLegendWrapper.

Used in the base game: 1 time in 1 file

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

layer_react_util.LayerLegendWrapper = react.RegisterRecipe("LayerLegendWrapper", function(param : LayerReactUtil.LayerLegendWrapperParam) : TreeNodeId

Fields

Name Type Description
content TreeNodeId Node to wrap.

LayerReactUtil.LayerLegendFakeWindowParam

record base/tealdef/gui/layers/layer_react_util.d.tl:47

record LayerLegendFakeWindowParam

Notes

Parameter of LayerLegendFakeWindow.

Used in the base game: 2 times in 2 files

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

layer_react_util.LayerLegendFakeWindow = react.RegisterRecipe("LayerLegendFakeWindow", function(param : LayerReactUtil.LayerLegendFakeWindowParam) : TreeNodeId
base/content/gui/gui/entity_window/town/town.tl:141
local TownLayerLegendOnFullscreen = react.RegisterRecipe("TownLayerLegendOnFullscreen", function(param : LayerReactUtil.LayerLegendFakeWindowParam) : TreeNodeId

Fields

Name Type Description
title string Optional title shown above the legend.
legendRecipe Recipe0 Legend recipe to show, e.g. LayerTraffic.Legend.