/// <summary>Sets the part to be adjusted.</summary>
 /// <param name="part">The part to set.</param>
 public void SetPart(Part part)
 {
     parentPart = part;
     if (part != null)
     {
         var adjustables = new List <KeyValuePair <string, IRenderableGUIControl[]> >();
         foreach (var module in part.Modules.Cast <PartModule>())
         {
             var moduleControls = new List <DebugGui.DebugMemberInfo>()
                                  .Concat(DebugGui.GetAdjustableFields(module, group: controlsGroup))
                                  .Concat(DebugGui.GetAdjustableProperties(module, group: controlsGroup))
                                  .Concat(DebugGui.GetAdjustableActions(module, group: controlsGroup))
                                  .Select(m => new StdTypesDebugGuiControl(
                                              m.attr.caption, module,
                                              fieldInfo: m.fieldInfo, propertyInfo: m.propertyInfo, methodInfo: m.methodInfo)
                                          )
                                  .ToArray();
             if (moduleControls.Length > 0)
             {
                 adjustables.Add(new KeyValuePair <string, IRenderableGUIControl[]>(
                                     module.moduleName, moduleControls));
             }
         }
         adjustableModules = adjustables.ToArray();
     }
     else
     {
         adjustableModules = null;
     }
 }
        /// <summary>Shows a window that displays the winch controls.</summary>
        /// <param name="windowId">Window ID.</param>
        void ConsoleWindowFunc(int windowId)
        {
            if (guiActions.ExecutePendingGuiActions())
            {
                if (parentPartTracking && Input.GetMouseButtonDown(0) &&
                    !windowRect.Contains(Mouse.screenPos))
                {
                    SetPart(Mouse.HoveredPart);
                    parentPartTracking = false;
                }
            }

            string parentPartName = parentPart != null?DbgFormatter.PartId(parentPart) : "NONE";

            if (!lockToPart)
            {
                if (GUILayout.Button(!parentPartTracking ? "Set part" : "Cancel set mode..."))
                {
                    guiActions.Add(() => { parentPartTracking = !parentPartTracking; });
                }
                if (parentPartTracking && Mouse.HoveredPart != null)
                {
                    parentPartName = "Select: " + DbgFormatter.PartId(Mouse.HoveredPart);
                }
                GUILayout.Label(parentPartName, new GUIStyle(GUI.skin.box)
                {
                    wordWrap = true
                });
            }

            // Render the adjustable fields.
            if (parentPart != null && adjustableModules != null)
            {
                if (adjustableModules.Length > 0)
                {
                    mainScrollView.BeginView(GUI.skin.box, Screen.height - 200);
                    for (var i = 0; i < adjustableModules.Length; i++)
                    {
                        var isSelected    = selectedModule == i;
                        var module        = adjustableModules[i];
                        var toggleCaption = (isSelected ? "\u25b2 " : "\u25bc ") + "Module: " + module.Key;
                        if (GUILayout.Button(toggleCaption))
                        {
                            var selectedModuleSnapshot = selectedModule == i ? -1 : i; // Make a copy for lambda!
                            guiActions.Add(() => selectedModule = selectedModuleSnapshot);
                        }
                        if (isSelected)
                        {
                            foreach (var control in module.Value)
                            {
                                control.RenderControl(
                                    guiActions, GUI.skin.label, new[] { GUILayout.Width(dialogValueSize) });
                            }
                        }
                    }
                    mainScrollView.EndView();
                }
                else
                {
                    GUILayout.Box("No adjustable members found");
                }
            }

            if (GUILayout.Button("Close", GUILayout.ExpandWidth(false)))
            {
                guiActions.Add(() => DebugGui.DestroyPartDebugDialog(this));
            }

            // Allow the window to be dragged by its title bar.
            GuiWindow.DragWindow(ref windowRect, titleBarRect);
        }