Ejemplo n.º 1
0
    internal static void Display(int windowId)
    {

      // Reset Tooltip active flag...
      ToolTipActive = false;

      Rect rect = new Rect(Position.width - 20, 4, 16, 16);
      if (GUI.Button(rect, new GUIContent("", "Close Window")))
      {
        OnCreate = false;
        SelectedKerbal = null;
        ToolTip = "";
        if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
          SMAddon.OnSMRosterToggle();
        else
          ShowWindow = false;

      }
      if (Event.current.type == EventType.Repaint && ShowToolTips == true)
        ToolTip = SMToolTips.SetActiveTooltip(rect, Position, GUI.tooltip, ref ToolTipActive, 10, 0);
      try
      {
        GUIStyle style = new GUIStyle(GUI.skin.button);
        var defaultColor = style.normal.textColor;
        GUILayout.BeginVertical();
        DisplayRosterFilter();

        DisplayRosterListViewer();

        if (OnCreate)
          CreateKerbalViewer();
        else if (SelectedKerbal != null)
        {
          EditKerbalViewer();
        }
        else
        {
          GUILayout.BeginHorizontal();
          GUIContent guilabel = new GUIContent("Create Kerbal", "Opens the Kerbal creation editor.");
          if (GUILayout.Button(guilabel, GUILayout.MaxWidth(120), GUILayout.Height(20)))
          {
            OnCreate = true;
          }
          rect = GUILayoutUtility.GetLastRect();
          if (Event.current.type == EventType.Repaint && ShowToolTips == true)
            ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, 10, 0);
          //if (SMSettings.RenameWithProfession)
          //{
          //    string toolTip = "This action resets all renamed Kerbals to their KSP default professions.\r\nIt removes any non printing chars previously used to maintain a specific profession.\r\nUse this if you wish to clean up a game save after updating to KSP 1.0.5 or above.";
          //    if (GUILayout.Button(new GUIContent("Reset Professions", toolTip), GUILayout.MaxWidth(120), GUILayout.Height(20)))
          //    {
          //        ResetKerbalNames();
          //    }
          //}
          //rect = GUILayoutUtility.GetLastRect();
          //if (Event.current.type == EventType.Repaint && ShowToolTips == true)
          //    ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, 10, 0);
          GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();
        GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
        SMAddon.RepositionWindow(ref WindowRoster.Position);
      }
      catch (Exception ex)
      {
        Utilities.LogMessage(string.Format(" in Roster Window.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
      }
    }
Ejemplo n.º 2
0
    private static void DisplayRosterListViewer()
    {
      try
      {
        GUILayout.BeginVertical();
        // Roster List Header...
        GUILayout.BeginHorizontal();
        //GUILayout.Label("", GUILayout.Width(5));
        GUILayout.Label("Name", GUILayout.Width(140));
        GUILayout.Label("Gender", GUILayout.Width(50));
        GUILayout.Label("Profession", GUILayout.Width(70));
        GUILayout.Label("Skill", GUILayout.Width(30));
        GUILayout.Label("Status", GUILayout.Width(220));
        GUILayout.Label("Edit", GUILayout.Width(55));
        GUILayout.Label("Action", GUILayout.Width(65));
        GUILayout.EndHorizontal();

        ScrollViewerPosition = GUILayout.BeginScrollView(ScrollViewerPosition, SMStyle.ScrollStyle, GUILayout.Height(230), GUILayout.Width(680));
        foreach (ProtoCrewMember kerbal in RosterList)
        {
          if (CanDisplayKerbal(kerbal))
          {
            GUIStyle labelStyle = null;
            if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Dead || kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Missing)
              labelStyle = SMStyle.LabelStyleRed;
            else if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
              labelStyle = SMStyle.LabelStyleYellow;
            else
              labelStyle = SMStyle.LabelStyle;

            // What vessel is this Kerbal Assigned to?
            string rosterDetails = "";
            if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
            {
              foreach (Vessel thisVessel in FlightGlobals.Vessels)
              {
                List<ProtoCrewMember> crew = thisVessel.GetVesselCrew();
                foreach (ProtoCrewMember crewMember in crew)
                {
                  if (crewMember == kerbal)
                  {
                    rosterDetails = "Assigned - " + thisVessel.GetName().Replace("(unloaded)", "");
                    break;
                  }
                }
              }
            }
            else if (DFInterface.IsDFInstalled && kerbal.type == ProtoCrewMember.KerbalType.Unowned)
            {
              // This kerbal could be frozen.  Lets find out...
              rosterDetails = GetFrozenKerbalDetials(kerbal);
              labelStyle = SMStyle.LabelStyleCyan;
            }
            else
            {
              // Since the kerbal has no vessel assignment, lets show what their status...
              rosterDetails = kerbal.rosterStatus.ToString();
            }
            string buttonText = string.Empty;
            string buttonToolTip = string.Empty;
            GUILayout.BeginHorizontal();
            GUILayout.Label(kerbal.name, labelStyle, GUILayout.Width(140), GUILayout.Height(20));
            GUILayout.Label(kerbal.gender.ToString(), labelStyle, GUILayout.Width(50));
            GUILayout.Label(kerbal.experienceTrait.Title, labelStyle, GUILayout.Width(70));
            GUILayout.Label(kerbal.experienceLevel.ToString().ToString(), labelStyle, GUILayout.Width(30));
            GUILayout.Label(rosterDetails, labelStyle, GUILayout.Width(215));

            SetupEditButton(kerbal, ref buttonText, ref buttonToolTip);

            if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(55), GUILayout.Height(20), GUILayout.Height(20)))
            {
              if (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal)
              {
                SelectedKerbal = new ModKerbal(kerbal, false);
                SetProfessionFlag();
              }
              else
              {
                SelectedKerbal = null;
              }
            }
            Rect rect = GUILayoutUtility.GetLastRect();
            if (Event.current.type == EventType.Repaint && ShowToolTips == true)
              ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - ScrollViewerPosition.y);

            // Setup buttons with gui state, button text and tooltip.
            SetupActionButton(kerbal, ref buttonText, ref buttonToolTip);

            if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(65), GUILayout.Height(20)))
            {
              if (buttonText == "Add")
                TransferCrew.AddCrewMember(kerbal, SMAddon.smController.SelectedPartsSource[0]);
              else if (buttonText == "Respawn")
                SMController.RespawnKerbal(kerbal);
              else if (buttonText == "Thaw")
                ThawKerbal(kerbal.name);
              else if (buttonText == "Freeze")
                FreezeKerbal(kerbal);
              else if (buttonText == "Remove")
              {
                // get part...
                Part part = SMAddon.smController.FindKerbalPart(kerbal);
                if (part != null)
                  TransferCrew.RemoveCrewMember(kerbal, part);
              }
            }
            Rect rect2 = GUILayoutUtility.GetLastRect();
            if (Event.current.type == EventType.Repaint && ShowToolTips == true)
              ToolTip = SMToolTips.SetActiveTooltip(rect2, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - ScrollViewerPosition.y);
            GUILayout.EndHorizontal();
            GUI.enabled = true;
          }
        }

        GUILayout.EndVertical();
        GUILayout.EndScrollView();

      }
      catch (Exception ex)
      {
        Utilities.LogMessage(string.Format(" in RosterListViewer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
      }
    }
Ejemplo n.º 3
0
    private static void EditKerbalViewer()
    {
      Rect rect = new Rect();
      string label = "";
      string toolTip = "";
      GUILayout.Label(SelectedKerbal.IsNew ? "Create a Kerbal" : "Edit a Kerbal");
      if (SMSettings.EnableKerbalRename)
      {
        GUILayout.BeginHorizontal();
        SelectedKerbal.Name = GUILayout.TextField(SelectedKerbal.Name, GUILayout.MaxWidth(300));
        GUILayout.Label(" - (" + SelectedKerbal.Kerbal.experienceTrait.Title + ")");
        GUILayout.EndHorizontal();
      }
      else
        GUILayout.Label(SelectedKerbal.Name + " - (" + SelectedKerbal.Trait + ")", SMStyle.LabelStyleBold, GUILayout.MaxWidth(300));

      if (!string.IsNullOrEmpty(SMAddon.saveMessage))
      {
        GUILayout.Label(SMAddon.saveMessage, SMStyle.ErrorLabelRedStyle);
      }
      if (SMSettings.EnableKerbalRename && SMSettings.RenameWithProfession)
      {
        DisplaySelectProfession();
      }
      bool isMale = ProtoCrewMember.Gender.Male == SelectedKerbal.Gender ? true : false;
      GUILayout.BeginHorizontal();
      GUILayout.Label("Gender");
      isMale = GUILayout.Toggle(isMale, ProtoCrewMember.Gender.Male.ToString(), GUILayout.Width(90));
      isMale = GUILayout.Toggle(!isMale, ProtoCrewMember.Gender.Female.ToString());
      SelectedKerbal.Gender = isMale ? ProtoCrewMember.Gender.Female : ProtoCrewMember.Gender.Male;
      GUILayout.EndHorizontal();

      GUILayout.Label("Courage");
      SelectedKerbal.Courage = GUILayout.HorizontalSlider(SelectedKerbal.Courage, 0, 1, GUILayout.MaxWidth(300));

      GUILayout.Label("Stupidity");
      SelectedKerbal.Stupidity = GUILayout.HorizontalSlider(SelectedKerbal.Stupidity, 0, 1, GUILayout.MaxWidth(300));

      SelectedKerbal.Badass = GUILayout.Toggle(SelectedKerbal.Badass, "Badass");

      GUILayout.BeginHorizontal();
      if (GUILayout.Button("Cancel", GUILayout.MaxWidth(50)))
      {
        SelectedKerbal = null;
      }
      label = "Apply";
      toolTip = "Applies the changes made to this Kerbal.\r\nDesired Name and Profession will be Retained after save.";
      if (GUILayout.Button(new GUIContent(label, toolTip), GUILayout.MaxWidth(50)))
      {
        if (SMSettings.EnableKerbalRename && SMSettings.RenameWithProfession)
        {
          SelectedKerbal.Trait = KerbalProfession;
        }
        SMAddon.saveMessage = SelectedKerbal.SubmitChanges();
        if (string.IsNullOrEmpty(SMAddon.saveMessage))
          SelectedKerbal = null;
      }
      rect = GUILayoutUtility.GetLastRect();
      if (Event.current.type == EventType.Repaint && ShowToolTips == true)
        ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, 10, 0);
      GUILayout.EndHorizontal();
    }
