@@ -1025,6 +1025,17 @@ Methods:
1025
1025
* returns last look vertical angle
1026
1026
* `get_key_pressed()`:
1027
1027
* returns last key typed by the player
1028
+ * `hud_add(definition)`
1029
+ * add a HUD element described by HUD def, returns ID number on success and `nil` on failure.
1030
+ * See [`HUD definition`](#hud-definition-hud_add-hud_get)
1031
+ * `hud_get(id)`
1032
+ * returns the [`definition`](#hud-definition-hud_add-hud_get) of the HUD with that ID number or `nil`, if non-existent.
1033
+ * `hud_remove(id)`
1034
+ * remove the HUD element of the specified id, returns `true` on success
1035
+ * `hud_change(id, stat, value)`
1036
+ * change a value of a previously added HUD element
1037
+ * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
1038
+ * Returns `true` on success, otherwise returns `nil`
1028
1039
1029
1040
### Settings
1030
1041
An interface to read config files in the format of `minetest.conf`.
@@ -1163,6 +1174,30 @@ Can be obtained via `minetest.get_meta(pos)`.
1163
1174
}
1164
1175
```
1165
1176
1177
+ ### HUD Definition (`hud_add`, `hud_get`)
1178
+ ```lua
1179
+ {
1180
+ hud_elem_type = "image", -- see HUD element types, default "text"
1181
+ -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
1182
+ position = {x=0.5, y=0.5},
1183
+ -- ^ Left corner position of element, default `{x=0,y=0}`.
1184
+ name = "<name>", -- default ""
1185
+ scale = {x=2, y=2}, -- default {x=0,y=0}
1186
+ text = "<text>", -- default ""
1187
+ number = 2, -- default 0
1188
+ item = 3, -- default 0
1189
+ -- ^ Selected item in inventory. 0 for no item selected.
1190
+ direction = 0, -- default 0
1191
+ -- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
1192
+ alignment = {x=0, y=0}, -- default {x=0, y=0}
1193
+ -- ^ See "HUD Element Types"
1194
+ offset = {x=0, y=0}, -- default {x=0, y=0}
1195
+ -- ^ See "HUD Element Types"
1196
+ size = { x=100, y=100 }, -- default {x=0, y=0}
1197
+ -- ^ Size of element in pixels
1198
+ }
1199
+ ```
1200
+
1166
1201
Escape sequences
1167
1202
----------------
1168
1203
Most text can contain escape sequences, that can for example color the text.
@@ -1206,3 +1241,80 @@ value must (always) be two hexadecimal digits.
1206
1241
`Color`
1207
1242
-------------
1208
1243
`{a = alpha, r = red, g = green, b = blue}` defines an ARGB8 color.
1244
+
1245
+ HUD element types
1246
+ -----------------
1247
+ The position field is used for all element types.
1248
+
1249
+ To account for differing resolutions, the position coordinates are the percentage
1250
+ of the screen, ranging in value from `0` to `1`.
1251
+
1252
+ The name field is not yet used, but should contain a description of what the
1253
+ HUD element represents. The direction field is the direction in which something
1254
+ is drawn.
1255
+
1256
+ `0` draws from left to right, `1` draws from right to left, `2` draws from
1257
+ top to bottom, and `3` draws from bottom to top.
1258
+
1259
+ The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`,
1260
+ with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down.
1261
+ Fractional values can be used.
1262
+
1263
+ The `offset` field specifies a pixel offset from the position. Contrary to position,
1264
+ the offset is not scaled to screen size. This allows for some precisely-positioned
1265
+ items in the HUD.
1266
+
1267
+ **Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor!
1268
+
1269
+ Below are the specific uses for fields in each type; fields not listed for that type are ignored.
1270
+
1271
+ **Note**: Future revisions to the HUD API may be incompatible; the HUD API is still
1272
+ in the experimental stages.
1273
+
1274
+ ### `image`
1275
+ Displays an image on the HUD.
1276
+
1277
+ * `scale`: The scale of the image, with 1 being the original texture size.
1278
+ Only the X coordinate scale is used (positive values).
1279
+ Negative values represent that percentage of the screen it
1280
+ should take; e.g. `x=-100` means 100% (width).
1281
+ * `text`: The name of the texture that is displayed.
1282
+ * `alignment`: The alignment of the image.
1283
+ * `offset`: offset in pixels from position.
1284
+
1285
+ ### `text`
1286
+ Displays text on the HUD.
1287
+
1288
+ * `scale`: Defines the bounding rectangle of the text.
1289
+ A value such as `{x=100, y=100}` should work.
1290
+ * `text`: The text to be displayed in the HUD element.
1291
+ * `number`: An integer containing the RGB value of the color used to draw the text.
1292
+ Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
1293
+ * `alignment`: The alignment of the text.
1294
+ * `offset`: offset in pixels from position.
1295
+
1296
+ ### `statbar`
1297
+ Displays a horizontal bar made up of half-images.
1298
+
1299
+ * `text`: The name of the texture that is used.
1300
+ * `number`: The number of half-textures that are displayed.
1301
+ If odd, will end with a vertically center-split texture.
1302
+ * `direction`
1303
+ * `offset`: offset in pixels from position.
1304
+ * `size`: If used, will force full-image size to this value (override texture pack image size)
1305
+
1306
+ ### `inventory`
1307
+ * `text`: The name of the inventory list to be displayed.
1308
+ * `number`: Number of items in the inventory to be displayed.
1309
+ * `item`: Position of item that is selected.
1310
+ * `direction`
1311
+ * `offset`: offset in pixels from position.
1312
+
1313
+ ### `waypoint`
1314
+ Displays distance to selected world position.
1315
+
1316
+ * `name`: The name of the waypoint.
1317
+ * `text`: Distance suffix. Can be blank.
1318
+ * `number:` An integer containing the RGB value of the color used to draw the text.
1319
+ * `world_pos`: World position of the waypoint.
1320
+
0 commit comments