示例#1
0
        public void Draw(string atlas, MyAtlasTextureCoordinate[] atlasCoords)
        {
            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            var   pos      = m_position;

            if (MyVideoSettingsManager.IsTripleHead())
            {
                pos.X += 1.0f;
            }

            foreach (var sprite in m_sprites)
            {
                if (!sprite.Visible)
                {
                    continue;
                }

                int spriteCoord = (int)sprite.SpriteEnum;
                if (spriteCoord >= atlasCoords.Length)
                {
                    Debug.Assert(false, "Out of bounds of the crosshair array!");
                    continue;
                }

                MyAtlasTextureCoordinate textureCoord = atlasCoords[spriteCoord];

                Color spriteColor = sprite.Color;
                if (sprite.TimeRemaining < sprite.FadeoutTime)
                {
                    spriteColor.A = (byte)(spriteColor.A * sprite.TimeRemaining / sprite.FadeoutTime);
                }

                VRageRender.MyRenderProxy.DrawSpriteAtlas(
                    atlas,
                    pos,
                    textureCoord.Offset,
                    textureCoord.Size,
                    m_rightVector,
                    new Vector2(hudSizeX, hudSizeY),
                    spriteColor,
                    sprite.HalfSize);
            }
        }
        public static void DrawCrosshair(string atlas, MyAtlasTextureCoordinate textureCoord, MyHudCrosshair crosshair)
        {
            Vector2 rightVector = new Vector2(crosshair.UpVector.Y, crosshair.UpVector.X);

            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            var   pos      = crosshair.Position;

            if (MyVideoSettingsManager.IsTripleHead())
            {
                pos.X += 1.0f;
            }

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                atlas,
                pos,
                textureCoord.Offset,
                textureCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                crosshair.Color,
                crosshair.HalfSize);
        }
        /// <summary>
        /// Draws fog (eg. background for notifications) at specified position in normalized GUI coordinates.
        /// </summary>
        public static void DrawFog(ref Vector2 centerPosition, ref Vector2 textSize)
        {
            Color   color       = new Color(0, 0, 0, (byte)(255 * 0.85f));
            Vector2 fogFadeSize = textSize * new Vector2(1.4f, 3.0f);

            MyGuiManager.DrawSpriteBatch(MyGuiConstants.FOG_SMALL, centerPosition, fogFadeSize, color,
                                         MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoSettingsManager.IsTripleHead());
        }
        /// <summary>
        /// Draws location marker on screen.
        /// </summary>
        public void DrawLocationMarker(int styleHandle, Vector3D position, MyHudEntityParams hudParams, float targetDamageRatio, float targetArmorRatio, float alphaMultiplifier = 1f)
        {
            if (MySession.ControlledEntity == null)
            {
                return;
            }

            //  Transform point to camera space, so Z = -1 is always forward and then do projective transformation
            Vector3D transformedPoint = Vector3D.Transform(position, MySector.MainCamera.ViewMatrix);
            Vector4D projectedPoint   = Vector4D.Transform(transformedPoint, MySector.MainCamera.ProjectionMatrix);

            //  If point is behind camera we swap X and Y (this is mirror-like transformation)
            if (transformedPoint.Z > 0)
            {
                projectedPoint.X *= -1;
                projectedPoint.Y *= -1;
            }

            if (projectedPoint.W == 0)
            {
                return;
            }

            MyMarkerStyle markerStyle = m_markerStyles[styleHandle];

            double distance         = Vector3D.Distance(position, MySession.ControlledEntity.Entity.WorldMatrix.Translation);
            float  maxDistance      = hudParams.MaxDistance;
            byte   colorAlphaInByte = 255;
            var    hudColor         = MyFakes.SHOW_FACTIONS_GUI ? markerStyle.Color : Color.White;

            hudColor.A = (byte)(colorAlphaInByte * alphaMultiplifier);

            //  Calculate centered coordinates in range <0..1>
            Vector2 projectedPoint2D = new Vector2((float)(projectedPoint.X / projectedPoint.W / 2.0f) + 0.5f, (float)(-projectedPoint.Y / projectedPoint.W) / 2.0f + 0.5f);

            if (MyVideoSettingsManager.IsTripleHead())
            {
                projectedPoint2D.X = (projectedPoint2D.X - (1.0f / 3.0f)) / (1.0f / 3.0f);
            }

            float objectNameYOffset = 0.0f; //offset to direction indicator

            //  This will bound the rectangle in circle, although it isn't real circle because we work in [1,1] dimensions,
            //  but number of horizontal pixels is bigger, so at the end it's more elypse
            //  It must be done when point is out of circle or behind the camera
            Vector2 direction = projectedPoint2D - MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER;

            if ((direction.Length() > MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE) || (transformedPoint.Z > 0))
            {
                if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS) == 0)
                {
                    return;
                }

                if (direction.LengthSquared() > MyMathConstants.EPSILON_SQUARED)
                {
                    direction.Normalize();
                }
                else
                {
                    direction = new Vector2(1f, 0f);
                }
                projectedPoint2D = MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER + direction * MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE;

                //  Fix vertical scale
                projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y;

                AddTexturedQuad(markerStyle.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 2.5f, direction,
                                hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f);
            }
            else
            {
                //  Fix vertical scale
                projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y;

                Color rectangleColor = Color.White;
                rectangleColor.A = colorAlphaInByte;

                if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_FOCUS_MARK) > 0)
                {
                    Vector2 upVector = new Vector2(0, -1);
                    if (markerStyle.TextureTargetRotationSpeed != 0)
                    {
                        upVector = new Vector2((float)Math.Cos(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi),
                                               (float)Math.Sin(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi));
                    }

                    AddTexturedQuad(markerStyle.TextureTarget, projectedPoint2D, upVector, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale);
                }

                objectNameYOffset = -MyHudConstants.HUD_TEXTS_OFFSET;
            }

            if (hudParams.Text != null && hudParams.Text.Length > 0 && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_TEXT) != 0)
            {
                //  Add object's name
                MyHudText objectName = m_hudScreen.AllocateText();
                if (objectName != null)
                {
                    objectName.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, hudParams.OffsetText ? objectNameYOffset : 0),
                                     hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                    objectName.Append(hudParams.Text);
                }
            }

            // display hud icon
            if (hudParams.Icon != null && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_ICON) != 0)
            {
                Color iconColor = hudParams.IconColor.HasValue && MyFakes.SHOW_FACTIONS_GUI ? hudParams.IconColor.Value : Color.White;
                iconColor.A = (byte)(colorAlphaInByte * alphaMultiplifier);

                AddTexturedQuad(hudParams.Icon.Value, projectedPoint2D + hudParams.IconOffset, new Vector2(0, -1), iconColor, hudParams.IconSize.X / 2f, hudParams.IconSize.Y / 2f);
            }

            if (MyFakes.SHOW_HUD_DISTANCES && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_DISTANCE) != 0)
            {
                //  Add distance to object
                MyHudText objectDistance = m_hudScreen.AllocateText();
                if (objectDistance != null)
                {
                    objectDistance.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, MyHudConstants.HUD_TEXTS_OFFSET),
                                         hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);

                    //  Create string builder with distance in metres, e.g. "123m"
                    objectDistance.AppendInt32((int)Math.Round(distance));
                    objectDistance.Append("m");
                }
            }
        }
 public override void Draw()
 {
     if (_currentMessage.HasValue)
     {
         MyGuiManager.DrawString("Debug", _currentMessage.Value.Text, _position,
                                 MyGuiSandbox.GetDefaultTextScaleWithLanguage() * 1.2f, _currentMessage.Value.Color,
                                 MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoSettingsManager.IsTripleHead());
     }
 }
