public int AllocateMarkerStyle(MyFontEnum font, MyHudTexturesEnum directionIcon, MyHudTexturesEnum targetIcon, Color color)
        {
            int newHandle = m_markerStyles.Count;

            m_markerStyles.Add(new MyMarkerStyle(font, directionIcon, targetIcon, color));
            return(newHandle);
        }
        /// <summary>
        /// Add textured quad with specified UP direction and width/height.
        /// </summary>
        protected void AddTexturedQuad(MyHudTexturesEnum texture, Vector2 position, Vector2 upVector, Color color, float halfWidth, float halfHeight)
        {
            Vector2 rightVector = new Vector2(-upVector.Y, upVector.X);

            MyAtlasTextureCoordinate textureCoord = m_hudScreen.GetTextureCoord(texture);

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

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

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                m_hudScreen.TextureAtlas,
                pos,
                textureCoord.Offset,
                textureCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                color,
                new Vector2(halfWidth, halfHeight));
        }
Example #3
0
 private void SetDefaults()
 {
     Position = ScreenCenter;
     Visible = false;
     Color = MyHudConstants.HUD_COLOR_LIGHT;
     HalfSize = Vector2.One * 0.02f;
     TextureEnum = MyHudTexturesEnum.crosshair;
     UpVector = Vector2.UnitY;
 }
 public MyMarkerStyle(MyFontEnum font, MyHudTexturesEnum textureDirectionIndicator, MyHudTexturesEnum textureTarget, Color color, float textureTargetRotationSpeed = 0f, float textureTargetScale = 1f)
 {
     Font = font;
     TextureDirectionIndicator = textureDirectionIndicator;
     TextureTarget             = textureTarget;
     this.Color = color;
     TextureTargetRotationSpeed = textureTargetRotationSpeed;
     TextureTargetScale         = textureTargetScale;
 }
Example #5
0
 private void SetDefaults()
 {
     Position    = ScreenCenter;
     Visible     = false;
     Color       = MyHudConstants.HUD_COLOR_LIGHT;
     HalfSize    = Vector2.One * 0.02f;
     TextureEnum = MyHudTexturesEnum.crosshair;
     UpVector    = Vector2.UnitY;
 }
        public void ChangeDefaultSprite(MyHudTexturesEnum newSprite, float size = 0.0f)
        {
            for (int i = 0; i < m_sprites.Count; ++i)
            {
                var sprite = m_sprites[i];
                if (sprite.SpriteId != m_defaultSpriteId)
                {
                    continue;
                }

                // Don't change the size by default
                if (size != 0.0f)
                {
                    sprite.HalfSize = Vector2.One * size;
                }
                sprite.SpriteEnum = newSprite;
                m_sprites[i]      = sprite;
            }
        }
        /// <summary>
        /// Adds a temporary sprite to the list of sprites that make up the crosshair
        /// </summary>
        /// <param name="spriteEnum">Texture of the sprite to use</param>
        /// <param name="spriteId">An id that will be checked to prevent adding the same sprite twice</param>
        /// <param name="timeout">Time the sprite will be visible (includes fadeout time)</param>
        /// <param name="fadeTime">For how long should the sprite fade out when it disappears</param>
        public void AddTemporarySprite(MyHudTexturesEnum spriteEnum, MyStringId spriteId, int timeout = 2000, int fadeTime = 1000, Color?color = null, float size = 0.02f)
        {
            SpriteInfo sprite = new SpriteInfo();

            sprite.Color         = color.HasValue ? color.Value : MyHudConstants.HUD_COLOR_LIGHT;
            sprite.FadeoutTime   = fadeTime;
            sprite.HalfSize      = Vector2.One * size;
            sprite.SpriteId      = spriteId;
            sprite.SpriteEnum    = spriteEnum;
            sprite.TimeRemaining = timeout;
            sprite.Visible       = true;

            for (int i = 0; i < m_sprites.Count; ++i)
            {
                if (m_sprites[i].SpriteId == spriteId)
                {
                    m_sprites[i] = sprite;
                    return;
                }
            }

            m_sprites.Add(sprite);
        }
        public void OverrideStyleForRelation(MyRelationsBetweenPlayerAndBlock relation, MyFontEnum font, MyHudTexturesEnum directionIcon, MyHudTexturesEnum targetIcon, Color color)
        {
            int handle = GetStyleForRelation(relation);

            m_markerStyles[handle] = new MyMarkerStyle(font, directionIcon, targetIcon, color);
        }
 public MyAtlasTextureCoordinate GetTextureCoord(MyHudTexturesEnum texture)
 {
     return m_atlasCoords[(int)texture];
 }
        private void DrawGravityVectorIndicator(Vector2 centerPos, Vector3 worldGravity, MyHudTexturesEnum texture, Color color)
        {
            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;

            var textureCoord = GetTextureCoord(texture);
            var viewGravity = Vector3.TransformNormal(worldGravity, MySector.MainCamera.ViewMatrix);
            var viewGravityLen = viewGravity.Length();
            if (!MyUtils.IsZero(viewGravityLen))
                viewGravity /= viewGravityLen;

            var right = new Vector2(viewGravity.Y, viewGravity.X);
            var rightLen = right.Length();

            if (!MyUtils.IsZero(rightLen))
                right /= rightLen;

            var scale = Vector2.One * new Vector2(0.003f, 0.013f);
            scale.Y *= rightLen;

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                centerPos + new Vector2(viewGravity.X, -viewGravity.Y) * 0.02f,
                textureCoord.Offset,
                textureCoord.Size,
                right,
                new Vector2(hudSizeX, hudSizeY),
                color,
                scale);
        }
