示例#1
0
        // ====================================================================
        //  Other UI Hooks
        // ====================================================================

        /// <summary>
        /// Re-sort the available list when we clear the vessel crew. (Callback)
        /// </summary>
        /// This is called after the vessel crew list has been emptied after
        /// pressing the Clear button.
        /// <param name="btn"></param>
        protected void OnClearBtn(IUIObject btn)
        {
            try {
                sortBar.SortRoster();
            }
            catch (Exception e) {
                Debug.LogError("KerbalSorter: Unexpected error in EditorHook: " + e);
            }
        }
示例#2
0
 /// <summary>
 /// Re-sort the applicant list when a kerbal is fired.
 /// </summary>
 /// <param name="kerbal">The kerbal just fired</param>
 /// <param name="numActiveKerbals">The new number of active kerbals</param>
 protected void OnFire(ProtoCrewMember kerbal, int numActiveKerbals)
 {
     try {
         sortBarApplicants.SortRoster(true);
     }
     catch (Exception e) {
         Debug.LogError("KerbalSorter: Unexpected error in AstronautComplexHook: " + e);
     }
 }
示例#3
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);
            }*/
        }
示例#4
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);
             * }*/
        }