Skip to content

view_manager

Source: base/tealdef/gui/entity_window/view_manager.d.tl

Notes

Types of the entity window manager (/gui/entity_window/view_manager.tl) and of the functions that build entity window contents (make_entity_window.tl, make_non_entity_window.tl). Also the return type that a construction's or model's entityWindowScript must produce.

IEntityWindowParam

interface global base/tealdef/gui/entity_window/view_manager.d.tl:3

global interface IEntityWindowParam

Notes

Base parameters passed to every entity window content recipe (vehicle, town, industry, station ... windows).

Details

Content recipes are created by make_entity_window.makeEntityWindowContent and returned inside a ViewManager.MakeEntityWindowResult. A content recipe typically calls params.setActionFn(...) to set the selector action of the window (e.g. selector_react_util.makeDefaultSelectorAction(params.gameCtx, layerConfig, true)).

Fields

Name Type Description
meta Meta React meta data of the content; the base game sets a tag such as "temp.view.entity.content.vehicle".
keyEntity Engine.Entity The entity which the window is displaying (mutually exclusive with keyNonEntity)
replacedEntity Engine.Entity Subconstruction the window was opened for when the window shows its parent construction; used to pre-select the matching tab.
keyNonEntity string Special case where EntityWindow tool is used for non-entities (mutually exclusive with keyEntity)
gameCtx GameContext Game context of the GUI.
simple boolean Set to true when the content is shown as a tab inside a ConstructionWindow.
isMapEditor boolean True when the window is opened in the map editor.
isSandboxMode boolean True when the game runs in sandbox mode.
setActionFn_compareProxy any Value compared instead of setActionFn when React checks whether the parameters changed.
closeFn_compareProxy any Value compared instead of closeFn when React checks whether the parameters changed.

Functions

setActionFn(actionFn? : (function() : TreeNodeId), key2? : string) base/tealdef/gui/entity_window/view_manager.d.tl:16

Notes

Sets the action function (the active selector or tool shown while the window is focused); key2 is an optional key that identifies the action.

closeFn() base/tealdef/gui/entity_window/view_manager.d.tl:18

Notes

Closes the window.

SetActionFnAndProxy

record global base/tealdef/gui/entity_window/view_manager.d.tl:22

global record SetActionFnAndProxy<T>

Notes

An action setter function together with its comparison proxy, returned by ViewManager.MakeEntityWindowContentFn.makeSetActionFnWithCombinedKey.

Fields

Name Type Description
proxy any Comparison proxy to pass as IEntityWindowParam.setActionFn_compareProxy.

Functions

fn(actionFn? : (function() : TreeNodeId), key2? : string) base/tealdef/gui/entity_window/view_manager.d.tl:23

Notes

Action setter to pass as IEntityWindowParam.setActionFn.

ConstructionWindowParam

record global base/tealdef/gui/entity_window/view_manager.d.tl:27

global record ConstructionWindowParam is IEntityWindowParam

Notes

Parameters of ViewManager.MakeEntityWindowContentFn.ConstructionWindow, the window of a construction with several parts shown as tabs.

Fields

Name Type Description
initialSubconstruction Engine.Entity Subconstruction whose tab is selected initially.
customTabs {ConData} Extra tabs added before the subconstruction tabs, e.g. the "Landmark" tab added by the landmark entityWindowScript.

Functions

filter(Engine.Entity) : boolean base/tealdef/gui/entity_window/view_manager.d.tl:40

Notes

Only subconstructions for which this returns true get a tab.

Returns boolean

ConstructionWindowParam.ConData

record base/tealdef/gui/entity_window/view_manager.d.tl:28

record ConData

Notes

One tab of a ConstructionWindow.

Used in the base game: 7 times in 3 files

base/content/landmarks/landmark_hud.script.tl:29

local customTabs : {ConstructionWindowParam.ConData} = {}
base/content/gui/gui/entity_window/make_entity_window.tl:121
subconstructions : {ConstructionWindowParam.ConData}
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:37
local customTabs : {ConstructionWindowParam.ConData} = {}

Fields

Name Type Description
entity Engine.Entity Subconstruction (or construction) entity shown in the tab.
name string Entity name of the tab's entity.
description string Tab label, e.g. "Train Station", "Depot", "Industry", "Landmark".
subconstructionIndex integer 1-based index in the construction's subconstructions; -1 means the construction itself.
sortKey integer Sort key of the tab (lower first); the base game uses values such as 6000 for industries and 11000+ for stations.
customTabData ViewManager.MakeEntityWindowResult Ready-made window content for the tab; when nil, the content of the subconstruction is built with makeEntityWindowContent.

