protected void CreateAreas() { if (!Utils.Nwn2ToolsetFunctions.ToolsetIsOpen()) { return; } if (NWN2Toolset.NWN2ToolsetMainForm.App.Module == null) { return; } foreach (NWN2GameArea area in NWN2Toolset.NWN2ToolsetMainForm.App.Module.Areas.Values) { ObjectBlock block = blocks.CreateAreaBlock(area); manager.AddMoveable(AreasBagName, block); } }
public ObjectBlock GetBlock(Nwn2Address address) { if (address == null) { throw new ArgumentNullException("address"); } if (session.GetModule() == null) { throw new InvalidOperationException("No module is open."); } if (address.TargetType == Nwn2Type.Module) { return(blocks.CreateModuleBlock()); } else if (address.TargetType == Nwn2Type.Area) { NWN2GameArea area = session.GetArea(address.AreaTag); if (area == null) { throw new ArgumentException("No such area in the current module.", "area"); } else { return(blocks.CreateAreaBlock(area)); } } else { NWN2ObjectType type = Nwn2ScriptSlot.GetObjectType(address.TargetType).Value; INWN2Blueprint blueprint = session.GetBlueprint(address.InstanceTag, type); if (blueprint != null) { return(blocks.CreateInstanceBlockFromBlueprint(blueprint)); } foreach (NWN2AreaViewer viewer in NWN2Toolset.NWN2ToolsetMainForm.App.GetAllAreaViewers()) { NWN2InstanceCollection instances = session.GetObjectsByAddressInArea(address, viewer.Area.Tag); if (instances.Count > 0) { INWN2Instance instance = instances[0]; return(blocks.CreateInstanceBlock(instance)); } } return(null); } }
public void UpdateBlockWithNewTag(NWN2PropertyValueChangedEventArgs e) { try { if (tracking.Contains(e.PropertyName) && e.NewValue != e.OldValue) { foreach (object o in e.ChangedObjects) { if (o is INWN2Instance) { INWN2Instance instance = (INWN2Instance)o; InstanceBehaviour behaviour = blocks.CreateInstanceBehaviour(instance); string bag = String.Format(Nwn2MoveableProvider.InstanceBagNamingFormat, instance.ObjectType); if (window.BlockBox.HasBag(bag)) { UIElementCollection existingBlocks = window.BlockBox.GetMoveables(bag); // If it's the tag that's changed, use the old tag to search, otherwise use the current one: string tag; if (e.PropertyName == "Tag") { tag = e.OldValue as string; } else { tag = ((INWN2Object)instance).Tag; } bool updated = false; foreach (UIElement u in existingBlocks) { ObjectBlock existing = u as ObjectBlock; if (existing == null) { continue; } InstanceBehaviour existingBehaviour = existing.Behaviour as InstanceBehaviour; if (existingBehaviour == null) { continue; } // If you find an instance of the same type, resref and tag, replace its behaviour to update it: if (existingBehaviour.ResRef == behaviour.ResRef && existingBehaviour.Nwn2Type == behaviour.Nwn2Type && existingBehaviour.Tag == tag) { existing.Behaviour = behaviour; updated = true; break; } } if (!updated) { ObjectBlock block = blocks.CreateInstanceBlock(behaviour); window.BlockBox.AddMoveable(bag, block, false); } } if (e.PropertyName == "Tag") { UpdateScriptsFollowingTagChange(instance, (string)e.OldValue, (string)e.NewValue, true); } } else if (o is NWN2GameArea) { NWN2GameArea area = (NWN2GameArea)o; // Refuse changes to tags or areas unless they are to match the resource name: if (e.PropertyName == "Tag" && ((string)e.NewValue) != area.Name) { area.Tag = area.Name; return; } else if (e.PropertyName == "Display Name" && (Nwn2Strings.GetStringFromOEIString((OEIShared.Utils.OEIExoLocString)e.NewValue) != area.Name)) { area.DisplayName = Nwn2Strings.GetOEIStringFromString(area.Name); return; } AreaBehaviour behaviour = blocks.CreateAreaBehaviour(area); if (window.BlockBox.HasBag(Nwn2MoveableProvider.AreasBagName)) { UIElementCollection existingBlocks = window.BlockBox.GetMoveables(Nwn2MoveableProvider.AreasBagName); string tag; if (e.PropertyName == "Tag") { tag = e.OldValue as string; } else { tag = area.Tag; } bool updated = false; foreach (UIElement u in existingBlocks) { ObjectBlock existing = u as ObjectBlock; if (existing == null) { continue; } AreaBehaviour existingBehaviour = existing.Behaviour as AreaBehaviour; if (existingBehaviour == null) { continue; } // If you find an area with the same tag, replace its behaviour to update it: if (existingBehaviour.Tag == tag) { existing.Behaviour = behaviour; updated = true; break; } } if (!updated) { ObjectBlock block = blocks.CreateAreaBlock(behaviour); window.BlockBox.AddMoveable(Nwn2MoveableProvider.AreasBagName, block, false); } } } } } } catch (Exception x) { MessageBox.Show("Something went wrong when updating a block.\n\n" + x); } }