public SubTextureSelector(EditorScreen parentScreen, SpriteBatch spriteBatch, TileSelector tileSelector, int layerIndex, int subLayerIndex)
            : base(parentScreen, spriteBatch, new RectangleF())
        {
            this.Color = Microsoft.Xna.Framework.Graphics.Color.White;
            textureService = (ITextureService)Game.Services.GetService(typeof(ITextureService));
            this.isSelectingSubTexture = false;
            this.layerIndex = layerIndex;
            this.subLayerIndex = subLayerIndex;

            this.tileSelector = tileSelector;

            // We make the silly assumption that there is at least one Sheet loaded. he-he-he.
            this.selectingSheet = textureService.SheetsArray[0];

            // Generate our position based on the layer/subLayer-index we have.
            int padding = 10;
            int hzOffset = -(TileMap.TileWidth + padding);
            int oneDown = padding + TileMap.TileHeight;
            int vtOffset = layerIndex*(TileMap.SubLayerCount*oneDown + 2*padding) + (subLayerIndex * oneDown) + padding;
            Position = new Vector2(tileSelector.Bounds.Left + hzOffset, tileSelector.Bounds.Top + vtOffset);

            Microsoft.Xna.Framework.Rectangle rect =
                new Microsoft.Xna.Framework.Rectangle(0, 0, TileMap.TileWidth, TileMap.TileHeight);
            this.Bounds = new RectangleF(Position.X, Position.Y, rect.Width, rect.Height);
        }
        public DestructableToggler(EditorScreen parentScreen, SpriteBatch spriteBatch, RectangleF bounds, TileSelector tileSelector)
            : base(parentScreen, spriteBatch, bounds)
        {
            this.tileSelector = tileSelector;
            this.textureService = (ITextureService)Game.Services.GetService(typeof(ITextureService));

            destructable = false;
            conflict = false;
        }
        public EdgeToggler(EditorScreen parentScreen, SpriteBatch spriteBatch, RectangleF bounds, TileSelector tileSelector)
            : base(parentScreen, spriteBatch, bounds)
        {
            this.tileSelector = tileSelector;
            this.textureService = (ITextureService)Game.Services.GetService(typeof(ITextureService));

            // By default, solid:
            this.edges = new bool[4];
            edges[0] = edges[1] = edges[2] = edges[3] = true;
            edgesConflict = false;
        }
        private void CreateUIComponents()
        {
            SpriteBatch sb = batchService.GetSpriteBatch(DebuggingOutputComponent.SpriteBatchName);

            // Where all the magic happens:
            tileSelector = new TileSelector(this, sb,
                                               new RectangleF(40, 0, 600, 480),
                                               world.interactiveLayers.Values.First<TileMapLayer>(),
                                               inputMonitor);
            tileSelector.DrawOrder = 0;
            this.Components.Add(tileSelector);

            this.subTextureSelectors = new List<SubTextureSelector>();

            for (int i = 0; i < world.Map.LayerCount; ++i)
            {
                for (int j = 0; j < world.Map.SubLayerCount; ++j)
                {
                    int index = i * world.Map.SubLayerCount + j;

                    SubTextureSelector subTexSel = new SubTextureSelector(this, sb, TileSelector, i, j);
                    tileSelector.TilePropertyComponents.Add(subTexSel);
                    subTexSel.DrawOrder = 25;
                    this.Components.Add(subTexSel);
                    SubTextureSelectors.Add(subTexSel);
                }
            }

            this.worldObjectMovers = new List<WorldObjectMover>();
            foreach (WorldObject wo in World.WorldObjects)
            {
                WorldObjectMover wom = new WorldObjectMover(this, sb, wo);
                WorldObjectMovers.Add(wom);
                this.Components.Add(wom);
            }

            RectangleF tmp = ((SubTextureSelector)tileSelector.TilePropertyComponents.Last<ITilePropertyComponent>()).Bounds;
            tmp.Y += 20 + world.Map.TileHeight;
            this.edgeToggler = new EdgeToggler(this, sb, tmp, TileSelector);
            EdgeToggler.DrawOrder = 25;
            TileSelector.TilePropertyComponents.Add(EdgeToggler);
            this.Components.Add(EdgeToggler);

            tmp.Y += 20 + world.Map.TileHeight;
            this.destructableToggler = new DestructableToggler(this, sb, tmp, TileSelector);
            DestructableToggler.DrawOrder = 25;
            TileSelector.TilePropertyComponents.Add(DestructableToggler);
            this.Components.Add(DestructableToggler);

            SaveButton saveButton = new SaveButton(this, sb, new RectangleF(5, 400, 30, 15), World);
            saveButton.DrawOrder = 20;
            this.Components.Add(saveButton);

            worldObjectPlacer = new WorldObjectPlacer(this, sb, new RectangleF(40, 0, 600, 480), World);
            worldObjectPlacer.DrawOrder = 25;
            this.Components.Add(worldObjectPlacer);

            playerMover = new WorldObjectMover(this, sb, World.Player);
            this.Components.Add(playerMover);
        }