Hudindicatorwatcher
Overview
This component manages HUD target indicators for entities tracked by the player (e.g., allies or notable actors). It monitors visibility changes (via playerexited and unregister_hudindicatable events) and updates the HUD accordingly—adding indicators when an entity enters view and is marked as trackable, and removing them when the entity exits view or is no longer trackable.
Dependencies & Tags
- Component Dependencies:
- Requires
inst.HUD(HUD component) to be present on the entity. - Relies on
target.components.hudindicatable:ShouldTrack(self.inst)for per-target tracking logic. - Requires
TheWorld.components.hudindicatablemanagerto provide the list of potential indicators (items).
- Requires
- Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
offScreenItems | table | {} | List of entities currently displayed as target indicators on the HUD. |
onScreenItemsLastTick | table | {} | Reserved for potential use (currently commented out in OnUpdate()). |
onitemexited | function | nil (set in constructor) | Event callback handler for playerexited and unregister_hudindicatable events. |
Main Functions
HudIndicatorWatcher:ShouldShowIndicator(target)
- Description: Determines whether the HUD should display a target indicator for the given entity.
- Parameters:
target: Entity to evaluate. Must have ahudindicatablecomponent.
- Logic: Checks if the target’s
hudindicatablecomponent indicates it should be tracked by the entity (self.inst).
HudIndicatorWatcher:ShouldRemoveIndicator(target)
- Description: Determines whether a target indicator should be removed from the HUD.
- Parameters:
target: Entity to evaluate. Must have ahudindicatablecomponent.
- Logic: Returns
trueif the target’shudindicatablecomponent indicates it should not be tracked by the entity.
HudIndicatorWatcher:OnUpdate()
- Description: Periodically updates the HUD indicators based on entity visibility and tracking state.
- Parameters: None.
- Logic:
- Removes indicators for entities no longer trackable or already processed.
- Adds indicators for new entities that are trackable and not already in
offScreenItems. - Uses
TheWorld.components.hudindicatablemanager.itemsas the source of potential targets.
HudIndicatorWatcher:OnRemoveFromEntity()
- Description: Cleans up state when the component is removed.
- Parameters: None.
- Logic:
- Unregisters event listeners (
playerexited,unregister_hudindicatable). - Removes all indicators from the HUD for entities in
offScreenItems. - Nullifies
offScreenItemsto prevent stale references.
- Unregisters event listeners (
Events & Listeners
- Listens For:
"playerexited"(fromTheWorld) → triggersOnItemExited."unregister_hudindicatable"(fromTheWorld) → triggersOnItemExited.
- No events are explicitly pushed by this component.