Esempio n. 1
0
        private void Init()
        {
            var cache = Application.ResourceCache;

            barTex  = cache.GetTexture2D("Textures/Bargraph.png");
            barFont = cache.GetFont("Fonts/OpenSans-SemiBold.ttf");

            graphRoot = new UIElement();
            graphRoot.SetStyleAuto(null);
            graphRoot.LayoutMode = LayoutMode.Free;

            panel = Node.CreateComponent <UIComponent>();
            panel.Material.SetTechnique(0, cache.GetTechnique("Techniques/DiffUnlitAlpha.xml"));
            panel.Root.LayoutMode          = LayoutMode.Free;
            panel.Root.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Root.VerticalAlignment   = VerticalAlignment.Center;
            panel.Root.AddChild(graphRoot);

            billboards = Node.CreateComponent <BillboardSet>();
            billboards.NumBillboards = 1;
            billboards.Material      = panel.Material;

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Enabled = false;
            billboards.Commit();
        }
Esempio n. 2
0
        public void SetHealth(float healthPercent)
        {
            healthPercent = Math.Max(Math.Min(healthPercent, 100), 0);

            var billboard  = billboardSet.GetBillboardSafe(billboardIndex);
            int imageIndex = (int)healthPercent / entity.Player.Insignia.HealthBarStepSize;

            Rect  uv     = entity.Player.Insignia.HealthBarFullUv;
            float offset = imageIndex / ((100.0f / entity.Player.Insignia.HealthBarStepSize) + 1);

            uv.Min.Y    += offset;
            uv.Max.Y    += offset;
            billboard.Uv = uv;

            billboardSet.Commit();
        }
Esempio n. 3
0
        private void Init()
        {
            var cache = Application.ResourceCache;

            label = new Text()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
            };
            label.SetColor(new Color(1.0f, 1.0f, 1.0f));
            label.SetFont(cache.GetFont("Fonts/OpenSans-Bold.ttf"), 20);

            background = new BorderImage()
            {
                //Texture = cache.GetTexture2D("Textures/UI.png"),
                //ImageRect = new IntRect(48, 0, 64, 16),
                //Border = new IntRect(4, 4, 4, 4),
                Texture   = cache.GetTexture2D("Textures/Panel.png"),
                ImageRect = new IntRect(0, 0, 64, 64),
                Border    = new IntRect(30, 30, 30, 30),
                BlendMode = BlendMode.Alpha,
            };

            panel = Node.CreateComponent <UIComponent>();
            panel.Material.SetTechnique(0, cache.GetTechnique("Techniques/DiffUnlitAlpha.xml"));
            panel.Root.LayoutMode          = LayoutMode.Free;
            panel.Root.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Root.VerticalAlignment   = VerticalAlignment.Center;
            panel.Root.AddChild(background);
            panel.Root.AddChild(label);

            billboards = Node.CreateComponent <BillboardSet>();
            billboards.NumBillboards = 1;
            billboards.Material      = panel.Material;

            Node.Position = Position;

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Enabled = false;
            billboards.Commit();


            /*
             * var node = Node.CreateChild();
             * node.Position = new Vector3(0.0f, 2.0f, 0.0f);
             * node.Scale = new Vector3(2.0f, 2.0f, 2.0f);
             */

            /*
             * var box = node.CreateComponent<StaticModel>();
             * box.Model = cache.GetModel("Models/Box.mdl");
             * //box.Material = Material.FromImage("Textures/StoneDiffuse.dds");
             */
        }
Esempio n. 4
0
        private void Init()
        {
            var cache = Application.ResourceCache;

            billboards = Node.CreateComponent <BillboardSet>();
            billboards.NumBillboards = 1;
            billboards.Material      = cache.GetMaterial("Materials/Sprite.xml").Clone();

            Node.Position = Position;

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Position = Vector3.Zero;
            billboard.Size     = new Vector2(0.1f, 0.1f);
            billboard.Enabled  = true;
            billboards.Commit();
        }
Esempio n. 5
0
        public void Update(IEnumerable <BarData> newData)
        {
            if (newData.Count() != data.Count)
            {
                graphRoot.Size = new IntVector2(MAX_BAR_WIDTH + labelWidth, newData.Count() * HEIGHT);

                graphRoot.RemoveAllChildren();
                for (int i = 0; i < newData.Count(); ++i)
                {
                    var row = new UIElement();

                    var label = new Text()
                    {
                        TextAlignment       = HorizontalAlignment.Right,
                        HorizontalAlignment = HorizontalAlignment.Right
                    };
                    label.SetColor(new Color(1.0f, 1.0f, 1.0f));
                    label.SetFont(barFont, 22);
                    label.Position = new IntVector2(labelWidth, i * HEIGHT);
                    label.Width    = labelWidth;
                    row.AddChild(label);

                    var bar = new BorderImage()
                    {
                        Texture   = barTex,
                        ImageRect = new IntRect(0, 0, 32, 32),
                        Border    = new IntRect(6, 9, 6, 9),

                        MinSize   = new IntVector2(20, 20),
                        BlendMode = BlendMode.Alpha
                    };
                    bar.Position = new IntVector2(labelWidth + LABEL_GAP, i * HEIGHT);
                    row.AddChild(bar);

                    graphRoot.AddChild(row);
                }
            }
            data.Clear();
            data.AddRange(newData);

            var selected = data.Select(bd => bd.Value);
            // TODO: Check whether this should be in or out

            /*if (!selected.Any()) {
             *  return;
             * }*/
            var maxValue      = selected.Max();
            int maxLabelWidth = -1;

            for (int i = 0; i < data.Count; ++i)
            {
                var row = graphRoot.GetChild((uint)i);

                var label = row.GetChild(0) as Text;
                label.Value   = data[i].Label;
                maxLabelWidth = (int)Math.Max(label.GetRowWidth(0), maxLabelWidth);

                var bar = row.GetChild(1) as BorderImage;
                if (data[i].Color.HasValue)
                {
                    bar.SetColor(data[i].Color.Value);
                }
                else
                {
                    bar.SetColor(colorCycle[i % colorCycle.Length]);
                }
                bar.Size = new IntVector2((int)(MAX_BAR_WIDTH * (data[i].Value / maxValue)), HEIGHT);
            }

            if (maxLabelWidth != labelWidth)
            {
                labelWidth = maxLabelWidth;
                for (int i = 0; i < data.Count; ++i)
                {
                    var row   = graphRoot.GetChild((uint)i);
                    var label = row.GetChild(0) as Text;
                    var bar   = row.GetChild(1) as BorderImage;

                    label.Position = new IntVector2(labelWidth, i * HEIGHT);
                    label.Width    = labelWidth;
                    bar.Position   = new IntVector2(labelWidth + LABEL_GAP, i * HEIGHT);
                }
            }

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Size    = new Vector2(0.001f * (MAX_BAR_WIDTH + labelWidth), 0.002f * (HEIGHT * data.Count));
            billboard.Enabled = true;
            billboards.Commit();
        }