private void onResize(Object sender, UISizeChangedEventArgs e)
        {
            // Update the position of the scrollbar.
            HPBar hpBar = getHPBar();

            if (hpBar != null)
            {
                int hpBarHeight         = hpBar.DrawBox.Height;
                int hpBarMargin         = 3;
                int pictureBoxDimension = e.DrawBox.Height - hpBarHeight - 3 * hpBarMargin;
                hpBar.DrawBox = new Rectangle(hpBar.DrawBox.X, e.DrawBox.Height - hpBarHeight - hpBarMargin, e.DrawBox.Width - (2 * hpBar.DrawBox.X), hpBarHeight);
                // Get picturebox
                TestUIComponent pictureBox = null;
                foreach (XnaUIComponent component in GetChildren())
                {
                    if (component is TestUIComponent)
                    {
                        pictureBox = (TestUIComponent)component;
                        break;
                    }
                }
                if (pictureBox != null)
                {
                    pictureBox.DrawBox = new Rectangle((e.DrawBox.Width - pictureBoxDimension) / 2, 3, pictureBoxDimension, pictureBoxDimension);
                }
            }
        }
        private HPBar getHPBar()
        {
            HPBar hpBar = null;

            foreach (XnaUIComponent child in GetChildren())
            {
                if (child is HPBar)
                {
                    hpBar = (HPBar)child;
                    break;
                }
            }
            return(hpBar);
        }
示例#3
0
        /// <summary>
        /// Create User Interface (icon) for each selected entity (Building
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        public SelectedEntityUI BuildSelectedEntityUI(Building building)
        {
            SelectedEntityUI seui = new SelectedEntityUI(game, building);

            seui.DrawBox = new Rectangle(0, 0, 75, 75);

            // Add the HP Bar to the UI.
            HPBar hpBar = new HPBar(game);

            hpBar.MaxHP     = building.MaxHealth;
            hpBar.CurrentHP = building.CurrentHealth;
            hpBar.DrawBox   = new Rectangle(5, 67, 65, 5);

            PictureBox pictureBox = BuildPictureBox("selectionAvatar", building.Type);

            pictureBox.DrawBox = new Rectangle(7, 3, 61, 61);
            seui.AddChild(pictureBox);
            seui.AddChild(hpBar);
            return(seui);
        }
        /// <summary>
        /// Create User Interface (icon) for each selected entity (Building
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        public SelectedEntityUI BuildSelectedEntityUI(Building building)
        {
            SelectedEntityUI seui = new SelectedEntityUI(game, building);
            seui.DrawBox = new Rectangle(0, 0, 75, 75);

            // Add the HP Bar to the UI.
            HPBar hpBar = new HPBar(game);
            hpBar.MaxHP = building.MaxHealth;
            hpBar.CurrentHP = building.CurrentHealth;
            hpBar.DrawBox = new Rectangle(5, 67, 65, 5);

            PictureBox pictureBox = BuildPictureBox("selectionAvatar", building.Type);
            pictureBox.DrawBox = new Rectangle(7, 3, 61, 61);
            seui.AddChild(pictureBox);
            seui.AddChild(hpBar);
            return seui;
        }
        /// <summary>
        /// Trigger when the health information of the unit has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void UpdateHPBar(Object sender, UnitHPChangedEventArgs args)
        {
            HPBar hpBar = getHPBar();

            hpBar.CurrentHP = args.NewHP;
        }