Skip to content

construction_react_util

Source: base/tealdef/gui/construction/construction_react_util.d.tl

Notes

Helper module of the construction menu (::/gui/construction/construction_react_util.tl). Builds the menu entries from the resource repositories (constructions, streets, tracks, modules, terrain materials, construction_tool resources, edge decorations), converts script parameters into menu parameters and creates the parameters of the construction action.

StampData

record global base/tealdef/gui/construction/construction_react_util.d.tl:3

global record StampData

Notes

Data of a stamp resource, a heightmap stamp for the terrain heightmap tool.

Example

-- base/content/gui/gui/construction/shared/tex/stamps/temperate_hill1.res.lua
function data()
    return {
        type = "stamp",
        data = {
            heightmap = resolve("temperate_hill1.png"),
            icon = resolve("temperate_hill1.tga")
        }
    }
end

Fields

Name Type Description
heightmap string Heightmap image of the stamp.
icon string Icon shown for the stamp in the tool's "Heightmap" parameter.

ConstructionReactUtil

record global base/tealdef/gui/construction/construction_react_util.d.tl:8

global record ConstructionReactUtil

Load: local construction_react_util = ug_require "::/gui/construction/construction_react_util.tl"

Notes

Helper module of the construction menu. Load it with ug_require "::/gui/construction/construction_react_util.tl".

Fields

Name Type Description
SimpleTooltipRecipe Recipe<ConstructionReactUtil.SimpleTooltipRecipeParams> Recipe of a simple action tooltip with a message line and an optional cost line. used 4× in the base game

Functions

getConstructionDefinitions() : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:44

Call as construction_react_util.getConstructionDefinitions

Notes

Creates menu entries for all constructions and meta constructions; constructions with templates get one entry per template.

Returns {ConstructionDefinition}

Details

Constructions without a menu category are skipped. Edge object constructions become ACTION_STREET_TERMINAL_BUILDER entries, all others ACTION_CONSTRUCTION_BUILDER.

convertScriptParamsToMenuParams(descParams : {ScriptParam}, filterByPostconstructionModifiable? : boolean) : {ConstructionMenuParam} base/tealdef/gui/construction/construction_react_util.d.tl:45

Call as construction_react_util.convertScriptParamsToMenuParams

Notes

Converts script parameters of a construction description into menu parameters.

Parameter Type Description
descParams {ScriptParam} Script parameters.
filterByPostconstructionModifiable? boolean Keeps only parameters flagged postConstructionModifiable.

Returns {ConstructionMenuParam}

Used in the base game: 3 times in 1 file

base/content/gui/gui/construction/construction.tl:1245

local menuParams = construction_react_util.convertScriptParamsToMenuParams(desc.params, true)

getPerksProspectionDefinitions() : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:46

Call as construction_react_util.getPerksProspectionDefinitions

Notes

Creates the prospection perk entries from the company_exploration resources (with required tags) of the current economy.

Returns {ConstructionDefinition}

getModuleDefinitions() : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:47

Call as construction_react_util.getModuleDefinitions

Notes

Creates ACTION_MODULE_BUILDER entries for all modules that have a menu category.

Returns {ConstructionDefinition}

getStreetDefinitions(tramOnly? : boolean) : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:48

Call as construction_react_util.getStreetDefinitions

Notes

Creates street builder entries for all street templates of road type STREET.

Parameter Type Description
tramOnly? boolean Returns only tram-only roads.

Returns {ConstructionDefinition}

getStreetToolsHudIcons(depotType : ConstructionActionHudIconConstructionType) : ConstructionActionHudIcons base/tealdef/gui/construction/construction_react_util.d.tl:49

Call as construction_react_util.getStreetToolsHudIcons

Notes

HUD icon configuration for street tools (industries, towns, stations, depots, warehouses).

Parameter Type Description
depotType ConstructionActionHudIconConstructionType Carrier filter for depot icons.

Returns ConstructionActionHudIcons

