color_util¶
Source: base/tealdef/gui/main/color_util.d.tl
Notes
Colour types of GUI resource files (*.gres) and helpers that turn them into
Vec3f/Vec4f values, add transparency, mix colours and derive hover/active shades.
GResColor¶
record global base/tealdef/gui/main/color_util.d.tl:3
global record GResColor is {number}
{number} is expected to have length 3 or 4
GResColorRange¶
record global base/tealdef/gui/main/color_util.d.tl:4
global record GResColorRange
Notes
A pair of GUI resource colours (minimum and maximum), e.g. for a colour gradient.
Fields
| Name | Type | Description |
|---|---|---|
min |
GResColor |
Colour at the lower end of the range. |
max |
GResColor |
Colour at the upper end of the range. |
GResColorArray¶
record global base/tealdef/gui/main/color_util.d.tl:8
global record GResColorArray is {GResColor}
Notes
A list of GUI resource colours.
GResTransparency¶
record global base/tealdef/gui/main/color_util.d.tl:10
global record GResTransparency
Notes
Standard alpha values of the GUI, from the resource ::/gui/main/transparency.gres.
Details
Read it with api.gui.genericRep.get(api.gui.genericRep.find("::/gui/main/transparency.gres")).data
and pass the values as alpha to color_util.withTransparency.
Fields
| Name | Type | Description |
|---|---|---|
VeryLow |
number |
Alpha 0.9 (almost opaque). |
Low |
number |
Alpha 0.75. |
Medium |
number |
Alpha 0.5. |
High |
number |
Alpha 0.25. |
VeryHigh |
number |
Alpha 0.1 (almost transparent). |
Functions
metamethod __index(GResTransparency, string) : number base/tealdef/gui/main/color_util.d.tl:11
Notes
Lookup of the alpha values by name (transparency["Low"]).
Returns number
ColorUtil¶
record global base/tealdef/gui/main/color_util.d.tl:20
global record ColorUtil
Load: local color_util = require "::/gui/main/color_util.tl" as ColorUtil
Notes
Conversion and mixing helpers for GUI resource colours (GResColor, a list of 3 or 4 numbers in 0..1).
Functions
toVec3(color : GResColor) : Vec3f base/tealdef/gui/main/color_util.d.tl:21
Call as color_util.toVec3(…)
Notes
Converts a colour to a Vec3f (red, green, blue); alpha is dropped.
Returns Vec3f
Used in the base game: 5 times in 2 files
base/content/gui/gui/main/particle_react_util.tl:19
base/content/mission/mission/mission_sim.script.tl:1191
toVec4(color : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:22
Call as color_util.toVec4(…)
Notes
Converts a colour to a Vec4f; a missing alpha becomes 1.0.
Returns Vec4f
Used in the base game: 163 times in 49 files
base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:199
colors = { color_util.toVec4(defaultColorsRef:get().Positive), color_util.toVec4(defaultColorsRef:get().Negative) },
base/content/game_mechanics/game_mechanics/finance/finances_react_util.tl:141
base/content/gui/gui/construction/construction_desc_layers.script.tl:19
base/content/gui/gui/construction/construction_react_util.tl:43
base/content/gui/gui/entity_window/double_slip_switch.tl:70
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:807
… and 43 more files.
toRange3(colorRange : GResColorRange) : {Vec3f, Vec3f} base/tealdef/gui/main/color_util.d.tl:24
Call as color_util.toRange3(…)
{min, max}
toRange4(colorRange : GResColorRange) : {Vec4f, Vec4f} base/tealdef/gui/main/color_util.d.tl:25
Call as color_util.toRange4(…)
{min, max}
Used in the base game: 11 times in 5 files
base/content/gui/gui/entity_window/town/town.tl:54
base/content/gui/gui/layers/layer_cargo_flow.tl:37
base/content/gui/gui/layers/layer_noise.tl:20
base/content/gui/gui/layers/layer_passenger_flow.tl:16
base/content/gui/gui/layers/layer_pollution.tl:19
toArray3(colorArray : GResColorArray) : {Vec3f} base/tealdef/gui/main/color_util.d.tl:27
Call as color_util.toArray3(…)
Notes
Converts each colour of the list with toVec3.
Returns {Vec3f}
Used in the base game: 7 times in 6 files
base/content/gui/gui/construction/construction_react_util.tl:3326
laneModifier.lineColors = color_util.toArray3(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).data as GResColorArra
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:139
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:601
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/line_util.tl:40
local lineColors = color_util.toArray3(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).data as GResColorArray)
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:3600
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:4866
toArray4(colorArray : GResColorArray) : {Vec4f} base/tealdef/gui/main/color_util.d.tl:28
Call as color_util.toArray4(…)
Notes
Converts each colour of the list with toVec4.
Returns {Vec4f}
Used in the base game: 16 times in 14 files
base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:233
local chartColorsRef = react.useRef(color_util.toArray4(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/main/chart_colors.gres")).data as GResColorArray)
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo/deliver_cargo.script.tl:408
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo_town/deliver_cargo_town.script.tl:506
base/content/game_mechanics/game_mechanics/subventions/deliver_passengers/deliver_passengers.script.tl:461
base/content/game_mechanics/game_mechanics/subventions/deliver_workers/deliver_workers.script.tl:295
base/content/gui/gui/construction/construction_react_util.tl:549
… and 8 more files.
toArray4WithTransparency(colorArray : GResColorArray, alpha : number) : {Vec4f} base/tealdef/gui/main/color_util.d.tl:29
Call as color_util.toArray4WithTransparency(…)
Notes
Converts each colour of the list to a Vec4f with the given alpha (the colour's own alpha is replaced).
Returns {Vec4f}
Used in the base game: 6 times in 3 files
base/content/gui/gui/entity_window/industry/industry.tl:332
local potentialColors = color_util.toArray4WithTransparency(layerColors.CargoFlow.Suppliers3D.Potential, transparency.VeryLow)
base/content/gui/gui/entity_window/town/town.tl:1024
local actualColors = color_util.toArray4WithTransparency(layerColors.CargoFlow.Suppliers3D.Actual, transparency.VeryLow)
base/content/gui/gui/layers/layer_infrastructure.tl:37
withTransparency(gResColor : GResColor, alpha : number) : Vec4f base/tealdef/gui/main/color_util.d.tl:31
Call as color_util.withTransparency(…)
Notes
Returns the colour as Vec4f with its alpha replaced by alpha.
Returns Vec4f
Used in the base game: 30 times in 8 files
base/content/gui/gui/construction/construction_desc_layers.script.tl:38
base/content/gui/gui/construction/construction_react_util.tl:37
modifierColor.validSubtle = color_util.withTransparency(constructionColors.Modifier.Valid, transparency.Medium)
base/content/gui/gui/entity_window/double_slip_switch.tl:76
base/content/gui/gui/layers/layer_infrastructure.tl:39
edgeRenderableConfig.tunnelOutlineColor = color_util.withTransparency(layerColors.Infrastructure.Tunnel, transparency.Low)
base/content/gui/gui/layers/layer_terrain.tl:20
base/content/gui/gui/layers/layer_traffic.tl:34
… and 2 more files.
withTransparencyRaw(gResColor : GResColor, alpha : number) : GResColor base/tealdef/gui/main/color_util.d.tl:32
Call as color_util.withTransparencyRaw(…)
Notes
Returns a new GResColor with its alpha replaced by alpha.
Returns GResColor
Used in the base game: 323 times in 37 files
base/content/game_mechanics/game_mechanics/achievements/achievements.css.lua:103
base/content/game_mechanics/game_mechanics/company/company.css.lua:14
base/content/game_mechanics/game_mechanics/finance/finances.css.lua:28
local financesTableHoverColor = color_util.withTransparencyRaw(colorDefault.AccentLight, transparency.Medium)
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:16
local notificationCautionTransparent = color_util.withTransparencyRaw(notificationCautionSolid, transparency.High)
base/content/game_mechanics/game_mechanics/towns/town_react_util.css.lua:23
base/content/gui/gui/camera_tool/camera_tool.css.lua:12
… and 31 more files.
mixColors(colorA : GResColor, colorB : GResColor, amount : number) : Vec4f base/tealdef/gui/main/color_util.d.tl:34
Call as color_util.mixColors(…)
Notes
Linearly interpolates between two colours (including alpha) and returns a Vec4f.
| Parameter | Type | Description |
|---|---|---|
colorA |
GResColor |
|
colorB |
GResColor |
|
amount |
number |
0 gives colorA, 1 gives colorB. |
Returns Vec4f
mixColorsRaw(colorA : GResColor, colorB : GResColor, amount : number) : GResColor base/tealdef/gui/main/color_util.d.tl:35
Call as color_util.mixColorsRaw(…)
Notes
Like mixColors, but returns a GResColor.
Returns GResColor
getHoverFrom(enabledColor : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:37
Call as color_util.getHoverFrom(…)
Notes
Derives the hover shade of a colour (brightness +0.2, slightly less saturation, in HSV) as Vec4f.
Returns Vec4f
getHoverFromRaw(enabledColor : GResColor) : GResColor base/tealdef/gui/main/color_util.d.tl:38
Call as color_util.getHoverFromRaw(…)
Notes
Like getHoverFrom, but returns a GResColor.
Returns GResColor
Used in the base game: 54 times in 8 files
base/content/game_mechanics/game_mechanics/company/company.css.lua:139
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:130
base/content/gui/gui/game_bar/game_bar.css.lua:132
base/content/gui/gui/line_vehicle_mgmt/line_vehicle_mgmt.css.lua:1930
base/content/gui/gui/main/builtin.css.lua:207
base/content/gui/gui/main/default.css.lua:84
… and 2 more files.
getActiveFrom(enabledColor : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:40
Call as color_util.getActiveFrom(…)
Notes
Derives the pressed/active shade of a colour (brightness +0.1, slightly less saturation, in HSV) as Vec4f.
Returns Vec4f
getActiveFromRaw(enabledColor : GResColor) : GResColor base/tealdef/gui/main/color_util.d.tl:41
Call as color_util.getActiveFromRaw(…)
Notes
Like getActiveFrom, but returns a GResColor.
Returns GResColor
Used in the base game: 57 times in 9 files
base/content/game_mechanics/game_mechanics/company/company.css.lua:146
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:134
base/content/gui/gui/game_bar/game_bar.css.lua:137
base/content/gui/gui/line_vehicle_mgmt/line_vehicle_mgmt.css.lua:409
base/content/gui/gui/main/builtin.css.lua:224
base/content/gui/gui/main/content_card.css.lua:80
… and 3 more files.