Repository navigation
UI and Hud
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.
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| 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). |
- Notifications show one at a time, about 5 seconds apart.
- They only show while you're driving. One you send 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 notifications wait in line. If you add more, the oldest waiting one is dropped.
- 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
?.) -
platform.logsays when a notification shows, waits for the HUD, or is dropped (lines startingUI.Notify:). - About 100 characters fit on a line. Longer text is cut and ends with
.... - On a game build the SDK doesn't support, nothing shows and
IsReadystays false.platform.logsays why.
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).
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| 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. |
ClearGaugeItems() (method) |
Stops setting the gauge items. They keep their last values until the game sets them. |
-
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.
-
Game (for
Game.Tick) - Player and Vehicle
- Menus and UiElement
- DebugOverlay (text on screen for your own testing)
- Threads
Playing
Getting started
Writing mods
The FH2 classes
- Game
- Player
- Vehicle
- World
- Garage, CarCatalog, Profile
- UI and Hud
- Camera
- Audio
- ANNA
- Skills
- DebugOverlay
- Controller
- GameInput
- GameWindow
- Menus and UiElement
- SettingsTile
- ButtonIcons and Picture
- MapView, PhotoCamera, GarageCamera
More