Exemple #1
0
        public void CreateBucket(int bucketQuantity, int[] bucketVolumes)
        {
            (GetView() as SortingCanvasView).Dispatcher.Invoke(DispatcherPriority.Normal, new System.Windows.Forms.MethodInvoker(delegate()
            {
                var count = 0;

                BucketControls = new ObservableCollection <SortBar>();
                for (int i = 0; i < bucketVolumes.Length; i++)
                {
                    if (bucketVolumes[i] == 0)
                    {
                        continue;
                    }
                    var bucket = new SortBar()
                    {
                        Width                    = (_sortBarWidth + 1) * bucketVolumes[i],
                        Height                   = _sortBarHeight,
                        BorderThickness          = new Thickness(1),
                        InnerHeight              = _sortBarHeight,
                        Background               = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#55222222")),
                        Content                  = $"   桶{i + 1}\n({i * 10}~{i * 10 + 9})",
                        VerticalContentAlignment = VerticalAlignment.Top,
                        Left = count * (_sortBarWidth + 1) + 20,
                    };
                    BucketControls.Add(bucket);
                    count += bucketVolumes[i];
                }
            }));
        }
Exemple #2
0
        /// <summary>
        /// 设置排序条高亮。
        /// -2清空上一个 -1无操作 >=0设置指定的Bar
        /// </summary>
        public void SetHighLight(int index)
        {
            (GetView() as SortingCanvasView).Dispatcher.Invoke(DispatcherPriority.Normal, new System.Windows.Forms.MethodInvoker(delegate()
            {
                switch (index)
                {
                //清空
                case -2:
                    if (_lastColorChanged != null)
                    {
                        _lastColorChanged.IsHighLight = false;
                    }
                    break;

                //无操作
                case -1:
                    break;

                //正常索引
                default:
                    if (_lastColorChanged != null)
                    {
                        if (_lastColorChanged.Index == _indexList[index])
                        {
                            return;
                        }
                        _lastColorChanged.IsHighLight = false;
                    }
                    _lastColorChanged             = SortBarControls[_indexList[index]] as SortBar;
                    _lastColorChanged.IsHighLight = true;
                    break;
                }
            }));
        }
Exemple #3
0
        /// <summary>
        /// 初始化画布。
        /// </summary>
        public void InitCanvas(IList <int> data)
        {
            ResetIndexList(data.Count);
            //上左右留边距20
            _sortBarHeight = ((GetView() as SortingCanvasView).ActualHeight - 20);
            _sortBarWidth  = ((GetView() as SortingCanvasView).ActualWidth - 40 - data.Count()) / data.Count();

            var minvalue = data.Min();
            //高度增量(data每增加1),最小高度30,上边距20,去掉50
            var delta = (_sortBarHeight - 50) / (data.Max() - minvalue);

            //如果已有同样数量的控件,不再次生成(在Clear动画执行时需要重新生成)
            if (SortBarControls.Count == data.Count && !_clearHandle)
            {
                for (var i = 0; i < data.Count(); i++)
                {
                    SortBarControls[i].InnerHeight = GetInnerHeight(data[i], delta, minvalue);
                    SortBarControls[i].Content     = data[i];
                    SortBarControls[i].ToolTip     = data[i];
                    SortBarControls[i].Left        = 20 + i * (_sortBarWidth + 1);
                }
            }
            else
            {
                SortBarControls.Clear();
                for (var i = 0; i < data.Count(); i++)
                {
                    var bar = new SortBar()
                    {
                        Height      = _sortBarHeight,
                        Width       = _sortBarWidth,
                        Left        = 20 + i * (_sortBarWidth + 1),
                        Content     = data[i],
                        InnerHeight = GetInnerHeight(data[i], delta, minvalue),
                        Index       = i,
                        ToolTip     = data[i],
                    };

                    bar.DeleteThis += delegate
                    {
                        SortBarControls.Remove(bar);
                    };
                    SortBarControls.Add(bar);
                }
            }

            IndicatorControls = new ObservableCollection <SortBar>()
            {
                new SortBar()
                {
                    Height                   = _sortBarHeight + 20,
                    Width                    = _sortBarWidth,
                    BorderThickness          = new System.Windows.Thickness(1),
                    BorderBrush              = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF5D8CD0")),
                    Foreground               = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF5D8CD0")),
                    Left                     = -1 * _sortBarWidth,
                    Content                  = "A",
                    VerticalContentAlignment = System.Windows.VerticalAlignment.Top,
                },
                new SortBar()
                {
                    Height                   = _sortBarHeight + 20,
                    Width                    = _sortBarWidth,
                    BorderThickness          = new System.Windows.Thickness(1),
                    BorderBrush              = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE28153")),
                    Foreground               = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE28153")),
                    Left                     = -1 * _sortBarWidth,
                    Content                  = "B",
                    VerticalContentAlignment = System.Windows.VerticalAlignment.Top,
                },
            };
        }
