tool_react_util¶
Source: base/tealdef/gui/main/tool_react_util.d.tl
Notes
Helpers for tools of the tool stack (gameCtx.toolStack): register a tool that opens a
window while it is active, and delegating tools that are pushed through React events.
ToolReactUtil¶
record global base/tealdef/gui/main/tool_react_util.d.tl:3
global record ToolReactUtil
Load: local tool_react_util = ug_require "/gui/main/tool_react_util.tl"
Notes
Tool registration helpers.
Functions
registerToolWithWindow<TP is IToolParam, WP is IToolWindowParam<TP>>(toolName : string, windowId : string, windowRecipe : Recipe<WP>, getDebugString? : (function(toolParam : TP) : string)) : ReactToolDefinition<TP> base/tealdef/gui/main/tool_react_util.d.tl:24
Call as tool_react_util.registerToolWithWindow
Notes
Registers a tool that shows a singleton window while it is on the tool stack.
| Parameter | Type | Description |
|---|---|---|
toolName |
string |
Name of the tool. |
windowId |
string |
GUI id of the window; it is hidden while the tool is shelved. |
windowRecipe |
Recipe<WP> |
Recipe of the window; it receives an IToolWindowParam. |
getDebugString? |
(function(toolParam : TP) : string) |
Optional; returns a debug description of the tool parameter. |
Returns ReactToolDefinition<TP>: The tool definition, to push with gameCtx.toolStack:get():getApi().push(tool, key, param).
Example
-- from music_player.tl
local musicPlayerWindowId = "musicPlayerWindow"
local MusicPlayerWindow = react.RegisterWrapperRecipe("MusicPlayerWindow", builtin.Window, function(params)
return builtin.Window{
title = _("Music Player"),
closable = true,
onClose = params.onClose,
content = MusicPlayer(params.payload),
id = musicPlayerWindowId,
}
end)
local MusicPlayerTool = tool_react_util.registerToolWithWindow("MusicPlayer", musicPlayerWindowId, MusicPlayerWindow)
-- game_bar.tl:
getToolStackApi(gameCtx).push(MusicPlayerTool, nil, {gameCtx = gameCtx})
Used in the base game: 5 times in 5 files
base/content/gui/gui/music_player/music_player.tl:285
local MusicPlayerTool = tool_react_util.registerToolWithWindow("MusicPlayer", musicPlayerWindowId, MusicPlayerWindow)
base/content/gui/gui/game_bar/game_bar_widgets.tl:835
game_bar_widgets.CalendarEditorTool = tool_react_util.registerToolWithWindow("CalendarEditor", calendarEditorWindowId, CalendarEditorWindow)
base/content/game_mechanics/game_mechanics/company/company.tl:962
local CompanyTool = tool_react_util.registerToolWithWindow("Company", companyWindowId, CompanyWindow, getDebugString)
base/content/game_mechanics/game_mechanics/finance/account.tl:162
local FinanceTool = tool_react_util.registerToolWithWindow("Finances", financeWindowId, FinancesWindow, getDebugString)
base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:652
registerVariantToolWithWindow<TP is IToolParam, WP is IToolWindowParam<TP>>(toolName : string, windowId : string, windowRecipe : Recipe<WP>, getActiveVariant : (function(toolParam : TP) : string), getDebugString? : (function(toolParam : TP) : string)) : ReactToolDefinition<TP> base/tealdef/gui/main/tool_react_util.d.tl:25
Call as tool_react_util.registerVariantToolWithWindow
Notes
Like registerToolWithWindow, for a tool with variants; getActiveVariant returns the active variant for a tool parameter.
Returns ReactToolDefinition<TP>
registerVariantToolWithPersistentWindows<TP is IToolParam, WP is IToolWindowParam<TP>>(toolName : string, getWindowId : (function(TP) : string), windowRecipe : Recipe<WP>, getActiveVariant : (function(toolParam : TP) : string), getDebugString? : (function(toolParam : TP) : string)) : ReactToolDefinition<TP> base/tealdef/gui/main/tool_react_util.d.tl:26
Call as tool_react_util.registerVariantToolWithPersistentWindows
Notes
Like registerVariantToolWithWindow, but with one window per window id (from getWindowId) that is only hidden, not removed, when the tool is popped.
Returns ReactToolDefinition<TP>
prepareDefaultToolWithWindowDefinition<TP is ToolReactUtil.IToolParam, WP is ToolReactUtil.IToolWindowParam<TP>>(toolName : string, windowId : string, windowRecipe : Recipe<WP>, getActiveVariant? : (function(toolParam : TP) : string), getDebugString? : (function(toolParam : TP) : string), getWindowIdIfPersistent? : (function(TP) : string)) : ReactToolDefinition<TP> base/tealdef/gui/main/tool_react_util.d.tl:29
Call as tool_react_util.prepareDefaultToolWithWindowDefinition
same as registerToolWithWindow, but without the call to react.RegisterTool()
Returns ReactToolDefinition<TP>
registerDelegatingTool<PublicParam, InternalParam>(def : ReactToolDefinition<InternalParam>) : DelegatingToolDefinition<PublicParam, InternalParam> base/tealdef/gui/main/tool_react_util.d.tl:48
Call as tool_react_util.registerDelegatingTool
Notes
Registers def as tool and wraps it as DelegatingToolDefinition.
Returns DelegatingToolDefinition<PublicParam, InternalParam>
Used in the base game: 2 times in 2 files
base/content/gui/gui/layers/layers_button_ridge.tl:120
local LayerTool : ToolReactUtil.DelegatingToolDefinition<LayersButtonRidge.LayerToolParam, LayerToolParamInternal> = tool_react_util.registerDelegatingTool{
base/content/gui/gui/main/selector_react_util.tl:373
firePushToolEvent<TP, DP>(evtParam : PushToolEventParam<TP, DP>) base/tealdef/gui/main/tool_react_util.d.tl:50
Call as tool_react_util.firePushToolEvent
Notes
Fires the React event PushTool for a delegating tool.
firePopToolEvent<TP, DP>(evtParam : PopToolEventParam<TP, DP>) base/tealdef/gui/main/tool_react_util.d.tl:51
Call as tool_react_util.firePopToolEvent
Notes
Fires the React event PopTool for a delegating tool.
onPushToolEvent<TP, DP>(tool : DelegatingToolDefinition<TP, DP>, onPush : function(evtParam : ToolReactUtil.PushToolEventParam<TP, DP>)) base/tealdef/gui/main/tool_react_util.d.tl:52
Call as tool_react_util.onPushToolEvent
Notes
Hook that calls onPush when PushTool is fired for the given delegating tool.
Used in the base game: 2 times in 2 files
base/content/gui/gui/layers/layers_button_ridge.tl:495
tool_react_util.onPushToolEvent(LayerTool, function(pushEvt : ToolReactUtil.PushToolEventParam<LayersButtonRidge.LayerToolParam, LayerToolParamInternal>)
base/content/gui/gui/main/selector_react_util.tl:284
onPopToolEvent<TP, DP>(tool : DelegatingToolDefinition<TP, DP>, onPop : function(evtParam : ToolReactUtil.PopToolEventParam<TP, DP>)) base/tealdef/gui/main/tool_react_util.d.tl:53
Call as tool_react_util.onPopToolEvent
Notes
Hook that calls onPop when PopTool is fired for the given delegating tool.
Used in the base game: 2 times in 2 files
base/content/gui/gui/layers/layers_button_ridge.tl:499
tool_react_util.onPopToolEvent(LayerTool, function(popEvt : ToolReactUtil.PopToolEventParam<LayersButtonRidge.LayerToolParam, LayerToolParamInternal>)
base/content/gui/gui/main/selector_react_util.tl:291
ToolReactUtil.IToolParam¶
interface base/tealdef/gui/main/tool_react_util.d.tl:6
interface IToolParam
input parameters required for most tools
Used in the base game: 16 times in 8 files
base/content/gui/gui/music_player/music_player.tl:17
local MusicPlayer = react.RegisterRecipe("MusicPlayer", function(param : ToolReactUtil.ToolWindowParamPayload<ToolReactUtil.IToolParam>) : TreeNodeId
base/content/gui/gui/map_editor/map_editor.tl:25
base/content/gui/gui/game_bar/game_bar.tl:13
local MusicPlayerTool = ug_require "/gui/music_player/music_player.tl" as ReactToolDefinition<ToolReactUtil.IToolParam>
base/content/gui/gui/game_bar/game_bar_widgets.tl:6
local MusicPlayerTool = ug_require "/gui/music_player/music_player.tl" as ReactToolDefinition<ToolReactUtil.IToolParam>
base/content/gui/gui/main/pause_menu.tl:236
local WallClock = react.RegisterRecipe("WallClock", function(_params : ToolReactUtil.IToolParam) : TreeNodeId
base/content/gui/gui/main/tool_react_util.tl:12
… and 2 more files.
Fields
| Name | Type | Description |
|---|---|---|
gameCtx |
GameContext |
Game context; its window container hosts the tool window. |
ToolReactUtil.ToolWindowParamPayload¶
interface base/tealdef/gui/main/tool_react_util.d.tl:11
interface ToolWindowParamPayload<TP is IToolParam>
'output' that can be passed from the windowWrapper recipe to the windowContent recipe
Used in the base game: 9 times in 8 files
base/content/gui/gui/music_player/music_player.tl:17
local MusicPlayer = react.RegisterRecipe("MusicPlayer", function(param : ToolReactUtil.ToolWindowParamPayload<ToolReactUtil.IToolParam>) : TreeNodeId
base/content/gui/gui/map_editor/map_editor.tl:31
local FileListContainer = react.RegisterRecipe("FileListContainer", function(param : ToolReactUtil.ToolWindowParamPayload<FileListParam>) : TreeNodeId
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:5897
function(params : ToolReactUtil.ToolWindowParamPayload<ManagerWindow.ManagerToolParam>) : TreeNodeId
base/content/gui/gui/game_bar/game_bar_widgets.tl:768
local CalendarEditor = react.RegisterRecipe("CalendarEditor", function(params : ToolReactUtil.ToolWindowParamPayload<GameBarWidgets.CalendarEditorToolParams>) :
base/content/gui/gui/statistics/statistics.tl:201
local StatisticsContainer = react.RegisterRecipe("StatisticsContainer", function(param : ToolReactUtil.ToolWindowParamPayload<StatisticsToolParam>, expandedStat
base/content/game_mechanics/game_mechanics/company/company.tl:850
… and 2 more files.
Fields
| Name | Type | Description |
|---|---|---|
toolParam |
TP |
The parameter the tool was pushed with. |
Functions
setActionFn(actionFn : (function() : TreeNodeId), key2? : string) base/tealdef/gui/main/tool_react_util.d.tl:13
Notes
Sets the action function of the tool (the action descriptor shown while the tool is active), e.g. from SelectorReactUtil.makeDefaultSelectorAction.
setVariantOverride(variant : string) base/tealdef/gui/main/tool_react_util.d.tl:15
Notes
Overrides the active variant of the tool.
ToolReactUtil.IToolWindowParam¶
interface base/tealdef/gui/main/tool_react_util.d.tl:19
interface IToolWindowParam<TP>
parameters requires to be passed into the window
Used in the base game: 19 times in 11 files
base/content/gui/gui/music_player/music_player.tl:266
local MusicPlayerWindow = react.RegisterWrapperRecipe("MusicPlayerWindow", builtin.Window, function(params: ToolReactUtil.IToolWindowParam<ToolReactUtil.IToolPa
base/content/gui/gui/layers/layers_button_ridge.tl:22
local record LayerToolWindowParam is ToolReactUtil.IToolWindowParam<LayersButtonRidge.LayerToolParam>
base/content/gui/gui/map_editor/map_editor.tl:120
local FileListWindow = react.RegisterWrapperRecipe("FileListWindow", builtin.Window, function(param : ToolReactUtil.IToolWindowParam<FileListParam>) : TreeNodeI
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:8214
manager_window.ManagerToolWindow = react.RegisterWrapperRecipe("ManagerWindow", builtin.Window, function(param : ToolReactUtil.IToolWindowParam<ManagerWindow.Ma
base/content/gui/gui/game_bar/game_bar_widgets.tl:825
local CalendarEditorWindow = react.RegisterWrapperRecipe("CalendarEditorWindow", builtin.Window, function(params : ToolReactUtil.IToolWindowParam<GameBarWidgets
base/content/gui/gui/main/pause_menu.tl:260
… and 5 more files.
Fields
| Name | Type | Description |
|---|---|---|
payload |
ToolWindowParamPayload<TP> |
Tool parameter and tool callbacks, to pass on to the window content. |
Functions
onClose() base/tealdef/gui/main/tool_react_util.d.tl:20
Notes
Closes the window by popping the tool.
ToolReactUtil.DelegatingToolDefinition¶
interface base/tealdef/gui/main/tool_react_util.d.tl:32
interface DelegatingToolDefinition<PublicParam, InternalParam>
Notes
A tool that is pushed and popped through React events instead of directly; the recipe that handles the events pushes the real tool delegate.
Used in the base game: 4 times in 2 files
base/content/gui/gui/layers/layers_button_ridge.tl:120
local LayerTool : ToolReactUtil.DelegatingToolDefinition<LayersButtonRidge.LayerToolParam, LayerToolParamInternal> = tool_react_util.registerDelegatingTool{
base/content/gui/gui/main/tool_react_util.tl:119
Fields
| Name | Type | Description |
|---|---|---|
delegate |
ReactToolDefinition<InternalParam> |
The registered tool that is actually pushed onto the tool stack. |
ToolReactUtil.PushToolEventParam¶
record base/tealdef/gui/main/tool_react_util.d.tl:36
record PushToolEventParam<TP, DP>
Notes
Parameter of firePushToolEvent and of onPushToolEvent handlers.
Used in the base game: 5 times in 3 files
base/content/gui/gui/layers/layers_button_ridge.tl:495
tool_react_util.onPushToolEvent(LayerTool, function(pushEvt : ToolReactUtil.PushToolEventParam<LayersButtonRidge.LayerToolParam, LayerToolParamInternal>)
base/content/gui/gui/main/tool_react_util.tl:101
function tool_react_util.firePushToolEvent<TP, DP>(evtParam : ToolReactUtil.PushToolEventParam<TP, DP>)
base/content/gui/gui/main/selector_react_util.tl:284
Fields
| Name | Type | Description |
|---|---|---|
tool |
DelegatingToolDefinition<TP, DP> |
The delegating tool to push. |
key |
string |
Key of the tool instance. |
param |
TP |
Public tool parameter. |
allowStacking |
boolean |
Whether the tool may be stacked on top of the current one. |
ToolReactUtil.PopToolEventParam¶
record base/tealdef/gui/main/tool_react_util.d.tl:42
record PopToolEventParam<TP, DP>
Notes
Parameter of firePopToolEvent and of onPopToolEvent handlers.
Used in the base game: 5 times in 3 files
base/content/gui/gui/layers/layers_button_ridge.tl:499
tool_react_util.onPopToolEvent(LayerTool, function(popEvt : ToolReactUtil.PopToolEventParam<LayersButtonRidge.LayerToolParam, LayerToolParamInternal>)
base/content/gui/gui/main/tool_react_util.tl:111
function tool_react_util.firePopToolEvent<TP, DP>(evtParam : ToolReactUtil.PopToolEventParam<TP, DP>)
base/content/gui/gui/main/selector_react_util.tl:291
Fields
| Name | Type | Description |
|---|---|---|
tool |
DelegatingToolDefinition<TP, DP> |
The delegating tool to pop. |
key |
string |
Key of the tool instance. |