示例#1
0
        protected void CreateBlueprints()
        {
            if (!Utils.Nwn2ToolsetFunctions.ToolsetIsOpen())
            {
                return;
            }

            foreach (NWN2ObjectType type in Enum.GetValues(typeof(NWN2ObjectType)))
            {
                try {
                    string bag = String.Format(BlueprintBagNamingFormat, type.ToString());
                    if (!manager.HasBag(bag))
                    {
                        continue;
                    }

                    foreach (INWN2Blueprint blueprint in NWN2GlobalBlueprintManager.GetBlueprintsOfType(type, true, true, true))
                    {
                        ObjectBlock block = blocks.CreateBlueprintBlock(blueprint);
                        manager.AddMoveable(bag, block);
                    }
                }
                catch (Exception e) {
                    MessageBox.Show("Failed to populate bag of " + type + " blueprints.\n\n" + e);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates an instance of a blueprint and adds it to the area.
        /// </summary>
        /// <param name="blueprint">The blueprint to create the game
        /// object from.</param>
        /// <param name="tag">The tag to give the newly-created object.
        /// Pass null to use the default tag.</param>
        /// <returns>The newly-created game object.</returns>
        public override INWN2Instance AddGameObject(INWN2Blueprint blueprint, string tag)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException("blueprint", "Need a blueprint to create object from.");
            }

            INWN2Instance instance = NWN2GlobalBlueprintManager.CreateInstanceFromBlueprint(blueprint);

            if (tag != null)
            {
                ((INWN2Object)instance).Tag = tag;
            }

            nwn2Area.AddInstance(instance);

            return(instance);
        }
示例#3
0
        /// <summary>
        /// Creates an instance of a blueprint and adds it to the area.
        /// </summary>
        /// <param name="type">The type of object to add.</param>
        /// <param name="resref">The resref of the blueprint to create the object from.</param>
        /// <param name="tag">The tag to give the newly-created object.
        /// Pass null to use the default tag.</param>
        /// <param name="position">The position within the area to place
        /// the object.</param>
        /// <returns>The newly-created game object.</returns>
        public override INWN2Instance AddGameObject(NWN2ObjectType type, string resref, string tag, Vector3?position)
        {
            if (resref == null)
            {
                throw new ArgumentNullException("resref");
            }
            if (resref == String.Empty)
            {
                throw new ArgumentException("resref cannot be an empty string.", "resref");
            }

            INWN2Blueprint blueprint = NWN2GlobalBlueprintManager.FindBlueprint(type, new OEIResRef(resref), true, true, true);

            if (blueprint == null)
            {
                throw new ArgumentException("No blueprint with the given type and ResRef was found.", "resref");
            }

            return(AddGameObject(blueprint, tag, position));
        }
示例#4
0
        // NWN2Toolset.NWN2.Views.NWN2BlueprintView.ᐌ(object P_0, EventArgs P_1)
        // yeah whatever. Those idiots were too clever for anybody's good.
        /// <summary>
        /// Saves a specified blueprint to a user-labeled file.
        /// IMPORTANT: Allow only creature-blueprints to be saved!
        /// - NWN2ObjectType.Creature
        /// - resourcetype #2027
        /// @note Check that blueprint is valid before call.
        /// </summary>
        /// <param name="iblueprint">ElectronPanel_.Blueprint or .Instance
        /// converted to a blueprint</param>
        /// <param name="repo">null if Override</param>
        internal static void SaveBlueprintToFile(INWN2Blueprint iblueprint, DirectoryResourceRepository repo = null)
        {
            string fil = iblueprint.Resource.ResRef.Value;
            string ext = BWResourceTypes.GetFileExtension(iblueprint.Resource.ResourceType);

            var sfd = new SaveFileDialog();

            sfd.Title    = "Save blueprint as ...";
            sfd.FileName = fil + "." + ext;               // iblueprint.Resource.FullName
            sfd.Filter   = "blueprints (*." + ext + ")|*." + ext + "|all files (*.*)|*.*";
//			sfd.DefaultExt = ext;

            string dir;

            if (repo != null)
            {
                dir = repo.DirectoryName;
            }
            else
            {
                dir = String.Empty;
            }

            if (!String.IsNullOrEmpty(dir))
            {
                if (Directory.Exists(dir))
                {
                    sfd.InitialDirectory = dir;
                    sfd.RestoreDirectory = true;
                }
            }
            else if (!String.IsNullOrEmpty(CreatureVisualizerPreferences.that.LastSaveDirectory) &&
                     Directory.Exists(CreatureVisualizerPreferences.that.LastSaveDirectory))
            {
                sfd.InitialDirectory = CreatureVisualizerPreferences.that.LastSaveDirectory;
            }
            // else TODO: use NWN2ResourceManager.Instance.UserOverrideDirectory
            // else TODO: get BlueprintLocation dir if exists


            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (String.IsNullOrEmpty(dir))
                {
                    CreatureVisualizerPreferences.that.LastSaveDirectory = Path.GetDirectoryName(sfd.FileName);
                }


                // NOTE: Add 'AppearanceSEF' back in from the original blueprint
                // since it was removed when the original was duplicated by
                // ElectronPanel_.DuplicateBlueprint().
                (iblueprint as NWN2CreatureTemplate).AppearanceSEF = AppearanceSEF;


                IOEISerializable iserializable = iblueprint;
                if (iserializable != null)
                {
                    iserializable.OEISerialize(sfd.FileName);

                    if (File.Exists(sfd.FileName))                     // test that file exists before proceeding
                    {
                        INWN2BlueprintSet blueprintset;

                        dir = Path.GetDirectoryName(sfd.FileName).ToLower();
                        if (dir == NWN2ToolsetMainForm.App.Module.Repository.DirectoryName.ToLower())
                        {
                            repo         = NWN2ToolsetMainForm.App.Module.Repository;
                            blueprintset = NWN2ToolsetMainForm.App.Module as INWN2BlueprintSet;

                            iblueprint.BlueprintLocation = NWN2BlueprintLocationType.Module;
                        }
                        else if (NWN2CampaignManager.Instance.ActiveCampaign != null &&
                                 dir == NWN2CampaignManager.Instance.ActiveCampaign.Repository.DirectoryName.ToLower())
                        {
                            repo         = NWN2CampaignManager.Instance.ActiveCampaign.Repository;
                            blueprintset = NWN2CampaignManager.Instance.ActiveCampaign as INWN2BlueprintSet;

                            iblueprint.BlueprintLocation = NWN2BlueprintLocationType.Campaign;
                        }
                        else if (IsOverride(dir))
                        {
                            repo         = NWN2ResourceManager.Instance.UserOverrideDirectory;
                            blueprintset = NWN2GlobalBlueprintManager.Instance as INWN2BlueprintSet;

                            iblueprint.BlueprintLocation = NWN2BlueprintLocationType.Global;
                        }
                        else
                        {
                            return;
                        }


                        // so, which should be tested for first: resource or blueprint?
                        // and is there even any point in having one w/out the other?

                        string filelabel = Path.GetFileNameWithoutExtension(sfd.FileName);

                        NWN2BlueprintCollection collection = blueprintset.GetBlueprintCollectionForType(NWN2ObjectType.Creature);

                        INWN2Blueprint extantblueprint = NWN2GlobalBlueprintManager.FindBlueprint(NWN2ObjectType.Creature,
                                                                                                  new OEIResRef(filelabel),
                                                                                                  iblueprint.BlueprintLocation == NWN2BlueprintLocationType.Global,
                                                                                                  iblueprint.BlueprintLocation == NWN2BlueprintLocationType.Module,
                                                                                                  iblueprint.BlueprintLocation == NWN2BlueprintLocationType.Campaign);

                        if (extantblueprint != null && extantblueprint.Resource.Repository is DirectoryResourceRepository) // ie. exclude Data\Templates*.zip
                        {
                            collection.Remove(extantblueprint);                                                            // so, does removing a blueprint also remove its resource? no.
                        }

                        IResourceEntry extantresource = repo.FindResource(new OEIResRef(filelabel), 2027);                         // it's maaaaaagick
                        if (extantresource != null)
                        {
                            repo.Resources.Remove(extantresource);                             // so, does removing a resource also remove its blueprint? no.
                        }


                        iblueprint.Resource = repo.CreateResource(iblueprint.Resource.ResRef, iblueprint.Resource.ResourceType);
                        collection.Add(iblueprint);

                        var viewer = NWN2ToolsetMainForm.App.BlueprintView;
                        var list   = viewer.GetFocusedList();
                        list.Resort();

                        var objects = new object[1] {
                            iblueprint as INWN2Object
                        };
                        viewer.Selection = objects;
                    }
                }
            }
        }