/// <summary> /// Check whether the newly opened content is a property grid, and if so, /// hide its script slot fields. /// </summary> /// <param name="c">The content which was just opened.</param> /// <param name="cea">Arguments relating to this event.</param> protected void HideScriptSlotsOnFloatingGrid(Content c, EventArgs cea) { if (c.Control is NWN2PropertyGrid) { NWN2PropertyGrid grid = (NWN2PropertyGrid)c.Control; PropertyGrid innerGrid = (PropertyGrid)innerPropertyGridFieldInfo.GetValue(grid); HideScriptSlots(innerGrid); } }
protected void Watch(NWN2PropertyGrid grid) { if (grid == null) { throw new ArgumentNullException("grid"); } grid.ValueChanged += delegate(object sender, NWN2PropertyValueChangedEventArgs args) { try { updateBlockDelegate.Invoke(args); } catch (Exception x) { MessageBox.Show("Something went wrong when updating a block.\n\n" + x); } }; }
// /// <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)); }