Example #1
0
        public void DrawUI(SpriteReference sprite, Rectangle area, Color color)
        {
            int borderWidth  = (sprite.Width - 1) / 2;
            int borderHeight = (sprite.Height - 1) / 2;

            area.Inflate(-borderWidth + 2, -borderHeight + 2);
            sprite.ShouldLoad = true;
            if (sprite.Width % 2 == 0 || sprite.Height % 2 == 0)
            {
                return;
            }
            int borderX      = sprite.Width / 2;
            int borderY      = sprite.Height / 2;
            var leftBorder   = area.X - borderX;
            var topBorder    = area.Y - borderY;
            var rightBorder  = area.X + area.Width;
            var bottomBorder = area.Y + area.Height;

            SpriteBatch.Draw(sprite.Texture, new Rectangle(leftBorder, topBorder, borderX, borderY), new Rectangle(0, 0, borderX, borderY), color);
            SpriteBatch.Draw(sprite.Texture, new Rectangle(leftBorder, bottomBorder, borderX, borderY), new Rectangle(0, borderY + 1, borderX, borderY), color);
            SpriteBatch.Draw(sprite.Texture, new Rectangle(rightBorder, topBorder, borderX, borderY), new Rectangle(borderX + 1, 0, borderX, borderY), color);
            SpriteBatch.Draw(sprite.Texture, new Rectangle(rightBorder, bottomBorder, borderX, borderY), new Rectangle(borderX + 1, borderY + 1, borderX, borderY), color);

            SpriteBatch.Draw(sprite.Texture, new Rectangle(area.X, topBorder, area.Width, borderY), new Rectangle(borderX, 0, 1, borderY), color);
            SpriteBatch.Draw(sprite.Texture, new Rectangle(area.X, bottomBorder, area.Width, borderY), new Rectangle(borderX, borderY + 1, 1, borderY), color);

            SpriteBatch.Draw(sprite.Texture, new Rectangle(leftBorder, area.Y, borderX, area.Height), new Rectangle(0, borderY, borderX, 1), color);
            SpriteBatch.Draw(sprite.Texture, new Rectangle(rightBorder, area.Y, borderX, area.Height), new Rectangle(borderX + 1, borderY, borderX, 1), color);

            SpriteBatch.Draw(sprite.Texture, new Rectangle(area.X, area.Y, area.Width, area.Height), new Rectangle(borderX, borderY, 1, 1), color);
        }
Example #2
0
        private void Load(SpriteReference reference)
        {
            int      count    = 1;
            FileInfo fileinfo = new FileInfo(reference.FileName + ".png");

            if (!fileinfo.Exists)
            {
                DirectoryInfo dirinfo = fileinfo.Directory;
                fileinfo = dirinfo.GetFiles(Path.GetFileNameWithoutExtension(fileinfo.Name) + "_strip*").FirstOrDefault();
            }

            if (fileinfo == null || !fileinfo.Exists)
            {
                return;
            }

            var match = FileNameExpression.Match(fileinfo.Name);

            if (match.Success)
            {
                count = int.Parse(match.Groups[1].Value);
            }

            FileStream stream = fileinfo.OpenRead();

            reference.Texture       = Texture2D.FromStream(GraphicsDevice, stream);
            reference.SubImageCount = count;
            stream.Close();
            reference.OnLoad?.Invoke();
        }
Example #3
0
 public TextElementCursor(SpriteReference sprite, float width, float height, Func <bool> selected)
 {
     Sprite   = sprite;
     Width    = width;
     Height   = height;
     Selected = selected;
 }
