private void cloneSelectedObjectToolStripMenuItem_Click(object sender, EventArgs e)
{
ArrayList Arr = (ArrayList)lstProtos.SelectedObjects;
List<ItemProto> Prots = new List<ItemProto>((ItemProto[])Arr.ToArray(typeof(ItemProto)));
if (Prots.Count > 1)
{
Message.Show("Can't clone multiple objects at the same time, select one proto and try again!", MessageBoxButtons.OK, MessageBoxIcon.Error);
changeStatus("Unable to clone multiple object(s)");
}
else if (Prots.Count == 0)
{
Message.Show("No proto selected!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
ushort suggestedPid = 0;
for (int i = Prots[0].ProtoId; i < ushort.MaxValue; i++)
{
if (Data.ItemPid.ContainsValue(i))
continue;
if (isProtoIdLoaded(i))
continue;
suggestedPid = (ushort)i;
break;
}
frmClone frmClone = new frmClone(Prots[0], suggestedPid);
frmClone.ShowDialog();
if (!frmClone.clickedOk)
return;
if (isProtoIdLoaded(frmClone.protoId))
{
Message.Show("A proto with that id is already loaded!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ItemProto newProto = DeepCopier.DeepCopy(Prots[0]);
newProto.ProtoId = frmClone.protoId;
LoadedProtos.Add(newProto);
lstProtos.AddObject(newProto);
lstProtos.SelectedObject = newProto;
lstProtos.EnsureModelVisible(newProto);
SetNewProto(newProto);
changeStatus(string.Format("Cloned {0} ({1}) into a new object with PID {2}", Prots[0].Name, Prots[0].ProtoId, frmClone.protoId));
}
}