MFD rows ​
An addon lists rows in its manifest's hud.mfd_rows and the launcher builds them into the race MFD: on the pit page after the tyre row, on the car settings page after the ERS row, or on the addon's own page. The player moves onto a row with the MFD's up and down and changes it with its left and right, as with the game's own rows. swofty/mfd.hpp reads the value a row is on, hears every change the player makes, and sets a row's value, text and colour from native code. With hud.pit_info it also fills a line under the pit window graphic and the pit lane timer.
#include <swofty/events.hpp>
#include <swofty/mfd.hpp>
#include <swofty/mixin.hpp>
namespace ev = swofty::events;
namespace mfd = swofty::hud::mfd;
static void show_traffic(uint32_t level) // 0 LOW, 1 MEDIUM, 2 HIGH
{
static const mfd::Tone tones[3] = {mfd::Tone::green, mfd::Tone::amber, mfd::Tone::red};
static const char *names[3] = {"LOW", "MEDIUM", "HIGH"};
mfd::set_value("traffic", level);
mfd::set_tone("traffic", tones[level]);
mfd::set_pit_info("PITTING INTO TRAFFIC", names[level], tones[level]);
}
SWOFTY_ON_LOAD
{
if (!mfd::available()) // an older core
return;
ev::on<mfd::events::Row>().after([](const mfd::events::Row &e, const ev::Context &) {
if (mfd::addon(e) != "author.pit-traffic") // every addon's rows fire the one point
return;
if (mfd::row(e) == "stop_lap")
swofty::log("[pit-traffic] stop lap %u -> %u", e.old_index, e.new_index);
if (mfd::row(e) == "ask" && e.pressed)
show_traffic(2);
});
}
SWOFTY_ADDON(){
"schema_version": 1,
"id": "author.pit-traffic",
"name": "Pit Traffic",
"version": "1.0.0",
"author": "Your name",
"kind": ["native", "ui"],
"compat": { "game": "f1_25" },
"requires": [{ "id": "swofty.core", "version": ">=0.2.13" }],
"hud": {
"mfd_rows": [
{ "id": "traffic", "page": "pit_settings", "label": "PITTING INTO TRAFFIC", "values": ["LOW", "MEDIUM", "HIGH"], "read_only": true },
{ "id": "stop_lap", "page": "pit_settings", "label": "STOP LAP", "values": ["THIS LAP", "NEXT LAP", "LAP AFTER"] },
{ "id": "ask", "page": "addon", "label": "ASK FOR TRAFFIC", "values": ["SEND"] }
],
"mfd_page": { "title": "PIT TRAFFIC" },
"pit_info": true
},
"operations": { "native": [{ "dll": "native/pit_traffic.dll" }] }
}[mfd] row slot 0: author.pit-traffic/traffic on pit_settings, 3 value(s), read only
[mfd] row slot 1: author.pit-traffic/stop_lap on pit_settings, 3 value(s)
[mfd] row slot 4: author.pit-traffic/ask on addon, 1 value(s)
[mfd] 3 addon row(s); binding dispatcher at base+0x42c26b0
[mfd] row author.pit-traffic/stop_lap (slot 1) right: 0 -> 1 'NEXT LAP'
[mfd] row author.pit-traffic/ask (slot 4) right: pressed- Header:
swofty/mfd.hpp, namespaceswofty::hud::mfd - Table:
SwoftyMfdversion 1, from the core'sSwoftyCoreMfdexport, not aSwoftyApimember - Event:
hud.mfd.row, payloadevents::Rowversion 1, notify - Thread: the event runs on the flow thread; the calls from any thread, written to the MFD on the next flow tick
- Builds: the player's changes need the KB build or Steam 1.0.145; on another build the rows show but left and right do nothing, and the core log says so
A call names the row by its id and reaches only the calling addon's own rows. A row that is not on the MFD this launch (the page was full, or the addon is off) answers Result::no_row. Every call returns ok, no_row, bad_value or off (an older core, or a core without the rows table), and name(r) turns one into text.
available ​
bool available();True when the running core exports the rows table. A plugin built against this header loads on an older core, and every call there answers off.
value ​
std::optional<uint32_t> value(std::string_view row_id);The index of the value the row is on: its default until the player or the addon moves it. Empty when the addon has no such row on the MFD.
hud.mfd.row ​
struct Row { // hud.mfd.row, v1
uint32_t size, payload_version;
uint32_t old_index, new_index; // the value before and after
uint8_t pressed; // 1 for an action row (one value); its index stays 0
uint8_t right; // 1 for the MFD's right, 0 for its left
uint8_t reserved[2];
char addon[64]; // the row's addon; mfd::addon(e)
char row[36]; // the row's id; mfd::row(e)
};Fires after the player moves a row with the MFD's left or right. Left on the first value and right on the last do nothing, so the event always carries a change, or a press of an action row. A read-only row never fires. set_value does not fire it. Every addon's rows fire the one point, so a handler checks addon(e) before row(e).
set_value ​
Result set_value(std::string_view row_id, uint32_t index);Moves the row to that value, as if the player had stepped to it, without an event. bad_value for an index past the row's values. It also ends a set_text.
set_text ​
Result set_text(std::string_view row_id, std::string_view text);Shows text, up to 16 printable characters, in place of the value's own text until the value changes, by the player or by set_value. Empty goes back to the value's text. Use it for a live reading the fixed values cannot list, such as HIGH 3 CARS.
set_tone ​
enum class Tone : uint32_t { white, green, amber, red };
Result set_tone(std::string_view row_id, Tone tone);Colours the row's value: white, the game's own, or green, amber or red. The tone stays through value changes until the addon sets another.
set_pit_info ​
Result set_pit_info(std::string_view label, std::string_view value, Tone tone = Tone::white);
Result clear_pit_info();Shows label over value, the value in tone, in a box under the pit window graphic and under the pit lane timer, whenever the game shows them. Needs "pit_info": true in the manifest's hud; without it, or with the addon off, the call answers no_row. The label takes up to 24 printable characters and the value up to 16. An empty label hides the line, as clear_pit_info() does. The line belongs to no row: the last call from any addon with hud.pit_info shows.
Testing ​
swofty/fake_mfd.hpp runs MFD code on the host. fake::Mfd holds the rows the test adds, answers the calls for them, and fires hud.mfd.row when the test presses one as the player would:
#include <cassert>
#include <swofty/fake_mfd.hpp>
int main()
{
swofty::fake::Mfd fake;
fake.set_addon("author.pit-traffic");
fake.row("traffic", {"LOW", "MEDIUM", "HIGH"}, 0, true);
fake.row("ask", {"SEND"});
fake.install();
my_addon_load(); // subscribes to hud.mfd.row
fake.press("ask", true); // fires hud.mfd.row with pressed = 1
assert(fake.value("traffic") == 2u);
assert(fake.tone("traffic") == swofty::hud::mfd::Tone::red);
assert(fake.shown("traffic") == "HIGH");
}press steps a row one value, stops at the ends and refuses a read-only row, as the MFD does. pit_label(), pit_value() and pit_tone() give the last set_pit_info, and set_pit_info_declared(false) makes it answer no_row. set_table_present(false) makes the calls answer off, as on an older core.
Environment variables for the game process: SWOFTY_MFD_ROWS_TRACE=1 logs each command the HUD raises the first time it raises it, with its name, and every left and right of an addon row.
How it works ​
The launcher copies the pit page's repair row for each addon row: the copy reads its text, visibility and tone flags from #ui_menu_data.swofty.mfd_r<slot>, its icon is hidden or reads the texture the manifest's icon names from #overrides.osd.car_settings_icons, and its left and right raise the commands swofty_mfd_<slot>_left and swofty_mfd_<slot>_right in place of the repair row's own. The value label is copied three times, each tinted green, amber or red and shown only while its tone is set; each copy draws into its own text element, which the launcher adds beside the value's in the row scene mfd_car_settings_row.idf (the game's rows bind none of them). A read-only row is disabled, so the list skips it.
The addon page is a copy of the pit page: the owner's mfd_page.title replaces the pit window, and the addon page rows replace the game's rows. The MFD shows it after the game's own pages while #ui_menu_data.swofty.mfd_page_enabled is set.
The game's settings list moves only between the entries of its view model's list, not between the rows the template draws. The game builds the pit and car settings pages' lists itself, one entry per setting, when the HUD starts. Once a list holds the game's entries, the core appends an entry named swofty_mfd_<slot> for each addon row of that page; it looks the list up without creating anything, so it never stands in for the game's own. The addon page's list, ui_menu_data.swofty.mfd_list, is the core's own, with an entry for each of the page's rows.
With hud.pit_info, the launcher adds a block to the pit window and pit lane timer scenes, below their own elements, with a label and a value copied from the scene's own text and a copy of the value for each of green, amber and red, and a group to each graphic's template that reads #ui_menu_data.swofty.pit_info. Each value copy is tinted and shown only while its tone is set. The scenes are in persistent.erp as well as the race archives, and the launcher writes the block into each copy; the block has no text of its own, so a graphic whose template does not bind it, such as the second player's pit lane timer, draws nothing new.
The core reads the rows from swofty/settings.json at start, in the same slot order as the launcher. It hooks the game's binding message dispatcher, steps a row when its command arrives, and writes the row's text and flags into the UI data on the next flow tick, again whenever the HUD rebuilds its data, and after each addon call.