/// <summary> /// Load the Sustained Object from the XmlNode. /// </summary> /// <param name="objNode">XmlNode to load.</param> public void Load(XmlNode objNode) { if (objNode == null) { return; } string strLinkedId = string.Empty; if (!objNode.TryGetStringFieldQuickly("linkedobject", ref strLinkedId)) { _guiID = Guid.Empty; return; } if (objNode["linkedobjecttype"] != null) { _eLinkedObjectType = Improvement.ConvertToImprovementSource(objNode["linkedobjecttype"].InnerText); } else { _guiID = Guid.Empty; return; } IEnumerable <IHasInternalId> lstToSearch; // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (_eLinkedObjectType) { case Improvement.ImprovementSource.Spell: lstToSearch = _objCharacter.Spells; break; case Improvement.ImprovementSource.ComplexForm: lstToSearch = _objCharacter.ComplexForms; break; case Improvement.ImprovementSource.CritterPower: lstToSearch = _objCharacter.CritterPowers; break; default: _guiID = Guid.Empty; return; } _objLinkedObject = lstToSearch.FirstOrDefault(x => x.InternalId == strLinkedId); if (_objLinkedObject == null) { Utils.BreakIfDebug(); _guiID = Guid.Empty; return; } objNode.TryGetInt32FieldQuickly("force", ref _intForce); objNode.TryGetInt32FieldQuickly("nethits", ref _intNetHits); objNode.TryGetBoolFieldQuickly("self", ref _blnSelfSustained); }
/// <summary> /// Creates a sustained object from a thing that can be sustained (usually a Spell, Complex Form, or Critter Power) /// </summary> /// <param name="objLinkedObject">The liked object that is meant to be sustained.</param> /// <returns></returns> public void Create(IHasInternalId objLinkedObject) { _objLinkedObject = objLinkedObject; switch (objLinkedObject) { case Spell _: _eLinkedObjectType = Improvement.ImprovementSource.Spell; break; case ComplexForm _: _eLinkedObjectType = Improvement.ImprovementSource.ComplexForm; break; case CritterPower _: _eLinkedObjectType = Improvement.ImprovementSource.CritterPower; break; default: throw new ArgumentOutOfRangeException(nameof(objLinkedObject)); } }
public static void RefreshWeaponAccessories(this IHasInternalId objParent, TreeView treWeapons, ContextMenuStrip cmsWeaponAccessory, ContextMenuStrip cmsWeaponAccessoryGear, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs == null) { return; } TreeNode nodParent = treWeapons.FindNode(objParent.InternalId); if (nodParent == null) { return; } switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponAccessory, intNewIndex); objWeaponAccessory.Gear.AddTaggedCollectionChanged(treWeapons, (x, y) => objWeaponAccessory.RefreshChildrenGears(treWeapons, cmsWeaponAccessoryGear, null, y)); foreach (Gear objGear in objWeaponAccessory.Gear) { objGear.SetupChildrenGearsCollectionChanged(true, treWeapons, cmsWeaponAccessoryGear); } intNewIndex += 1; } } break; case NotifyCollectionChangedAction.Remove: { foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.OldItems) { objWeaponAccessory.Gear.RemoveTaggedCollectionChanged(treWeapons); foreach (Gear objGear in objWeaponAccessory.Gear) { objGear.SetupChildrenGearsCollectionChanged(false, treWeapons); } nodParent.FindNode(objWeaponAccessory.InternalId)?.Remove(); } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treWeapons.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.OldItems) { objWeaponAccessory.Gear.RemoveTaggedCollectionChanged(treWeapons); foreach (Gear objGear in objWeaponAccessory.Gear) { objGear.SetupChildrenGearsCollectionChanged(false, treWeapons); } nodParent.FindNode(objWeaponAccessory.InternalId)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponAccessory, intNewIndex); objWeaponAccessory.Gear.AddTaggedCollectionChanged(treWeapons, (x, y) => objWeaponAccessory.RefreshChildrenGears(treWeapons, cmsWeaponAccessoryGear, null, y)); foreach (Gear objGear in objWeaponAccessory.Gear) { objGear.SetupChildrenGearsCollectionChanged(true, treWeapons, cmsWeaponAccessoryGear); } intNewIndex += 1; } treWeapons.SelectedNode = treWeapons.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treWeapons.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.OldItems) { nodParent.FindNode(objWeaponAccessory.InternalId)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (WeaponAccessory objWeaponAccessory in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponAccessory, intNewIndex); intNewIndex += 1; } treWeapons.SelectedNode = treWeapons.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { nodParent.Nodes.Clear(); } break; } void AddToTree(WeaponAccessory objWeaponAccessory, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objWeaponAccessory.CreateTreeNode(cmsWeaponAccessory, cmsWeaponAccessoryGear); if (objNode == null) { return; } if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); if (blnSingleAdd) { treWeapons.SelectedNode = objNode; } } }
public static void RefreshChildrenGears(this IHasInternalId objParent, TreeView treGear, ContextMenuStrip cmsGear, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs == null) { return; } TreeNode nodParent = treGear.FindNodeByTag(objParent); if (nodParent == null) { return; } switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Gear objGear in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objGear, intNewIndex); objGear.SetupChildrenGearsCollectionChanged(true, treGear, cmsGear); intNewIndex += 1; } } break; case NotifyCollectionChangedAction.Remove: { foreach (Gear objGear in notifyCollectionChangedEventArgs.OldItems) { objGear.SetupChildrenGearsCollectionChanged(false, treGear); nodParent.FindNodeByTag(objGear)?.Remove(); } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treGear.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Gear objGear in notifyCollectionChangedEventArgs.OldItems) { objGear.SetupChildrenGearsCollectionChanged(false, treGear); nodParent.FindNodeByTag(objGear)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Gear objGear in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objGear, intNewIndex); objGear.SetupChildrenGearsCollectionChanged(true, treGear, cmsGear); intNewIndex += 1; } treGear.SelectedNode = treGear.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treGear.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Gear objGear in notifyCollectionChangedEventArgs.OldItems) { nodParent.FindNodeByTag(objGear)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Gear objGear in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objGear, intNewIndex); intNewIndex += 1; } treGear.SelectedNode = treGear.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { nodParent.Nodes.Clear(); } break; } void AddToTree(Gear objGear, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objGear.CreateTreeNode(cmsGear); if (objNode == null) { return; } if (objGear.Location == null) { if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); } else { TreeNode nodLocation = nodParent.FindNodeByTag(objGear.Location, false); if (nodLocation != null) { if (intIndex >= 0) { nodLocation.Nodes.Insert(intIndex, objNode); } else { nodLocation.Nodes.Add(objNode); } nodLocation.Expand(); } // Location Updating should be part of a separate method, so just add to parent instead else { if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); } } if (blnSingleAdd) { treGear.SelectedNode = objNode; } } }
public static void RefreshChildrenCyberware(this IHasInternalId objParent, TreeView treCyberware, ContextMenuStrip cmsCyberware, ContextMenuStrip cmsCyberwareGear, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs == null || objParent == null || treCyberware == null) { return; } TreeNode nodParent = treCyberware.FindNodeByTag(objParent); if (nodParent == null) { return; } switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); objCyberware.SetupChildrenCyberwareCollectionChanged(true, treCyberware, cmsCyberware, cmsCyberwareGear); intNewIndex += 1; } } break; case NotifyCollectionChangedAction.Remove: { foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { objCyberware.SetupChildrenCyberwareCollectionChanged(false, treCyberware); nodParent.FindNodeByTag(objCyberware)?.Remove(); } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treCyberware.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { objCyberware.SetupChildrenCyberwareCollectionChanged(false, treCyberware); nodParent.FindNodeByTag(objCyberware)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); objCyberware.SetupChildrenCyberwareCollectionChanged(true, treCyberware, cmsCyberware, cmsCyberwareGear); intNewIndex += 1; } treCyberware.SelectedNode = treCyberware.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treCyberware.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.OldItems) { nodParent.FindNodeByTag(objCyberware)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Cyberware objCyberware in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objCyberware, intNewIndex); intNewIndex += 1; } treCyberware.SelectedNode = treCyberware.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { nodParent.Nodes.Clear(); } break; } void AddToTree(Cyberware objCyberware, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objCyberware.CreateTreeNode(cmsCyberware, cmsCyberwareGear); if (objNode == null) { return; } if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); if (blnSingleAdd) { treCyberware.SelectedNode = objNode; } } }
public static void RefreshVehicleWeaponMounts(this IHasInternalId objParent, TreeView treVehicles, ContextMenuStrip cmsVehicleWeaponMount, ContextMenuStrip cmsVehicleWeapon, ContextMenuStrip cmsVehicleWeaponAccessory, ContextMenuStrip cmsVehicleWeaponAccessoryGear, ContextMenuStrip cmsCyberware, ContextMenuStrip cmsCyberwareGear, ContextMenuStrip cmsVehicleMod, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (treVehicles == null || notifyCollectionChangedEventArgs == null) { return; } TreeNode nodVehicleParent = treVehicles.FindNodeByTag(objParent); if (nodVehicleParent == null) { return; } TreeNode nodParent = nodVehicleParent.FindNode("String_WeaponMounts", false); switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponMount, intNewIndex); objWeaponMount.Mods.AddTaggedCollectionChanged(treVehicles, (x, y) => objWeaponMount.RefreshVehicleMods(treVehicles, cmsVehicleMod, cmsCyberware, cmsCyberwareGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, null, y)); objWeaponMount.Weapons.AddTaggedCollectionChanged(treVehicles, (x, y) => objWeaponMount.RefreshChildrenWeapons(treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, () => objWeaponMount.Mods.Count, y)); foreach (Weapon objWeapon in objWeaponMount.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(true, treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear); } foreach (VehicleMod objMod in objWeaponMount.Mods) { objMod.Cyberware.AddTaggedCollectionChanged(treVehicles, (x, y) => objMod.RefreshChildrenCyberware(treVehicles, cmsCyberware, cmsCyberwareGear, null, y)); foreach (Cyberware objCyberware in objMod.Cyberware) { objCyberware.SetupChildrenCyberwareCollectionChanged(true, treVehicles, cmsCyberware, cmsCyberwareGear); } objMod.Weapons.AddTaggedCollectionChanged(treVehicles, (x, y) => objMod.RefreshChildrenWeapons(treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, () => objMod.Cyberware.Count, y)); foreach (Weapon objWeapon in objMod.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(true, treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear); } } ++intNewIndex; } } break; case NotifyCollectionChangedAction.Remove: { foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.OldItems) { objWeaponMount.Mods.RemoveTaggedCollectionChanged(treVehicles); objWeaponMount.Weapons.RemoveTaggedCollectionChanged(treVehicles); foreach (Weapon objWeapon in objWeaponMount.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treVehicles); } foreach (VehicleMod objMod in objWeaponMount.Mods) { objMod.Cyberware.RemoveTaggedCollectionChanged(treVehicles); foreach (Cyberware objCyberware in objMod.Cyberware) { objCyberware.SetupChildrenCyberwareCollectionChanged(true, treVehicles); } objMod.Weapons.RemoveTaggedCollectionChanged(treVehicles); foreach (Weapon objWeapon in objMod.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treVehicles); } } if (nodParent != null) { nodParent.FindNodeByTag(objWeaponMount)?.Remove(); if (nodParent.Nodes.Count == 0) { nodParent.Remove(); } } } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treVehicles.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.OldItems) { objWeaponMount.Mods.RemoveTaggedCollectionChanged(treVehicles); objWeaponMount.Weapons.RemoveTaggedCollectionChanged(treVehicles); foreach (Weapon objWeapon in objWeaponMount.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treVehicles); } foreach (VehicleMod objMod in objWeaponMount.Mods) { objMod.Cyberware.RemoveTaggedCollectionChanged(treVehicles); foreach (Cyberware objCyberware in objMod.Cyberware) { objCyberware.SetupChildrenCyberwareCollectionChanged(false, treVehicles); } objMod.Weapons.RemoveTaggedCollectionChanged(treVehicles); foreach (Weapon objWeapon in objMod.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treVehicles); } } nodParent?.FindNodeByTag(objWeaponMount)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponMount, intNewIndex); objWeaponMount.Mods.AddTaggedCollectionChanged(treVehicles, (x, y) => objWeaponMount.RefreshVehicleMods(treVehicles, cmsVehicleMod, cmsCyberware, cmsCyberwareGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, null, y)); objWeaponMount.Weapons.AddTaggedCollectionChanged(treVehicles, (x, y) => objWeaponMount.RefreshChildrenWeapons(treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, () => objWeaponMount.Mods.Count, y)); foreach (Weapon objWeapon in objWeaponMount.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(true, treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear); } foreach (VehicleMod objMod in objWeaponMount.Mods) { objMod.Cyberware.AddTaggedCollectionChanged(treVehicles, (x, y) => objMod.RefreshChildrenCyberware(treVehicles, cmsCyberware, cmsCyberwareGear, null, y)); foreach (Cyberware objCyberware in objMod.Cyberware) { objCyberware.SetupChildrenCyberwareCollectionChanged(true, treVehicles, cmsCyberware, cmsCyberwareGear); } objMod.Weapons.AddTaggedCollectionChanged(treVehicles, (x, y) => objMod.RefreshChildrenWeapons(treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, () => objMod.Cyberware.Count, y)); foreach (Weapon objWeapon in objMod.Weapons) { objWeapon.SetupChildrenWeaponsCollectionChanged(true, treVehicles, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear); } } ++intNewIndex; } treVehicles.SelectedNode = treVehicles.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treVehicles.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.OldItems) { nodParent?.FindNodeByTag(objWeaponMount)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; foreach (WeaponMount objWeaponMount in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeaponMount, intNewIndex); ++intNewIndex; } treVehicles.SelectedNode = treVehicles.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { if (nodParent != null) { for (int i = nodParent.Nodes.Count - 1; i >= 0; --i) { TreeNode objNode = nodParent.Nodes[i]; if (objNode.Tag is WeaponMount objNodeWeaponMount && !ReferenceEquals(objNodeWeaponMount.Parent, objParent)) { objNode.Remove(); } } } } break; } void AddToTree(WeaponMount objWeaponMount, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objWeaponMount.CreateTreeNode(cmsVehicleWeaponMount, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, cmsCyberware, cmsCyberwareGear, cmsVehicleMod); if (objNode == null) { return; } if (nodParent == null) { nodParent = new TreeNode { Tag = "String_WeaponMounts", Text = LanguageManager.GetString("String_WeaponMounts") }; nodVehicleParent.Nodes.Insert(funcOffset?.Invoke() ?? 0, nodParent); nodParent.Expand(); } if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); if (blnSingleAdd) { treVehicles.SelectedNode = objNode; } } }
public static void RefreshChildrenWeapons(this IHasInternalId objParent, TreeView treWeapons, ContextMenuStrip cmsWeapon, ContextMenuStrip cmsWeaponAccessory, ContextMenuStrip cmsWeaponAccessoryGear, Func <int> funcOffset, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs == null || objParent == null || treWeapons == null) { return; } TreeNode nodParent = treWeapons.FindNode(objParent.InternalId); if (nodParent == null) { return; } switch (notifyCollectionChangedEventArgs.Action) { case NotifyCollectionChangedAction.Add: { int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeapon, intNewIndex); objWeapon.SetupChildrenWeaponsCollectionChanged(true, treWeapons, cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear); ++intNewIndex; } } break; case NotifyCollectionChangedAction.Remove: { foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.OldItems) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treWeapons); nodParent.FindNode(objWeapon.InternalId)?.Remove(); } } break; case NotifyCollectionChangedAction.Replace: { string strSelectedId = (treWeapons.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.OldItems) { objWeapon.SetupChildrenWeaponsCollectionChanged(false, treWeapons); nodParent.FindNode(objWeapon.InternalId)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; if (funcOffset != null) { intNewIndex += funcOffset.Invoke(); } foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeapon, intNewIndex); objWeapon.SetupChildrenWeaponsCollectionChanged(true, treWeapons, cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear); ++intNewIndex; } treWeapons.SelectedNode = treWeapons.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Move: { string strSelectedId = (treWeapons.SelectedNode?.Tag as IHasInternalId)?.InternalId ?? string.Empty; foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.OldItems) { nodParent.FindNode(objWeapon.InternalId)?.Remove(); } int intNewIndex = notifyCollectionChangedEventArgs.NewStartingIndex; foreach (Weapon objWeapon in notifyCollectionChangedEventArgs.NewItems) { AddToTree(objWeapon, intNewIndex); ++intNewIndex; } treWeapons.SelectedNode = treWeapons.FindNode(strSelectedId); } break; case NotifyCollectionChangedAction.Reset: { nodParent.Nodes.Clear(); for (int i = nodParent.Nodes.Count - 1; i >= 0; --i) { TreeNode objNode = nodParent.Nodes[i]; if (objNode.Tag is Weapon objNodeWeapon && !ReferenceEquals(objNodeWeapon.Parent, objParent) && !ReferenceEquals(objNodeWeapon.ParentMount, objParent) && !ReferenceEquals(objNodeWeapon.ParentVehicle, objParent) && !ReferenceEquals(objNodeWeapon.ParentVehicleMod, objParent)) { objNode.Remove(); } } } break; } void AddToTree(Weapon objWeapon, int intIndex = -1, bool blnSingleAdd = true) { TreeNode objNode = objWeapon.CreateTreeNode(cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear); if (objNode == null) { return; } if (intIndex >= 0) { nodParent.Nodes.Insert(intIndex, objNode); } else { nodParent.Nodes.Add(objNode); } nodParent.Expand(); if (blnSingleAdd) { treWeapons.SelectedNode = objNode; } } }