| 278 | } |
| 279 | |
| 280 | void InteractionHighlighterController::Draw() const |
| 281 | { |
| 282 | if (!g_Configuration.EnableInteractionHighlighter) |
| 283 | return; |
| 284 | |
| 285 | if (_previous.Fade == 0.0f && _current.Fade == 0.0f) |
| 286 | return; |
| 287 | |
| 288 | if (!Objects[ID_INTERACTION_SPRITES].loaded || Objects[ID_INTERACTION_SPRITES].nmeshes == 0) |
| 289 | { |
| 290 | TENLog(fmt::format("Missing sprite sequence {} for drawing interaction highlighter.", GetObjectName(ID_INTERACTION_SPRITES)), LogLevel::Warning); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | auto distance = Vector3::Distance(Camera.pos.ToVector3(), _current.Position); |
| 295 | float scale = std::min(SPRITE_SCALE, INTERACTION_DISTANCE / distance * SPRITE_SCALE); |
| 296 | float distanceAlpha = std::min(1.0f, scale * 10.0f); |
| 297 | |
| 298 | auto drawState = [&](const HighlightState& state) |
| 299 | { |
| 300 | if (state.Fade <= 0.0f) |
| 301 | return; |
| 302 | |
| 303 | auto pos2D = g_Renderer.Get2DPosition(state.Position); |
| 304 | if (!pos2D.has_value()) |
| 305 | return; |
| 306 | |
| 307 | int spriteID = std::max(0, (int)state.Type - 1); |
| 308 | if (abs(Objects[ID_INTERACTION_SPRITES].nmeshes) <= spriteID) |
| 309 | spriteID = 0; |
| 310 | |
| 311 | float alpha = state.Fade; |
| 312 | float phase = (GlobalCounter % (int)FADE_RATE) / FADE_RATE; |
| 313 | float oscillation = 0.75f + 0.25f * sin(phase * PI * 2.0f); |
| 314 | alpha *= oscillation; |
| 315 | alpha *= distanceAlpha; |
| 316 | |
| 317 | auto color = Vector4(1.0f, 1.0f, 1.0f, alpha); |
| 318 | |
| 319 | AddDisplaySprite( |
| 320 | ID_INTERACTION_SPRITES, spriteID, |
| 321 | *pos2D, 0, Vector2(scale), color, |
| 322 | 0, DisplaySpriteAlignMode::Center, DisplaySpriteScaleMode::Fill, |
| 323 | BlendMode::Additive, DisplaySpritePhase::Draw); |
| 324 | }; |
| 325 | |
| 326 | drawState(_previous); |
| 327 | drawState(_current); |
| 328 | } |
| 329 | |
| 330 | void InteractionHighlighterController::Update() |
| 331 | { |
nothing calls this directly
no test coverage detected