Exemple #1
0
        private void AddBlocks(ScrollPanel palette)
        {
            selectableBlocks = new Dictionary <string, SelectableBlock>();
            int x         = PALETTE_SPACING;
            int y         = PALETTE_SPACING;
            int blockSize = GameplayState.BLOCK_SIZE * GUIElement.scale;

            foreach (Block block in resources.GetBlocks())
            {
                SelectableBlock blockSelect  = new SelectableBlock(new Rectangle(x, y, blockSize, blockSize), block, palette);
                Action          selectAction = () =>
                {
                    if (selectedBlock == blockSelect)
                    {
                        return;                                                   //already selected
                    }
                    if (selectedBlock != null)
                    {
                        selectedBlock.Deselect();
                    }
                    selectedBlock = blockSelect;
                };
                blockSelect.SetSelectAction(selectAction);

                selectableBlocks[block.name] = blockSelect;
                palette.AddScrollable(blockSelect);

                x += blockSize + PALETTE_SPACING;
                if (x + blockSize > palette.GetInnerBounds().Width)
                {
                    x  = PALETTE_SPACING;
                    y += blockSize + PALETTE_SPACING;
                }
            }
        }