Example #11
0
 public MyHudSetting(MyGuiFont font, MyHudTexturesEnum textureDirectionIndicator, MyHudTexturesEnum textureTarget, MyHudTexturesEnum textureUnpowered, Color color, float textureTargetRotationSpeed = 0f, float textureTargetScale = 1f) 
 {
     Font = font;
     TextureDirectionIndicator = textureDirectionIndicator;
     TextureTarget = textureTarget;
     this.Color = color;
     TextureTargetRotationSpeed = textureTargetRotationSpeed;
     TextureTargetScale = textureTargetScale;
     TextureUnpowered = textureUnpowered;
 }
Example #12
0
        /// <summary>
        /// Adds a temporary sprite to the list of sprites that make up the crosshair
        /// </summary>
        /// <param name="spriteEnum">Texture of the sprite to use</param>
        /// <param name="spriteId">An id that will be checked to prevent adding the same sprite twice</param>
        /// <param name="timeout">Time the sprite will be visible (includes fadeout time)</param>
        /// <param name="fadeTime">For how long should the sprite fade out when it disappears</param>
        public void AddTemporarySprite(MyHudTexturesEnum spriteEnum, MyStringId spriteId, int timeout = 2000, int fadeTime = 1000, Color? color = null, float size = 0.02f)
        {
            SpriteInfo sprite = new SpriteInfo();
            sprite.Color = color.HasValue ? color.Value : MyHudConstants.HUD_COLOR_LIGHT;
            sprite.FadeoutTime = fadeTime;
            sprite.HalfSize = Vector2.One * size;
            sprite.SpriteId = spriteId;
            sprite.SpriteEnum = spriteEnum;
            sprite.TimeRemaining = timeout;
            sprite.Visible = true;

            for (int i = 0; i < m_sprites.Count; ++i)
            {
                if (m_sprites[i].SpriteId == spriteId)
                {
                    m_sprites[i] = sprite;
                    return;
                }
            }

            m_sprites.Add(sprite);
        }
        private void DrawGravityVectorIndicator(Vector2 centerPos, Vector3 worldGravity, MyHudTexturesEnum texture, Color color)
        {
            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;

            var textureCoord   = GetTextureCoord(texture);
            var viewGravity    = Vector3.TransformNormal(worldGravity, MySector.MainCamera.ViewMatrix);
            var viewGravityLen = viewGravity.Length();

            if (!MyUtils.IsZero(viewGravityLen))
            {
                viewGravity /= viewGravityLen;
            }

            var right    = new Vector2(viewGravity.Y, viewGravity.X);
            var rightLen = right.Length();

            if (!MyUtils.IsZero(rightLen))
            {
                right /= rightLen;
            }

            var scale = Vector2.One * new Vector2(0.003f, 0.013f);

            scale.Y *= rightLen;

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                centerPos + new Vector2(viewGravity.X, -viewGravity.Y) * 0.02f,
                textureCoord.Offset,
                textureCoord.Size,
                right,
                new Vector2(hudSizeX, hudSizeY),
                color,
                scale);
        }
