public void Add(IWadObjectId newId, IWadObject wadObject) { // Change id if necessary if (newId != wadObject.Id) { var property = wadObject.GetType().GetProperty("Id"); property.SetValue(wadObject, newId); } // Add object if (newId is WadMoveableId) { Moveables.Add((WadMoveableId)newId, (WadMoveable)wadObject); } else if (newId is WadStaticId) { Statics.Add((WadStaticId)newId, (WadStatic)wadObject); } else if (newId is WadSpriteSequenceId) { SpriteSequences.Add((WadSpriteSequenceId)newId, (WadSpriteSequence)wadObject); } else { throw new ArgumentException("Argument not of a valid type."); } }
private void comboItems_Format(object sender, ListControlConvertEventArgs e) { IWadObject listItem = e.ListItem as IWadObject; if (listItem != null) { e.Value = listItem.ToString(_editor.Level.Settings.GameVersion); } }
private void comboItems_Format(object sender, ListControlConvertEventArgs e) { TRVersion.Game?gameVersion = _editor?.Level?.Settings?.GameVersion; IWadObject listItem = e.ListItem as IWadObject; if (gameVersion != null && listItem != null) { e.Value = listItem.ToString(gameVersion.Value); } }
public void AssignNewId(IWadObjectId oldId, IWadObjectId newId) { if (Contains(newId)) { throw new ArgumentException("Id " + newId.ToString(GameVersion) + " already exists."); } IWadObject @object = TryGet(oldId); if (@object == null) { throw new KeyNotFoundException("Id " + newId.ToString(GameVersion) + " not found."); } Remove(oldId); Add(newId, @object); }
public static void EditObject(WadToolClass tool, IWin32Window owner, DeviceManager deviceManager) { Wad2 wad = tool.GetWad(tool.MainSelection?.WadArea); IWadObject wadObject = wad?.TryGet(tool.MainSelection?.Id); if (wadObject == null || tool.MainSelection?.WadArea == WadArea.Source) { return; } if (wad == null) { tool.SendMessage("You must have a wad loaded and an object selected.", PopupType.Error); return; } // Choose behaviour if (wadObject is WadStatic) { using (var form = new FormStaticEditor(tool, deviceManager, wad, (WadStatic)wadObject)) if (form.ShowDialog(owner) != DialogResult.OK) { return; } tool.WadChanged(tool.MainSelection.Value.WadArea); } else if (wadObject is WadMoveable) { using (var form = new FormAnimationEditor(tool, deviceManager, wad, ((WadMoveable)wadObject).Id)) { if (form.ShowDialog(owner) != DialogResult.OK) { return; } tool.WadChanged(tool.MainSelection.Value.WadArea); } } else if (wadObject is WadSpriteSequence) { using (var form = new FormSpriteSequenceEditor(tool, wad, (WadSpriteSequence)wadObject)) if (form.ShowDialog(owner) != DialogResult.OK) { return; } tool.WadChanged(tool.MainSelection.Value.WadArea); } }
public bool Contains(IWadObject wadObject) { if (wadObject is WadMoveable) { return(Moveables.Any(obj => obj.Value == (WadMoveable)wadObject)); } else if (wadObject is WadStatic) { return(Statics.Any(obj => obj.Value == (WadStatic)wadObject)); } else if (wadObject is WadSpriteSequence) { return(SpriteSequences.Any(obj => obj.Value == (WadSpriteSequence)wadObject)); } else { throw new ArgumentException("Argument not of a valid type."); } }
public static IWadObjectId ChangeSlot(WadToolClass tool, IWin32Window owner) { if (tool.MainSelection?.WadArea == WadArea.Source) { return(null); } Wad2 wad = tool.GetWad(tool.MainSelection?.WadArea); IWadObject wadObject = wad?.TryGet(tool.MainSelection?.Id); if (wad == null || wadObject == null) { tool.SendMessage("You must have an object selected", PopupType.Error); return(null); } // Ask for the new slot using (var form = new FormSelectSlot(tool.DestinationWad, wadObject.Id)) { if (form.ShowDialog(owner) != DialogResult.OK) { return(null); } if (form.NewId == wadObject.Id) { return(null); } if (wad.Contains(form.NewId)) { tool.SendMessage("The slot " + form.NewId.ToString(wad.GameVersion) + " is already occupied.", PopupType.Error); return(null); } wad.AssignNewId(wadObject.Id, form.NewId); } tool.WadChanged(tool.MainSelection.Value.WadArea); return(wadObject.Id); }
public static IWadObjectId CreateObject(WadToolClass tool, IWin32Window owner, IWadObject initialWadObject) { Wad2 destinationWad = tool.DestinationWad; if (destinationWad == null) { tool.SendMessage("You must have a destination wad opened.", PopupType.Error); return(null); } IWadObjectId result; using (var form = new FormSelectSlot(tool.DestinationWad, initialWadObject.Id)) { if (form.ShowDialog(owner) != DialogResult.OK) { return(null); } if (destinationWad.Contains(form.NewId)) { tool.SendMessage("The slot " + form.NewId.ToString(destinationWad.GameVersion) + " is already occupied.", PopupType.Error); return(null); } if (initialWadObject is WadMoveable) { var moveable = initialWadObject as WadMoveable; var bone = new WadBone(); bone.Name = "Root"; bone.Mesh = CreateFakeMesh("Root"); moveable.Bones.Add(bone); } destinationWad.Add(form.NewId, initialWadObject); result = form.NewId; } tool.WadChanged(WadArea.Destination); tool.ToggleUnsavedChanges(); return(result); }
public static List <IWadObjectId> CopyObject(WadToolClass tool, IWin32Window owner, List <IWadObjectId> objectIdsToMove, bool alwaysChooseId) { Wad2 sourceWad = tool.SourceWad; Wad2 destinationWad = tool.DestinationWad; if (destinationWad == null || sourceWad == null || objectIdsToMove.Count == 0) { tool.SendMessage("You must have two wads loaded and at least one source object selected.", PopupType.Error); return(null); } var listInProgress = new List <uint>(); // Figure out the new ids if there are any id collisions IWadObjectId[] newIds = objectIdsToMove.ToArray(); // If destination is TR5Main, try to remap object IDs if (destinationWad.GameVersion == TRVersion.Game.TR5Main) { for (int i = 0; i < objectIdsToMove.Count; ++i) { var objectId = objectIdsToMove[i]; if (objectId is WadMoveableId) { var moveableId = (WadMoveableId)objectId; // Try to get a compatible slot var newSlot = TrCatalog.GetMoveableTR5MainSlot(sourceWad.GameVersion, moveableId.TypeId); if (newSlot == "") { continue; } // Get the new ID bool isMoveable; var newId = TrCatalog.GetItemIndex(destinationWad.GameVersion, newSlot, out isMoveable); if (!newId.HasValue) { continue; } // Save the new ID newIds[i] = new WadMoveableId(newId.Value); } } } for (int i = 0; i < objectIdsToMove.Count; ++i) { if (!sourceWad.Contains(objectIdsToMove[i])) { continue; } if (!alwaysChooseId) { if (!destinationWad.Contains(newIds[i])) { if (!newIds.Take(i).Contains(newIds[i])) // There also must not be collisions with the other custom assigned ids. { continue; } } } bool askConfirm = !alwaysChooseId; // Ask for the new slot do { DialogResult dialogResult; if (askConfirm) { dialogResult = DarkMessageBox.Show(owner, "The id " + newIds[i].ToString(destinationWad.GameVersion) + " is already occupied in the destination wad.\n" + "Do you want to replace it (Yes) or to select another Id (No)?", "Occupied slot", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); } else { dialogResult = DialogResult.No; } // From this time, always ask for confirm askConfirm = true; if (dialogResult == DialogResult.Cancel) { return(null); } else if (dialogResult == DialogResult.No) { using (var form = new FormSelectSlot(destinationWad, newIds[i], listInProgress)) { if (form.ShowDialog(owner) != DialogResult.OK) { return(null); } if (destinationWad.Contains(form.NewId) || newIds.Take(i).Contains(form.NewId)) { destinationWad.Remove(form.NewId); tool.WadChanged(WadArea.Destination); } newIds[i] = form.NewId; if (form.NewId is WadStaticId) { listInProgress.Add(((WadStaticId)form.NewId).TypeId); } if (form.NewId is WadMoveableId) { listInProgress.Add(((WadMoveableId)form.NewId).TypeId); } if (form.NewId is WadSpriteSequenceId) { listInProgress.Add(((WadSpriteSequenceId)form.NewId).TypeId); } break; } } else { destinationWad.Remove(objectIdsToMove[i]); tool.WadChanged(WadArea.Destination); break; } } while (destinationWad.Contains(newIds[i]) || newIds.Take(i).Contains(newIds[i])); // There also must not be collisions with the other custom assigned ids. } // HACK: Until this is fixed... https://github.com/MontyTRC89/Tomb-Editor/issues/413 // We just block copying of same object to another slot and warn user it's in another slot. var failedIdList = new List <IWadObjectId>(); // Move objects for (int i = 0; i < objectIdsToMove.Count; ++i) { IWadObject obj = sourceWad.TryGet(objectIdsToMove[i]); if (obj == null) { continue; } if (destinationWad.Contains(obj)) // Aforementioned HACK continues here - just add object which failed to copy to failed list { failedIdList.Add(newIds[i]); } else { destinationWad.Add(newIds[i], obj); if (destinationWad.GameVersion == TRVersion.Game.TR5Main && obj is WadMoveable) { var moveable = obj as WadMoveable; foreach (var animation in moveable.Animations) { foreach (var command in animation.AnimCommands) { if (command.Type == WadAnimCommandType.PlaySound) { int id = command.Parameter2 & 0x3FFF; id += TrCatalog.GetTR5MainSoundMapStart(sourceWad.GameVersion); command.Parameter2 = (short)((command.Parameter2 & 0xC000) | (id & 0x3FFF)); } } } } } } // Aforementioned HACK continues here - count amount of actually copied objects int actualAmountOfCopiedObjects = objectIdsToMove.Count - failedIdList.Count; if (actualAmountOfCopiedObjects > 0) { // Update the situation tool.WadChanged(WadArea.Destination); string infoString = (objectIdsToMove.Count == 1 ? "Object" : "Objects") + " successfully copied."; // Aforementioned HACK continues here - additionally inform user that some objects are in different slots. if (failedIdList.Count > 0) { infoString += "\n" + failedIdList.Count + " object" + (failedIdList.Count > 1 ? "s" : "") + " weren't copied because " + (failedIdList.Count > 1 ? "they are" : "it's") + " already in different slot" + (failedIdList.Count > 1 ? "s." : "."); } // Indicate that object is copied tool.SendMessage(infoString, PopupType.Info); } return(newIds.Where(item => !failedIdList.Any(failed => failed == item)).ToList()); }