Example #1
0
        public override void Draw(SceneGame scene)
        {
            SpriteReference cursor       = SpriteLoader.Instance.AddSprite("content/cursor");
            SpriteReference textbox      = SpriteLoader.Instance.AddSprite("content/ui_box");
            int             edgeDistance = 50;
            int             width        = scene.Viewport.Width - edgeDistance * 2;
            int             height       = 16 * Actions.Count;
            int             x            = edgeDistance;
            int             y            = (scene.Viewport.Height - height) / 2;
            float           openCoeff    = Math.Min(Ticks / 7f, 1f);
            float           openResize   = MathHelper.Lerp(-0.5f, 0.0f, openCoeff);
            RectangleF      rect         = new RectangleF(x, y, width, height);

            rect.Inflate(rect.Width * openResize, rect.Height * openResize);
            if (openCoeff > 0)
            {
                scene.DrawUI(textbox, rect.ToRectangle(), Color.White);
            }
            int i = 0;

            if (openCoeff >= 1)
            {
                foreach (var menupoint in Actions)
                {
                    if (menupoint == SelectedAction)
                    {
                        scene.SpriteBatch.Draw(cursor.Texture, new Vector2(x + 0, y + i * 16), cursor.GetFrameRect(0), Color.White);
                    }
                    scene.DrawText(menupoint.Name, new Vector2(x + 32, y + i * 16), Alignment.Left, new TextParameters().SetConstraints(width - 32, 16).SetBold(true).SetColor(Color.White, Color.Black));
                    i++;
                }
            }
        }
Example #2
0
        public override void Draw(SceneGame scene)
        {
            var             memory  = Player.Memory;
            SpriteReference textbox = SpriteLoader.Instance.AddSprite("content/ui_box");

            if (NearestItem != null)
            {
                int        width      = 256;
                int        height     = 16;
                int        x          = (scene.Viewport.Width - width) / 2;
                int        y          = scene.Viewport.Height - height - 4;
                float      openCoeff  = Math.Min(NearestItemTicks / 7f, 1f);
                float      openResize = MathHelper.Lerp(-0.5f, 0.0f, openCoeff);
                RectangleF rect       = new RectangleF(x, y, width, height);
                rect.Inflate(rect.Width * openResize * 0.5f, rect.Height * openResize);
                if (openCoeff > 0)
                {
                    scene.DrawUI(textbox, rect.ToRectangle(), Color.White);
                }
                if (openCoeff >= 1)
                {
                    scene.DrawText($"Pick up {memory.GetName(NearestItem.Item)}", new Vector2(x, y), Alignment.Center, new TextParameters().SetConstraints(width, height).SetBold(true).SetColor(Color.White, Color.Black));
                }
            }

            DrawMessageHistory(scene, Player.History);
        }
Example #3
0
        public void DrawUI(SpriteReference sprite, Rectangle area, Color color)
        {
            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 #4
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 #5
0
 public Background(SceneGame sceneGame, SpriteReference backgroundImage, Func <Vector2> offset, Vector2 speed)
 {
     SceneGame       = sceneGame;
     BackgroundImage = backgroundImage;
     BackgroundSize  = backgroundImage.Texture.Bounds.Size.ToVector2();
     Offset          = offset;
     Speed           = speed;
 }
Example #6
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 #7
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 #8
0
        public override void Draw(SceneGame scene)
        {
            SpriteReference textbox      = SpriteLoader.Instance.AddSprite("content/ui_box");
            int             edgeDistance = 75;
            int             width        = scene.Viewport.Width - edgeDistance * 2;
            int             height       = 16 * 4;
            int             x            = edgeDistance;
            int             y            = (scene.Viewport.Height - height) / 2;
            float           openCoeff    = Math.Min(Ticks / 7f, 1f);
            float           openResize   = MathHelper.Lerp(-0.5f, 0.0f, openCoeff);
            RectangleF      rect         = new RectangleF(x, y, width, height);

            rect.Inflate(rect.Width * openResize, rect.Height * openResize);
            if (openCoeff > 0)
            {
                scene.DrawUI(textbox, rect.ToRectangle(), Color.White);
            }
            if (openCoeff >= 1)
            {
                scene.DrawText(Text, new Vector2(x, y), Alignment.Left, new TextParameters().SetConstraints(width, height).SetBold(true).SetColor(Color.White, Color.Black));
            }
        }
Example #9
0
        public override void Draw(SceneGame scene)
        {
            var             memory       = Player.Memory;
            SpriteReference cursor       = SpriteLoader.Instance.AddSprite("content/cursor");
            SpriteReference textbox      = SpriteLoader.Instance.AddSprite("content/ui_box");
            SpriteReference flagEquipped = SpriteLoader.Instance.AddSprite("content/flag_equip");

            int        edgeDistance = 75;
            int        width        = scene.Viewport.Width - edgeDistance * 2;
            int        height       = 16 * Math.Max(Items.Count, 1);
            int        x            = edgeDistance;
            int        y            = (scene.Viewport.Height - height) / 2;
            float      openCoeff    = Math.Min(Ticks / 7f, 1f);
            float      openResize   = MathHelper.Lerp(-0.5f, 0.0f, openCoeff);
            RectangleF rect         = new RectangleF(x, y, width, height);

            rect.Inflate(rect.Width * openResize, rect.Height * openResize);
            if (openCoeff > 0)
            {
                scene.DrawUI(textbox, rect.ToRectangle(), Color.White);
            }
            int i = 0;

            if (openCoeff >= 1)
            {
                if (Items.Count <= 0)
                {
                    scene.DrawText("You haven't anything.", new Vector2(x, y), Alignment.Left, new TextParameters().SetConstraints(width - 32, 16).SetBold(true).SetColor(Color.LightGray, Color.Black));
                }
                foreach (var menupoint in Items)
                {
                    var item = menupoint.Representative;

                    if (CombineSelections.Any(selection => selection.Stack == menupoint))
                    {
                        var combineSelection = CombineSelections.Find(selection => selection.Stack == menupoint);
                        if (Ticks % 2 == 0)
                        {
                            scene.SpriteBatch.Draw(cursor.Texture, new Vector2(x + 6, y + i * 16), cursor.GetFrameRect(0), Color.White);
                        }
                        item = combineSelection.Item;
                    }
                    if (menupoint == Selection.Stack)
                    {
                        scene.SpriteBatch.Draw(cursor.Texture, new Vector2(x + 0, y + i * 16), cursor.GetFrameRect(0), Color.White);
                        item = Selection.Item;
                    }

                    int selectedItems = CombineSelections.Count(selection => selection.Stack == menupoint);

                    item.DrawIcon(scene, new Vector2(x + 16 + 8, y + i * 16 + 8));
                    if (item == Player.Weapon)
                    {
                        scene.DrawSprite(flagEquipped, 0, new Vector2(x + 16, y + i * 16), SpriteEffects.None, 0);
                    }
                    if (selectedItems > 1)
                    {
                        scene.DrawText(Game.ConvertToSmallPixelText(selectedItems.ToString()), new Vector2(x + 32, y + i * 16), Alignment.Right, new TextParameters().SetColor(Color.White, Color.Black));
                    }
                    scene.DrawText($"{memory.GetName(item)} x{menupoint.Count}", new Vector2(x + 32, y + i * 16), Alignment.Left, new TextParameters().SetConstraints(width - 32, 16).SetBold(true).SetColor(Color.White, Color.Black));
                    i++;
                }
            }
        }