ViewManager

record global base/tealdef/gui/entity_window/view_manager.d.tl:43

global record ViewManager

Load: local view_manager = ug_require "/gui/entity_window/view_manager.tl"

Notes

Manager of the entity windows; opens a window when an entity is selected.

Details

The ViewManager recipe listens to the React events selectEntity ({entity, stack, dontBlink}), selectViewKey ({entity, nonEntity, stack, dontBlink, extraParam}, for windows of non-entities such as missions and subsidies) and closeAllWindows. To open the window of an entity from GUI code, fire react.fireEvent(nil, "selectEntity", { entity = entity, stack = true }); with stack = false other unpinned windows are closed first.

Fields

Name Type Description
ViewManager Recipe<ViewManagerParam> Recipe that opens and closes entity windows in reaction to the selectEntity, selectViewKey and closeAllWindows events; renders nothing itself. used 2× in the base game

Functions

getEntityDetailsDefaultTool(gameCtx : GameContext, isMapEditor : boolean, isSandboxMode : boolean, sharedStateRef : ReactRefT<ViewManager.ViewManagerParam.SharedState>) : ReactToolDefinition<any>, any base/tealdef/gui/entity_window/view_manager.d.tl:116

Call as view_manager.getEntityDetailsDefaultTool

get the EntityDetailsTool + parameters to be used for the special case of it being the default tool

Returns ReactToolDefinition<any>, any

Used in the base game: 1 time in 1 file

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

local defaultTool, defaultToolParam = view_manager.getEntityDetailsDefaultTool(gameCtx, params.isMapEditor, params. isSandboxMode, sharedStateRef)

ViewManager.MakeEntityWindowResult

record base/tealdef/gui/entity_window/view_manager.d.tl:44

record MakeEntityWindowResult

Notes

Description of the content of an entity window: which recipe to show with which parameter, plus title, locate and auto-close behaviour. Also the return value of an entityWindowScript function.

Used in the base game: 14 times in 9 files

base/content/landmarks/landmark_hud.script.tl:25

entityRevisionCloseConditionAndProxy : ({(function() : boolean), any})) : ViewManager.MakeEntityWindowResult
base/content/mission/mission/mission_framework/mission_framework_react.tl:1375
extraParam : any) : ViewManager.MakeEntityWindowResult
base/content/gui/gui/entity_window/make_entity_window.tl:122
content : ViewManager.MakeEntityWindowResult
base/content/gui/gui/entity_window/make_non_entity_window.tl:16
extraParam : any) : ViewManager.MakeEntityWindowResult
base/content/gui/gui/entity_window/view_manager.tl:175
local recipeAndParamsState = engine_react_util.useStepState(function() : ViewManager.MakeEntityWindowResult
base/content/game_mechanics/game_mechanics/subventions/subventions_gui.tl:513
extraParam : any) : ViewManager.MakeEntityWindowResult
… and 3 more files.

Fields

Name Type Description
recipe Recipe<IEntityWindowParam> Content recipe, called with param.
builtin Recipe<Builtin.ICompParam> Built-in component recipe used when recipe is nil; called with {entity = param.keyEntity}.
param IEntityWindowParam parameter used only as argument to the recipe (i.e. you can put a subclass here and downcast inside the recipe)
replacedEntity Engine.Entity Entity renamed by editing the window title instead of the window's key entity (e.g. the construction for a construction window).
autoCloseCondition_compareProxy any Value compared instead of autoCloseCondition when React checks whether the parameters changed.
fallbackTitle string Window title used when the entity has no name, e.g. "Vehicle" or "Construction".
locate_compareProxy any Value compared instead of locate when React checks whether the parameters changed.

Functions

autoCloseCondition() : boolean base/tealdef/gui/entity_window/view_manager.d.tl:52

Notes

Function returning true when the window should close (the base game closes it when the entity no longer exists or its revision changed).

Returns boolean

locate() base/tealdef/gui/entity_window/view_manager.d.tl:55

Notes

Called by the window's locate button; by default the camera follows the key entity.

ViewManager.MakeEntityWindowContentFn

record base/tealdef/gui/entity_window/view_manager.d.tl:59

record MakeEntityWindowContentFn

Load: local make_entity_window = ug_require "/gui/entity_window/make_entity_window.tl"

Notes

Interface of /gui/entity_window/make_entity_window.tl, which picks the content recipe for an entity.

Used in the base game: 4 times in 4 files

base/content/landmarks/landmark_hud.script.tl:4