示例#6
0
        private void DrawNotifications(int visibleCount)
        {
            var notificationPosition = Position;
            int textIdx = 0;

            for (int i = MAX_PRIORITY; i >= 0; --i)
            {
                List <MyHudNotificationBase> notifications;
                m_notificationsByPriority.TryGetValue(i, out notifications);
                if (notifications == null)
                {
                    continue;
                }

                foreach (var notification in notifications)
                {
                    if (!IsDrawn(notification))
                    {
                        continue;
                    }

                    MyGuiManager.DrawString(notification.Font, m_texts[textIdx], notificationPosition,
                                            MyGuiSandbox.GetDefaultTextScaleWithLanguage(), Color.White,
                                            MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoSettingsManager.IsTripleHead());
                    notificationPosition.Y += m_textSizes[textIdx].Y;
                    ++textIdx;
                    --visibleCount;
                    if (visibleCount == 0)
                    {
                        return;
                    }
                }
            }
        }
        private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo)
        {
            if (indicator.Entity == null)
            {
                return;
            }

            Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position);
            //gravity += MyPhysics.HavokWorld.Gravity;
            bool anyGravity = !MyUtils.IsZero(gravity.Length());

            // Background and text drawing
            MyFontEnum    font;
            StringBuilder text;

            m_hudIndicatorText.Clear();
            m_hudIndicatorText.AppendFormatedDecimal("", gravity.Length() / 9.81f, 1, " g");
            MyGuiPaddedTexture bg;

            if (anyGravity)
            {
                font = MyFontEnum.Blue;
                text = MyTexts.Get(MySpaceTexts.HudInfoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            }
            else
            {
                font = MyFontEnum.Red;
                text = MyTexts.Get(MySpaceTexts.HudInfoNoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED;
            }

            bool    drawOxygen  = MySession.Static.Settings.EnableOxygen;
            Vector2 bgSizeDelta = new Vector2(0.015f, 0f);
            float   oxygenLevel = 0f;

            Vector2 bgSize = bg.SizeGui + bgSizeDelta;

            Vector2            bgPos, textPos, gTextPos, position;
            MyGuiDrawAlignEnum align;

            if (indicator.Entity is MyCharacter)
            {
                bgPos    = new Vector2(0.99f, 0.99f);
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos - bgSize * new Vector2(0.94f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos - bgSize * new Vector2(0.56f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                oxygenLevel = (indicator.Entity as MyCharacter).EnvironmentOxygenLevel;
            }
            else
            {
                bgPos    = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f));
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos + bgSize * new Vector2(1 - 0.94f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos + bgSize * new Vector2(1 - 0.56f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(-0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                var cockpit = indicator.Entity as MyCockpit;
                if (cockpit != null && cockpit.Pilot != null)
                {
                    oxygenLevel = cockpit.Pilot.EnvironmentOxygenLevel;
                }
                else
                {
                    drawOxygen = false;
                }
            }

            if (drawOxygen)
            {
                bgSizeDelta += new Vector2(0f, 0.025f);
            }

            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui + bgSizeDelta, Color.White, align);

            MyGuiManager.DrawString(font, text, textPos, m_textScale);

            if (drawOxygen)
            {
                var oxygenFont = MyFontEnum.Blue;
                var oxygenText = new StringBuilder("Oxygen: ");
                if (oxygenLevel == 0f)
                {
                    oxygenText.Append("None");
                    oxygenFont = MyFontEnum.Red;
                }
                else if (oxygenLevel < 0.5f)
                {
                    oxygenText.Append("Low");
                    oxygenFont = MyFontEnum.Red;
                }
                else
                {
                    oxygenText.Append("High");
                }

                MyGuiManager.DrawString(oxygenFont, oxygenText, textPos - new Vector2(0f, 0.025f), m_textScale);
            }

            if (anyGravity)
            {
                MyGuiManager.DrawString(MyFontEnum.White, m_hudIndicatorText, gTextPos, m_textScale);
            }

            position = MyGuiManager.GetHudSize() * ConvertNormalizedGuiToHud(ref position);
            if (MyVideoSettingsManager.IsTripleHead())
            {
                position.X += 1.0f;
            }

            // Draw each of gravity indicators.
            foreach (var generatorGravity in MyGravityProviderSystem.GravityVectors)
            {
                DrawGravityVectorIndicator(position, generatorGravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);
            }

            //if (MyPhysics.HavokWorld.Gravity != Vector3.Zero)
            //    DrawGravityVectorIndicator(position, MyPhysics.HavokWorld.Gravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);

            if (anyGravity)
            {
                DrawGravityVectorIndicator(position, gravity, MyHudTexturesEnum.gravity_arrow, Color.White);
            }

            // Draw center
            MyAtlasTextureCoordinate centerTextCoord;

            if (anyGravity)
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_white);
            }
            else
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_red);
            }

            float   hudSizeX    = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float   hudSizeY    = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            Vector2 rightVector = Vector2.UnitX;

            MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                position,
                centerTextCoord.Offset,
                centerTextCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                MyHudConstants.HUD_COLOR_LIGHT,
                Vector2.One * 0.005f);
        }
        public override bool Draw()
        {
            if (m_transitionAlpha < 1.0f)
            {
                return(false);
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.J) && MyFakes.ENABLE_OBJECTIVE_LINE)
            {
                MyHud.ObjectiveLine.AdvanceObjective();
            }

            m_toolbarControl.Visible = !MyHud.MinimalHud;

            Vector2 position = new Vector2(0.99f, 0.8f);

            position = ConvertHudToNormalizedGuiPosition(ref position);
            if (MyVideoSettingsManager.IsTripleHead())
            {
                position.X += 1.0f;
            }

            // TODO: refactor this
            m_blockInfo.Visible     = MyHud.BlockInfo.Visible && !MyHud.MinimalHud;
            m_blockInfo.BlockInfo   = m_blockInfo.Visible ? MyHud.BlockInfo : null;
            m_blockInfo.Position    = position;
            m_blockInfo.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;

            m_rotatingWheelControl.Visible = MyHud.RotatingWheelVisible && !MyHud.MinimalHud;

            if (!base.Draw())
            {
                return(false);
            }

            var bgPos = new Vector2(0.01f, 0.85f);

            bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
            m_chatControl.Position  = bgPos + new Vector2(0.15f, 0);
            m_chatControl.TextScale = 0.9f;

            bgPos = new Vector2(0.03f, 0.1f);
            bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
            m_cameraInfoMultilineControl.Position  = bgPos;
            m_cameraInfoMultilineControl.TextScale = 0.9f;

            if (MyHud.Crosshair.Visible && MySandboxGame.Config.ShowCrosshair)
            {
                DrawCrosshair(m_atlas, GetTextureCoord(MyHud.Crosshair.TextureEnum), MyHud.Crosshair);
            }

            MyHud.Notifications.Draw();

            m_buildModeLabel.Visible = !MyHud.MinimalHud && MyHud.IsBuildMode;

            if (MyHud.ShipInfo.Visible && !MyHud.MinimalHud)
            {
                DrawShipInfo(MyHud.ShipInfo);
            }

            if (MyHud.CharacterInfo.Visible && !MyHud.MinimalHud)
            {
                DrawSuitInfo(MyHud.CharacterInfo);
            }

            if (MyHud.ObjectiveLine.Visible && !MyHud.MinimalHud && MyFakes.ENABLE_OBJECTIVE_LINE)
            {
                DrawObjectiveLine(MyHud.ObjectiveLine);
            }

            MyHud.BlockInfo.Visible = false;
            m_blockInfo.BlockInfo   = null;

            if (MyHud.GravityIndicator.Visible && !MyHud.MinimalHud)
            {
                DrawGravityIndicator(MyHud.GravityIndicator, MyHud.CharacterInfo);
            }

            if (MyHud.ConsumerGroupInfo.Visible && !MyHud.MinimalHud)
            {
                DrawPowerGroupInfo(MyHud.ConsumerGroupInfo);
            }

            if (MyHud.SelectedObjectHighlight.Visible && MyFakes.ENABLE_USE_OBJECT_HIGHLIGHT)
            {
                DrawSelectedObjectHighlight(m_atlas, GetTextureCoord(MyHudTexturesEnum.corner), MyHud.SelectedObjectHighlight);
            }

            if (MyHud.LocationMarkers.Visible && !MyHud.MinimalHud)
            {
                m_markerRender.DrawLocationMarkers(MyHud.LocationMarkers);
            }

            if (MyHud.GpsMarkers.Visible && !MyHud.MinimalHud && MyFakes.ENABLE_GPS)
            {
                DrawGpsMarkers(MyHud.GpsMarkers);
            }

            if (MyHud.ButtonPanelMarkers.Visible && !MyHud.MinimalHud)
            {
                DrawButtonPanelMarkers(MyHud.ButtonPanelMarkers);
            }

            if (MyHud.OreMarkers.Visible && !MyHud.MinimalHud)
            {
                DrawOreMarkers(MyHud.OreMarkers);
            }

            if (MyHud.LargeTurretTargets.Visible && !MyHud.MinimalHud)
            {
                DrawLargeTurretTargets(MyHud.LargeTurretTargets);
            }

            if (!MyHud.MinimalHud)
            {
                DrawWorldBorderIndicator(MyHud.WorldBorderChecker);
            }

            if (MyHud.HackingMarkers.Visible && !MyHud.MinimalHud)
            {
                DrawHackingMarkers(MyHud.HackingMarkers);
            }

            //m_chatControl.Visible = !MyHud.MinimalHud;

            if (!MyHud.MinimalHud)
            {
                DrawCameraInfo(MyHud.CameraInfo);
            }

            ProfilerShort.Begin("Draw netgraph");
            if (MyFakes.ENABLE_NETGRAPH && MyHud.IsNetgraphVisible)
            {
                DrawNetgraph(MyHud.Netgraph);
            }
            ProfilerShort.End();
            //if (Sync.MultiplayerActive)
            DrawMultiplayerNotifications();

            if (!MyHud.MinimalHud && MyHud.VoiceChat.Visible)
            {
                DrawVoiceChat(MyHud.VoiceChat);
            }

            return(true);
        }
示例#9
0
        /// <summary>
        /// Draws fog (eg. background for notifications) at specified position in normalized GUI coordinates.
        /// </summary>
        private static void DrawFogInternal(string texture, ref Vector2 centerPosition, ref Vector2 size, float fogAlphaMultiplier, MyGuiDrawAlignEnum alignment)
        {
            Color color = new Color(0, 0, 0, (byte)(255 * 0.85f * fogAlphaMultiplier));

            MyGuiManager.DrawSpriteBatch(texture, centerPosition, size, color, alignment, MyVideoSettingsManager.IsTripleHead());
        }