Example #4
0
        public void DrawCircle(SpriteReference sprite, SamplerState samplerState, Vector2 center, int precision, float angleStart, float angleEnd, float radius, float texOffset, float texPrecision, float start, float end, ColorMatrix color, BlendState blend)
        {
            if (start == end)
            {
                return;
            }

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite?.Texture ?? Pixel, blendState: blend, rasterizerState: RasterizerState, samplerState: samplerState, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < precision; i++)
            {
                float   angleSlide = (float)i / (precision - 1);
                Vector2 offset     = Util.AngleToVector(MathHelper.Lerp(angleStart, angleEnd, angleSlide));
                var     inside     = center;// + offset * radius * MathHelper.Clamp(start, 0, 1);
                var     outside    = center + offset * radius * MathHelper.Clamp(end, 0, 1);

                var texHorizontal = texPrecision * angleSlide + texOffset;
                var texInside     = 1 - Util.ReverseLerp(MathHelper.Clamp(0, 0, 1), start, end);
                var texOutside    = 1 - Util.ReverseLerp(MathHelper.Clamp(end, 0, 1), start, end);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(inside, 0), Color.White, new Vector2(texHorizontal, texInside)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(outside, 0), Color.White, new Vector2(texHorizontal, texOutside)));
            }

            PrimitiveBatch.End();
        }
Example #5
0
 public ExplosionParticle(SceneGame world, SpriteReference sprite, Vector2 pos, int time) : base(world)
 {
     Sprite   = sprite;
     Position = pos;
     Angle    = Random.NextAngle();
     Frame    = new Slider(time);
 }
Example #6
0
 public SmokeParticleTimeless(SceneGame world, SpriteReference sprite, Vector2 pos, int time) : base(world)
 {
     Sprite   = sprite;
     SubImage = Random.Next(1000);
     Position = pos;
     Angle    = Random.NextAngle();
     Frame    = new Slider(time);
 }
Example #7
0
 public LabelledUIText(SpriteReference labelSprite, SpriteReference contentSprite, Action <TextBuilder> label, Action <TextBuilder> content) : base(labelSprite, contentSprite, label, null)
 {
     Content = new TextBuilder(float.PositiveInfinity, 16);
     label(Content);
     Content.EndContainer();
     Content.Finish();
     Size = GetSize;
 }
Example #8
0
 public BloodStain(SceneGame world, SpriteReference sprite, int subImage, Vector2 pos, float scale, float angle, float time) : base(world)
 {
     Sprite   = sprite;
     SubImage = subImage;
     Position = Vector2.Transform(pos, world.WorldTransform);
     Scale    = scale;
     Angle    = angle;
     Frame    = new Slider(time);
 }
Example #9
0
        public MenuActNew(Scene scene, Action <TextBuilder> name, Vector2 position, SpriteReference label, SpriteReference ui, int width, int height)
        {
            Scene    = scene;
            Position = position;
            Width    = width;
            Height   = height;

            UI = new LabelledUI(label, ui, name, () => new Point(Width, Height));

            Init();
        }
Example #10
0
        private void LoadFontPart(SpriteReference sprite, int index)
        {
            Texture2D tex = sprite.Texture;

            Color[] blah = new Color[tex.Width * tex.Height];
            tex.GetData <Color>(0, new Rectangle(0, 0, tex.Width, tex.Height), blah, 0, blah.Length);

            for (int i = 0; i < FontUtil.CharsPerPage; i++)
            {
                FontUtil.RegisterChar(blah, tex.Width, tex.Height, (char)(index * FontUtil.CharsPerPage + i), i);
            }
        }
Example #11
0
 public LabelledUI(SpriteReference labelSprite, SpriteReference contentSprite, Action <TextBuilder> label, Func <Point> size)
 {
     ContentSprite = contentSprite;
     LabelSprite   = labelSprite;
     Label         = new TextBuilder(float.PositiveInfinity, 16);
     if (label != null)
     {
         Label.StartLine(LineAlignment.Center);
         label(Label);
         Label.EndLine();
     }
     Label.EndContainer();
     Label.Finish();
     Size = size;
 }