local make_entity_window = ug_require "/gui/entity_window/make_entity_window.tl" as ViewManager.MakeEntityWindowContentFn
base/content/gui/gui/entity_window/make_entity_window.tl:24
local make_entity_window : ViewManager.MakeEntityWindowContentFn = {}
base/content/gui/gui/entity_window/view_manager.tl:9
local make_entity_window = ug_require "/gui/entity_window/make_entity_window.tl" as ViewManager.MakeEntityWindowContentFn
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:4
local make_entity_window = ug_require "/gui/entity_window/make_entity_window.tl" as ViewManager.MakeEntityWindowContentFn

Fields

Name Type Description
ConstructionWindow Recipe<IEntityWindowParam> Window content of a construction with one tab per relevant subconstruction (station, depot, industry, warehouse) and optional custom tabs; the parameter is a ConstructionWindowParam. used 4× in the base game

Functions

makeEntityWindowContent(entity : Engine.Entity, gameCtx : GameContext, isMapEditor : boolean, isSandboxMode : boolean, skipConstruction : boolean, setActionFnAndProxy : {function(actionFn? : (function() : TreeNodeId), key2? : string), any}, entityRevisionCloseConditionAndProxy : ({(function() : boolean), any}), closeFnAndProxy : {function(), any}, filter? : (function(Engine.Entity) : boolean), replacedEntity? : Engine.Entity) : MakeEntityWindowResult base/tealdef/gui/entity_window/view_manager.d.tl:60

Call as make_entity_window.makeEntityWindowContent

Notes

Builds the window content for an entity, choosing the recipe by the entity's components.

Parameter Type Description
entity Engine.Entity Entity to show.
gameCtx GameContext Game context.
isMapEditor boolean True in the map editor.
isSandboxMode boolean True in sandbox mode.
skipConstruction boolean Do not resolve the construction of the entity (used for the tabs of a construction window).
setActionFnAndProxy {function(actionFn? : (function() : TreeNodeId), key2? : string), any} Action setter and its comparison proxy.
entityRevisionCloseConditionAndProxy ({(function() : boolean), any}) Auto-close condition and its comparison proxy; may be nil.
closeFnAndProxy {function(), any} Close function and its comparison proxy.
filter? (function(Engine.Entity) : boolean) Only subconstructions passing this filter are shown.
replacedEntity? Engine.Entity Subconstruction whose tab is selected initially.

Returns MakeEntityWindowResult: The content description, or nil if no window exists for the entity.

Details