Exemple #4
0
        /// <summary>
        /// Set up the SortBar for the Editors' crew assignment panel. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                // Game Event Hooks
                GameEvents.onEditorScreenChange.Add(OnEditorScreenChange);
                GameEvents.onEditorLoad.Add(OnEditorLoad);
                GameEvents.onEditorRestart.Add(OnEditorRestart);
                GameEvents.onEditorShipModified.Add(OnEditorShipModified);
                // We actually do need these:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);


                // Get Roster:
                UIScrollList[] lists = UIManager.instance.gameObject.GetComponentsInChildren <UIScrollList>(true);
                availableCrew = null;
                vesselCrew    = null;
                foreach (UIScrollList list in lists)
                {
                    if (list.name == "scrolllist_avail")
                    {
                        availableCrew = list;
                        if (vesselCrew != null)
                        {
                            break;
                        }
                    }
                    else if (list.name == "scrolllist_crew")
                    {
                        vesselCrew = list;
                        if (availableCrew != null)
                        {
                            break;
                        }
                    }
                }
                if (availableCrew == null)
                {
                    throw new Exception("Could not find Available Crew List!");
                }
                if (vesselCrew == null)
                {
                    throw new Exception("Could not find Vessel Crew List!");
                }
                StockRoster available = new StockRoster(availableCrew);


                // Get position: (This is probably the one time we actually want to do this here)
                Transform tab_crewavail = availableCrew.transform.parent.Find("tab_crewavail");
                BTButton  tab           = tab_crewavail.GetComponent <BTButton>();
                Vector3   tabPos        = Utilities.GetPosition(tab_crewavail);
                float     x             = tabPos.x + tab.width + 5;
                float     y             = tabPos.y - 1;

                // Set up button list:
                SortButtonDef[] buttons = new SortButtonDef[] {
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };

                // Initialize the sort bar:
                sortBar = gameObject.AddComponent <SortBar>();
                sortBar.SetRoster(available);
                sortBar.SetButtons(buttons);
                sortBar.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBar.SetPos(x, y);
                sortBar.enabled = false;

                // Create a fly-in animation for the sort bar.
                baseX = x;
                baseY = y;
                float animBeginTime = 0.2f;
                animEndTime = 0.5f;
                anim        = AnimationCurve.Linear(animBeginTime, -575f, animEndTime, 0f);

                // This is what I would have *liked* to have done, but Unity decided this should do absolutely nothing.

                /*AnimationCurve curve = AnimationCurve.Linear(0f, 0f, 10f, 100f);
                 * AnimationClip clip = new AnimationClip();
                 * clip.SetCurve("", typeof(Transform), "position.x", curve);
                 * sortBar.gameObject.AddComponent<Animation>().AddClip(clip, "flyin");*/


                // Add some extra hooks:
                availableCrew.AddValueChangedDelegate(OnAvailListValueChanged);
                Transform trans = UIManager.instance.transform.FindChild("panel_CrewAssignmentInEditor");
                foreach (BTButton btn in trans.GetComponentsInChildren <BTButton>())
                {
                    if (btn.name == "button_reset")
                    {
                        btn.AddValueChangedDelegate(OnResetBtn);
                    }
                    else if (btn.name == "button_clear")
                    {
                        btn.AddValueChangedDelegate(OnClearBtn);
                    }
                }
                trans = UIManager.instance.transform.FindChild("TopRightAnchor");
                foreach (UIButton btn in trans.GetComponentsInChildren <UIButton>())
                {
                    if (btn.name == "ButtonLoad")
                    {
                        btn.AddValueChangedDelegate(OnLoadBtn);
                    }
                }

                fixDefaultAssignment = false;
                loadBtnPressed       = false;
                noParts = true;
            }
            catch (Exception e) {
                Debug.LogError("KerbalSorter: Unexpected error in EditorHook: " + e);
            }
        }
        /// <summary>
        /// Replaces a vessel's default crew with the first few kerbals available according to the given sortbar's settings.
        /// </summary>
        /// Prequisites: The vessel has only one cabin with crew in it.
        /// <param name="vesselCrew">List containing the vessel's crew</param>
        /// <param name="availableCrew">List containing the available crew</param>
        /// <param name="sortBar">The sortbar whose criterion to sort by</param>
        public static void FixDefaultVesselCrew(UIScrollList vesselCrew, UIScrollList availableCrew, SortBar sortBar)
        {
            // WARNING: Apparently this causes NullReferenceExceptions when used. I have yet to determine exactly why.
            // Until I can fix the NullReferenceExceptions, this will be commented out.

            // Find the one cabin with crew in it:
            /*int numCrew = 0;
            int crewLoc = -1;
            for( int i = 0; i < vesselCrew.Count; i++ ) {
                IUIListObject obj = vesselCrew.GetItem(i);
                CrewItemContainer cont = obj.gameObject.GetComponent<CrewItemContainer>();
                if( cont == null && crewLoc >= 0 ) {
                    // If both the above are true, we've hit the end of the crewed cabin.
                    break;
                }
                else if( cont != null ) {
                    if( crewLoc < 0 ) {
                        crewLoc = i;
                    }
                    string debug = "KerbalSorter: " + cont.GetName() + " found in the vessel's crew.";
                    debug += " In Vessel ";
                    if( cont.GetCrewRef() != null && cont.GetCrewRef().KerbalRef != null && cont.GetCrewRef().KerbalRef.InVessel != null ) {
                        debug += cont.GetCrewRef().KerbalRef.InVessel.name;
                    }
                    else {
                        debug += "???";
                    }
                    debug += " In Part ";
                    if( cont.GetCrewRef() != null && cont.GetCrewRef().KerbalRef != null && cont.GetCrewRef().KerbalRef.InPart != null ) {
                        debug += cont.GetCrewRef().KerbalRef.InPart.name;
                    }
                    else {
                        debug += "???";
                    }
                    debug += " Seat ";
                    if( cont.GetCrewRef() != null && cont.GetCrewRef().seat != null ) {
                        debug += cont.GetCrewRef().seat.name;
                    }
                    else {
                        debug += "???";
                    }
                    debug += " Idx ";
                    if( cont.GetCrewRef() != null ) {
                        debug += cont.GetCrewRef().seatIdx;
                    }
                    else {
                        debug += "?";
                    }
                    Debug.Log(debug);
                    cont.SetButton(CrewItemContainer.ButtonTypes.V);
                    vesselCrew.RemoveItem(i, false);
                    availableCrew.AddItem(obj);
                    numCrew++;
                    i--; // Don't accidentally skip something!
                }
            }*/

            // Re-sort the kerbals
            sortBar.SortRoster();

            // Add input listeners to each of the kerbals so we can tell when they're dragged
            /*for( int i = 0; i < availableCrew.Count; i++ ) {
                availableCrew.GetItem(i).AddInputDelegate(OnInput);
            }*/

            // Place the appropriate number of kerbals back into the crew roster
            /*for( int i = 0; i < numCrew; i++ ) {
                IUIListObject obj = availableCrew.GetItem(0);
                availableCrew.RemoveItem(0, false);
                vesselCrew.InsertItem(obj, crewLoc + i);

                obj.gameObject.GetComponent<CrewItemContainer>().SetButton(CrewItemContainer.ButtonTypes.X);
            }*/
        }
