Example #1
0
        private void OnTileSheetNew(object sender, EventArgs eventArgs)
        {
            TileSheet tileSheet = new TileSheet("untitled tile sheet", m_map, "",
                new Size(8, 8), new Size(8, 8));
            TileSheetPropertiesDialog tileSheetPropertiesDialog
                = new TileSheetPropertiesDialog(tileSheet, true, m_mapTreeView);

            if (tileSheetPropertiesDialog.ShowDialog(this) == DialogResult.Cancel)
                return;

            StartWaitCursor();

            m_mapPanel.LoadTileSheet(tileSheet);

            StopWaitCursor();

            m_needsSaving = true;
            UpdateFileControls();
            UpdateEditControls();
            UpdateTileSheetControls();
            m_tilePicker.UpdatePicker();

            m_tilePicker.SelectedTileSheet = tileSheet;
            m_tilePicker.SelectedTileIndex = tileSheet.TileCount > 0 ? 0 : -1;
            m_mapPanel.SelectedTileSheet = tileSheet;
            m_mapPanel.SelectedTileIndex = m_tilePicker.SelectedTileIndex;
        }
Example #2
0
        private void OnTileSheetProperties(object sender, EventArgs eventArgs)
        {
            if (m_selectedComponent == null
                || !(m_selectedComponent is TileSheet))
                return;

            TileSheet tileSheet = (TileSheet)m_selectedComponent;
            TileSheetPropertiesDialog TileSheetPropertiesDialog
                = new TileSheetPropertiesDialog(tileSheet, false, m_mapTreeView);

            if (TileSheetPropertiesDialog.ShowDialog(this) == DialogResult.Cancel)
                return;

            StartWaitCursor();

            m_tilePicker.UpdatePicker();
            m_tilePicker.RefreshSelectedTileSheet();

            StopWaitCursor();

            m_needsSaving = true;
            UpdateFileControls();
            UpdateEditControls();
            UpdateTileSheetControls();
            m_mapTreeView.UpdateTree();
        }
Example #3
0
        public Map Load(Stream stream)
        {
            Map map = new Map("Flixel Map");

            // if using wait cursor, switch to default one during dialog
            bool useWaitCursor = Application.UseWaitCursor;
            Application.UseWaitCursor = false;
            Application.DoEvents();

            TileSheet tilesheet = new TileSheet("Flixel Tile Sheet", map, "", new Size(10, 10), new Size(16, 15));
            TileSheetPropertiesDialog tileSheetPropertiesDialog = new TileSheetPropertiesDialog(tilesheet, true, null);
            if (tileSheetPropertiesDialog.ShowDialog() == DialogResult.Cancel)
                throw new Exception("No tile sheet configured");

            Application.UseWaitCursor = useWaitCursor;
            Application.DoEvents();

            TextReader layerTextReader = new StreamReader(stream);

            List<List<int>> tileIndices = new List<List<int>>();

            char[] commas = new char[] { ',' };
            Size layerSize = new Size();

            while (true)
            {
                string layerLine = layerTextReader.ReadLine();
                if (layerLine == null)
                    break;

                List<int> indexRow = new List<int>();
                tileIndices.Add(indexRow);

                string[] tokens = layerLine.Split(commas);

                layerSize.Width = Math.Max(layerSize.Width, tokens.Length);

                foreach (string token in tokens)
                {
                    int tileIndex = int.Parse(token.Trim());
                    indexRow.Add(tileIndex);
                }

                layerSize.Height++;
            }

            Layer layer = new Layer("Flixel Layer", map, layerSize, tilesheet.TileSize);
            map.AddLayer(layer);

            for (int tileY = 0; tileY < tileIndices.Count; tileY++)
            {
                List<int> indexRow = tileIndices[tileY];
                for (int tileX = 0; tileX < indexRow.Count; tileX++)
                    layer.Tiles[tileX, tileY] = new StaticTile(layer, tilesheet, BlendMode.Alpha, indexRow[tileX]);
            }

            return map;
        }