OpenBF1942-Plus
Refractor 1, rebuilt from scratch
Loading...
Searching...
No Matches
hud.h
Go to the documentation of this file.
1// HUD: bitmap fonts (.font) and the on-screen layout as textured / solid quads. No GL: render.cpp draws them.
2// Spec: docs/formats/hud.md
3#pragma once
4#include <array>
5#include <cstdint>
6#include <map>
7#include <string>
8#include <vector>
9
10namespace obf {
11
12struct Glyph {
13 int x0 = 0, y = 0, x1 = -1; // texels, x1 inclusive; x1 < x0: none
14};
15struct Font {
16 std::string texture; // VFS path
17 int tex_w = 128, tex_h = 128, height = 0, between = 1, space = 1;
18 std::array<Glyph, 256> glyphs{}; // by Latin-1 code
19};
20Font font_parse(const std::string& text); // throws std::runtime_error without a header or glyphs
21// lexiconAll.dat (Mods/<mod>/, loose): uint32 records, uint32 strings per record, then UTF-16LE zero-terminated
22// strings, a key and one text per language (the first record names them: English, French, Italian, Spanish,
23// German, Japanese, Korean, Chinese). Returns key -> text in language `lang` (0 English), as Latin-1 ('?' beyond).
24std::map<std::string, std::string> lexicon_parse(const std::vector<uint8_t>& data, int lang = 0);
25
26struct HudQuad {
27 float x, y, w, h; // pixels, top-left origin
28 float u0, v0, u1, v1; // texture coordinates; u0 < 0: solid colour
29 float rgba[4];
30 std::string tex{}; // VFS path without extension; empty: the font; "@minimap": the level's map
31 float angle = 0; // radians, clockwise about the centre
32};
33
34struct MapIcon { // a minimap marker
35 float x = 0, z = 0, yaw = 0; // world position, heading (radians, 0 = +z, clockwise)
36 std::string tex; // VFS path without extension
37 float size = 16; // setMinimapIconSize (texels at 640 x 480)
38 float rgba[4] = {1, 1, 1, 1};
39};
40
41// What the game shows; built by Game::hud_info.
42struct HudInfo {
43 bool on = false; // a player exists
44 int team = 0, hp = 0, winner = 0;
45 int tickets[2] = {}, flags[2] = {};
46 std::string weapon, vehicle;
47 int vehicle_hp = -1; // -1: on foot
48 int rounds = -1, spare = 0; // rounds -1: unlimited (not shown)
49 bool reloading = false;
50 std::vector<std::string> feed; // newest last
51 // radio bar: closed, the category row (F8 shows / hides it); open, its category on top and a row of messages
52 struct RadioButton {
53 std::string icon, label; // menu/texture/radio/icon_<x>; empty icon: nothing on that key
54 };
55 bool radio_bar = false;
56 int radio_open = -1; // the open category (0-6), -1 closed
57 std::vector<RadioButton> radio_row; // 8 keys: the categories (closed) or the messages and F8 cancel (open)
58 // original HUD textures (VFS paths without extension; empty: drawn as plain bars and text)
59 std::string health_empty, health_full; // menu/texture/ingame/healthbar_*_<kit>_64x64 (the vehicle's on board)
60 std::string ammo_empty, ammo_full; // the weapon's setAmmoBar / setAmmoBarFill
61 float ammo_rows = 0; // setAmmoBarSize: texels of the fill, from the bottom
62 float ammo_x = 5, ammo_y = -11; // setAmomBarPosX / PosY (sic): from the panel's left, the screen's bottom
63 std::string flag_tex[2];
64 // in a vehicle: its picture (128 x 128) and the seat's spot on it, its hit points, the seat's weapons
65 std::string vehicle_icon;
66 float seat_x = -1, seat_y = -1, vehicle_frac = 1;
68 std::string icon; // setPrimaryAmmoIcon / setSecondaryAmmoIcon
69 int bar = 0; // setPrimaryAmmoBar: 1 ABAmmoBarReloadBar, 2 ABAmmoBarHeatBar, 0 none
70 int rounds = -1; // -1: unlimited or not fired by us (no count, full bar)
71 float frac = 1; // rounds / magSize: the ammunition bar's fill
72 };
73 std::vector<VehicleWeapon> vehicle_weapons; // teams 1, 2: their soldiers' setMinimapIcon (national flag)
74 int mag = 0; // magSize: a full fill
75 float world = 0, map_x = 0, map_z = 0; // minimap: world size (0: none), the point it centres on
76 std::vector<MapIcon> icons;
77};
78
79float text_width(const Font& f, const std::string& s, float scale);
80void hud_text(const Font& f, const std::string& s, float x, float y, float scale, const float rgba[4], std::vector<HudQuad>& out);
81std::vector<HudQuad> hud_layout(const Font& f, const HudInfo& info, int w, int h);
82
83} // namespace obf
Definition anim.cpp:7
std::vector< HudQuad > hud_layout(const Font &f, const HudInfo &in, int w, int h)
Definition hud.cpp:104
void hud_text(const Font &f, const std::string &s, float x, float y, float scale, const float rgba[4], std::vector< HudQuad > &out)
Definition hud.cpp:91
Font font_parse(const std::string &text)
Definition hud.cpp:36
float text_width(const Font &f, const std::string &s, float scale)
Definition hud.cpp:85
Mat4 scale(float x, float y, float z)
Definition mat.h:30
std::map< std::string, std::string > lexicon_parse(const std::vector< uint8_t > &data, int lang)
Definition hud.cpp:12
Definition hud.h:15
std::array< Glyph, 256 > glyphs
Definition hud.h:18
int between
Definition hud.h:17
int space
Definition hud.h:17
int tex_h
Definition hud.h:17
std::string texture
Definition hud.h:16
int tex_w
Definition hud.h:17
int height
Definition hud.h:17
Definition hud.h:12
int x0
Definition hud.h:13
int x1
Definition hud.h:13
int y
Definition hud.h:13
Definition hud.h:52
std::string label
Definition hud.h:53
std::string icon
Definition hud.h:53
Definition hud.h:67
float frac
Definition hud.h:71
int rounds
Definition hud.h:70
std::string icon
Definition hud.h:68
int bar
Definition hud.h:69
Definition hud.h:42
int spare
Definition hud.h:48
float vehicle_frac
Definition hud.h:66
std::string weapon
Definition hud.h:46
int tickets[2]
Definition hud.h:45
float world
Definition hud.h:75
int vehicle_hp
Definition hud.h:47
std::string health_empty
Definition hud.h:59
std::vector< std::string > feed
Definition hud.h:50
float map_x
Definition hud.h:75
std::string ammo_full
Definition hud.h:60
std::vector< MapIcon > icons
Definition hud.h:76
std::string vehicle_icon
Definition hud.h:65
int radio_open
Definition hud.h:56
float ammo_rows
Definition hud.h:61
int rounds
Definition hud.h:48
bool reloading
Definition hud.h:49
bool radio_bar
Definition hud.h:55
float ammo_x
Definition hud.h:62
float ammo_y
Definition hud.h:62
float seat_y
Definition hud.h:66
float map_z
Definition hud.h:75
int flags[2]
Definition hud.h:45
int hp
Definition hud.h:44
int team
Definition hud.h:44
std::string health_full
Definition hud.h:59
std::string flag_tex[2]
Definition hud.h:63
std::string vehicle
Definition hud.h:46
int winner
Definition hud.h:44
bool on
Definition hud.h:43
std::vector< VehicleWeapon > vehicle_weapons
Definition hud.h:73
std::string ammo_empty
Definition hud.h:60
float seat_x
Definition hud.h:66
std::vector< RadioButton > radio_row
Definition hud.h:57
int mag
Definition hud.h:74
Definition hud.h:26
float u1
Definition hud.h:28
float u0
Definition hud.h:28
float v1
Definition hud.h:28
float y
Definition hud.h:27
float v0
Definition hud.h:28
float h
Definition hud.h:27
float angle
Definition hud.h:31
float w
Definition hud.h:27
std::string tex
Definition hud.h:30
float rgba[4]
Definition hud.h:29
float x
Definition hud.h:27
Definition hud.h:34
std::string tex
Definition hud.h:36
float rgba[4]
Definition hud.h:38
float size
Definition hud.h:37
float x
Definition hud.h:35
float z
Definition hud.h:35
float yaw
Definition hud.h:35