Used in the base game: 6 times in 6 files

base/content/gui/gui/construction/tools/crosswalk_modifier_tool.script.tl:30

hudIcons = construction_react_util.getStreetToolsHudIcons("ROAD"),
base/content/gui/gui/construction/tools/bus_lane_tool.script.tl:31
hudIcons = construction_react_util.getStreetToolsHudIcons("ROAD"),
base/content/gui/gui/construction/tools/tram_track_tool.script.tl:60
hudIcons = construction_react_util.getStreetToolsHudIcons("TRAM"),
base/content/gui/gui/construction/tools/lane_modifier_tool.script.tl:39
hudIcons = construction_react_util.getStreetToolsHudIcons("ROAD"),
base/content/gui/gui/construction/tools/player_owned_tool.script.tl:25
hudIcons = construction_react_util.getStreetToolsHudIcons("ROAD"),
base/content/gui/gui/construction/tools/traffic_light_tool.script.tl:21
hudIcons = construction_react_util.getStreetToolsHudIcons("ROAD"),

getTrackDefinitions() : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:50

Call as construction_react_util.getTrackDefinitions

Notes

Creates track builder entries for all street templates of road type TRACK, sorted by speed.

Returns {ConstructionDefinition}

getMaterialsDefinitions(terrainToolData : ConstructionToolParam.TerrainToolData, includeEraser : boolean) : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:51

Call as construction_react_util.getMaterialsDefinitions

Notes

Creates terrain painter entries for all terrain materials, sorted by their order.

Parameter Type Description
terrainToolData ConstructionToolParam.TerrainToolData Size data for the brush parameters.
includeEraser boolean Adds the material eraser entry (resIndex 0).

Returns {ConstructionDefinition}

forEachDefinition(fn : function(definition : ConstructionDefinition), repository : ConstructionActionRepository) base/tealdef/gui/construction/construction_react_util.d.tl:55

Call as construction_react_util.forEachDefinition

Note: no ordering guarantees. The same item might appear more than once (if actually present in multiple tabs). SLOW!

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:4284

construction_react_util.forEachDefinition(append, params.repository)

makeItemDisabledCache(allDefinitions : {ConstructionDefinition}) : ItemDisableCache base/tealdef/gui/construction/construction_react_util.d.tl:57

Call as construction_react_util.makeItemDisabledCache

Notes

Creates the cache for checkItemDisabledDefault and checkItemRemainingNum from all menu entries.

Returns ItemDisableCache

Used in the base game: 2 times in 1 file

base/content/gui/gui/construction/construction.tl:4301

itemDisableCacheRef:set(construction_react_util.makeItemDisabledCache(refAllDefinitions:get()))

checkItemDisabledDefault(ConstructionDefinition, cache : ItemDisableCache) : ItemDisableReason base/tealdef/gui/construction/construction_react_util.d.tl:58

Call as construction_react_util.checkItemDisabledDefault

Notes

Checks the company permits of an entry.

Returns ItemDisableReason: The reason the entry is disabled, or nil if it is usable.

Used in the base game: 3 times in 1 file

base/content/gui/gui/construction/construction.tl:277

local disabledReason = params.itemDisableCacheRef and construction_react_util.checkItemDisabledDefault(definition, params.itemDisableCacheRef:get()) or nil

checkItemRemainingNum(definition : ConstructionDefinition, cache : ItemDisableCache) : integer | nil base/tealdef/gui/construction/construction_react_util.d.tl:59

Call as construction_react_util.checkItemRemainingNum

Notes

Returns how many uses of an entry's company permit remain, or nil if not limited.

Returns integer | nil

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:286

construction_react_util.checkItemRemainingNum(definition, params.itemDisableCacheRef:get()) or nil

makeUndergroundParam(stepValueFn : (function(value : integer, direction : integer, precise : boolean) : integer), checkEnabledFn? : (function(params : {string : number}) : ConstructionMenuParam.CheckEnabledResult), defaultUnderground? : boolean) : ConstructionMenuParam base/tealdef/gui/construction/construction_react_util.d.tl:61

