Beispiel #1
0
        //自动添加地图元素
        public int generateTiles(MImgElement imgElment, int tileW, int tileH)
        {
            int  number = 0;
            bool full   = false;

            if (imgElment != null)
            {
                for (int j = 0; j < imgElment.getHeight() / tileH; j++)
                {
                    for (int i = 0; i < imgElment.getWidth() / tileW; i++)
                    {
                        TileGfxElement element = new TileGfxElement(this);
                        element.setImageValue(imgElment, new Rectangle(i * tileW, j * tileH, tileW, tileH));
                        if (Add(element))
                        {
                            number++;
                        }
                        else
                        {
                            full = true;
                            break;
                        }
                    }
                    if (full)
                    {
                        break;
                    }
                }
            }
            return(number);
        }
Beispiel #2
0
        public new TileGfxElement Clone()
        {
            TileGfxElement newInstance = new TileGfxElement(tileGfxContainer);

            newInstance.copyBase(this);
            newInstance.transFlag    = transFlag;
            newInstance.xInContainer = xInContainer;
            newInstance.yInContainer = yInContainer;
            return(newInstance);
        }
Beispiel #3
0
 public bool equalsClip(TileGfxElement clip)
 {
     if (!base.equalsClip(clip))
     {
         return(false);
     }
     if (transFlag != clip.transFlag)
     {
         return(false);
     }
     return(true);
 }
Beispiel #4
0
        public override void WriteObject(System.IO.Stream s)
        {
            short len = (short)this.Count();

            IOUtil.writeShort(s, len);
            for (short i = 0; i < len; i++)
            {
                TileGfxElement clipElem = (TileGfxElement)this[i];
                clipElem.WriteObject(s);
            }
            IOUtil.writeString(s, name);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public override void ReadObject(System.IO.Stream s)
        {
            Clear();
            short len = IOUtil.readShort(s);

            for (short i = 0; i < len; i++)
            {
                TileGfxElement clipElem = new TileGfxElement(this);
                clipElem.ReadObject(s);
                Add(clipElem);
            }
            name = IOUtil.readString(s);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        //获得使用的图片ID列表
        public ArrayList getUsedImgs()
        {
            ArrayList arrayList = new ArrayList();

            for (int i = 0; i < Count(); i++)
            {
                TileGfxElement element = (TileGfxElement)this[i];
                if (element != null && element.imageElement != null && !arrayList.Contains(element.imageElement))
                {
                    arrayList.Add(element.imageElement);
                }
            }
            return(arrayList);
        }
Beispiel #9
0
 //清除所有图形元素
 public void clearAllElement()
 {
     //清除地图引用
     for (int i = 0; i < Count(); i++)
     {
         TileGfxElement element     = (TileGfxElement)this[i];
         MapsManager    mapsManager = ((TileGfxManager)parent).mapsManager;
         for (int j = 0; j < mapsManager.Count(); j++)
         {
             MapElement map = mapsManager[j];
             map.deleteTileUsed(element);
         }
     }
     Clear();
 }
Beispiel #10
0
        public override void ExportObject(System.IO.Stream fs_bin)
        {
            //导出地形风格单元
            short len = (short)this.Count();

            IOUtil.writeShort(fs_bin, len);
            for (short i = 0; i < len; i++)
            {
                TileGfxElement clipElem = (TileGfxElement)this[i];
                clipElem.ExportObject(fs_bin);
            }
            //导出所使用到的图片ID
            ArrayList array = getUsedImgs();

            len = (short)array.Count;
            IOUtil.writeShort(fs_bin, len);
            for (short i = 0; i < len; i++)
            {
                MImgElement imgElement = (MImgElement)array[i];
                short       id         = (short)imgElement.GetID();
                IOUtil.writeShort(fs_bin, id);
            }
        }
Beispiel #11
0
        //合并
        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);
        }
Beispiel #12
0
 public byte transFlag = Consts.TRANS_NONE;//叠加翻转信息
 public TransTileGfxElement(TileGfxElement tileGfxElementT, byte transFlagT)
 {
     tileGfxElement = tileGfxElementT;
     transFlag      = transFlagT;
 }
Beispiel #13
0
        //返回使用情况信息
        public String getCondition()
        {
            String text = "";

            text += "----------------------数目统计----------------------\n";
            text += "当前容器中的图形元素数目:" + Count();
            if (Count() > byte.MaxValue)
            {
                text += " (已经超出最大限度[255])\n";
            }
            else
            {
                text += " (在最大限度[255]以内)\n";
            }
            int nbUnUsed = 0;

            for (int i = 0; i < Count(); i++)
            {
                TileGfxElement element = (TileGfxElement)this[i];
                if (element.getUsedTime() == 0)
                {
                    nbUnUsed++;
                }
            }
            text += "图形元素中未被使用到的元素数目:" + nbUnUsed + "\n";
            text += "----------------------重复检查----------------------\n";
            //检查重复的图形块
            int count = 0;

            for (int i = 0; i < Count(); i++)
            {
                TileGfxElement element     = (TileGfxElement)this[i];
                bool           finRepeated = false;
                for (int j = i + 1; j < Count(); j++)
                {
                    TileGfxElement elementT = (TileGfxElement)this[j];
                    if (elementT.equalsClip(element))
                    {
                        text       += "重复的图形元素:(" + i + "," + j + ")\n";
                        finRepeated = true;
                    }
                }
                if (finRepeated)
                {
                    count++;
                }
            }
            text += "共发现" + count + "个重复的图形元素\n";
            text += "----------------------翻转检查----------------------\n";
            count = 0;
            for (int i = 0; i < Count(); i++)
            {
                TileGfxElement element   = (TileGfxElement)this[i];
                byte           transFlag = element.getTansFlag();
                if (transFlag != Consts.TRANS_NONE)
                {
                    count++;
                }
            }
            text += "共发现" + count + "个翻转的元素\n";
            return(text);
        }