Ejemplo n.º 1
0
        private void SetupGUI(Entity player)
        {
            //Setup GUI
            var uiCanvas = CreateEntity("UICanvas").AddComponent(new UICanvas());

            uiCanvas.Entity.Transform.LocalPosition = new Vector2(-45, -45);
            uiCanvas.Entity.SetParent(player.Transform);

            var table = uiCanvas.Stage.AddElement(new Table());

            table.SetFillParent(true);

            var bar = new ProgressBar(0, 60, 0.1f, false, ProgressBarStyle.Create(Color.Orange, Color.Gray));

            bar.Value = 20;
            table.Add(bar);
            table.Top();
            table.PadTop(10f);
            table.Left();

            var gameManager = CreateEntity("GameManager")
                              .AddComponent(new GameManagerController());

            gameManager.UpdateOrder = 0;
            gameManager.Bar         = bar;
        }
Ejemplo n.º 2
0
        private void SetUpUI()
        {
            frame = AddComponent(new UICanvas());
            frame.IsFullScreen = true;
            frame.RenderLayer  = -1;
            frame.LayerDepth   = 0.1f;

            internals = AddComponent(new UICanvas());
            internals.IsFullScreen = true;
            internals.RenderLayer  = -1;

            {
                int x = 20, y = 20;

                var frameTexture = Scene.Content.LoadTexture(ContentPaths.HealthBarFrame);
                var healthFrame  = frame.Stage.AddElement(new Image(frameTexture));
                healthFrame.SetPosition(x, y);
                healthFrame.SetSize(508, 58);

                ShadedImage <UIMaskEffect> AddBar(string path, Vector2 pos)
                {
                    var effect  = Scene.Content.LoadEffect <UIMaskEffect>(ContentPaths.MaskEffect);
                    var texture = Scene.Content.LoadTexture(path);
                    var image   = new ShadedImage <UIMaskEffect>(effect, texture);

                    image.SetPosition(pos.X, pos.Y);
                    image.SetSize(texture.Width * 2, texture.Height * 2);
                    internals.Stage.AddElement(image);
                    return(image);
                }

                speedRegular = new SpriteDrawable(Scene.Content.LoadTexture(ContentPaths.SpeedInternal));
                speedMaxed   = new SpriteDrawable(Scene.Content.LoadTexture(ContentPaths.SpeedInternalMaxed));

                healthBar = AddBar(ContentPaths.HealthInternal, new Vector2(x + 50, y + 8));
                dashBar   = AddBar(ContentPaths.DashInternal, new Vector2(x + 80, y + 34));
                speedBar  = AddBar(ContentPaths.SpeedInternal, new Vector2(x + 342, y + 34));
            }
            {
                var x = 20;
                var y = 140;

                var texture   = Scene.Content.LoadTexture(ContentPaths.AmmoFrame);
                var ammoFrame = frame.Stage.AddElement(new Table().Top().Left());
                ammoFrame.SetPosition(x, y);
                var cell = ammoFrame.Add(new Image(texture));
                cell.Size(64, 384);

                var style = ProgressBarStyle.Create(Color.Transparent, AmmoHighlight);
                style.KnobBefore.MinWidth  = style.KnobAfter.MinWidth = 24;
                style.KnobBefore.MinHeight = 0;

                ammo = internals.Stage.AddElement(new ProgressBar(0, playerAmmo.MaxAmmo, 1, true, style));
                ammo.SetSize(0, 324);
                ammo.SetOrigin((int)Align.TopLeft);
                ammo.SetPosition(x + 16 * 2, y + 29 * 2);
            }
            {
                weaponSlots = new List <Image>();

                var table = internals.Stage.AddElement(new Table());
                table.SetOrigin((int)VerticalAlign.Bottom);
                table.SetPosition(internals.Stage.GetWidth() / 2, internals.Stage.GetHeight() - 48 - 20);

                var iconTextures = Scene.Content.LoadTexture(ContentPaths.WeaponIcons);
                weaponIcons = Sprite.SpritesFromAtlas(iconTextures, 32, 32);

                void addIcon(int size)
                {
                    var image = new Image(Scene.Content.LoadTexture(ContentPaths.EmptySprite));

                    table.Add(image).Size(size).Pad(5);
                    weaponSlots.Add(image);
                }

                addIcon(64);
                addIcon(96);
                addIcon(64);

                UpdateWeaponIcons();
            }
        }