public TileGfxContainer clone() { TileGfxContainer newInstance = new TileGfxContainer((TileGfxManager)parent, name); for (int i = 0; i < Count(); i++) { TileGfxElement baseClip = (TileGfxElement)this[i]; TileGfxElement newBaseClip = baseClip.Clone(newInstance); newInstance.Add(newBaseClip); } return(newInstance); }
public TileGfxContainer cloneForExceport(MapsManager mapsManager, MImgsManager imagesManager) { TileGfxContainer newInstance = new TileGfxContainer((TileGfxManager)parent, name); for (int i = 0; i < Count(); i++) { TileGfxElement baseClip = (TileGfxElement)this[i]; TileGfxElement newBaseClip = baseClip.Clone(newInstance); newBaseClip.imageElement = imagesManager[newBaseClip.imageElement.GetID()]; newInstance.Add(newBaseClip); } return(newInstance); }
//合并 public String combine(TileGfxManager src_Manager, ArrayList mapsID) { String errorString = null; for (int srcConIndex = 0; srcConIndex < src_Manager.Count(); srcConIndex++) { TileGfxContainer srcContainer = src_Manager[srcConIndex]; //检查是否被源关卡所用到 bool usingBySrc = false; for (int j = 0; j < mapsID.Count; j++) { MapElement map = src_Manager.mapsManager[(int)mapsID[j]]; if (map.tileGfxContainer.Equals(srcContainer)) { usingBySrc = true; break; } } if (!usingBySrc) { continue; } TileGfxContainer destContainer = null; //检查重复的图形容器 for (int localConIndex = 0; localConIndex < Count(); localConIndex++) { TileGfxContainer localContainer = this[localConIndex]; if (localContainer.name.Equals(srcContainer.name)) { destContainer = localContainer; break; } } if (destContainer == null) { destContainer = new TileGfxContainer(this, srcContainer.name); this.Add(destContainer); } //转移地图中的图形容器的引用 for (int k = 0; k < src_Manager.mapsManager.Count(); k++) { MapElement map = src_Manager.mapsManager[k]; if (map.tileGfxContainer.Equals(srcContainer)) { map.tileGfxContainer = destContainer; } } //向目标容器添加图形元素 for (int elementIndex = 0; elementIndex < srcContainer.Count(); elementIndex++) { TileGfxElement srcElement = (TileGfxElement)srcContainer[elementIndex]; TileGfxElement newElement = null; //检查重复的图形元素 if (!destContainer.Equals(srcContainer)) { for (int j = 0; j < destContainer.Count(); j++) { TileGfxElement localClip = (TileGfxElement)destContainer[j]; if (localClip.equalsClip(srcElement)) { newElement = localClip; break; } } } if (newElement == null) { newElement = srcElement.Clone(destContainer); } if (!destContainer.Contains(newElement)) { if (!destContainer.Add(newElement)) { errorString = "合并图形容器“" + srcContainer.name + "”时,图形元素数量超出65536。"; break; } } //转移地图中的块的引用 for (int k = 0; k < src_Manager.mapsManager.Count(); k++) { MapElement map = src_Manager.mapsManager[k]; for (int x = 0; x < map.getMapW(); x++) { for (int y = 0; y < map.getMapH(); y++) { MapTileElement mapTile = map.getTile(x, y); if (mapTile.tile_gfx_ground != null && mapTile.tile_gfx_ground.tileGfxElement != null && mapTile.tile_gfx_ground.tileGfxElement.Equals(srcElement)) { mapTile.tile_gfx_ground.tileGfxElement = newElement; } if (mapTile.tile_gfx_surface != null && mapTile.tile_gfx_surface.tileGfxElement != null && mapTile.tile_gfx_surface.tileGfxElement.Equals(srcElement)) { mapTile.tile_gfx_surface.tileGfxElement = newElement; } } } } } if (errorString != null) { break; } } return(errorString); }