public object Clone() { var layer = new TileLayer(mLayoutMap) { Name = mName, Alpha = mAlpha, IsBackground = mIsBackground }; return layer; }
private void AddLayerToTree(string layername, bool canRename, int imageIndex, bool addContextMenu, bool canChoiceBgFg = true, bool isBackgroundSelected = true) { TreeNode node; var frm = new frmNewLayer { txtName = { Text = layername } }; if (canRename || canChoiceBgFg) { if (canRename == false) { frm.txtName.ReadOnly = true; } if (canChoiceBgFg == false) { frm.chkBackground.Enabled = false; frm.chkForeground.Enabled = false; } frm.chkBackground.Checked = isBackgroundSelected; frm.chkForeground.Checked = !isBackgroundSelected; do { frm.ShowDialog(); } while (frm.OKPressed == false); } var layer = new TileLayer(mTileMap.Width, mTileMap.Height); layer.Name = frm.txtName.Text; layer.IsBackground = frm.chkBackground.Checked; var lastBgIndex = GetLastBGIndex(); // vor FG [wenn BG Layer] oder ans Ende [wenn FG Layer] // wnen keine Layer vorhanden, reicht Add() if (layer.IsBackground && lastBgIndex > -1 && lastBgIndex < mTileMap.Layers.Count) { node = ProjectTree.Nodes[0].Nodes.Insert(lastBgIndex + 2, layer.Name); // Tree enthält noch Collision mTileMap.Layers.Insert(lastBgIndex + 1, layer); } else { node = ProjectTree.Nodes[0].Nodes.Add(layer.Name); mTileMap.Layers.Add(layer); } if (addContextMenu) { node.ContextMenuStrip = ProjectTreeNodeContext; } node.ImageIndex = (imageIndex != -1 ? imageIndex : (layer.IsBackground ? 1 : 3)); node.SelectedImageIndex = imageIndex; node.Tag = layer.Name; ProjectTree.Nodes[0].Text = BuildMapName(); if (layer.IsBackground && lastBgIndex > 0) { mLastTilesetIndex.Insert(lastBgIndex, 0); mLastAutotileIndex.Insert(lastBgIndex, 0); mLastAnimationIndex.Insert(lastBgIndex, 0); mLastObjectIndex.Insert(lastBgIndex, 0); } else { mLastTilesetIndex.Add(0); mLastAutotileIndex.Add(0); mLastAnimationIndex.Add(0); mLastObjectIndex.Add(0); } }
public TileLayer(TileLayer existingLayer, int newWidth, int newHeight) { mAlpha = existingLayer.Alpha; mIsBackground = existingLayer.IsBackground; mName = existingLayer.Name; mLayoutMap = new TileCell[newWidth][]; for (int x = 0; x < newWidth; x++) { mLayoutMap[x] = new TileCell[newHeight]; for (int y = 0; y < newHeight; y++) { if (existingLayer.LayoutMap == null || x >= existingLayer.LayoutMap.Length || y >= existingLayer.LayoutMap[x].Length) { mLayoutMap[x][y] = TileCell.Empty; mLayoutMap[x][y].X = x; mLayoutMap[x][y].Y = y; } else { mLayoutMap[x][y] = existingLayer.LayoutMap[x][y].Clone() as TileCell; } } } }