Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
KeyValueInfoHUDBox
DescriptionInfo box with key-value layoutParent
InfoHUDBoxFunctions
- addLine
- canDraw
- clear
- draw
- getDisplayHeight
- new
- setScale
- setTitle
- showNextFrame
- storeScaledValues
- textSizeToFit
addLine
DescriptionDefinitionaddLine()Code
159 | function KeyValueInfoHUDBox:addLine(key, value, accentuate, accentuateColor) |
160 | local line |
161 | local cached = self.cachedLines |
162 | local numCached = #cached |
163 | if numCached > 0 then |
164 | line = self.cachedLines[numCached] |
165 | self.cachedLines[numCached] = nil |
166 | else |
167 | line = {} |
168 | end |
169 | |
170 | line.key = key |
171 | line.value = value or "" |
172 | line.accentuate = accentuate |
173 | line.accentuateColor = accentuateColor |
174 | |
175 | self.activeLines[#self.activeLines + 1] = line |
176 | end |
canDraw
DescriptionDefinitioncanDraw()Code
34 | function KeyValueInfoHUDBox:canDraw() |
35 | return self.doShowNextFrame |
36 | end |
clear
DescriptionDefinitionclear()Code
109 | function KeyValueInfoHUDBox:clear() |
110 | for i = #self.activeLines, 1, -1 do |
111 | self.cachedLines[#self.cachedLines + 1] = self.activeLines[i] |
112 | self.activeLines[i] = nil |
113 | end |
114 | end |
draw
DescriptionDefinitiondraw()Code
47 | function KeyValueInfoHUDBox:draw(posX, posY) |
48 | local rightX = posX |
49 | local leftX = posX - self.boxWidth |
50 | local y = posY |
51 | |
52 | local height = 2 * self.listMarginHeight + #self.activeLines * self.rowHeight |
53 | drawFilledRect(leftX, y, self.boxWidth, height, 0, 0, 0, 0.75) |
54 | |
55 | -- Draw title |
56 | setTextAlignment(RenderText.ALIGN_LEFT) |
57 | setTextColor(unpack(KeyValueInfoHUDBox.COLOR.TEXT_DEFAULT)) |
58 | setTextBold(true) |
59 | renderText(leftX + self.labelTextOffsetX, y + height + self.labelTextOffsetY, self.titleTextSize, self.title) |
60 | setTextBold(false) |
61 | |
62 | -- Displayitems |
63 | y = y + self.listMarginHeight |
64 | leftX = leftX + self.leftTextOffsetX + self.listMarginWidth |
65 | rightX = rightX - self.rightTextOffsetX - self.listMarginWidth |
66 | |
67 | local textAreaX = self.boxWidth - self.leftTextOffsetX - self.listMarginWidth - self.rightTextOffsetX - self.listMarginWidth |
68 | |
69 | for i = #self.activeLines, 1, -1 do |
70 | local line = self.activeLines[i] |
71 | |
72 | setTextBold(true) |
73 | if line.accentuate then |
74 | setTextColor(unpack(line.accentuateColor or KeyValueInfoHUDBox.COLOR.TEXT_HIGHLIGHT)) |
75 | end |
76 | |
77 | setTextAlignment(RenderText.ALIGN_LEFT) |
78 | renderText(leftX, y + self.leftTextOffsetY, self.rowTextSize, line.key) |
79 | |
80 | setTextAlignment(RenderText.ALIGN_RIGHT) |
81 | local maxWidth = textAreaX - 0.025 * self.boxWidth - getTextWidth(self.rowTextSize, line.key) |
82 | setTextBold(false) |
83 | |
84 | local text = Utils.limitTextToWidth(line.value, self.rowTextSize, maxWidth, false, "...") |
85 | renderText(rightX, y + self.rightTextOffsetY, self.rowTextSize, text) |
86 | |
87 | if line.accentuate then |
88 | setTextColor(unpack(KeyValueInfoHUDBox.COLOR.TEXT_DEFAULT)) |
89 | end |
90 | |
91 | if i < #self.activeLines then |
92 | drawFilledRect(leftX, y, self.rowWidth, 1 / g_screenHeight, unpack(KeyValueInfoHUDBox.COLOR.SEPARATOR)) |
93 | end |
94 | |
95 | y = y + self.rowHeight |
96 | end |
97 | |
98 | setTextAlignment(RenderText.ALIGN_LEFT) |
99 | |
100 | self.doShowNextFrame = false |
101 | end |
getDisplayHeight
DescriptionGet this HUD extension's display height.Definition
getDisplayHeight()Return Values
float | Display | height in screen space |
41 | function KeyValueInfoHUDBox:getDisplayHeight() |
42 | return 2 * self.listMarginHeight + #self.activeLines * self.rowHeight + self.labelTextSize + self.labelTextOffsetY |
43 | end |
new
DescriptionDefinitionnew()Code
15 | function KeyValueInfoHUDBox.new(uiScale) |
16 | local self = InfoHUDBox.new(KeyValueInfoHUDBox_mt, uiScale) |
17 | |
18 | self.displayComponents = {} |
19 | |
20 | self.cachedLines = {} |
21 | self.activeLines = {} |
22 | |
23 | self.title = "Unknown Title" |
24 | |
25 | return self |
26 | end |
setScale
DescriptionDefinitionsetScale()Code
190 | function KeyValueInfoHUDBox:setScale(uiScale) |
191 | self.uiScale = uiScale |
192 | self:storeScaledValues() |
193 | end |
setTitle
DescriptionDefinitionsetTitle()Code
118 | function KeyValueInfoHUDBox:setTitle(title) |
119 | title = utf8ToUpper(title) |
120 | if title ~= self.title then |
121 | self.title = title |
122 | |
123 | -- Try to fit text by wrapping it at max-length and then testing is we lost any characters after |
124 | -- the first line |
125 | self.titleTextSize = self:textSizeToFit(self.labelTextSize, self.title, self.boxWidth) |
126 | end |
127 | end |
showNextFrame
DescriptionDefinitionshowNextFrame()Code
180 | function KeyValueInfoHUDBox:showNextFrame() |
181 | self.doShowNextFrame = true |
182 | end |
storeScaledValues
DescriptionDefinitionstoreScaledValues()Code
197 | function KeyValueInfoHUDBox:storeScaledValues() |
198 | local scale = self.uiScale |
199 | |
200 | local function normalize(x, y) |
201 | return x * scale * g_aspectScaleX / g_referenceScreenWidth, y * scale * g_aspectScaleY / g_referenceScreenHeight |
202 | end |
203 | |
204 | self.boxWidth = normalize(340, 0) |
205 | |
206 | local _ |
207 | _, self.labelTextSize = normalize(0, HUDElement.TEXT_SIZE.DEFAULT_TITLE) |
208 | _, self.rowTextSize = normalize(0, HUDElement.TEXT_SIZE.DEFAULT_TEXT) |
209 | self.titleTextSize = self.labelTextSize |
210 | |
211 | self.labelTextOffsetX, self.labelTextOffsetY = normalize(0, 3) |
212 | self.leftTextOffsetX, self.leftTextOffsetY = normalize(0, 6) |
213 | self.rightTextOffsetX, self.rightTextOffsetY = normalize(0, 6) |
214 | |
215 | self.rowWidth, self.rowHeight = normalize(308, 26) |
216 | self.listMarginWidth, self.listMarginHeight = normalize(16, 15) |
217 | end |
textSizeToFit
DescriptionDefinitiontextSizeToFit()Code
131 | function KeyValueInfoHUDBox:textSizeToFit(baseSize, text, maxWidth, minSize) |
132 | local size = baseSize |
133 | if minSize == nil then |
134 | minSize = baseSize / 2 |
135 | end |
136 | |
137 | setTextWrapWidth(maxWidth) |
138 | local lengthWithNoLineLimit = getTextLength(size, text, 99999) |
139 | |
140 | while getTextLength(size, text, 1) < lengthWithNoLineLimit do |
141 | size = size - baseSize * 0.05 |
142 | |
143 | -- Limit size. Cut off any extra text |
144 | if size <= baseSize / 2 then |
145 | -- Undo |
146 | size = size + baseSize * 0.05 |
147 | |
148 | break |
149 | end |
150 | end |
151 | |
152 | setTextWrapWidth(0) |
153 | |
154 | return size |
155 | end |