Example #1
0
        IAssemblySpace find_best_assembly_space(VesselKit kit, IList <IAssemblySpace> spaces)
        {
            float          best_ratio      = -1;
            IAssemblySpace available_space = null;

            foreach (var space in spaces)
            {
                if (space.Valid)
                {
                    if (space.CheckKit(kit, kit_part, out float ratio))
                    {
                        if (ratio > best_ratio)
                        {
                            best_ratio      = ratio;
                            available_space = space;
                        }
                    }
                }
            }
            return(available_space);
        }
 protected virtual void assembly_spaces_pane()
 {
     if (available_spaces.Count == 0)
     {
         return;
     }
     GUILayout.Label("Available assembly spaces:", Styles.label, GUILayout.ExpandWidth(true));
     GUILayout.BeginVertical(Styles.white);
     BeginScroll(available_spaces.Count, ref assembly_spaces_scroll, 40);
     foreach (var space in available_spaces)
     {
         GUILayout.BeginHorizontal(Styles.white);
         if (GUILayout.Button(new GUIContent(Colors.Active.Tag("<b>{0}</b>", space.Name),
                                             "Press to select to assign assembly task to this space. " +
                                             "Press again to deselect."),
                              selected_space == space ? Styles.normal_button : Styles.rich_label,
                              GUILayout.ExpandWidth(true)))
         {
             if (selected_space != space)
             {
                 selected_space = space;
             }
             else
             {
                 selected_space = null;
             }
         }
         var module = space as PartModule;
         if (module != null)
         {
             set_highlighted_part(module.part);
         }
         if (space.Empty)
         {
             var animated = space as IAnimatedSpace;
             var producer = space as IContainerProducer;
             if (producer != null)
             {
                 if (GUILayout.Button(new GUIContent("Create Empty Container",
                                                     "Create a new empty container of the selected type"),
                                      Styles.active_button, GUILayout.ExpandWidth(false)))
                 {
                     producer.SpawnEmptyContainer(kit_part);
                 }
             }
             if (animated != null)
             {
                 var opened = animated.Opened;
                 if (Utils.ButtonSwitch("Close", "Open", opened, "",
                                        GUILayout.ExpandWidth(false)))
                 {
                     if (opened)
                     {
                         animated.Close();
                     }
                     else
                     {
                         animated.Open();
                     }
                 }
             }
         }
         else
         {
             var construction_space = space as IConstructionSpace;
             if (construction_space != null && construction_space.Valid)
             {
                 GUILayout.Label(new GUIContent(Colors.Enabled.Tag("In-place Construction"),
                                                "It is possible to construct this kit directly in the assembly space"),
                                 Styles.rich_label, GUILayout.ExpandWidth(false));
             }
             GUILayout.Space(10);
             GUILayout.Label(new GUIContent(Colors.Warning.Tag("Occupied"),
                                            "The assembly space is occupied by a kit being assembled " +
                                            "or just by something located inside."),
                             Styles.rich_label, GUILayout.ExpandWidth(false));
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndScrollView();
     if (kit_parts.Count > 1)
     {
         GUILayout.BeginHorizontal();
         SelectedPart = Utils.LeftRightChooser(SelectedPart, kit_parts, "Select container type to use");
         GUILayout.EndHorizontal();
     }
     GUILayout.BeginHorizontal();
     if (GUILayout.Button(new GUIContent("Add Vessel",
                                         "Add a vessel from VAB/SPH to construction queue"),
                          Styles.active_button, GUILayout.ExpandWidth(true)))
     {
         construct_loader.SelectVessel();
     }
     if (GUILayout.Button(new GUIContent("Add Subassembly",
                                         "Add a subassembly to construction queue"),
                          Styles.active_button, GUILayout.ExpandWidth(true)))
     {
         construct_loader.SelectSubassembly();
     }
     if (GUILayout.Button(new GUIContent("Add Part",
                                         "Add a single part to construction queue"),
                          Styles.active_button, GUILayout.ExpandWidth(true)))
     {
         construct_loader.SelectPart(part.flagURL);
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
 }