Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
GuiUtils
DescriptionGUI utility functionsFunctions
checkOverlayOverlap
DescriptionCheck if a point lies within or a hotspot overlaps an overlay.Definition
checkOverlayOverlap(posX Point, posY Point, overlayX Overlay, overlayY Overlay, overlaySizeX Overlay, overlaySizeY Overlay, hotspot If)Arguments
posX | Point | or hotspot x position |
posY | Point | or hotspot y position |
overlayX | Overlay | x position |
overlayY | Overlay | y position |
overlaySizeX | Overlay | width |
overlaySizeY | Overlay | height |
hotspot | If | provided as an array having 4 numbers for the bounding points of a rectangle {minX, minY, maxX, maxY}, will be checked if it overlaps the overlay area given by the other parameters. |
125 | function GuiUtils.checkOverlayOverlap(posX, posY, overlayX, overlayY, overlaySizeX, overlaySizeY, hotspot) |
126 | if hotspot ~= nil and #hotspot == 4 then |
127 | return posX >= overlayX + hotspot[1] and posX <= overlayX + overlaySizeX + hotspot[3] and posY >= overlayY + hotspot[2] and posY <= overlayY + overlaySizeY + hotspot[4] |
128 | else |
129 | return posX >= overlayX and posX <= overlayX + overlaySizeX and posY >= overlayY and posY <= overlayY + overlaySizeY |
130 | end |
131 | end |
get2DArray
DescriptionTransform an attribute string representing a 2D array into an actual array.Definition
get2DArray(str Attribute, defaultValue Default)Arguments
str | Attribute | string containing exactly 2 numbers |
defaultValue | Default | value to return if the "str" parameter value is nil or invalid for transformation. |
Array | of | the 2 converted values as numbers: {value1, value2} |
62 | function GuiUtils.get2DArray(str, defaultValue) |
63 | if str ~= nil then |
64 | local parts = StringUtil.splitString(" ", str) |
65 | local x,y = unpack(parts) |
66 | if x ~= nil and y ~= nil then |
67 | return {Utils.evaluateFormula(x), Utils.evaluateFormula(y)} |
68 | end |
69 | end |
70 | |
71 | return defaultValue |
72 | end |
get4DArray
DescriptionTransform an attribute string representing a 4D array into an actual array.Definition
get4DArray(str Attribute, defaultValue Default)Arguments
str | Attribute | string containing exactly 4 numbers |
defaultValue | Default | value to return if the "str" parameter value is nil or invalid for transformation. |
Array | of | the 4 converted values as numbers: {value1, value2, value3, value4} |
79 | function GuiUtils.get4DArray(str, defaultValue) |
80 | local w,x,y,z = StringUtil.getVectorFromString(str) |
81 | if w ~= nil and x ~= nil and y ~= nil and z ~= nil then |
82 | return {w, x, y, z} |
83 | end |
84 | |
85 | return defaultValue |
86 | end |
getColorArray
DescriptionTransform an attribute string representing a 4D color array into an actual array.Definition
getColorArray(str Attribute, defaultValue Default)Arguments
str | Attribute | string containing exactly 4 numbers |
defaultValue | Default | value to return if the "str" parameter value is nil or invalid for transformation. |
Array | of | the 4 converted values as numbers: {red, green, blue, alpha} |
93 | function GuiUtils.getColorArray(colorStr, defaultValue) |
94 | local r,g,b,a = StringUtil.getVectorFromString(colorStr) |
95 | if r ~= nil and g ~= nil and b ~= nil and a ~= nil then |
96 | return {r, g, b, a} |
97 | end |
98 | return defaultValue |
99 | end |
getNormalizedValues
DescriptionTransform an attribute string representing a list of numbers into an array and normalize the values.Definition
getNormalizedValues(str Attribute, refSize Reference, defaultValue Default)Arguments
str | Attribute | string containing numbers, either raw or with a pixel unit designation on each number (e.g. "12 24" or "12px 24px") |
refSize | Reference | size for normalization, e.g. a reference screen resolution used to scale pixel values, {sizeX, sizeY} |
defaultValue | Default | value to return if the "str" parameter value is nil |
Array | of | normalized values |
18 | function GuiUtils.getNormalizedValues(str, refSize, defaultValue) |
19 | if str ~= nil then |
20 | local parts = StringUtil.splitString(" ", str) |
21 | local values = {} |
22 | for k, part in pairs(parts) do |
23 | local isPixelValue, isDisplayPixelValue = false, false |
24 | local value = part |
25 | if string.find(value, "px") ~= nil then |
26 | isPixelValue = true |
27 | value = string.gsub(value, "px", "") |
28 | elseif string.find(value, "dp") ~= nil then |
29 | isDisplayPixelValue = true |
30 | value = string.gsub(value, "dp", "") |
31 | end |
32 | |
33 | value = Utils.evaluateFormula(value) |
34 | |
35 | if isPixelValue then |
36 | -- refSize stores only 2 values (width, height). As str can contains more than 2 values we have to do a |
37 | -- loop match with this modulo operation (1->1, 2->2, 3->1, 4->2, 5->1, 6->1...) |
38 | value = value / refSize[((k + 1) % 2) + 1] |
39 | elseif isDisplayPixelValue then |
40 | local s = (k + 1) % 2 |
41 | if s == 0 then -- horizontal |
42 | value = value / g_screenWidth |
43 | else -- vertical |
44 | value = value / g_screenHeight |
45 | end |
46 | end |
47 | |
48 | table.insert(values, value) |
49 | end |
50 | |
51 | return values |
52 | end |
53 | |
54 | return defaultValue |
55 | end |
getUVs
DescriptionTransform an attribute string representing a UV array into an actual array and normalize the values.Definition
getUVs(str Attribute, ref Texture, defaultValue Default)Arguments
str | Attribute | string containing exactly 4 numbers, order and format: "x[px] y[px] sizeX[px] sizeY[px]" |
ref | Texture | reference size used to normalize pixel UV coordinates into unit sized UV coordinates |
defaultValue | Default | value to return if the "str" parameter value is nil or invalid for transformation. |
Array | of | the UV coordinates as {u1, v1, u2, v2, u3, v3, u4, v4} |
107 | function GuiUtils.getUVs(str, ref, defaultValue) |
108 | if str ~= nil then |
109 | local uvs = GuiUtils.getNormalizedValues(str, ref) |
110 | return {uvs[1], 1 - uvs[2] - uvs[4], uvs[1], 1 - uvs[2], uvs[1] + uvs[3], 1 - uvs[2] - uvs[4], uvs[1] + uvs[3], 1 - uvs[2]} |
111 | end |
112 | |
113 | return defaultValue |
114 | end |