Call as construction_react_util.makeUndergroundParam

Notes

Creates the toolbar parameter undergroundMode ("Underground", Yes/No) that shows and snaps only to underground objects. Its value is preserved across categories.

Parameter Type Description
stepValueFn (function(value : integer, direction : integer, precise : boolean) : integer) Step function of the parameter.
checkEnabledFn? (function(params : {string : number}) : ConstructionMenuParam.CheckEnabledResult) Enabled check of the parameter.
defaultUnderground? boolean Makes "Yes" the default.

Returns ConstructionMenuParam

Used in the base game: 7 times in 7 files

base/content/gui/gui/construction/tools/crosswalk_modifier_tool.script.tl:26

construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, __ : boolean) : integer
base/content/gui/gui/construction/tools/bus_lane_tool.script.tl:27
construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, __ : boolean) : integer
base/content/gui/gui/construction/tools/tram_track_tool.script.tl:56
construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, __ : boolean) : integer
base/content/gui/gui/construction/tools/rail_electrification_tool.script.tl:18
construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, ___ : boolean) : integer
base/content/gui/gui/construction/tools/lane_modifier_tool.script.tl:34
construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, __ : boolean) : integer
base/content/gui/gui/construction/tools/player_owned_tool.script.tl:21
construction_react_util.makeUndergroundParam(function(value : integer, __ : integer, __ : boolean) : integer
… and 1 more files.

getBrushConstructionParams(args : ConstructionReactUtil.BrushConstructionArgs) : {ConstructionMenuParam} base/tealdef/gui/construction/construction_react_util.d.tl:81

Call as construction_react_util.getBrushConstructionParams

Notes

Creates the toolbar parameters of a brush tool (size, strength, rotation, brush shape and the optional parameters selected in args).

Returns {ConstructionMenuParam}

Used in the base game: 6 times in 5 files

base/content/gui/gui/construction/tools/terrain_painter_eraser_tool.script.tl:23

params = construction_react_util.getBrushConstructionParams({
base/content/gui/gui/construction/tools/mixed_assets.script.tl:66
local params = construction_react_util.getBrushConstructionParams({
base/content/gui/gui/construction/tools/vegetation_eraser_tool.script.tl:24
params = construction_react_util.getBrushConstructionParams({
base/content/gui/gui/construction/tools/asset_eraser_tool.script.tl:24
params = construction_react_util.getBrushConstructionParams({
base/content/gui/gui/construction/tools/terrain_tools.script.tl:6
return construction_react_util.getBrushConstructionParams({

getMenuCategories(repository : ConstructionActionRepository) : {ConstructionMenu : {{ConstructionMenuCategory, {ConstructionDefinition}}}} base/tealdef/gui/construction/construction_react_util.d.tl:83

Call as construction_react_util.getMenuCategories

Notes

Groups all menu entries by construction menu tab and menu_category, sorted by category order and entry order.

Returns {ConstructionMenu : {{ConstructionMenuCategory, {ConstructionDefinition}}}}: For each menu tab, a list of {category, definitions} pairs.

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:4363

return initCategories(refEntity, params.bulldozerHudIconFilter, construction_react_util.getMenuCategories(params.repository))

getConstructionActionRepository(terrainToolData : ConstructionToolParam.TerrainToolData, hasHeightMapTextureTool : boolean) : ConstructionActionRepository base/tealdef/gui/construction/construction_react_util.d.tl:85

Call as construction_react_util.getConstructionActionRepository

Notes

Creates the repository with all heightmap stamps, ordered cargo types and land-use cargo types.

Returns ConstructionActionRepository

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:5027

repository = construction_react_util.getConstructionActionRepository(param.payload.toolParam.terrainToolData, param.payload.toolParam.hasHeightMapTextureTool),

getActionParams(definition : ConstructionDefinition, params : {string : number}, repository : ConstructionActionRepository, isGamepadMode : boolean, refParams : ReactRefWrapApiT<any, ConstructionMenuParamsAPI>, entity : Engine.Entity, accessNotificationCacheFn : (function(Engine.Entity) : {Notification}), sublistParamsApi : ReactRefWrapApiT<any, ConstructionMenuParamsAPI>) : ConstructionMenuActionParams base/tealdef/gui/construction/construction_react_util.d.tl:86

Call as construction_react_util.getActionParams

Notes

Creates the construction action, HUD icon and layer parameters for a menu entry and its current parameter values, including the input action handlers of its toolbar parameters.

Returns ConstructionMenuActionParams

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:4437

local actionParams = construction_react_util.getActionParams(

getAllCompanyDefinitions(terrainToolData : ConstructionToolParam.TerrainToolData) : {ConstructionDefinition} base/tealdef/gui/construction/construction_react_util.d.tl:92

Call as construction_react_util.getAllCompanyDefinitions

Very slow -> Do not use! If needed, get allCompanyDefinitionsCacheRef from game.tl

Returns {ConstructionDefinition}

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/game.tl:314

return construction_react_util.getAllCompanyDefinitions(terrainToolDataRef:get())

constructIcon(icon : IconWithAvailability, locked : boolean) : TreeNodeId base/tealdef/gui/construction/construction_react_util.d.tl:94

Call as construction_react_util.constructIcon

Notes

Creates the icon node of a menu entry (the year-dependent or locked icon if applicable).

Returns TreeNodeId

Used in the base game: 3 times in 2 files

base/content/gui/gui/construction/construction.tl:354

innerItem = construction_react_util.constructIcon(internalState:old().icon, true)
base/content/game_mechanics/game_mechanics/company/company.tl:159
} or construction_react_util.constructIcon(currentPerk.icon, false)) or nil,

mergeLayerConfig(fromConstructionItem : LayerConfig, preferredLayerConfig : LayerConfig) : LayerConfig base/tealdef/gui/construction/construction_react_util.d.tl:96

Call as construction_react_util.mergeLayerConfig

Notes

Returns the preferred layer configuration (the one chosen in the layers menu) if set, otherwise the configuration of the construction entry.

Returns LayerConfig

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:4474

local finalLayerConfig = construction_react_util.mergeLayerConfig(actionParams.layerConfig, layerToolLayerConfig:old())

makeWhiteScreen(layerConfig : LayerConfig, layerColors : LayerColors) base/tealdef/gui/construction/construction_react_util.d.tl:97

Call as construction_react_util.makeWhiteScreen

Notes

Sets a color pass on the layer configuration that renders the scene in the neutral construction fallback colors.

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction.tl:4228

construction_react_util.makeWhiteScreen(layerConfig, layerColors)

RegisterCustomSelectorBasedActionRecipe<P>(recipeName : string, outerParams : RegisterCustomSelectorBasedActionRecipeParams<P>) : Recipe<ConstructionCustomActionParams<P>> base/tealdef/gui/construction/construction_react_util.d.tl:100

Call as construction_react_util.RegisterCustomSelectorBasedActionRecipe

Notes

Registers a custom action recipe that lets the player pick an entity on the map, with tooltip, cursor and HUD icons. The base game uses it for the prospection, marketing and industry greenification perks.

Parameter Type Description
recipeName string Name of the recipe.
outerParams RegisterCustomSelectorBasedActionRecipeParams<P> Callbacks and selector filter.

Returns Recipe<ConstructionCustomActionParams<P>>: A recipe for ConstructionCustomAction.recipe.

Example

-- abridged from base/content/gui/gui/construction/tools/industry_greenify_tool.script.tl
local IndustryGreenifyRecipe = construction_react_util.RegisterCustomSelectorBasedActionRecipe("IndustryGreenifyAction", {
    onHover = function(__, entity : Engine.Entity) : SelectorBasedActionHoverResult
        return {
            param = {
                recipe = construction_react_util.SimpleTooltipRecipe,
                param = { message = { message = _("Select an Industry to Greenify") } },
            },
            mouseCursor = gui_react_util.getMouseCursorInteger("CompanyMechanics"),
        }
    end,
    onSelect = function(params : ConstructionCustomActionParams<string>, entity : Engine.Entity)
        -- send a command for the selected entity
    end,
    filter = componentFilter(api.type.ComponentType.INDUSTRY),
})
Used in the base game: 2 times in 2 files

base/content/gui/gui/construction/tools/marketing_campaign_tool.script.tl:23

local MarketingActionRecipe = construction_react_util.RegisterCustomSelectorBasedActionRecipe("MarketingAction", {
base/content/gui/gui/construction/tools/industry_greenify_tool.script.tl:16
local IndustryGreenifyRecipe = construction_react_util.RegisterCustomSelectorBasedActionRecipe("IndustryGreenifyAction", {

ConstructionReactUtil.ItemDisableCache

record base/tealdef/gui/construction/construction_react_util.d.tl:9

record ItemDisableCache

Notes

Cached company data used to decide whether menu entries are locked or used up; create it with makeItemDisabledCache.

Used in the base game: 12 times in 3 files

base/content/gui/gui/construction/construction_desc_react_util.tl:440

local getNumberOfAvailablePermitsFromCache = function(permitKey : ResName, cache : ConstructionReactUtil.ItemDisableCache) : integer
base/content/gui/gui/construction/construction.tl:113
itemDisableCacheRef : ReactRefT<ConstructionReactUtil.ItemDisableCache>
base/content/gui/gui/construction/construction_react_util.tl:1163
function construction_react_util.makeItemDisabledCache(allDefinitions : {ConstructionDefinition}) : ConstructionReactUtil.ItemDisableCache

Fields

Name Type Description
company CompanyUtil.ConstructionDisableCacheData Company permit data of all entries.

ConstructionReactUtil.ItemDisableReason

record base/tealdef/gui/construction/construction_react_util.d.tl:13

record ItemDisableReason

Notes

Why a menu entry is disabled.

Used in the base game: 3 times in 2 files

base/content/gui/gui/construction/construction.tl:3720

local disabledReason : ConstructionReactUtil.ItemDisableReason = params.itemDisableCacheRef and construction_react_util.checkItemDisabledDefault(definition, par
base/content/gui/gui/construction/construction_react_util.tl:1183
function construction_react_util.checkItemDisabledDefault(def : ConstructionDefinition, cache : ConstructionReactUtil.ItemDisableCache) : ConstructionReactUtil.

Fields

Name Type Description
reason string Message shown for the disabled entry.
elapsedCooldownFraction number Elapsed part of a cooldown (0 to 1), shown as progress on the entry.
category string Category of the reason; "company-rank" shows the entry as locked.

ConstructionReactUtil.ConstructionMenuSetTabEventParam

record base/tealdef/gui/construction/construction_react_util.d.tl:19

record ConstructionMenuSetTabEventParam

Notes

Parameter of the GUI event constructionMenuSetTab, which opens a construction menu tab.

Used in the base game: 3 times in 1 file

base/content/gui/gui/construction/construction.tl:2810

local evtParam = param as ConstructionReactUtil.ConstructionMenuSetTabEventParam

Fields

Name Type Description
tabIndex integer Index of the tab to open.
allowStacking boolean Passed to the tool stack when the construction tool is pushed.
sublistId string Id of the sub tab to select.

ConstructionReactUtil.ConstructionMenuSelectConstructionEventParam

record base/tealdef/gui/construction/construction_react_util.d.tl:25

record ConstructionMenuSelectConstructionEventParam

Notes

Parameter of the GUI event constructionMenuSelectTabForConstruction, which opens the menu tab containing a construction.

Example

-- base/content/game_mechanics/game_mechanics/notifications/types/con_availability.script.tl
react.fireEvent(nil, "constructionMenuSelectTabForConstruction", {
    resName = notificationParams.resName,
})
Used in the base game: 2 times in 2 files

base/content/gui/gui/construction/construction.tl:4890

local evtParam = param as ConstructionReactUtil.ConstructionMenuSelectConstructionEventParam
base/content/game_mechanics/game_mechanics/notifications/types/con_availability.script.tl:35
} as ConstructionReactUtil.ConstructionMenuSelectConstructionEventParam)

Fields

Name Type Description
resName ResName Resource name of the entry to find; an entry available in the current year is preferred.

ConstructionReactUtil.SimpleTooltipRecipeParams

record base/tealdef/gui/construction/construction_react_util.d.tl:29

record SimpleTooltipRecipeParams

Notes

Parameters of SimpleTooltipRecipe.

Used in the base game: 4 times in 3 files

base/content/gui/gui/construction/construction_react_util.tl:1208

construction_react_util.SimpleTooltipRecipe = react.RegisterRecipe("SimpleTooltipRecipe", function(params : ConstructionReactUtil.SimpleTooltipRecipeParams) : T
base/content/gui/gui/construction/tools/marketing_campaign_tool.script.tl:35
local tooltip : Builtin.ActionTooltipParam<ConstructionReactUtil.SimpleTooltipRecipeParams> = nil
base/content/gui/gui/construction/tools/industry_greenify_tool.script.tl:28
local tooltip : Builtin.ActionTooltipParam<ConstructionReactUtil.SimpleTooltipRecipeParams> = nil

Fields

Name Type Description
message MessageGoodOrBad Message line.
cost integer Cost in game currency; adds a "Cost" line, shown as bad when the player cannot afford it.

ConstructionReactUtil.SimpleTooltipRecipeParams.MessageGoodOrBad

record base/tealdef/gui/construction/construction_react_util.d.tl:30

record MessageGoodOrBad

Notes

A tooltip message with its style.

Used in the base game: 2 times in 1 file

base/content/gui/gui/construction/construction_react_util.tl:1209

local function makeStyle(message : ConstructionReactUtil.SimpleTooltipRecipeParams.MessageGoodOrBad) : string

Fields

Name Type Description
message string Text of the message.
good boolean Shows the message in the success style.
bad boolean Shows the message in the error style (if not good); otherwise it uses the information style.

ConstructionReactUtil.DefinitionWithFilterCategories

record base/tealdef/gui/construction/construction_react_util.d.tl:39

record DefinitionWithFilterCategories

Notes

A menu entry together with the filter categories of one of its menu categories.

Fields

Name Type Description
definition ConstructionDefinition The menu entry.
filterCategories {string} Filter categories of the entry in that menu category.

ConstructionReactUtil.BrushConstructionArgs

record base/tealdef/gui/construction/construction_react_util.d.tl:64

record BrushConstructionArgs

Notes

Options for getBrushConstructionParams.

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction_react_util.tl:2891

function construction_react_util.getBrushConstructionParams(args : ConstructionReactUtil.BrushConstructionArgs) : {ConstructionMenuParam}

Fields

Name Type Description
numSizes integer Number of brush sizes.
minSize number Smallest brush size.
maxSize number Largest brush size.
scale number Factor applied to the sizes for display.
prefix string Prefix of the parameter keys (for example terrainPainter gives terrainPainter_size).
defaultStrength number Default strength, from 0 to 1.
single boolean Adds a mode switch between single placement and brush mode, with a height parameter for single mode.
slope boolean Adds the incline threshold and "Paint Steep" parameters.
invert boolean Adds an "Invert" parameter.
invertTooltip string Tooltip of the "Invert" parameter.
randomize boolean Adds a "Random Rotation" parameter.
ignoreCollision boolean Adds a "No Collision" parameter (single mode).
eraseWhenEmpty boolean Makes eraser mode the default.
heightMaps {integer} Stamp resource ids; adds a "Heightmap" parameter with their icons.