Example #12
0
        public void DrawLine(SpriteReference sprite, Vector2 pos1, Vector2 pos2, float widthMod, float lengthMod, float offset, ColorMatrix color, BlendState blend)
        {
            var delta = pos2 - pos1;
            var dist  = delta.Length();
            var side  = (delta / dist).TurnLeft();
            var width = sprite.Height;

            //SetupNormal(WorldTransform, Projection);
            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 + side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 - side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 0)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 + side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 - side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 0)));
            PrimitiveBatch.End();
        }
Example #13
0
        public SpriteReference AddSprite(string filename, bool keeploaded)
        {
            if (Sprites.ContainsKey(filename))
            {
                return(Sprites[filename]);
            }

            var rval = new SpriteReference(filename)
            {
                KeepLoaded = keeploaded
            };

            Sprites.Add(filename, rval);
            AllSprites.Add(rval);
            return(rval);
        }
Example #14
0
        public void DrawMissileCurve(SpriteReference sprite, Func <float, Vector2> curve, int precision, Func <float, float> thickness, float start, float end, ColorMatrix color, BlendState blend)
        {
            List <Vector2> points  = new List <Vector2>();
            List <float>   lengths = new List <float>();
            List <Vector2> pivots  = new List <Vector2>();

            LineSet line = new LineSet();

            for (int i = 0; i <= precision; i++)
            {
                line.AddPoint(curve((float)i / precision));
            }

            line.GetBeam(start, end, points, pivots, lengths);

            var dist  = line.TotalDistance;
            var width = sprite.Height;

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < points.Count; i++)
            {
                var point    = points[i];
                var side     = pivots[i];
                var len      = lengths[i];
                var slide    = len / dist;
                var tex      = (slide - start) / (end - start);
                var widthMod = thickness(slide);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point + side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 1)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point - side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 0)));
            }

            PrimitiveBatch.End();
        }
Example #15
0
 private void DrawTooltip()
 {
     if (TooltipText != null && !TooltipText.IsEmpty())
     {
         SpriteReference ui_tooltip   = SpriteLoader.Instance.AddSprite("content/ui_box");
         int             tooltipWidth = (int)TooltipText.GetContentWidth();
         int             screenWidth  = Viewport.Width - 8 - InputState.MouseX + 4;
         bool            invert       = false;
         if (tooltipWidth > screenWidth)
         {
             screenWidth = Viewport.Width - screenWidth;
             invert      = true;
         }
         int tooltipHeight = (int)TooltipText.GetContentHeight();
         int tooltipX      = InputState.MouseX + 4;
         int tooltipY      = Math.Max(0, InputState.MouseY - 4 - tooltipHeight);
         if (invert)
         {
             tooltipX -= tooltipWidth;
         }
         DrawUI(ui_tooltip, new Rectangle(tooltipX - 2, tooltipY - 2, tooltipWidth + 4, tooltipHeight + 4), Color.White);
         TooltipText.Draw(new Vector2(tooltipX, tooltipY), FontRenderer);
     }
 }
Example #16
0
 public BigStar(Scene world, SpriteReference sprite) : base(world)
 {
     Sprite = sprite;
 }
