UI shows the game's own HUD notification (the panel with a title and a line of text that the game uses for skills and rewards). Hud tells you whether the speedometer is up, and feeds values to a speedometer of your own.
Thread: any. Both classes can be used from any thread.
UI
Example
Show a notification when your mod starts.
protected override void OnInit()
{
UI.Notify("My Mod", "Loaded. Have fun!");
}
Protected Overrides Sub OnInit()
UI.Notify("My Mod", "Loaded. Have fun!")
End Sub
Members
| Member | What it does |
|---|---|
Notify(string title, string text = "") (method) | Shows title with text under it, as the game's HUD notification. |
IsReady (property, bool) | True once notifications can be shown (the game's code was checked). |
Notes
With FH2 Mod Platform 2.9.0 or later (new in 0.12.0), notifications are the platform's pop-ups:
- One queue for every mod, spaced around the game's own notifications. They wait while you're in a menu, loading, in photo mode or a replay, and one that can't show within 2 minutes is dropped.
- The title shows up to 28 characters, in capitals; the line under it up to 45. Longer text ends with
.... - Up to 4 wait at once. For hosted mods and scripts that's all of them together, because they show under Platform.NET's name. A 5th drops the oldest waiting one.
- The player decides whether they show: the Pop-ups row on Platform.NET's page (a NativeAOT mod gets the row on its own page), the platform's Mod pop-ups row, and the game's own Minor notifications option.
platform.loglists each one shown, with its text.
On older platforms, the SDK shows them itself:
- One at a time, about 5 seconds apart, only while you're driving. One sent during a loading screen, a menu or an event's intro waits until you're on the road again; one that can't show within 2 minutes is dropped. (A teleport rebuilds the HUD, so "Teleported!" shows a few seconds after you land.)
- Up to 8 wait in line; more drops the oldest waiting one.
- About 100 characters fit on a line. Longer text is cut and ends with
.... platform.logsays when one shows, waits for the HUD, or is dropped (lines startingUI.Notify:).- On a game build the SDK doesn't support, nothing shows and
IsReadystays false.platform.logsays why.
Either way, any language shows, as long as the HUD's font for the game's language has the characters: Chinese text with the game in Chinese, say. (Before 0.10.0, anything outside ASCII showed as ?.)
Hud
The speedometer's XAML (ui/Controls/HUDSpeedometerControl.xaml) binds to the RPM gauge's number items: RPMGaugeNumbers[n].XPos and RPMGaugeNumbers[n].YPos. Items 16 to 20 are not used by the game. Replace that XAML with your own (using SetFile on your mod), set items 16 to 20 with SetGaugeItem, and bind your own gauge parts to them (for example a bar's Ratio, a glow's angle, or an Opacity).
Example
Feed the car's speed to gauge item 16, as a value from 0 to 1.
protected override void OnInit()
{
Game.Tick += () =>
{
if (Player.Car is { } car)
Hud.SetGaugeItem(16, Math.Min(car.SpeedKmh / 400f, 1f), 0f);
};
}
Protected Overrides Sub OnInit()
AddHandler Game.Tick, Sub()
Dim car = Player.Car
If car IsNot Nothing Then
Hud.SetGaugeItem(16, Math.Min(car.SpeedKmh / 400.0F, 1.0F), 0.0F)
End If
End Sub
End Sub
Members
| Member | What it does |
|---|---|
IsReady (property, bool) | True if the HUD can be read and fed (the game's code is as expected). |
IsSpeedometerShown (property, bool) | True while the speedometer is up: you're driving with the HUD showing. False in a menu, the garage, a car meet lobby, a race intro, a rewind or photo mode. |
SetGaugeItem(int index, float x, float y) (method) | Sets RPM gauge item index to x (its XPos) and y (its YPos), for the speedometer XAML to show. Items 16 to 20 are free for your own use. ⚠️ Not tested much in the game yet. |
ClearGaugeItems() (method) | Stops setting the gauge items. They keep their last values until the game sets them. |
HideAll (property, get/set, bool) | Hides all of the game's UI (the HUD, the map, menus) for screenshots or a cinematic camera. It comes back by itself when the pause menu opens, so the player is never stuck in a menu they can't see. New in 0.12.0. |
Notes
SetGaugeItemtakes an index from 0 to 20. Any other index throwsArgumentOutOfRangeException.- Items 0 to 15 are the game's own numbers. You can set them, but 16 to 20 are the ones meant for you.
- Values are applied every HUD frame, so set them whenever you like. You don't need to be on the game thread.
- On a game build the SDK doesn't support,
Hudswitches itself off:IsReadystays false andplatform.logsays so.
See also
- Game (for
Game.Tick) - Player and Vehicle
- Menus and UiElement
- DebugOverlay (text on screen for your own testing)
- Threads
