Exemplo n.º 1
0
        public void CreateInstanceBlocksFromBlueprints(NWN2BlueprintCollection blueprints)
        {
            if (blueprints == null || blueprints.Count == 0)
            {
                return;
            }

            LaunchFlip();

            try {
                foreach (INWN2Blueprint blueprint in blueprints)
                {
                    ObjectBlock block = blocks.CreateInstanceBlockFromBlueprint(blueprint);
                    string      bag   = String.Format(Nwn2MoveableProvider.InstanceBagNamingFormat, blueprint.ObjectType);
                    if (window.BlockBox.HasBag(bag))
                    {
                        window.BlockBox.AddMoveable(bag, block, true);
                        //ActivityLog.Write(new Activity("CreatedBlockFromBlueprint","Block",block.GetLogText()));
                        Log.WriteMessage("created blueprint block (" + block.GetLogText() + ")");
                    }
                }
            }
            catch (Exception x) {
                MessageBox.Show("Something went wrong when creating a block from a blueprint.\n\n" + x);
            }
        }
Exemplo n.º 2
0
        static Globals()
        {
            mod = NWN2Toolset.NWN2ToolsetMainForm.App.Module;
            repository = mod.Repository;
            items = mod.GetBlueprintCollectionForType(NWN2Toolset.NWN2.Data.Templates.NWN2ObjectType.Item);

            customTlk = new OEIShared.IO.TalkTable.TalkTable();
            customTlk.OpenCustom(OEIShared.Utils.BWLanguages.BWLanguage.English, "alfa_acr02.tlk");

            tdaManager = TwoDAManager.Instance;

            spellschools2da = tdaManager.Get("spellschools");
            nwn2_icons2da = tdaManager.Get("nwn2_icons");
            iprp_spells2da = tdaManager.Get("iprp_spells");

            spells = new NWN2Toolset.NWN2.Rules.CNWSpellArray();
            spells.Load();

            globalItemCollection = NWN2Toolset.NWN2.Data.Blueprints.NWN2GlobalBlueprintManager.GetBlueprintsOfType(NWN2Toolset.NWN2.Data.Templates.NWN2ObjectType.Item);

            iconHash = new Dictionary<string, int>();
            int rowCount = Globals.nwn2_icons2da.RowCount;
            for (int i = 0; i < rowCount; i++)
            {
                string twodaString = Globals.nwn2_icons2da["ICON"][i];
                if (!iconHash.ContainsKey(twodaString))
                {
                    iconHash.Add(twodaString, i);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a subset of a given blueprint collection containing only those blueprints
        /// which appear to have been created by Narrative Threads.
        /// </summary>
        /// <param name="blueprints">A collection of blueprints.</param>
        /// <returns>A subset of the given collection of blueprints.</returns>
        public NWN2BlueprintCollection GetBlueprintsCreatedByNarrativeThreads(NWN2BlueprintCollection blueprints)
        {
            if (blueprints == null)
            {
                throw new ArgumentNullException("blueprints");
            }

            NWN2BlueprintCollection narrativeThreadsBlueprints = new NWN2BlueprintCollection();

            foreach (INWN2Blueprint blueprint in blueprints)
            {
                if (CreatedByNarrativeThreads(blueprint))
                {
                    narrativeThreadsBlueprints.Add(blueprint);
                }
            }

            return(narrativeThreadsBlueprints);
        }
Exemplo n.º 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;
                    }
                }
            }
        }