Example #14
0
        //  Add textured quad with specified UP direction
        static void AddTexturedQuad(MyHudTexturesEnum texture, Vector2 position, Vector2 upVector, Color color, float scale)
        {
            //  Left vector is 2D cross product
            Vector2 leftVector = new Vector2(upVector.Y, -upVector.X);
            MyAtlasTextureCoordinate textureCoord = GetTextureCoord(texture);
            float halfWidth = textureCoord.Size.X / 2f * scale;
            float halfHeight = textureCoord.Size.Y / 2f * scale * (3f/4f);

            //  Rectangle representing the middle of the line
            int vertexIndexMiddle = m_quadsCount * MyHudConstants.VERTEXES_PER_HUD_QUAD;
            m_vertices[vertexIndexMiddle + 0].Position = new Vector3(position + leftVector * halfWidth + upVector * halfHeight, 0);
            m_vertices[vertexIndexMiddle + 1].Position = new Vector3(position - leftVector * halfWidth + upVector * halfHeight, 0);
            m_vertices[vertexIndexMiddle + 2].Position = new Vector3(position + leftVector * halfWidth - upVector * halfHeight, 0);
            m_vertices[vertexIndexMiddle + 3].Position = m_vertices[vertexIndexMiddle + 1].Position;
            m_vertices[vertexIndexMiddle + 4].Position = new Vector3(position - leftVector * halfWidth - upVector * halfHeight, 0);
            m_vertices[vertexIndexMiddle + 5].Position = m_vertices[vertexIndexMiddle + 2].Position;

            m_vertices[vertexIndexMiddle + 0].TexCoord = textureCoord.Offset;
            m_vertices[vertexIndexMiddle + 1].TexCoord = new Vector2(textureCoord.Offset.X + textureCoord.Size.X, textureCoord.Offset.Y);
            m_vertices[vertexIndexMiddle + 2].TexCoord = new Vector2(textureCoord.Offset.X, textureCoord.Offset.Y + textureCoord.Size.Y);
            m_vertices[vertexIndexMiddle + 3].TexCoord = m_vertices[vertexIndexMiddle + 1].TexCoord;
            m_vertices[vertexIndexMiddle + 4].TexCoord = new Vector2(textureCoord.Offset.X + textureCoord.Size.X, textureCoord.Offset.Y + textureCoord.Size.Y);
            m_vertices[vertexIndexMiddle + 5].TexCoord = m_vertices[vertexIndexMiddle + 2].TexCoord;

            m_vertices[vertexIndexMiddle + 0].Color = color.ToVector4();
            m_vertices[vertexIndexMiddle + 1].Color = color.ToVector4();
            m_vertices[vertexIndexMiddle + 2].Color = color.ToVector4();
            m_vertices[vertexIndexMiddle + 3].Color = color.ToVector4();
            m_vertices[vertexIndexMiddle + 4].Color = color.ToVector4();
            m_vertices[vertexIndexMiddle + 5].Color = color.ToVector4();

            m_quadsCount++;
        }
