233 lines
6.2 KiB
Markdown
233 lines
6.2 KiB
Markdown
---
|
|
title: Gestionnaire HUD
|
|
type: docs
|
|
weight: 1
|
|
---
|
|
|
|
Le `HudManager` contrôle quels composants HUD sont visibles pour le joueur.
|
|
|
|
**Package:** `com.hypixel.hytale.server.core.entity.entities.player.hud`
|
|
|
|
## Composants HUD
|
|
|
|
Tous les composants HUD disponibles :
|
|
|
|
| Composant | Description |
|
|
|-----------|-------------|
|
|
| `HudComponent.Hotbar` | Barre d'objets du joueur |
|
|
| `HudComponent.StatusIcons` | Icônes d'effets de statut |
|
|
| `HudComponent.Reticle` | Réticule/viseur |
|
|
| `HudComponent.Chat` | Fenêtre de chat |
|
|
| `HudComponent.Requests` | UI des demandes en attente |
|
|
| `HudComponent.Notifications` | Notifications d'alerte |
|
|
| `HudComponent.KillFeed` | Messages de kill/mort |
|
|
| `HudComponent.InputBindings` | Indications de contrôle |
|
|
| `HudComponent.PlayerList` | Liste des joueurs (Tab) |
|
|
| `HudComponent.EventTitle` | Grands titres d'événements |
|
|
| `HudComponent.Compass` | Boussole de direction |
|
|
| `HudComponent.ObjectivePanel` | Suivi de quêtes/objectifs |
|
|
| `HudComponent.PortalPanel` | Interface de portail |
|
|
| `HudComponent.BuilderToolsLegend` | Indications d'outils de construction |
|
|
| `HudComponent.Speedometer` | Indicateur de vitesse |
|
|
| `HudComponent.UtilitySlotSelector` | UI des slots d'utilitaires |
|
|
| `HudComponent.BlockVariantSelector` | Sélecteur de variantes de blocs |
|
|
| `HudComponent.BuilderToolsMaterialSlotSelector` | Slots de matériaux du builder |
|
|
| `HudComponent.Stamina` | Barre d'endurance |
|
|
| `HudComponent.AmmoIndicator` | Compteur de munitions |
|
|
| `HudComponent.Health` | Barre de vie |
|
|
| `HudComponent.Mana` | Barre de mana |
|
|
| `HudComponent.Oxygen` | Barre d'oxygène/respiration |
|
|
| `HudComponent.Sleep` | Indicateur de sommeil |
|
|
|
|
## Composants par Défaut
|
|
|
|
Ces composants sont visibles par défaut :
|
|
|
|
```java
|
|
Set<HudComponent> DEFAULT = Set.of(
|
|
HudComponent.UtilitySlotSelector,
|
|
HudComponent.BlockVariantSelector,
|
|
HudComponent.StatusIcons,
|
|
HudComponent.Hotbar,
|
|
HudComponent.Chat,
|
|
HudComponent.Notifications,
|
|
HudComponent.KillFeed,
|
|
HudComponent.InputBindings,
|
|
HudComponent.Reticle,
|
|
HudComponent.Compass,
|
|
HudComponent.Speedometer,
|
|
HudComponent.ObjectivePanel,
|
|
HudComponent.PortalPanel,
|
|
HudComponent.EventTitle,
|
|
HudComponent.Stamina,
|
|
HudComponent.AmmoIndicator,
|
|
HudComponent.Health,
|
|
HudComponent.Mana,
|
|
HudComponent.Oxygen,
|
|
HudComponent.BuilderToolsLegend,
|
|
HudComponent.Sleep
|
|
);
|
|
```
|
|
|
|
## Accéder au Gestionnaire HUD
|
|
|
|
```java
|
|
Player player = ...;
|
|
HudManager hudManager = player.getHudManager();
|
|
```
|
|
|
|
## Afficher des Composants
|
|
|
|
```java
|
|
// Afficher des composants spécifiques (additif)
|
|
hudManager.showHudComponents(player.getPlayerRef(),
|
|
HudComponent.Health,
|
|
HudComponent.Stamina,
|
|
HudComponent.Hotbar
|
|
);
|
|
|
|
// Afficher depuis un Set
|
|
Set<HudComponent> components = Set.of(
|
|
HudComponent.Chat,
|
|
HudComponent.Notifications
|
|
);
|
|
hudManager.showHudComponents(player.getPlayerRef(), components);
|
|
```
|
|
|
|
## Masquer des Composants
|
|
|
|
```java
|
|
// Masquer des composants spécifiques
|
|
hudManager.hideHudComponents(player.getPlayerRef(),
|
|
HudComponent.Compass,
|
|
HudComponent.Speedometer
|
|
);
|
|
```
|
|
|
|
## Définir les Composants
|
|
|
|
Remplacer tous les composants visibles :
|
|
|
|
```java
|
|
// Définir exactement les composants visibles (remplace tout)
|
|
hudManager.setVisibleHudComponents(player.getPlayerRef(),
|
|
HudComponent.Hotbar,
|
|
HudComponent.Health
|
|
);
|
|
|
|
// Vider tous les composants HUD
|
|
hudManager.setVisibleHudComponents(player.getPlayerRef());
|
|
```
|
|
|
|
## Requêter les Composants Visibles
|
|
|
|
```java
|
|
Set<HudComponent> visible = hudManager.getVisibleHudComponents();
|
|
|
|
if (visible.contains(HudComponent.Health)) {
|
|
// La barre de vie est visible
|
|
}
|
|
```
|
|
|
|
## Réinitialiser le HUD
|
|
|
|
```java
|
|
// Réinitialiser aux composants par défaut et vider le HUD personnalisé
|
|
hudManager.resetHud(player.getPlayerRef());
|
|
|
|
// Réinitialiser l'état UI complet
|
|
hudManager.resetUserInterface(player.getPlayerRef());
|
|
```
|
|
|
|
## HUD Personnalisé
|
|
|
|
Pour les overlays persistants :
|
|
|
|
```java
|
|
public class ScoreboardHud extends CustomUIHud {
|
|
|
|
public ScoreboardHud(PlayerRef ref) {
|
|
super(ref);
|
|
}
|
|
|
|
@Override
|
|
protected void build(UICommandBuilder builder) {
|
|
// L'extension .ui est OBLIGATOIRE
|
|
builder.append("Hud/Scoreboard.ui");
|
|
builder.set("#score", 1500);
|
|
builder.set("#rank", "Or");
|
|
}
|
|
}
|
|
|
|
// Définir le HUD personnalisé
|
|
hudManager.setCustomHud(player.getPlayerRef(), new ScoreboardHud(player.getPlayerRef()));
|
|
|
|
// Supprimer le HUD personnalisé
|
|
hudManager.setCustomHud(player.getPlayerRef(), null);
|
|
```
|
|
|
|
## Exemples Pratiques
|
|
|
|
### Mode Cinématique
|
|
|
|
Masquer toute l'UI pour les cinématiques :
|
|
|
|
```java
|
|
public void enterCinematicMode(Player player) {
|
|
HudManager hud = player.getHudManager();
|
|
|
|
// Stocker l'état actuel si nécessaire pour restauration
|
|
Set<HudComponent> previous = new HashSet<>(hud.getVisibleHudComponents());
|
|
|
|
// Vider tout le HUD
|
|
hud.setVisibleHudComponents(player.getPlayerRef());
|
|
}
|
|
|
|
public void exitCinematicMode(Player player, Set<HudComponent> restore) {
|
|
player.getHudManager().setVisibleHudComponents(player.getPlayerRef(), restore);
|
|
}
|
|
```
|
|
|
|
### Mode HUD Minimal
|
|
|
|
N'afficher que les composants essentiels :
|
|
|
|
```java
|
|
public void setMinimalHud(Player player) {
|
|
player.getHudManager().setVisibleHudComponents(player.getPlayerRef(),
|
|
HudComponent.Hotbar,
|
|
HudComponent.Health,
|
|
HudComponent.Reticle
|
|
);
|
|
}
|
|
```
|
|
|
|
### HUD Mode Construction
|
|
|
|
Afficher les composants spécifiques au builder :
|
|
|
|
```java
|
|
public void enableBuilderHud(Player player) {
|
|
HudManager hud = player.getHudManager();
|
|
hud.showHudComponents(player.getPlayerRef(),
|
|
HudComponent.BuilderToolsLegend,
|
|
HudComponent.BuilderToolsMaterialSlotSelector,
|
|
HudComponent.BlockVariantSelector
|
|
);
|
|
}
|
|
```
|
|
|
|
## Bonnes Pratiques
|
|
|
|
{{< callout type="info" >}}
|
|
**Directives HUD :**
|
|
- Utilisez toujours `PlayerRef` lors de l'appel des méthodes HUD
|
|
- Stockez l'état précédent avant de vider si vous devez restaurer plus tard
|
|
- Considérez le mode de jeu lors du choix des composants à afficher
|
|
- Utilisez `resetHud()` pour revenir à l'état par défaut
|
|
{{< /callout >}}
|
|
|
|
{{< callout type="warning" >}}
|
|
**Note de Performance :** Évitez le basculement rapide des composants HUD car chaque changement envoie des paquets au client.
|
|
{{< /callout >}}
|