public Sprite DuplicateSprite(Sprite sToCopy, UndoMgr undo) { if (sToCopy == null) { return(null); } // Calulate an appropriate name for the copy string strNewBaseName; int nCopy = 1; string strNewName; string strCopySuffix = ResourceMgr.GetString("CopySuffix"); Match m = Regex.Match(sToCopy.Name, String.Format("^(.*){0}([0-9]*)$", strCopySuffix)); if (m.Success) { strNewBaseName = String.Format("{0}{1}", m.Groups[1].Value, strCopySuffix); if (m.Groups[2].Value != "") { nCopy = Int32.Parse(m.Groups[2].Value); } strNewName = String.Format("{0}{1}", strNewBaseName, ++nCopy); } else { strNewBaseName = String.Format("{0}{1}", sToCopy.Name, strCopySuffix); strNewName = strNewBaseName; } while (HasNamedSprite(strNewName)) { strNewName = String.Format("{0}{1}", strNewBaseName, ++nCopy); } Sprite sNew = AddSprite(sToCopy.TileWidth, sToCopy.TileHeight, strNewName, NextTileId++, sToCopy.Description, undo); sNew.Duplicate(sToCopy); return(sNew); }