Exemplo n.º 5
0
//		/// <summary>
//		///
//		/// </summary>
//		/// <returns></returns>
//		/// <remarks>Use this method rather than NWN2BlueprintView.GetAllSelectedBlueprints() as
//		/// it returns the selected blueprint in EVERY category (bizarrely).</remarks>
//		protected NWN2BlueprintCollection GetSelectedBlueprints()
//		{
//			NWN2BlueprintCollection blueprints = new NWN2BlueprintCollection();
//
//			if (blueprintView != null && blueprintView.ActivePalette != null) {
//				foreach (object o in blueprintView.ActivePalette.Selection) {
//					INWN2Blueprint blueprint = o as INWN2Blueprint;
//					if (blueprint != null) {
//						blueprints.Add(blueprint);
//					}
//				}
//			}
//
//			return blueprints;
//		}


        /// <summary>
        /// Gather references to toolset fields which are used by other plugin methods.
        /// </summary>
        protected void FindFields()
        {
            foreach (FieldInfo field in typeof(NWN2PropertyGrid).GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                if (field.FieldType == typeof(PropertyGrid))
                {
                    innerPropertyGridFieldInfo = field;
                }
            }

            foreach (FieldInfo field in typeof(NWN2ToolsetMainForm).GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                if (field.FieldType == typeof(NWN2PropertyGrid))
                {
                    NWN2PropertyGrid mainPropertyGrid = (NWN2PropertyGrid)field.GetValue(NWN2ToolsetMainForm.App);

                    /*
                     * If Narrative Threads is running the main property grid may already have been disposed,
                     * so check that it (and its inner grid) are not null or disposed whenever using them.
                     */
                    if (mainPropertyGrid != null)
                    {
                        Watch(mainPropertyGrid);
                        mainPropertyInnerGrid = (PropertyGrid)innerPropertyGridFieldInfo.GetValue(mainPropertyGrid);
                    }
                }

                else if (field.FieldType == typeof(DockingManager))
                {
                    dockingManager = (DockingManager)field.GetValue(NWN2ToolsetMainForm.App);
                }

                else if (field.FieldType == typeof(TD.SandBar.ToolBar))
                {
                    ToolBar tb = (ToolBar)field.GetValue(NWN2ToolsetMainForm.App);
                    if (tb.Text == "Object Manipulation")
                    {
                        objectsToolbar = tb;
                    }
                }

                else if (field.FieldType == typeof(NWN2ModuleScriptList))
                {
                    scriptPanels.Add((NWN2ModuleScriptList)field.GetValue(NWN2ToolsetMainForm.App));
                }

                else if (field.FieldType == typeof(NWN2BlueprintView))
                {
                    blueprintView = (NWN2BlueprintView)field.GetValue(NWN2ToolsetMainForm.App);

                    winforms.ContextMenu menu = blueprintView.ActivePalette.ContextMenu;

                    if (menu != null)
                    {
                        try {
                            winforms.MenuItem item = new winforms.MenuItem("Create a Flip block from this blueprint");

                            item.Click += delegate
                            {
                                NWN2BlueprintCollection blueprints = blueprintView.GetFocusedListSelectedBlueprints();

                                if (blueprints.Count == 0)
                                {
                                    MessageBox.Show("No blueprint selected.");
                                }

                                else if (blueprints.Count > 1)
                                {
                                    MessageBox.Show("Select one blueprint at a time (you have " + blueprints.Count + " blueprints selected).");
                                }

                                else
                                {
                                    try {
                                        createBlockFromBlueprintDelegate.Invoke(blueprints);
                                    }
                                    catch (Exception x) {
                                        MessageBox.Show("Something went wrong when trying to create a block from a blueprint.\n\n" + x);
                                    }
                                }
                            };

                            menu.Popup += delegate
                            {
                                NWN2BlueprintCollection blueprints = blueprintView.GetFocusedListSelectedBlueprints();
                                item.Enabled = blueprints != null && blueprints.Count > 0;
                            };

                            menu.MenuItems.Add("-");
                            menu.MenuItems.Add(item);
                        }
                        catch (Exception x) {
                            MessageBox.Show("Something went wrong when adding a new option to the Blueprints menu.\n\n" + x);
                        }
                    }
                }

                else if (field.FieldType == typeof(TD.SandBar.MenuButtonItem))
                {
                    TD.SandBar.MenuButtonItem mbi = (TD.SandBar.MenuButtonItem)field.GetValue(NWN2ToolsetMainForm.App);
                    if (mbi.Text == "&Script" || mbi.Text == "Open Conversation/Script")
                    {
                        scriptMenuItems.Add(mbi);
                    }
                }

                // No longer required to find mainPropertyInnerGrid as a result of Narrative Threads integration:
                if (dockingManager != null &&
                    //mainPropertyInnerGrid != null &&
                    innerPropertyGridFieldInfo != null &&
                    scriptPanels.Count == 2 &&
                    scriptMenuItems.Count == 2)
                {
                    return;
                }
            }

            string missingField = null;

            if (innerPropertyGridFieldInfo == null)
            {
                missingField = "inner property grid field info";
            }
            else if (dockingManager == null)
            {
                missingField = "dockingManager";
            }
            else if (scriptPanels.Count != 2)
            {
                missingField = "script panels";
            }
            else if (scriptMenuItems.Count != 2)
            {
                missingField = "script menu items";
            }

            throw new ApplicationException(String.Format("Failed to find a crucial field ('{0}') via reflection.", missingField));
        }