Exemple #6
0
        /// <summary>
        /// Set up the SortBars for the Astronaut Complex. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                // Set up hooks:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);
                GameEvents.OnCrewmemberHired.Add(OnHire);
                GameEvents.OnCrewmemberSacked.Add(OnFire);

                // Get rosters:
                complex = UIManager.instance.gameObject.GetComponentsInChildren <CMAstronautComplex>(true).FirstOrDefault();
                if (complex == null)
                {
                    throw new Exception("Could not find astronaut complex");
                }
                UIScrollList availableList = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_available/scrolllist_available").GetComponent <UIScrollList>();
                UIScrollList assignedList  = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_assigned/scrolllist_assigned").GetComponent <UIScrollList>();
                UIScrollList killedList    = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_kia/scrolllist_kia").GetComponent <UIScrollList>();
                UIScrollList applicantList = complex.transform.Find("CrewPanels/panel_applicants/scrolllist_applicants").GetComponent <UIScrollList>();
                available  = new StockRoster(availableList);
                assigned   = new StockRoster(assignedList);
                killed     = new StockRoster(killedList);
                applicants = new StockRoster(applicantList);

                // Set up button list:
                SortButtonDef[] buttonsCrew = new SortButtonDef[] {
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };
                SortButtonDef[] buttonsApplicants = new SortButtonDef[] {
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass, StandardButtonDefs.ByGender
                };

                // Initialize the crew sort bar:
                sortBarCrew = gameObject.AddComponent <SortBar>();
                sortBarCrew.SetRoster(available);
                sortBarCrew.SetButtons(buttonsCrew);
                sortBarCrew.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBarCrew.enabled = false;
                curPanel            = CrewPanel.Available;

                /// Initialize the applicant sort bar:
                sortBarApplicants = gameObject.AddComponent <SortBar>();
                sortBarApplicants.SetRoster(applicants);
                sortBarApplicants.SetButtons(buttonsApplicants);
                sortBarApplicants.SetDefaultOrdering(StandardKerbalComparers.DefaultApplicant);
                sortBarApplicants.enabled = false;


                // Assign enable listeners to the rosters:
                Utilities.AddOnEnableListener(availableList.gameObject, OnTabAvailable, true);
                Utilities.AddOnEnableListener(assignedList.gameObject, OnTabAssigned, true);
                Utilities.AddOnEnableListener(killedList.gameObject, OnTabKilled, true);

                // There's no other way to detect KSI's presence, unfortunately. :/
                foreach (AssemblyLoader.LoadedAssembly asm in AssemblyLoader.loadedAssemblies)
                {
                    if (asm.dllName == "KSI")
                    {
                        KSILoaded = true;
                    }
                }
            }
            catch (Exception e) {
                Debug.LogError("KerbalSorter: Unexpected error in AstronautComplexHook: " + e);
            }
        }
        /// <summary>
        /// Set up the SortBars for the Astronaut Complex. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                // Set up hooks:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);
                GameEvents.OnCrewmemberHired.Add(OnHire);
                GameEvents.OnCrewmemberSacked.Add(OnFire);

                // Get rosters:
                complex = UIManager.instance.gameObject.GetComponentsInChildren<CMAstronautComplex>(true).FirstOrDefault();
                if( complex == null ) throw new Exception("Could not find astronaut complex");
                UIScrollList availableList = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_available/scrolllist_available").GetComponent<UIScrollList>();
                UIScrollList assignedList = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_assigned/scrolllist_assigned").GetComponent<UIScrollList>();
                UIScrollList killedList = complex.transform.Find("CrewPanels/panel_enlisted/panelManager/panel_kia/scrolllist_kia").GetComponent<UIScrollList>();
                UIScrollList applicantList = complex.transform.Find("CrewPanels/panel_applicants/scrolllist_applicants").GetComponent<UIScrollList>();
                available = new StockRoster(availableList);
                assigned = new StockRoster(assignedList);
                killed = new StockRoster(killedList);
                applicants = new StockRoster(applicantList);

                // Set up button list:
                SortButtonDef[] buttonsCrew = new SortButtonDef[]{
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };
                SortButtonDef[] buttonsApplicants = new SortButtonDef[]{
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass, StandardButtonDefs.ByGender
                };

                // Initialize the crew sort bar:
                sortBarCrew = gameObject.AddComponent<SortBar>();
                sortBarCrew.SetRoster(available);
                sortBarCrew.SetButtons(buttonsCrew);
                sortBarCrew.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBarCrew.enabled = false;
                curPanel = CrewPanel.Available;

                /// Initialize the applicant sort bar:
                sortBarApplicants = gameObject.AddComponent<SortBar>();
                sortBarApplicants.SetRoster(applicants);
                sortBarApplicants.SetButtons(buttonsApplicants);
                sortBarApplicants.SetDefaultOrdering(StandardKerbalComparers.DefaultApplicant);
                sortBarApplicants.enabled = false;

                // Assign enable listeners to the rosters:
                Utilities.AddOnEnableListener(availableList.gameObject, OnTabAvailable, true);
                Utilities.AddOnEnableListener(assignedList.gameObject, OnTabAssigned, true);
                Utilities.AddOnEnableListener(killedList.gameObject, OnTabKilled, true);

                // There's no other way to detect KSI's presence, unfortunately. :/
                foreach( AssemblyLoader.LoadedAssembly asm in AssemblyLoader.loadedAssemblies ){
                    if( asm.dllName == "KSI" ){
                        KSILoaded = true;
                    }
                }
            }
            catch( Exception e ) {
                Debug.LogError("KerbalSorter: Unexpected error in AstronautComplexHook: " + e);
            }
        }
        /// <summary>
        /// Set up the Sort Bar for the Launch Windows. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                GameEvents.onGUILaunchScreenSpawn.Add(LaunchScreenSpawn);
                GameEvents.onGUILaunchScreenDespawn.Add(LaunchScreenDespawn);
                GameEvents.onGUILaunchScreenVesselSelected.Add(VesselSelect);
                // We actually do need these:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);

                // Get the Roster and the vessel crew list:
                VesselSpawnDialog window = UIManager.instance.gameObject.GetComponentsInChildren <VesselSpawnDialog>(true).FirstOrDefault();
                if (window == null)
                {
                    throw new Exception("Could not find Launch Window!");
                }
                UIScrollList[] lists = window.GetComponentsInChildren <UIScrollList>(true);
                availableCrew = null;
                vesselCrew    = null;
                foreach (UIScrollList list in lists)
                {
                    if (list.name == "scrolllist_avail")
                    {
                        availableCrew = list;
                        if (vesselCrew != null)
                        {
                            break;
                        }
                    }
                    else if (list.name == "scrolllist_crew")
                    {
                        vesselCrew = list;
                        if (availableCrew != null)
                        {
                            break;
                        }
                    }
                }
                if (availableCrew == null)
                {
                    throw new Exception("Could not find Available Crew List!");
                }
                if (vesselCrew == null)
                {
                    throw new Exception("Could not find Vessel Crew List!");
                }
                StockRoster available = new StockRoster(availableCrew);

                // Set up button list:
                SortButtonDef[] buttons = new SortButtonDef[] {
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };

                // Initialize the sort bar:
                sortBar = gameObject.AddComponent <SortBar>();
                sortBar.SetRoster(available);
                sortBar.SetButtons(buttons);
                sortBar.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBar.enabled = false;


                // Set up some hooks to detect when the list is changing:
                availableCrew.AddValueChangedDelegate(OnAvailListValueChanged);
                Transform anchorButtons = window.transform.FindChild("anchor/vesselInfo/crewAssignment/crewAssignmentSpawnpoint/anchorButtons");
                BTButton  btn           = anchorButtons.FindChild("button_reset").GetComponent <BTButton>();
                btn.AddValueChangedDelegate(OnResetBtn);
                btn = anchorButtons.FindChild("button_clear").GetComponent <BTButton>();
                btn.AddValueChangedDelegate(OnClearBtn);
            }
            catch (Exception e) {
                Debug.LogError("KerbalSorter: Unexpected error in LaunchWindowHook: " + e);
            }
        }