Ejemplo n.º 4
0
 private static void CreateKerbalViewer()
 {
   DisplaySelectProfession();
   GUILayout.BeginHorizontal();
   GUIContent guilabel = new GUIContent("Create", "Creates a Kerbal with profession selected above.\r\nAdds him/her to the Roster.");
   if (GUILayout.Button(guilabel, GUILayout.MaxWidth(80), GUILayout.Height(20)))
   {
     bool kerbalFound = false;
     while (!kerbalFound)
     {
       SelectedKerbal = ModKerbal.CreateKerbal();
       if (SelectedKerbal.Trait == KerbalProfession)
         kerbalFound = true;
     }
     OnCreate = false;
   }
   Rect rect = GUILayoutUtility.GetLastRect();
   if (Event.current.type == EventType.Repaint && ShowToolTips == true)
     ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, 10, 0);
   guilabel = new GUIContent("Cancel", "Cancels current creation and exit editor.");
   if (GUILayout.Button(guilabel, GUILayout.MaxWidth(80), GUILayout.Height(20)))
   {
     OnCreate = false;
     SelectedKerbal = null;
   }
   rect = GUILayoutUtility.GetLastRect();
   if (Event.current.type == EventType.Repaint && ShowToolTips == true)
     ToolTip = SMToolTips.SetActiveTooltip(rect, WindowRoster.Position, GUI.tooltip, ref ToolTipActive, 10, 0);
   GUILayout.EndHorizontal();
 }