Example #17
0
        public override void Draw(GameTime gameTime)
        {
            CameraTarget.Setup(this, Viewport.Width, Viewport.Height);
            Util.SetupRenderTarget(this, ref DistortionMap, Viewport.Width, Viewport.Height);
            Util.SetupRenderTarget(this, ref BloodMapAdditive, Viewport.Width, Viewport.Height);
            Util.SetupRenderTarget(this, ref BloodMapMultiply, Viewport.Width, Viewport.Height);

            Projection     = Matrix.CreateOrthographicOffCenter(0, Viewport.Width, Viewport.Height, 0, 0, -1);
            WorldTransform = CreateViewMatrix();
            ApplyScreenShake(ref WorldTransform);

            DrawTextures();

            SetRenderTarget(null);

            var cameraTile = CameraCurio.GetMainTile();
            //var tiles = cameraTile?.GetNearby(15) ?? Enumerable.Empty<MapTile>();
            //var curios = Manager.GetCurios().Where(x => !(x is MapTile)).Concat(tiles);
            //var gameObjects = curios.SelectMany(curio => curio.GetDrawables());
            var globalDrawables = Manager.Drawable.GetDrawables();
            var cameraPos       = CameraCurio.GetVisualTarget();
            var drawPasses      = globalDrawables
                                  .Concat(VisualEffects)
                                  .Concat(Menu.GetAllMenus().OfType <IDrawable>())
                                  .Where(x => x.ShouldDraw(this, cameraPos))
                                  .ToMultiLookup(x => x.GetDrawPasses());

            SetRenderTarget(CameraTarget.A);

            int width  = 19 * 32;
            int height = 19 * 32;

            GraphicsDevice.ScissorRectangle = new Rectangle((Viewport.Width - width) / 2, (Viewport.Height - height) / 2, width, height);
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: WorldTransform, projection: Projection);
            PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.80f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0)));
            drawPasses.DrawPass(this, DrawPass.ChasmBottom);
            PopSpriteBatch();
            PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.85f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0)));
            drawPasses.DrawPass(this, DrawPass.Chasm1);
            PopSpriteBatch();
            PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.90f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0)));
            drawPasses.DrawPass(this, DrawPass.Chasm2);
            PopSpriteBatch();
            PushSpriteBatch(transform: WorldTransform *Matrix.CreateTranslation(new Vector3(-CameraSize, 0)) * Matrix.CreateScale(0.95f) * Matrix.CreateTranslation(new Vector3(CameraSize, 0)));
            drawPasses.DrawPass(this, DrawPass.Chasm3);
            PopSpriteBatch();
            drawPasses.DrawPass(this, DrawPass.Tile);
            drawPasses.DrawPass(this, DrawPass.Item);
            drawPasses.DrawPass(this, DrawPass.EffectLow);
            PushSpriteBatch(blendState: BlendState.Additive);
            drawPasses.DrawPass(this, DrawPass.EffectLowAdditive);
            PopSpriteBatch();
            drawPasses.DrawPass(this, DrawPass.WallBottom);
            drawPasses.DrawPass(this, DrawPass.Creature);
            PushSpriteBatch(blendState: BlendState.Additive);
            drawPasses.DrawPass(this, DrawPass.EffectCreatureAdditive);
            PopSpriteBatch();
            drawPasses.DrawPass(this, DrawPass.WallTop);
            drawPasses.DrawPass(this, DrawPass.Effect);
            PushSpriteBatch(blendState: BlendState.Additive);
            drawPasses.DrawPass(this, DrawPass.EffectAdditive);
            PopSpriteBatch();
            PopSpriteBatch();

            SetRenderTarget(CameraTarget.B);
            CameraTarget.Swap();

            //Draw screenflashes
            ColorMatrix color = ColorMatrix.Identity;

            ApplyScreenFlash(ref color);

            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(color, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(CameraTarget.B, CameraTarget.B.Bounds, Color.White);
            PopSpriteBatch();

            SetRenderTarget(CameraTarget.B);
            CameraTarget.Swap();

            //Draw glitches
            RenderGlitches(CameraTarget);

            //Draw to screen
            SetRenderTarget(null);

            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(CameraTarget.B, CameraTarget.B.Bounds, Color.White);
            PopSpriteBatch();


            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: BlendState.Additive, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(BloodMapAdditive, BloodMapAdditive.Bounds, Color.White);
            PopSpriteBatch();
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: MultiplyBoth, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(BloodMapMultiply, BloodMapMultiply.Bounds, Color.White);
            PopSpriteBatch();

            //Draw cursor and tooltip
            SpriteReference cursor_tile = SpriteLoader.Instance.AddSprite("content/cursor_tile");

            SetupNormal(Matrix.Identity, Projection);
            //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transformMatrix: WorldTransform);
            PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection);

            if (TileCursor.HasValue)
            {
                DrawSprite(cursor_tile, Frame / 8, new Vector2(TileCursor.Value.X * 16, TileCursor.Value.Y * 16), SpriteEffects.None, 0);
            }

            drawPasses.DrawPass(this, DrawPass.UIWorld);

            //SpriteBatch.End();
            PopSpriteBatch();

            //SetupNormal(Matrix.Identity);
            //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap);

            PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, projection: Projection);

            drawPasses.DrawPass(this, DrawPass.UI);

            Menu.Draw(this);

            var mousePos    = new Vector2(InputState.MouseX, InputState.MouseY);
            var mouseCursor = SpriteLoader.Instance.AddSprite("content/ui_mouse_cursor");

            DrawSprite(mouseCursor, 0, mousePos, SpriteEffects.None, 0);

            DrawTooltip();

            PopSpriteBatch();
        }