Example #15
0
        public void ChangeDefaultSprite(MyHudTexturesEnum newSprite, float size = 0.0f)
        {
            for (int i = 0; i < m_sprites.Count; ++i)
            {
                var sprite = m_sprites[i];
                if (sprite.SpriteId != m_defaultSpriteId)
                {
                    continue;
                }

                // Don't change the size by default
                if (size != 0.0f)
                {
                    sprite.HalfSize = Vector2.One * size;
                }
                sprite.SpriteEnum = newSprite;
                m_sprites[i] = sprite;
            }
        }
 public MyAtlasTextureCoordinate GetTextureCoord(MyHudTexturesEnum texture)
 {
     return(m_atlasCoords[(int)texture]);
 }
        void AddDirectionNavigator(MyHudTexturesEnum texture, Vector3 position, string text, Vector4 color)
        {         
            Vector3 cameraToObject = position - MyCamera.Position;
            Vector2 projectedPoint2D;
            Vector3 target = SharpDXHelper.ToXNA(MyCamera.Viewport.Project(SharpDXHelper.ToSharpDX(position), SharpDXHelper.ToSharpDX(MyCamera.ProjectionMatrix), SharpDXHelper.ToSharpDX(MyCamera.ViewMatrix), SharpDXHelper.ToSharpDX(Matrix.Identity)));

            // if the target is behind the camera, flip coordinates along center of the screen
            if (Vector3.Dot(MyCamera.ForwardVector, cameraToObject) <= 0)
            {
                projectedPoint2D.X = MyMinerGame.ScreenSize.X / 2 - (target.X - MyMinerGame.ScreenSize.X / 2);
                projectedPoint2D.Y = MyMinerGame.ScreenSize.Y / 2 - (target.Y - MyMinerGame.ScreenSize.Y / 2);
            }
            else
            {
                projectedPoint2D.X = target.X;
                projectedPoint2D.Y = target.Y;
            }

            // if the position is visible, don't draw the direction navigator
            if (projectedPoint2D.X >= 0f &&
                projectedPoint2D.X <= MyMinerGame.ScreenSize.X &&
                projectedPoint2D.Y >= 0f &&
                projectedPoint2D.Y <= MyMinerGame.ScreenSize.Y)
            {
                return;
            }

            var textureCoords = MyHud.GetTextureCoord(texture);
            Vector2 textureSize = new Vector2(MyHud.Texture.Width, MyHud.Texture.Height);

            var sourceRectangle = new Rectangle((int)(textureCoords.Offset.X * textureSize.X), (int)(textureCoords.Offset.Y * textureSize.Y), (int)(textureCoords.Size.X * textureSize.X), (int)(textureCoords.Size.Y * textureSize.Y));


            // calculate direction from nonfixed coords
            MyTexture2D directionTexture = MyHud.Texture;
            Vector2 origin = new Vector2(sourceRectangle.Height / 2f, sourceRectangle.Width / 2f);
            Vector2 direction = Vector2.Normalize(projectedPoint2D - new Vector2(MyMinerGame.ScreenSizeHalf.X, MyMinerGame.ScreenSizeHalf.Y));

            // clip direction indicator position to screen coord            
            if (projectedPoint2D.X < 0f + origin.X) projectedPoint2D.X = 0f + origin.X;
            if (projectedPoint2D.X > MyMinerGame.ScreenSize.X - origin.X) projectedPoint2D.X = MyMinerGame.ScreenSize.X - origin.X;
            if (projectedPoint2D.Y < 0f + origin.Y) projectedPoint2D.Y = 0f + origin.Y;
            if (projectedPoint2D.Y > MyMinerGame.ScreenSize.Y - origin.Y) projectedPoint2D.Y = MyMinerGame.ScreenSize.Y - origin.Y;

            // calculate rotation of direciton texture
            double rotation = Math.Atan2(direction.Y, direction.X) + MathHelper.PiOver2;

            MyGuiManager.DrawSpriteBatch(directionTexture, projectedPoint2D, sourceRectangle, new Color(color), (float)rotation, origin, 1f, SharpDX.Toolkit.Graphics.SpriteEffects.None, 0f);

            // draw text
            Vector2 normalizedProjectedPoint2D = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(projectedPoint2D);
            Vector2 textOffset = new Vector2(0, 0.05f);
            MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsWhite(), new StringBuilder(text),
                                    normalizedProjectedPoint2D + textOffset, 0.7f, new Color(color),
                                    MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);   
        }