private void menu_InvertMiddleFrontLayersToggle_Click(object sender, EventArgs e) //M2P
{
if (M2CellInfo != null)
{
//this should swap the points if point 2 is not a higher value
if (p1.X > p2.X)
{
p1.X += p2.X;
p2.X = p1.X - p2.X - 1;
p1.X -= p2.X;
}
if (p1.Y > p2.Y)
{
p1.Y += p2.Y;
p2.Y = p1.Y - p2.Y - 1;
p1.Y -= p2.Y;
}
for (var x = p1.X; x <= p2.X; x++)
{
for (var y = p1.Y; y <= p2.Y; y++)
{
string str;
if ((M2CellInfo[x, y].MiddleImage != 0) && ((M2CellInfo[x, y].FrontImage & 0x7FFF) == 0)) //M2P - Invert Middle to Front if Only MiddleImage Exists
{
str = GetLibName(M2CellInfo[x, y].MiddleIndex);
if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
{
if ((M2CellInfo[x, y].MiddleAnimationFrame != 0) &&
(M2CellInfo[x, y].MiddleAnimationFrame != 255) &&
(M2CellInfo[x, y].FrontAnimationFrame == 0))
{
M2CellInfo[x, y].FrontAnimationFrame =
(byte)(M2CellInfo[x, y].MiddleAnimationFrame & 0x0F);
M2CellInfo[x, y].FrontAnimationTick = M2CellInfo[x, y].MiddleAnimationTick;
M2CellInfo[x, y].MiddleAnimationFrame = 0;
M2CellInfo[x, y].MiddleAnimationTick = 0;
}
M2CellInfo[x, y].FrontImage = M2CellInfo[x, y].MiddleImage;
M2CellInfo[x, y].FrontIndex = M2CellInfo[x, y].MiddleIndex;
M2CellInfo[x, y].MiddleImage = 0;
M2CellInfo[x, y].MiddleIndex = 0;
}
}
else if ((M2CellInfo[x, y].FrontImage != 0) && ((M2CellInfo[x, y].MiddleImage & 0x7FFF) == 0)) //M2P - Invert Front to Middle if Only Front Exists
{
str = GetLibName(M2CellInfo[x, y].FrontIndex);
if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
{
if ((M2CellInfo[x, y].FrontAnimationFrame != 0) &&
(M2CellInfo[x, y].FrontAnimationFrame != 255) &&
(M2CellInfo[x, y].MiddleAnimationFrame == 0))
{
M2CellInfo[x, y].MiddleAnimationFrame =
(byte)(M2CellInfo[x, y].FrontAnimationFrame & 0x0F);
M2CellInfo[x, y].MiddleAnimationTick = M2CellInfo[x, y].FrontAnimationTick;
M2CellInfo[x, y].FrontAnimationFrame = 0;
M2CellInfo[x, y].FrontAnimationTick = 0;
}
M2CellInfo[x, y].MiddleImage = M2CellInfo[x, y].FrontImage;
M2CellInfo[x, y].MiddleIndex = M2CellInfo[x, y].FrontIndex;
M2CellInfo[x, y].FrontImage = 0;
M2CellInfo[x, y].FrontIndex = 0;
}
}
else if ((M2CellInfo[x, y].MiddleImage != 0) && ((M2CellInfo[x, y].FrontImage & 0x7FFF) != 0)) //M2P - Invert (Swap) Layers if Both FrontImage & MiddleImage Exist [Toggle]
{
str = GetLibName(M2CellInfo[x, y].MiddleIndex);
if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
{
if ((M2CellInfo[x, y].MiddleAnimationFrame == 255) ||
(M2CellInfo[x, y].MiddleAnimationFrame == 0))
{
if (M2CellInfo[x, y].FrontAnimationFrame == 0)
{
var temp = M2CellInfo[x, y].MiddleImage;
M2CellInfo[x, y].MiddleImage =
(short)(M2CellInfo[x, y].FrontImage & 0x7FFF);
M2CellInfo[x, y].FrontImage = temp;
temp = M2CellInfo[x, y].MiddleIndex;
M2CellInfo[x, y].MiddleIndex = M2CellInfo[x, y].FrontIndex;
M2CellInfo[x, y].FrontIndex = temp;
}
}
}
}
}
}
}
}