If the entity belongs to a construction whose description has an entityWindowScript, that script function is called instead (with the script's params, the construction entity, a tag prefix, gameCtx, isMapEditor, isSandboxMode, setActionFnAndProxy and entityRevisionCloseConditionAndProxy) and must return a MakeEntityWindowResult; the landmarks and the pollution cleanup facility use this. Models of custom-state entities can name such a script in metadata.metadata.entityWindowScript. Constructions with more than one relevant subconstruction get a ConstructionWindow with tabs.

Used in the base game: 1 time in 1 file

base/content/gui/gui/entity_window/view_manager.tl:181

return make_entity_window.makeEntityWindowContent(params.keyEntity, params.gameCtx, params.isMapEditor,

makeSetActionFnWithCombinedKey<T>(recipe : Recipe<T>, innerSetActionFnAndProxy : {function(actionFn? : (function() : TreeNodeId), key2? : string), any}) : SetActionFnAndProxy<T> base/tealdef/gui/entity_window/view_manager.d.tl:74

Call as make_entity_window.makeSetActionFnWithCombinedKey

Notes

Wraps an action setter so that the action key is prefixed with the recipe name.

Parameter Type Description
recipe Recipe<T> Content recipe whose name is used as key prefix.
innerSetActionFnAndProxy {function(actionFn? : (function() : TreeNodeId), key2? : string), any} Outer action setter and its comparison proxy.

Returns SetActionFnAndProxy<T>: The wrapped setter and a matching comparison proxy, to pass as setActionFn and setActionFn_compareProxy.

Used in the base game: 4 times in 2 files

base/content/landmarks/landmark_hud.script.tl:27

local actionFnAndProxy = make_entity_window.makeSetActionFnWithCombinedKey(make_entity_window.ConstructionWindow, setActionFnAndProxy)
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:35
local actionFnAndProxy = make_entity_window.makeSetActionFnWithCombinedKey(make_entity_window.ConstructionWindow, setActionFnAndProxy)

ViewManager.MakeNonEntityWindowContentFn

record base/tealdef/gui/entity_window/view_manager.d.tl:78

record MakeNonEntityWindowContentFn

Load: local make_non_entity_window = ug_require "/gui/entity_window/make_non_entity_window.tl"

Notes

Interface of /gui/entity_window/make_non_entity_window.tl, which builds windows that do not show an entity.

Used in the base game: 2 times in 2 files

base/content/gui/gui/entity_window/make_non_entity_window.tl:5

local make_non_entity_window : ViewManager.MakeNonEntityWindowContentFn = {}
base/content/gui/gui/entity_window/view_manager.tl:10
local make_non_entity_window = ug_require "/gui/entity_window/make_non_entity_window.tl" as ViewManager.MakeNonEntityWindowContentFn

Functions

makeNonEntityWindowContent(nonEntity : string, gameCtx : GameContext, isMapEditor : boolean, isSandboxMode : boolean, setActionFnAndProxy : {function(actionFn? : (function() : TreeNodeId), key2? : string), any}, closeFnAndProxy : {function(), any}, extraParam : any) : MakeEntityWindowResult base/tealdef/gui/entity_window/view_manager.d.tl:79

Call as make_non_entity_window.makeNonEntityWindowContent

Notes

Builds the window content for a non-entity key.

Parameter Type Description
nonEntity string Window key; the base game handles "mission" and keys starting with "subsidy_".
gameCtx GameContext
isMapEditor boolean
isSandboxMode boolean
setActionFnAndProxy {function(actionFn? : (function() : TreeNodeId), key2? : string), any}
closeFnAndProxy {function(), any}
extraParam any Extra parameter passed with the selectViewKey event.

Returns MakeEntityWindowResult: The content description, or nil for unknown keys.

Used in the base game: 1 time in 1 file

base/content/gui/gui/entity_window/view_manager.tl:184

return make_non_entity_window.makeNonEntityWindowContent(params.keyNonEntity, params.gameCtx, params.isMapEditor, params.isSandboxMode, {setActionFn, setActionF

ViewManager.EntityWindowState

record base/tealdef/gui/entity_window/view_manager.d.tl:89

record EntityWindowState

Notes

Bookkeeping of one open entity window in ViewManagerParam.SharedState.openEntityWindows.

Used in the base game: 5 times in 1 file

base/content/gui/gui/entity_window/view_manager.tl:352

local openEntities : {(Engine.Entity | string) : ViewManager.EntityWindowState} = param.sharedStateRef:get().openEntityWindows

Fields

Name Type Description
revision Engine.Revision Revision of the entity when the window was opened.
pinned boolean True when the window is pinned (stays open when other windows open).
handoverToPinned boolean Set when the window was pinned; the window is then handed over to the default entity window tool.
extraParam any Extra parameter the window was opened with (selectViewKey event).
actionFnKey string Key of actionFn.

Functions

actionFn() : TreeNodeId base/tealdef/gui/entity_window/view_manager.d.tl:94

Notes

Action function set by the window content with setActionFn; applied while the window is active.

Returns TreeNodeId

ViewManager.ViewManagerParam

record base/tealdef/gui/entity_window/view_manager.d.tl:98

record ViewManagerParam

Notes

Parameters of the ViewManager recipe.

Used in the base game: 1 time in 1 file

base/content/gui/gui/entity_window/view_manager.tl:524

view_manager.ViewManager = react.RegisterRecipe("ViewManager", function(params : ViewManager.ViewManagerParam) : TreeNodeId

Fields

Name Type Description
refRc ReactNodeRefApiT<Builtin.RendererComponent>
gameCtx GameContext Game context.
isMapEditor boolean True in the map editor.
isSandboxMode boolean True in sandbox mode.
sharedStateRef ReactRefT<SharedState> these need to be owned by the parent

ViewManager.ViewManagerParam.SharedState

record base/tealdef/gui/entity_window/view_manager.d.tl:104

record SharedState

Notes

State of the open entity windows, shared between the ViewManager and the entity window tool.

Used in the base game: 3 times in 2 files

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

local sharedStateRef : ReactRefT<ViewManager.ViewManagerParam.SharedState> = react.useRef({
base/content/gui/gui/entity_window/view_manager.tl:25
sharedStateRef : ReactRefT<ViewManager.ViewManagerParam.SharedState>

Fields

Name Type Description
openEntityWindows {(Engine.Entity | string) : EntityWindowState} Open windows by key (entity id, or the non-entity key string).
activeEntityWindow (Engine.Entity | string) Key of the window that has focus.
windowOrder {(Engine.Entity | string)} Keys of the open windows; the front-most window is last.
forceBlink boolean