コード例 #1
0
 void setOccupancy(Rectangle bounds, BuildingEntity occupant)
 {
     for (int x = bounds.X; x < bounds.Right; x++)
     {
         for (int y = bounds.Y; y < bounds.Bottom; y++)
         {
             // set passibility to the given state at x, y
             world.Grid[x, y].Occupant = occupant;
         }
     }
 }
コード例 #2
0
        public void Open(BuildingEntity building)
        {
            state = MenuState.Hidden;

            menuItems = building.GetContextMenuItems();

            if (menuItems == null)
            {
                return;
            }

            state = MenuState.TransitionIn;

            var properties = building.Properties;

            title = properties.Description;
            level = string.Format("Level {0}", properties.Level + 1);

            var titleSize = Font.Measure(titleFont, title, titleTextSize);
            var levelSize = Font.Measure(levelFont, level, levelTextSize);

            menuBounds.Width = (int)Math.Max(titleSize.X + 12, minMenuWidth);

            titlePosition = new Vector2()
            {
                X = (int)(menuBounds.Width - titleSize.X) / 2,
                Y = 10
            };

            levelPosition = new Vector2()
            {
                X = (int)(menuBounds.Width - levelSize.X) / 2,
                Y = (int)(titlePosition.Y + titleSize.Y) + 5
            };

            titleOffset = new Vector2()
            {
                X = (int)(menuBounds.Width - titleSize.X) / 2,
                Y = (int)(titlePosition.Y + titleSize.Y +
                          levelSize.Y + menuPadding)
            };

            buttonSize.X = menuBounds.Width - (2 * buttonPadding);

            for (int i = 0; i < menuItems.Count; i++)
            {
                var item = menuItems[i];

                var size = Font.Measure(buttonFont, item.Text, buttonTextSize);

                item.ButtonPosition = new Vector2()
                {
                    X = buttonPadding,
                    Y = i * (buttonSize.Y + 5) + titleOffset.Y
                };

                item.TextPosition = new Vector2()
                {
                    X = (int)(item.ButtonPosition.X +
                              ((buttonSize.X - size.X) / 2)),
                    Y = (int)(item.ButtonPosition.Y +
                              ((buttonSize.Y - size.Y) / 2)),
                };

                item.Size = buttonSize;
            }

            menuBounds.Height =
                (int)menuItems[menuItems.Count - 1].ButtonPosition.Y +
                buttonSize.Y + menuPadding;

            var menuSize = new Vector2(menuBounds.Width, menuBounds.Height);

            var offset = InputManager.MousePosition.ToVector();

            menuBounds.Location = (offset - world.Camera.RawPosition -
                                   (menuSize / 2)).ToPoint();
        }