Exemple #9
0
        /// <summary>
        /// Replaces a vessel's default crew with the first few kerbals available according to the given sortbar's settings.
        /// </summary>
        /// Prequisites: The vessel has only one cabin with crew in it.
        /// <param name="vesselCrew">List containing the vessel's crew</param>
        /// <param name="availableCrew">List containing the available crew</param>
        /// <param name="sortBar">The sortbar whose criterion to sort by</param>
        public static void FixDefaultVesselCrew(UIScrollList vesselCrew, UIScrollList availableCrew, SortBar sortBar)
        {
            // WARNING: Apparently this causes NullReferenceExceptions when used. I have yet to determine exactly why.
            // Until I can fix the NullReferenceExceptions, this will be commented out.

            // Find the one cabin with crew in it:

            /*int numCrew = 0;
             * int crewLoc = -1;
             * for( int i = 0; i < vesselCrew.Count; i++ ) {
             *  IUIListObject obj = vesselCrew.GetItem(i);
             *  CrewItemContainer cont = obj.gameObject.GetComponent<CrewItemContainer>();
             *  if( cont == null && crewLoc >= 0 ) {
             *      // If both the above are true, we've hit the end of the crewed cabin.
             *      break;
             *  }
             *  else if( cont != null ) {
             *      if( crewLoc < 0 ) {
             *          crewLoc = i;
             *      }
             *      string debug = "KerbalSorter: " + cont.GetName() + " found in the vessel's crew.";
             *      debug += " In Vessel ";
             *      if( cont.GetCrewRef() != null && cont.GetCrewRef().KerbalRef != null && cont.GetCrewRef().KerbalRef.InVessel != null ) {
             *          debug += cont.GetCrewRef().KerbalRef.InVessel.name;
             *      }
             *      else {
             *          debug += "???";
             *      }
             *      debug += " In Part ";
             *      if( cont.GetCrewRef() != null && cont.GetCrewRef().KerbalRef != null && cont.GetCrewRef().KerbalRef.InPart != null ) {
             *          debug += cont.GetCrewRef().KerbalRef.InPart.name;
             *      }
             *      else {
             *          debug += "???";
             *      }
             *      debug += " Seat ";
             *      if( cont.GetCrewRef() != null && cont.GetCrewRef().seat != null ) {
             *          debug += cont.GetCrewRef().seat.name;
             *      }
             *      else {
             *          debug += "???";
             *      }
             *      debug += " Idx ";
             *      if( cont.GetCrewRef() != null ) {
             *          debug += cont.GetCrewRef().seatIdx;
             *      }
             *      else {
             *          debug += "?";
             *      }
             *      Debug.Log(debug);
             *      cont.SetButton(CrewItemContainer.ButtonTypes.V);
             *      vesselCrew.RemoveItem(i, false);
             *      availableCrew.AddItem(obj);
             *      numCrew++;
             *      i--; // Don't accidentally skip something!
             *  }
             * }*/

            // Re-sort the kerbals
            sortBar.SortRoster();

            // Add input listeners to each of the kerbals so we can tell when they're dragged

            /*for( int i = 0; i < availableCrew.Count; i++ ) {
             *  availableCrew.GetItem(i).AddInputDelegate(OnInput);
             * }*/

            // Place the appropriate number of kerbals back into the crew roster

            /*for( int i = 0; i < numCrew; i++ ) {
             *  IUIListObject obj = availableCrew.GetItem(0);
             *  availableCrew.RemoveItem(0, false);
             *  vesselCrew.InsertItem(obj, crewLoc + i);
             *
             *  obj.gameObject.GetComponent<CrewItemContainer>().SetButton(CrewItemContainer.ButtonTypes.X);
             * }*/
        }
        /// <summary>
        /// Set up the SortBar for the Editors' crew assignment panel. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                // Game Event Hooks
                GameEvents.onEditorScreenChange.Add(OnEditorScreenChange);
                GameEvents.onEditorLoad.Add(OnEditorLoad);
                GameEvents.onEditorRestart.Add(OnEditorRestart);
                GameEvents.onEditorShipModified.Add(OnEditorShipModified);
                // We actually do need these:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);

                // Get Roster:
                UIScrollList[] lists = UIManager.instance.gameObject.GetComponentsInChildren<UIScrollList>(true);
                availableCrew = null;
                vesselCrew = null;
                foreach( UIScrollList list in lists ) {
                    if( list.name == "scrolllist_avail" ) {
                        availableCrew = list;
                        if( vesselCrew != null ) {
                            break;
                        }
                    }
                    else if( list.name == "scrolllist_crew" ) {
                        vesselCrew = list;
                        if( availableCrew != null ) {
                            break;
                        }
                    }
                }
                if( availableCrew == null ) {
                    throw new Exception("Could not find Available Crew List!");
                }
                if( vesselCrew == null ) {
                    throw new Exception("Could not find Vessel Crew List!");
                }
                StockRoster available = new StockRoster(availableCrew);

                // Get position: (This is probably the one time we actually want to do this here)
                Transform tab_crewavail = availableCrew.transform.parent.Find("tab_crewavail");
                BTButton tab = tab_crewavail.GetComponent<BTButton>();
                Vector3 tabPos = Utilities.GetPosition(tab_crewavail);
                float x = tabPos.x + tab.width + 5;
                float y = tabPos.y - 1;

                // Set up button list:
                SortButtonDef[] buttons = new SortButtonDef[]{
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };

                // Initialize the sort bar:
                sortBar = gameObject.AddComponent<SortBar>();
                sortBar.SetRoster(available);
                sortBar.SetButtons(buttons);
                sortBar.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBar.SetPos(x, y);
                sortBar.enabled = false;

                // Create a fly-in animation for the sort bar.
                baseX = x;
                baseY = y;
                float animBeginTime = 0.2f;
                animEndTime = 0.5f;
                anim = AnimationCurve.Linear(animBeginTime, -575f, animEndTime, 0f);

                // This is what I would have *liked* to have done, but Unity decided this should do absolutely nothing.
                /*AnimationCurve curve = AnimationCurve.Linear(0f, 0f, 10f, 100f);
                AnimationClip clip = new AnimationClip();
                clip.SetCurve("", typeof(Transform), "position.x", curve);
                sortBar.gameObject.AddComponent<Animation>().AddClip(clip, "flyin");*/

                // Add some extra hooks:
                availableCrew.AddValueChangedDelegate(OnAvailListValueChanged);
                Transform trans = UIManager.instance.transform.FindChild("panel_CrewAssignmentInEditor");
                foreach( BTButton btn in trans.GetComponentsInChildren<BTButton>() ) {
                    if( btn.name == "button_reset" ) {
                        btn.AddValueChangedDelegate(OnResetBtn);
                    }
                    else if( btn.name == "button_clear" ) {
                        btn.AddValueChangedDelegate(OnClearBtn);
                    }
                }
                trans = UIManager.instance.transform.FindChild("TopRightAnchor");
                foreach( UIButton btn in trans.GetComponentsInChildren<UIButton>() ) {
                    if( btn.name == "ButtonLoad" ) {
                        btn.AddValueChangedDelegate(OnLoadBtn);
                    }
                }

                fixDefaultAssignment = false;
                loadBtnPressed = false;
                noParts = true;
            }
            catch( Exception e ) {
                Debug.LogError("KerbalSorter: Unexpected error in EditorHook: " + e);
            }
        }
        /// <summary>
        /// Set up the Sort Bar for the Launch Windows. (Callback)
        /// </summary>
        protected void Start()
        {
            try {
                GameEvents.onGUILaunchScreenSpawn.Add(LaunchScreenSpawn);
                GameEvents.onGUILaunchScreenDespawn.Add(LaunchScreenDespawn);
                GameEvents.onGUILaunchScreenVesselSelected.Add(VesselSelect);
                // We actually do need these:
                GameEvents.onGUIAstronautComplexSpawn.Add(OnACSpawn);
                GameEvents.onGUIAstronautComplexDespawn.Add(OnACDespawn);

                // Get the Roster and the vessel crew list:
                VesselSpawnDialog window = UIManager.instance.gameObject.GetComponentsInChildren<VesselSpawnDialog>(true).FirstOrDefault();
                if( window == null ) {
                    throw new Exception("Could not find Launch Window!");
                }
                UIScrollList[] lists = window.GetComponentsInChildren<UIScrollList>(true);
                availableCrew = null;
                vesselCrew = null;
                foreach( UIScrollList list in lists ) {
                    if( list.name == "scrolllist_avail" ) {
                        availableCrew = list;
                        if( vesselCrew != null ) {
                            break;
                        }
                    }
                    else if( list.name == "scrolllist_crew" ) {
                        vesselCrew = list;
                        if( availableCrew != null ) {
                            break;
                        }
                    }
                }
                if( availableCrew == null ) {
                    throw new Exception("Could not find Available Crew List!");
                }
                if( vesselCrew == null ) {
                    throw new Exception("Could not find Vessel Crew List!");
                }
                StockRoster available = new StockRoster(availableCrew);

                // Set up button list:
                SortButtonDef[] buttons = new SortButtonDef[]{
                    StandardButtonDefs.ByName, StandardButtonDefs.ByClass,
                    StandardButtonDefs.ByLevel, StandardButtonDefs.ByGender,
                    StandardButtonDefs.ByNumFlights
                };

                // Initialize the sort bar:
                sortBar = gameObject.AddComponent<SortBar>();
                sortBar.SetRoster(available);
                sortBar.SetButtons(buttons);
                sortBar.SetDefaultOrdering(StandardKerbalComparers.DefaultAvailable);
                sortBar.enabled = false;

                // Set up some hooks to detect when the list is changing:
                availableCrew.AddValueChangedDelegate(OnAvailListValueChanged);
                Transform anchorButtons = window.transform.FindChild("anchor/vesselInfo/crewAssignment/crewAssignmentSpawnpoint/anchorButtons");
                BTButton btn = anchorButtons.FindChild("button_reset").GetComponent<BTButton>();
                btn.AddValueChangedDelegate(OnResetBtn);
                btn = anchorButtons.FindChild("button_clear").GetComponent<BTButton>();
                btn.AddValueChangedDelegate(OnClearBtn);
            }
            catch( Exception e ) {
                Debug.LogError("KerbalSorter: Unexpected error in LaunchWindowHook: " + e);
            }
        }