Exemplo n.º 1
0
        private void DrawTarget()
        {
            var s           = _session;
            var focus       = s.TrackingAi.Construct.Data.Repo.FocusData;
            var detailedHud = !_session.Settings.ClientConfig.MinimalHud;

            for (int i = 0; i < s.TrackingAi.TargetState.Length; i++)
            {
                if (focus.Target[i] <= 0)
                {
                    continue;
                }
                var lockMode = focus.Locked[i];

                var targetState = s.TrackingAi.TargetState[i];
                var isActive    = i == focus.ActiveId;
                var primary     = i == 0;
                var shielded    = detailedHud && targetState.ShieldHealth >= 0;

                Dictionary <string, HudInfo> collection;
                if (detailedHud)
                {
                    collection = primary ? _primaryTargetHuds : _secondaryTargetHuds;
                }
                else
                {
                    collection = primary ? _primaryMinimalHuds : _secondaryMinimalHuds;
                }

                foreach (var hud in collection.Keys)
                {
                    if (isActive && (hud == InactiveShield || hud == InactiveNoShield))
                    {
                        continue;
                    }

                    if (!isActive && (hud == ActiveShield || hud == ActiveNoShield))
                    {
                        continue;
                    }

                    if (shielded && (hud == ActiveNoShield || hud == InactiveNoShield))
                    {
                        continue;
                    }
                    if (!shielded && (hud == ActiveShield || hud == InactiveShield))
                    {
                        continue;
                    }

                    Vector3D offset;
                    Vector2  localOffset;

                    float      scale;
                    float      screenScale;
                    float      fontScale;
                    MyStringId textureName;
                    var        hudInfo = collection[hud];
                    hudInfo.GetTextureInfo(s, out textureName, out scale, out screenScale, out fontScale, out offset, out localOffset);

                    var color = Color.White;
                    switch (lockMode)
                    {
                    case FocusData.LockModes.None:
                        color = Color.White;
                        break;

                    case FocusData.LockModes.Locked:
                        color = s.Count < 60 ? Color.White : new Color(255, 255, 255, 64);
                        break;

                    case FocusData.LockModes.ExclusiveLock:
                        color = s.SCount < 30 ? Color.White : new Color(255, 255, 255, 64);
                        break;
                    }

                    var hudOpacity = MathHelper.Clamp(_session.UIHudOpacity, 0.25f, 1f);
                    color = new Vector4(1, 1, 1, hudOpacity);
                    MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, screenScale, BlendTypeEnum.PostPP);
                    var quickUpdate = _session.UiInput.FirstPersonView && _session.HudUi.NeedsUpdate && _session.ControlledEntity is IMyGunBaseUser;
                    if (s.Tick20 || quickUpdate)
                    {
                        for (int j = 0; j < 11; j++)
                        {
                            string  text;
                            Vector2 textOffset;
                            if (TargetTextStatus(j, targetState, scale, localOffset, shielded, detailedHud, out text, out textOffset))
                            {
                                var textColor   = Color.White;
                                var fontSize    = (float)Math.Round(21 * fontScale, 1);
                                var fontHeight  = 0.75f;
                                var fontAge     = !quickUpdate ? 18 : 0;
                                var fontJustify = Hud.Justify.None;
                                var fontType    = Hud.FontType.Shadow;
                                var elementId   = MathFuncs.UniqueId(i, j);

                                s.HudUi.AddText(text: text, x: textOffset.X, y: textOffset.Y, elementId: elementId, ttl: fontAge, color: textColor, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
                            }
                        }
                    }
                }

                MyEntity target;
                if (isActive && MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target))
                {
                    var targetSphere = target.PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos    = s.Camera.WorldToScreen(ref targetCenter);

                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y  = -1;
                    }

                    var dotpos      = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));
                    var screenScale = 0.1 * s.ScaleFov;
                    dotpos.X *= (float)(screenScale * _session.AspectRatio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);
                }
            }
        }