Example #18
0
 public void DrawSpriteExt(SpriteReference sprite, int frame, Vector2 position, Vector2 origin, float angle, Vector2 scale, SpriteEffects mirror, Color color, float depth)
 {
     SpriteBatch.Draw(sprite.Texture, position + origin, sprite.GetFrameRect(frame), color, angle, origin, scale.Mirror(mirror), SpriteEffects.None, depth);
 }
Example #19
0
 public void DrawSpriteExt(SpriteReference sprite, int frame, Vector2 position, Vector2 origin, float angle, SpriteEffects mirror, float depth)
 {
     DrawSpriteExt(sprite, frame, position, origin, angle, Vector2.One, mirror, Color.White, depth);
 }
Example #20
0
 public void DrawSprite(SpriteReference sprite, int frame, Vector2 position, SpriteEffects mirror, Color color, float depth)
 {
     SpriteBatch.Draw(sprite.Texture, position, sprite.GetFrameRect(frame), color, 0, Vector2.Zero, Vector2.One, mirror, depth);
 }
Example #21
0
 public Wave(Scene scene, SpriteReference sprite, int time) : base(scene)
 {
     WaveSprite = sprite;
     Frame      = new Slider(time);
 }
Example #22
0
 public CutterParticle(SceneGame world, SpriteReference sprite, Vector2 pos, int time) : base(world)
 {
     Sprite   = sprite;
     Position = pos;
     Frame    = new Slider(time);
 }
Example #23
0
 public ExplosionParticleAnchored(SceneGame world, SpriteReference sprite, Func <Vector2> pos, int time) : base(world, sprite, Vector2.Zero, time)
 {
     Anchor = pos;
 }
Example #24
0
 public Explosion(Scene world, SpriteReference sprite, int time) : base(world)
 {
     Sprite = sprite;
     Angle  = Random.NextAngle();
     Frame  = new Slider(time);
 }
Example #25
0
 public int AnimationFrame(SpriteReference sprite, float slide)
 {
     return((int)MathHelper.Clamp(sprite.SubImageCount * slide, 0, sprite.SubImageCount - 1));
 }
Example #26
0
 public SymbolTinted(SpriteReference sprite) : base(sprite)
 {
 }
Example #27
0
        /*public void DrawText(string str, Vector2 drawpos, Alignment alignment, TextParameters parameters)
         * {
         *  Game.DrawText(str, drawpos, alignment, parameters);
         * }*/

        public void DrawSprite(SpriteReference sprite, int frame, Vector2 position, SpriteEffects mirror, float depth)
        {
            DrawSprite(sprite, frame, position, mirror, Color.White, depth);
        }
Example #28
0
 public Symbol(SpriteReference sprite)
 {
     ID     = AllSymbols.Count;
     Sprite = sprite;
     AllSymbols.Add(this);
 }
Example #29
0
 public SymbolBar(SpriteReference sprite) : base(sprite)
 {
 }