/// <summary> /// /// </summary> /// <param name="tileCountX">X軸のタイル数</param> /// <param name="tileCountY">Y軸のタイル数</param> /// <param name="type"></param> /// <param name="outCount"></param> /// <param name="strOut"></param> /// <returns></returns> public bool CheckReplaceLap(int tileCountX, int tileCountY, int type, out int outCount, out string strOut) { outCount = -1; strOut = ""; if (tileCountX >= m_tileCountX && tileCountY >= m_tileCountY) { return(false); } int tmpW = 0, tmpH = 0; BLOCK_AABB aabb = new BLOCK_AABB(); this.ReSizeAABB(tileCountX, tileCountY, type, aabb, out tmpW, out tmpH); outCount = 0; string strFrameOut = "", strFrameCat = ""; BLOCK_AABB aabbR = new BLOCK_AABB(); BLOCK_AABB aabbOut = new BLOCK_AABB(); foreach (KeyValuePair <string, SquareTilesTranspose> kvp in m_transPoseTiles) { aabbR.vMin.Set(kvp.Value.tilePosX, kvp.Value.tilePosY); aabbR.vMax.Set(aabbR.vMin); aabbR.vMax.x += kvp.Value.tileNumX - 1; aabbR.vMax.y += kvp.Value.tileNumY - 1; if (aabb.BooleanOperation_AND(aabbOut, aabbR)) { if (!aabbR.Equal(aabbOut)) { strFrameCat += " " + kvp.Key + "\n"; ++outCount; } } else { strFrameOut += " " + kvp.Key + "\n"; ++outCount; } } if (strFrameCat.Length > 0) { strOut += "切り取られるのは\n" + strFrameCat; } if (strFrameOut.Length > 0) { strOut += "\n削除されるのは\n" + strFrameOut; } return(true); }
/// <summary> /// 現行のタイルマップのサイズを変更する /// </summary> /// <param name="tileCountX">X軸のタイル数</param> /// <param name="tileCountY">Y軸のタイル数</param> /// <param name="type"></param> /// <returns></returns> public bool Resize(int tileCountX, int tileCountY, int type) { int i, j, k, l, n, kk, ll; int tmpW = 0, tmpH = 0; FSquareTileInfoMap rMIM0 = null, rMIM1 = null; BLOCK_AABB aabbNow = new BLOCK_AABB(); BLOCK_AABB aabb = new BLOCK_AABB(); aabbNow.vMin.Set(0, 0); aabbNow.vMax.Set(m_tileCountX - 1, m_tileCountY - 1); this.ReSizeAABB(tileCountX, tileCountY, type, aabb, out tmpW, out tmpH); D2ArrayObject <FSquareTileInfoMap> newMapChip = new D2ArrayObject <FSquareTileInfoMap>(tileCountX, tileCountY); for (i = aabb.vMin.y, k = 0; i <= aabb.vMax.y; ++i, ++k) { for (j = aabb.vMin.x, l = 0; j <= aabb.vMax.x; ++j, ++l) { if (i >= aabbNow.vMin.y && i <= aabbNow.vMax.y && j >= aabbNow.vMin.x && j <= aabbNow.vMax.x) { rMIM0 = newMapChip[k, l]; rMIM1 = m_mapTiles[i, j]; rMIM0.L00._n = rMIM1.L00._n; rMIM0.L01._n = rMIM1.L01._n; } } } m_mapTiles = newMapChip; m_tileCountX = (short)m_mapTiles.LengthX; m_tileCountY = (short)m_mapTiles.LengthY; List <String> aStrDel = new List <string>(); List <String> aStrCat = new List <string>(); BLOCK_AABB aabbR = new BLOCK_AABB(); BLOCK_AABB aabbOut = new BLOCK_AABB(); SquareTilesTransposeFrame rTCF; //aabb.vMin.Set(0, 0); //aabb.vMax.Set(m_tileNumX - 1, m_tileNumY - 1); foreach (KeyValuePair <string, SquareTilesTranspose> kvp in m_transPoseTiles) { aabbR.vMin.Set(kvp.Value.tilePosX, kvp.Value.tilePosY); aabbR.vMax.Set(aabbR.vMin); aabbR.vMax.x += kvp.Value.tileNumX - 1; aabbR.vMax.y += kvp.Value.tileNumY - 1; if (aabb.BooleanOperation_AND(aabbOut, aabbR)) { if (!aabbR.Equal(aabbOut)) { kvp.Value.tileNumX = (short)aabbOut.GetWidthBlockCount(); kvp.Value.tileNumY = (short)aabbOut.GetHeightBlockCount(); // X if (aabbOut.vMin.x <= aabb.vMin.x) { kvp.Value.tilePosX = 0; } else if (aabb.vMin.x < 0) { kvp.Value.tilePosX += (short)(Math.Abs(aabb.vMin.x)); } // Y if (aabbOut.vMin.y <= aabb.vMin.y) { kvp.Value.tilePosY = 0; } else if (aabb.vMin.y < 0) { kvp.Value.tilePosY += (short)(Math.Abs(aabb.vMin.y)); } for (n = 0; n < kvp.Value.aTCF.Count; ++n) { newMapChip = new D2ArrayObject <FSquareTileInfoMap>(kvp.Value.tileNumX, kvp.Value.tileNumY); rTCF = kvp.Value.aTCF[n]; kk = -1; bool bRY = false; for (i = aabbR.vMin.y, k = 0; i <= aabbR.vMax.y; ++i, ++k) { ll = 0; if (i >= aabbOut.vMin.y && i <= aabbOut.vMax.y) { kk++; bRY = true; } for (j = aabbR.vMin.x, l = 0; j <= aabbR.vMax.x; ++j, ++l) { if (bRY && j >= aabbOut.vMin.x && j <= aabbOut.vMax.x) { rMIM0 = newMapChip[kk, ll++]; rMIM1 = rTCF.aaMapChip[k, l]; rMIM0.L00._n = rMIM1.L00._n; rMIM0.L01._n = rMIM1.L01._n; } } } rTCF.aaMapChip = newMapChip; } } else { // if (aabb.vMin.x < 0) { kvp.Value.tilePosX += (short)(Math.Abs(aabb.vMin.x)); } // Y if (aabb.vMin.y < 0) { kvp.Value.tilePosY += (short)(Math.Abs(aabb.vMin.y)); } } } else { // 削除する置き換え aStrDel.Add(kvp.Key); } }// foreach for (i = 0; i < aStrDel.Count; ++i) { m_transPoseTiles.Remove(aStrDel[i]); } return(true); }
/// <summary> /// 現行のタイルマップのサイズを変更した際のデータを取得する。現行のタイルマップの影響は無い /// </summary> /// <param name="tileCountX">X軸のタイル数</param> /// <param name="tileCountY">Y軸のタイル数</param> /// <param name="type">リサイズタイプ</param> /// <param name="aabb"></param> /// <param name="diffTileCountX">変更前のX軸のタイル群の差</param> /// <param name="diffTileCountY">変更前のY軸のタイル群の差</param> /// <returns>常にtrueを返す</returns> private bool ReSizeAABB(int tileCountX, int tileCountY, int type, BLOCK_AABB aabb, out int diffTileCountX, out int diffTileCountY) { int tmpW, tmpH; aabb.vMin.Set(0, 0); aabb.vMax.Set(m_tileCountX - 1, m_tileCountY - 1); diffTileCountX = tmpW = m_tileCountX - tileCountX; diffTileCountY = tmpH = m_tileCountY - tileCountY; switch (type) { // 1行目 case TOP_LEFT: // 左上 aabb.vMin.x += tmpW; aabb.vMin.y += tmpH; break; case TOP_CENTER: // 中央上 tmpW /= 2; aabb.vMin.x += tmpW; aabb.vMax.x -= tmpW; aabb.vMin.y += tmpH; break; case TOP_RIGHT: // 右上 aabb.vMax.x -= tmpW; aabb.vMin.y += tmpH; break; // 2行目 case CENTER_LEFT: aabb.vMin.x += tmpW; tmpH /= 2; aabb.vMin.y += tmpH; aabb.vMax.y -= tmpH; break; case CENTER_CENTER: tmpW /= 2; aabb.vMin.x += tmpW; aabb.vMax.x -= tmpW; tmpH /= 2; aabb.vMin.y += tmpH; aabb.vMax.y -= tmpH; break; case CENTER_RIGHT: aabb.vMax.x -= tmpW; tmpH /= 2; aabb.vMin.y += tmpH; aabb.vMax.y -= tmpH; break; // 3行目 case BOTTOM_LEFT: // 左下 aabb.vMin.x += tmpW; aabb.vMax.y -= tmpH; break; case BOTTOM_CENTER: // 中央下 aabb.vMax.y -= tmpH; tmpW /= 2; aabb.vMin.x += tmpW; aabb.vMax.x -= tmpW; break; case BOTTOM_RIGHT: // 右下 aabb.vMax.x -= tmpW; aabb.vMax.y -= tmpH; break; } return(true); }