Пример #1
0
        internal void Load(ConfigNode node)
        {
            AllrmKerbals.Clear();

            if (node.HasNode(ConfigNodeName))
            {
                ConfigNode kerbalLifeRecordNode = node.GetNode(ConfigNodeName);

                List <ConfigNode> .Enumerator kerbalNodes = kerbalLifeRecordNode.GetNodes(RMKerbal.ConfigNodeName).ToList().GetEnumerator();
                while (kerbalNodes.MoveNext())
                {
                    if (kerbalNodes.Current == null)
                    {
                        continue;
                    }
                    if (!kerbalNodes.Current.HasValue("kerbalName"))
                    {
                        continue;
                    }
                    string id = kerbalNodes.Current.GetValue("kerbalName");
                    RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbals Loading kerbal = " + id, "info", RMSettings.VerboseLogging);
                    RMKerbal kerballifeinfo = RMKerbal.Load(kerbalNodes.Current, id);
                    AllrmKerbals[id] = kerballifeinfo;
                }
                kerbalNodes.Dispose();
            }
            RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbals Loading Completed", "info", RMSettings.VerboseLogging);
        }
Пример #2
0
        // Stock Toolbar Startup and cleanup
        private void OnGuiAppLauncherReady()
        {
            RmUtils.LogMessage("RosterManagerAddon.OnGUIAppLauncherReady active...", "Info", RMSettings.VerboseLogging);
            try
            {
                // Setup Roster Button
                if ((HighLogic.LoadedScene != GameScenes.SPACECENTER && HighLogic.LoadedScene != GameScenes.EDITOR &&
                     HighLogic.LoadedScene != GameScenes.TRACKSTATION && HighLogic.LoadedScene != GameScenes.FLIGHT) ||
                    _rmRosterStock != null || RMSettings.EnableBlizzyToolbar)
                {
                    return;
                }
                const string iconfile = "Icon_Off_128";
                _rmRosterStock = ApplicationLauncher.Instance.AddModApplication(
                    OnRMRosterToggle,
                    OnRMRosterToggle,
                    DummyVoid,
                    DummyVoid,
                    DummyVoid,
                    DummyVoid,
                    ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.FLIGHT |
                    ApplicationLauncher.AppScenes.MAPVIEW | ApplicationLauncher.AppScenes.SPH | ApplicationLauncher.AppScenes.VAB |
                    ApplicationLauncher.AppScenes.TRACKSTATION,
                    GameDatabase.Instance.GetTexture(TextureFolder + iconfile, false));

                if (WindowRoster.ShowWindow)
                {
                    _rmRosterStock.SetTexture(GameDatabase.Instance.GetTexture(WindowRoster.ShowWindow ? TextureFolder + "Icon_On_128" : TextureFolder + "Icon_Off_128", false));
                }
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.OnGUIAppLauncherReady.  " + ex, "Error", true);
            }
        }
Пример #3
0
        //Toolbar button click handlers
        internal static void OnRMRosterToggle()
        {
            //Debug.Log("[RosterManager]:  RosterManagerAddon.OnRMRosterToggle");
            try
            {
                if (HighLogic.LoadedScene != GameScenes.SPACECENTER && HighLogic.LoadedScene != GameScenes.EDITOR &&
                    HighLogic.LoadedScene != GameScenes.TRACKSTATION && HighLogic.LoadedScene != GameScenes.FLIGHT)
                {
                    return;
                }
                WindowRoster.ShowWindow = !WindowRoster.ShowWindow;
                if (RMSettings.EnableBlizzyToolbar)
                {
                    _rmRosterBlizzy.TexturePath = WindowRoster.ShowWindow ? TextureFolder + "Icon_On_24" : TextureFolder + "Icon_Off_24";
                }
                else
                {
                    _rmRosterStock.SetTexture(GameDatabase.Instance.GetTexture(WindowRoster.ShowWindow ? TextureFolder + "Icon_On_128" : TextureFolder + "Icon_Off_128", false));
                }

                if (!WindowRoster.ShowWindow)
                {
                    return;
                }
                WindowRoster.DisplayMode = WindowRoster.DisplayModes.Index;
                WindowRoster.UpdateRosterList();
                //AllCrew.Clear();
                //if (RMLifeSpan.Instance != null)
                //    AllCrew = RMLifeSpan.Instance.rmkerbals.ALLRMKerbals.ToList();
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.OnRMRosterToggle.  " + ex, "Error", true);
            }
        }
Пример #4
0
 public void OnDestroy()
 {
     RmUtils.LogMessage("RosterManagerLifeSpanAddon OnDestroy...", "info", RMSettings.VerboseLogging);
     GameEvents.onKerbalAdded.Remove(OnKerbalAdded);
     GameEvents.onKerbalRemoved.Remove(OnKerbalRemoved);
     GameEvents.OnCrewmemberSacked.Remove(OnKerbalSacked);
 }
Пример #5
0
 public void Awake()
 {
     RmUtils.LogMessage("RosterManagerLifeSpanAddon Awake...", "info", RMSettings.VerboseLogging);
     GameEvents.onKerbalAdded.Add(OnKerbalAdded);
     GameEvents.onKerbalRemoved.Add(OnKerbalRemoved);
     GameEvents.OnCrewmemberSacked.Add(OnKerbalSacked);
     GameEvents.OnCrewmemberHired.Add(OnKerbalHired);
 }
Пример #6
0
 internal static void FireEventTriggers(Vessel vessel)
 {
     // Per suggestion by shaw (http://forum.kerbalspaceprogram.com/threads/62270?p=1033866&viewfull=1#post1033866)
     // and instructions for using CLS API by codepoet.
     RmUtils.LogMessage("FireEventTriggers:  Active.", "info", RMSettings.VerboseLogging);
     WindowRoster.UpdateRosterList();
     GameEvents.onVesselChange.Fire(vessel);
 }
Пример #7
0
        private void OnKerbalHired(ProtoCrewMember crew, int num)
        {
            double currentTime = Planetarium.GetUniversalTime();
            KeyValuePair <string, RMKerbal> rmkerbal = RMLifeSpan.Instance.RMKerbals.AllrmKerbals.FirstOrDefault(a => a.Key == crew.name);

            rmkerbal.Value.Timelastsalary = currentTime;
            rmkerbal.Value.TimeSalaryDue  = RMKerbal.SalaryNextDue(currentTime);
            RmUtils.LogMessage($"RosterManagerLifeSpanAddon.onKerbalHired {crew.name} has been hired to the crew roster.", "info", RMSettings.VerboseLogging);
        }
Пример #8
0
 protected void OnDestroy()
 {
     RmUtils.LogMessage("RosterManagerLifeSpan.Awake OnDestroy...", "info", RMSettings.VerboseLogging);
     foreach (Component child in _children)
     {
         RmUtils.LogMessage($"RosterManagerLifeSpan.Awake Destroying {child.name}", "info", RMSettings.VerboseLogging);
         Destroy(child);
     }
     _children.Clear();
 }
Пример #9
0
 public void RemoveKerbal(ProtoCrewMember crew)
 {
     //First find them in the internal Dictionary.
     if (!RMLifeSpan.Instance.RMKerbals.AllrmKerbals.ContainsKey(crew.name))
     {
         return;
     }
     RmUtils.LogMessage($"RosterManagerLifeSpanAddon.removeKerbal {crew.name} removed from ALLRMKerbals.", "info", RMSettings.VerboseLogging);
     //Then remove them.
     RMLifeSpan.Instance.RMKerbals.AllrmKerbals.Remove(crew.name);
 }
Пример #10
0
 private void ProcessContractDispute(ProtoCrewMember crew, KeyValuePair <string, RMKerbal> kerbal, double currentTime, bool start, bool extend)
 {
     // They will continue to work for RMLifeSpan.Instance.rmGameSettings.MaxContractDisputePeriods of salaryperiod, with a payrise that must be accepted each time. All backpay is accrued.
     // Or they quit/strike after RMLifeSpan.Instance.rmGameSettings.MaxContractDisputePeriods or if user does not accept the payrise.
     RmUtils.LogMessage($"RosterManagerLifeSpanAddon.CheckSalary unable to pay {crew.name} salary.", "info", RMSettings.VerboseLogging);
     if (start)                                                                                                                          //Start a new contract dispute
     {
         ScreenMessages.PostScreenMessage($"{Localizer.Format("#autoLOC_RM_1103")} {crew.name}", 5.0f, ScreenMessageStyle.UPPER_CENTER); // #autoLOC_RM_1103 = Insufficient funds to pay {0} salary at this time.
         kerbal.Value.SalaryContractDispute = true;
         kerbal.Value.RealTrait             = kerbal.Value.Trait;
         //Start processing dispute, increase the periods we have been in dispute, user must accept payrise as well (if they don't the kerbal Quits) and calculate and store their backpay owed.
         ExtendContractDispute(crew, kerbal);
     }
     else // Process existing contract dispute
     {
         //Check if we have funds now?
         //If we have pay them.
         //Else extend the contract dispute.
         if (Funding.CanAfford((float)kerbal.Value.Salary + (float)kerbal.Value.OwedSalary))
         {
             Funding.Instance.AddFunds(-(kerbal.Value.Salary + kerbal.Value.OwedSalary), TransactionReasons.CrewRecruited);
             kerbal.Value.Timelastsalary                 = currentTime;
             kerbal.Value.SalaryContractDispute          = false;
             kerbal.Value.SalaryContractDisputeProcessed = true;
             kerbal.Value.SalaryContractDisputePeriods   = 0;
             kerbal.Value.PayriseRequired                = 0d;
             kerbal.Value.OwedSalary = 0d;
             //If they are a tourist (dispute) and not dead (DeepFreeze frozen/comatose) set them back to crew
             if (kerbal.Value.Type == ProtoCrewMember.KerbalType.Tourist && crew.rosterStatus != ProtoCrewMember.RosterStatus.Dead)
             {
                 kerbal.Value.Type  = ProtoCrewMember.KerbalType.Crew;
                 crew.type          = ProtoCrewMember.KerbalType.Crew;
                 kerbal.Value.Trait = kerbal.Value.RealTrait;
                 crew.trait         = kerbal.Value.RealTrait;
                 KerbalRoster.SetExperienceTrait(crew, crew.trait);
                 RMKerbal.RegisterExperienceTrait(kerbal.Value);
             }
             RmUtils.LogMessage($"RosterManagerLifeSpanAddon.CheckSalary paid {crew.name} salary.", "info", RMSettings.VerboseLogging);
             RmUtils.LogMessage($"RosterManagerLifeSpanAddon.CheckSalary contract dispute ended {crew.name}", "info", RMSettings.VerboseLogging);
             ScreenMessages.PostScreenMessage(
                 $"{crew.name} {Localizer.Format("#autoLOC_RM_1104")} {kerbal.Value.Salary + kerbal.Value.OwedSalary}", 5.0f, ScreenMessageStyle.UPPER_CENTER); // #autoLOC_RM_1104 = Paid {0} salary of {1}
             ScreenMessages.PostScreenMessage($"{crew.name} {Localizer.Format("#autoLOC_RM_1105")}", 5.0f, ScreenMessageStyle.UPPER_CENTER);                    // #autoLOC_RM_1105 = {0} contract dispute ended.
         }
         else //Can't end dispute
         {
             if (!extend)
             {
                 return;
             }
             kerbal.Value.Timelastsalary = currentTime;
             ExtendContractDispute(crew, kerbal);
         }
     }
 }
Пример #11
0
 public void Start()
 {
     RmUtils.LogMessage("RosterManagerLifeSpanAddon Startup...", "info", RMSettings.VerboseLogging);
     try
     {
         CheckDatabase();
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage($"Error in:  RosterManagerLifeSpanAddon.Start.  {ex}", "Error", true);
     }
 }
Пример #12
0
        // Addon state event handlers
        internal void Awake()
        {
            try
            {
                if (HighLogic.LoadedScene != GameScenes.FLIGHT && HighLogic.LoadedScene != GameScenes.SPACECENTER &&
                    HighLogic.LoadedScene != GameScenes.EDITOR && HighLogic.LoadedScene != GameScenes.TRACKSTATION)
                {
                    return;
                }
                //DontDestroyOnLoad(this);
                RMSettings.ApplySettings();
                //WindowRoster.ResetKerbalProfessions();
                RmUtils.LogMessage("RosterManagerAddon.Awake Active...", "info", RMSettings.VerboseLogging);

                if (RMSettings.EnableBlizzyToolbar)
                {
                    // Let't try to use Blizzy's toolbar
                    RmUtils.LogMessage("RosterManagerAddon.Awake - Blizzy Toolbar Selected.", "Info", RMSettings.VerboseLogging);
                    if (!ActivateBlizzyToolBar())
                    {
                        // We failed to activate the toolbar, so revert to stock
                        if (ApplicationLauncher.Ready)
                        {
                            OnGuiAppLauncherReady();
                        }
                        else
                        {
                            GameEvents.onGUIApplicationLauncherReady.Add(OnGuiAppLauncherReady);
                        }
                        RmUtils.LogMessage("RosterManagerAddon.Awake - Stock Toolbar Selected.", "Info", RMSettings.VerboseLogging);
                    }
                }
                else
                {
                    // Use stock Toolbar
                    RmUtils.LogMessage("RosterManagerAddon.Awake - Stock Toolbar Selected.", "Info", RMSettings.VerboseLogging);
                    if (ApplicationLauncher.Ready)
                    {
                        OnGuiAppLauncherReady();
                    }
                    else
                    {
                        GameEvents.onGUIApplicationLauncherReady.Add(OnGuiAppLauncherReady);
                    }
                }
                // lets add our event handlers for kerbal actions
                //GameEvents.onKerbalAdded.Add(OnKerbalAdded);
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.Awake.  Error:  " + ex, "Error", true);
            }
        }
Пример #13
0
 public static RMKerbal Load(ConfigNode node, string name)
 {
     try
     {
         double lastUpdate = GetNodes.GetNodeValue(node, "lastUpdate", 0d);
         List <ProtoCrewMember> crewList = HighLogic.CurrentGame.CrewRoster.Crew.Concat(HighLogic.CurrentGame.CrewRoster.Applicants).ToList();
         //If Deepfreeze is installed add Unowned and Tourists to the list (could be frozen or comatose).
         if (Api.InstalledMods.IsDfInstalled)
         {
             crewList = crewList.Concat(HighLogic.CurrentGame.CrewRoster.Unowned).Concat(HighLogic.CurrentGame.CrewRoster.Tourist).ToList();
         }
         //var tmpvesselId = GetNodes.GetNodeValue(node, "vesselID", "");
         ProtoCrewMember kerbal = crewList.FirstOrDefault(a => a.name == name);
         RMKerbal        info   = new RMKerbal(lastUpdate, kerbal, false, false)
         {
             Status                         = GetNodes.GetNodeValue(node, "status", ProtoCrewMember.RosterStatus.Available),
             Type                           = GetNodes.GetNodeValue(node, "type", ProtoCrewMember.KerbalType.Crew),
             VesselId                       = GetNodes.GetNodeValue(node, "vesselID", Guid.Empty),
             PartId                         = GetNodes.GetNodeValue(node, "partID", (uint)0),
             VesselName                     = GetNodes.GetNodeValue(node, "VesselName", " "),
             SeatIdx                        = GetNodes.GetNodeValue(node, "seatIdx", 0),
             SeatName                       = GetNodes.GetNodeValue(node, "seatName", ""),
             Age                            = GetNodes.GetNodeValue(node, "age", 25.0d),
             Lifespan                       = GetNodes.GetNodeValue(node, "lifespan", 75.0d),
             TimelastBirthday               = GetNodes.GetNodeValue(node, "timelastBirthday", lastUpdate),
             TimeDfFrozen                   = GetNodes.GetNodeValue(node, "timeDFFrozen", 0d),
             Salary                         = GetNodes.GetNodeValue(node, "salary", 0d),
             TimeSalaryDue                  = GetNodes.GetNodeValue(node, "timeSalaryDue", lastUpdate),
             Timelastsalary                 = GetNodes.GetNodeValue(node, "timelastsalary", lastUpdate),
             Notes                          = GetNodes.GetNodeValue(node, "notes", ""),
             SalaryContractDispute          = GetNodes.GetNodeValue(node, "salaryContractDispute", false),
             OwedSalary                     = GetNodes.GetNodeValue(node, "owedSalary", 0d),
             SalaryContractDisputePeriods   = GetNodes.GetNodeValue(node, "salaryContractDisputePeriods", 0),
             SalaryContractDisputeProcessed = GetNodes.GetNodeValue(node, "salaryContractDisputeProcessed", false),
             PayriseRequired                = GetNodes.GetNodeValue(node, "payriseRequired", 0d),
             Stupidity                      = GetNodes.GetNodeValue(node, "Stupidity", 0f),
             Courage                        = GetNodes.GetNodeValue(node, "Courage", 0f),
             Badass                         = GetNodes.GetNodeValue(node, "Badass", false),
             Trait                          = GetNodes.GetNodeValue(node, "Trait", "Pilot"),
             RealTrait                      = GetNodes.GetNodeValue(node, "RealTrait", "Pilot"),
             Gender                         = GetNodes.GetNodeValue(node, "Gender", ProtoCrewMember.Gender.Male),
             Skill                          = GetNodes.GetNodeValue(node, "Skill", 0),
             Experience                     = GetNodes.GetNodeValue(node, "Experience", 0f)
         };
         info.TimeNextBirthday = GetNodes.GetNodeValue(node, "timeNextBirthday", BirthdayNextDue(info.TimelastBirthday));
         return(info);
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbal Load error... " + ex, "Error", RMSettings.VerboseLogging);
         return(null);
     }
 }
Пример #14
0
        // ReSharper disable once InconsistentNaming
        internal void OnGUI()
        {
            //Debug.Log("[RosterManager]:  RosterManagerAddon.OnGUI");
            try
            {
                Display();

                RMToolTips.ShowToolTips();
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.OnGUI.  " + ex, "Error", true);
            }
        }
Пример #15
0
 internal void Start()
 {
     RmUtils.LogMessage("RosterManagerAddon.Start.", "Info", RMSettings.VerboseLogging);
     try
     {
         if (WindowRoster.ResetRosterSize)
         {
             WindowRoster.Position.height = 335; //reset height
         }
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage("Error in:  RosterManagerAddon.Start.  " + ex, "Error", true);
     }
 }
Пример #16
0
 internal void Update()
 {
     try
     {
         CheckForToolbarTypeToggle();
     }
     catch (Exception ex)
     {
         if (!FrameErrTripped)
         {
             RmUtils.LogMessage($" in Update (repeating error).  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", "Error", true);
             FrameErrTripped = true;
         }
     }
 }
Пример #17
0
        internal void Display()
        {
            string step = "";

            try
            {
                step = "0 - Start";
                RMStyle.SetupGui();

                if (WindowDebugger.ShowWindow)
                {
                    step = "2 - Debugger";
                    WindowDebugger.Position = GUILayout.Window(318643, WindowDebugger.Position, WindowDebugger.Display, $"{Localizer.Format("#autoLOC_RM_1001")} {RMSettings.CurVersion}", GUILayout.MinHeight(20));    // #autoLOC_RM_1001 = Roster Manager -  Debug Console - Ver.
                }

                if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT)
                {
                    if (WindowSettings.ShowWindow)
                    {
                        step = "3 - Show Settings";
                        WindowSettings.Position = GUILayout.Window(318546, WindowSettings.Position, WindowSettings.Display, Localizer.Format("#autoLOC_RM_1002"), GUILayout.MinHeight(20)); // #autoLOC_RM_1002 = Roster Manager Settings
                    }

                    if (WindowContracts.ShowWindow)
                    {
                        step = "4 - Roster Contracts";
                        WindowContracts.Position = GUILayout.Window(318987, WindowContracts.Position, WindowContracts.Display, Localizer.Format("#autoLOC_RM_1003"), GUILayout.MinHeight(20));  // #autoLOC_RM_1003 = Roster Contracts
                    }

                    if (WindowRoster.ShowWindow)
                    {
                        if (WindowRoster.DisplayMode == WindowRoster.DisplayModes.Index)
                        {
                            step = "5 - Reset Roster Size";
                            WindowRoster.Position.height = 335; //reset hight
                        }

                        step = "6 - Show Roster";
                        WindowRoster.Position = GUILayout.Window(318547, WindowRoster.Position, WindowRoster.Display, Localizer.Format("#autoLOC_RM_1004"), GUILayout.MinHeight(20));   // #autoLOC_RM_1004 = Roster Manager
                    }
                }
                step = "1 - Show Interface(s)";
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage($" in drawGui at or near step:  {step}.  Error:  {ex.Message} \n\n{ex.StackTrace}", "Error", true);
            }
        }
Пример #18
0
        internal void UpdateKerbal(ProtoCrewMember crew, bool addifNotFound)
        {
            double currentTime = Planetarium.GetUniversalTime();
            //First find them in the internal Dictionary.
            KeyValuePair <string, RMKerbal> kerbal = RMLifeSpan.Instance.RMKerbals.AllrmKerbals.FirstOrDefault(a => a.Key == crew.name);

            //If not found and addifNotFound is true create a new entry
            if (kerbal.Value == null && addifNotFound)
            {
                RmUtils.LogMessage(
                    $"RosterManagerLifeSpanAddon.updateKerbal {crew.name} not found in ALLRMKerbals, adding new entry.", "info", RMSettings.VerboseLogging);
                RMKerbal rmkerbal = new RMKerbal(Planetarium.GetUniversalTime(), crew, true, false);
                RMLifeSpan.Instance.RMKerbals.AllrmKerbals.Add(crew.name, rmkerbal);
            }
            //If found update their entry
            else if (kerbal.Value != null)
            {
                if (!(currentTime - kerbal.Value.LastUpdate > RMSettings.LifeInfoUpdatePeriod))
                {
                    return;
                }
                RmUtils.LogMessage($"RosterManagerLifeSpanAddon.updateKerbal {crew.name} updating entry.", "info", RMSettings.VerboseLogging);
                if (RMLifeSpan.Instance.RMGameSettings.EnableAging)
                {
                    CheckAge(crew, kerbal, currentTime);
                }
                if (RMLifeSpan.Instance.RMGameSettings.EnableSalaries)
                {
                    //We only pay salaries to Crew or Dead/Unowned (frozen)
                    if (kerbal.Value.Type == ProtoCrewMember.KerbalType.Crew ||
                        kerbal.Value.Status == ProtoCrewMember.RosterStatus.Dead && kerbal.Value.Type == ProtoCrewMember.KerbalType.Unowned)
                    {
                        CheckSalary(crew, kerbal, currentTime);
                    }
                }
                kerbal.Value.LastUpdate = currentTime;
                kerbal.Value.Trait      = crew.trait;
                kerbal.Value.Type       = crew.type;
                kerbal.Value.Status     = crew.rosterStatus;
                if (crew.rosterStatus != ProtoCrewMember.RosterStatus.Available)
                {
                    return;
                }
                kerbal.Value.VesselId   = Guid.Empty;
                kerbal.Value.VesselName = string.Empty;
            }
        }
Пример #19
0
 internal static Guid GetNodeValue(ConfigNode confignode, string fieldname, Guid guid)
 {
     if (!confignode.HasValue(fieldname))
     {
         return(Guid.Empty);
     }
     try
     {
         Guid id = new Guid(confignode.GetValue(fieldname));
         return(id);
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbal error loading vesselID " + ex, "Error", RMSettings.VerboseLogging);
         return(Guid.Empty);
     }
 }
Пример #20
0
 internal static void SetPartHighlight(Part part, Color color)
 {
     try
     {
         if (part == null)
         {
             return;
         }
         part.SetHighlightColor(color);
         part.SetHighlight(true, false);
         part.highlightType = Part.HighlightType.AlwaysOn;
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage($" in  SetPartHighlight.  Error:  {ex.Message} \n\n{ex.StackTrace}", "Error", true);
     }
 }
Пример #21
0
 /// <summary>
 /// Remove highlighting on a part.
 /// </summary>
 /// <param name="part">Part to remove highlighting from.</param>
 internal static void ClearPartHighlight(Part part)
 {
     try
     {
         if (part == null)
         {
             return;
         }
         part.SetHighlight(false, false);
         part.SetHighlightDefault();
         part.highlightType = Part.HighlightType.OnMouseOver;
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage($" in  ClearPartHighlight.  Error:  {ex.Message} \n\n{ex.StackTrace}", "Error", true);
     }
 }
Пример #22
0
 private void OnGuiAppLauncherDestroyed()
 {
     //Debug.Log("[RosterManager]:  RosterManagerAddon.OnGUIAppLauncherDestroyed");
     try
     {
         if (_rmRosterStock == null)
         {
             return;
         }
         ApplicationLauncher.Instance.RemoveModApplication(_rmRosterStock);
         _rmRosterStock = null;
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage("Error in:  RosterManagerAddon.OnGUIAppLauncherDestroyed.  " + ex, "Error", true);
     }
 }
Пример #23
0
        //Vessel state handlers
        internal void OnDestroy()
        {
            //Debug.Log("[RosterManager]:  RosterManagerAddon.OnDestroy");
            try
            {
                if (RMSettings.Loaded)
                {
                    try
                    {
                        RMSettings.SaveSettings();
                    }
                    catch
                    {
                        // Do nothing.
                    }
                }

                // Handle Toolbars
                if (_rmRosterBlizzy == null)
                {
                    if (_rmRosterStock != null)
                    {
                        ApplicationLauncher.Instance.RemoveModApplication(_rmRosterStock);
                        _rmRosterStock = null;
                    }
                    if (_rmRosterStock == null)
                    {
                        // Remove the stock toolbar button launcher handler
                        GameEvents.onGUIApplicationLauncherReady.Remove(OnGuiAppLauncherReady);
                    }
                }
                else
                {
                    _rmRosterBlizzy?.Destroy();
                }
                //Reset Roster Window data
                WindowRoster.DisplayMode    = WindowRoster.DisplayModes.None;
                WindowRoster.SelectedKerbal = null;
                WindowRoster.ToolTip        = "";
                //Settings.ShowRoster = false;
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.OnDestroy.  " + ex, "Error", true);
            }
        }
Пример #24
0
 public void Update()
 {
     try
     {
         if (HighLogic.LoadedScene == GameScenes.FLIGHT)
         {
             //Update vesselID and Name for crew in the RM confignode dictionary. We aren't actually using this now, but will come into use/handy later.
             //This is necessary because SP doesn't actually store assigned vessels to crew in game neatly. They are stored ito the vessel modules, not the kerbal or crewroster,
             // which would make things easier!! DEVS take note!!!
             if (FlightGlobals.ActiveVessel != null)
             {
                 foreach (ProtoCrewMember crew in FlightGlobals.ActiveVessel.GetVesselCrew().ToList())
                 {
                     KeyValuePair <string, RMKerbal> kerbal = RMLifeSpan.Instance.RMKerbals.AllrmKerbals.FirstOrDefault(a => a.Key == crew.name);
                     if (kerbal.Key == null)
                     {
                         continue;
                     }
                     kerbal.Value.VesselId   = FlightGlobals.ActiveVessel.id;
                     kerbal.Value.VesselName = FlightGlobals.ActiveVessel.vesselName;
                 }
             }
         }
         //Update all known Crew, Applicants in any game scene.
         List <ProtoCrewMember> crewList = HighLogic.CurrentGame.CrewRoster.Crew.Concat(HighLogic.CurrentGame.CrewRoster.Applicants).ToList();
         //If Deepfreeze is installed add Unowned and Tourists to the list (could be frozen or comatose).
         if (Api.InstalledMods.IsDfInstalled)
         {
             crewList = crewList.Concat(HighLogic.CurrentGame.CrewRoster.Unowned).Concat(HighLogic.CurrentGame.CrewRoster.Tourist).ToList();
         }
         foreach (ProtoCrewMember crew in crewList)
         {
             // If they are not Dead or they are Dead status and they are unowned (frozen) or tourist (comatose) - We update their Life stats.
             if (crew.rosterStatus != ProtoCrewMember.RosterStatus.Dead ||
                 (crew.rosterStatus == ProtoCrewMember.RosterStatus.Dead && (crew.type == ProtoCrewMember.KerbalType.Unowned || crew.type == ProtoCrewMember.KerbalType.Tourist)))
             {
                 UpdateKerbal(crew, true);
             }
         }
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage($"Error in:  RosterManagerLifeSpanAddon.Update.  {ex}", "Error", true);
     }
 }
Пример #25
0
        // ReSharper disable once InconsistentNaming
        internal void OnGUI()
        {
            //Debug.Log("[RosterManager]:  RosterManagerAddon.OnGUI");
            if (Event.current.type == EventType.MouseUp)
            {
                // Turn off window resizing
                RmUtils.ResetResize();
            }
            try
            {
                Display();

                RMToolTips.ShowToolTips();
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage("Error in:  RosterManagerAddon.OnGUI.  " + ex, "Error", true);
            }
        }
Пример #26
0
 internal void Save(ConfigNode node)
 {
     try
     {
         ConfigNode kerbalLifeRecordNode = node.HasNode(ConfigNodeName) ? node.GetNode(ConfigNodeName) : node.AddNode(ConfigNodeName);
         Dictionary <string, RMKerbal> .Enumerator allRmKerbals = AllrmKerbals.GetEnumerator();
         while (allRmKerbals.MoveNext())
         {
             ConfigNode kerbalNode = allRmKerbals.Current.Value.Save(kerbalLifeRecordNode);
             RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbals Saving kerbal = " + allRmKerbals.Current.Key, "info", RMSettings.VerboseLogging);
             kerbalNode.AddValue("kerbalName", allRmKerbals.Current.Key);
         }
         allRmKerbals.Dispose();
     }
     catch (Exception ex)
     {
         RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbal Save error... " + ex, "Error", RMSettings.VerboseLogging);
     }
     RmUtils.LogMessage("RosterManagerLifeSpan.RMKerbals Saving Completed", "info", RMSettings.VerboseLogging);
 }
Пример #27
0
 private void CheckSalary(ProtoCrewMember crew, KeyValuePair <string, RMKerbal> kerbal, double currentTime)
 {
     if (currentTime >= kerbal.Value.TimeSalaryDue) // Salary Due??
     {
         //Set time next salary due
         kerbal.Value.TimeSalaryDue = RMKerbal.SalaryNextDue(currentTime);
         //Pay Salary
         if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
         {
             return;
         }
         //Check if contractdispute is active and if it is process that
         if (kerbal.Value.SalaryContractDispute && kerbal.Value.SalaryContractDisputeProcessed)
         {
             //If they are a Tourist they are on strike. We don't process dispute.
             if (kerbal.Value.Type == ProtoCrewMember.KerbalType.Tourist)
             {
                 return;
             }
             ProcessContractDispute(crew, kerbal, currentTime, false, true);
         }
         else //No contract dispute so process normal salary.
         {
             if (Funding.CanAfford((float)kerbal.Value.Salary))
             {
                 Funding.Instance.AddFunds(-kerbal.Value.Salary, TransactionReasons.CrewRecruited);
                 kerbal.Value.Timelastsalary = currentTime;
                 RmUtils.LogMessage($"RosterManagerLifeSpanAddon.CheckSalary paid {crew.name} salary.", "info", RMSettings.VerboseLogging);
                 ScreenMessages.PostScreenMessage(
                     $"{crew.name} {Localizer.Format("#autoLOC_RM_1102")} {kerbal.Value.Salary}", 5.0f, ScreenMessageStyle.UPPER_CENTER); // #autoLOC_RM_1102 = Paid {0} salary of {1}
             }
             else //Unable to pay, start a contract dispute.
             {
                 if (!kerbal.Value.SalaryContractDispute && kerbal.Value.SalaryContractDisputeProcessed)
                 {
                     ProcessContractDispute(crew, kerbal, currentTime, true, true);
                 }
             }
         }
     }
 }
Пример #28
0
 internal void ResignKerbal(ProtoCrewMember crew, KeyValuePair <string, RMKerbal> kerbal)
 {
     RmUtils.LogMessage(
         $"RosterManagerLifeSpanAddon.resignKerbal {crew.name} contract in dispute. They will remain a tourist until they are paid.", "info", RMSettings.VerboseLogging);
     ScreenMessages.PostScreenMessage($"{crew.name} contract in dispute. They will remain a tourist until they are paid.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
     //We don't change their status if they are unowned/dead (DeepFreeze Frozen)
     if (crew.type == ProtoCrewMember.KerbalType.Unowned || crew.rosterStatus == ProtoCrewMember.RosterStatus.Dead)
     {
         return;
     }
     RMKerbal.UnregisterExperienceTrait(kerbal.Value);
     //kerbal.Value.RealTrait = kerbal.Value.Trait;
     kerbal.Value.Type  = ProtoCrewMember.KerbalType.Tourist;
     crew.type          = ProtoCrewMember.KerbalType.Tourist;
     kerbal.Value.Trait = "Tourist";
     crew.trait         = "Tourist";
     KerbalRoster.SetExperienceTrait(crew, crew.trait);
     kerbal.Value.PayriseRequired = 0d;
     kerbal.Value.SalaryContractDisputeProcessed = true;
     kerbal.Value.SalaryContractDispute          = true;
 }
Пример #29
0
        internal void Display()
        {
            try
            {
                RMStyle.SetupGui();

                if (WindowDebugger.ShowWindow)
                {
                    WindowDebugger.Position = GUILayout.Window(318643, WindowDebugger.Position, WindowDebugger.Display, $"{Localizer.Format("#autoLOC_RM_1001")} {RMSettings.CurVersion}", GUILayout.MinHeight(20));    // #autoLOC_RM_1001 = Roster Manager -  Debug Console - Ver.
                }

                if (IsCorrectSceneLoaded())
                {
                    if (WindowSettings.ShowWindow)
                    {
                        WindowSettings.Position = GUILayout.Window(318546, WindowSettings.Position, WindowSettings.Display, Localizer.Format("#autoLOC_RM_1002"), GUILayout.MinHeight(20)); // #autoLOC_RM_1002 = Roster Manager Settings
                    }

                    if (WindowContracts.ShowWindow)
                    {
                        WindowContracts.Position = GUILayout.Window(318987, WindowContracts.Position, WindowContracts.Display, Localizer.Format("#autoLOC_RM_1003"), GUILayout.MinHeight(20));  // #autoLOC_RM_1003 = Roster Contracts
                    }

                    if (WindowRoster.ShowWindow)
                    {
                        if (WindowRoster.DisplayMode == WindowRoster.DisplayModes.None)
                        {
                            WindowRoster.Position.height = WindowRoster.WindowHeight + WindowRoster.HeightScale; //reset height
                        }

                        WindowRoster.Position = GUILayout.Window(318547, WindowRoster.Position, WindowRoster.Display, Localizer.Format("#autoLOC_RM_1004"), GUILayout.MinHeight(20));   // #autoLOC_RM_1004 = Roster Manager
                    }
                }
            }
            catch (Exception ex)
            {
                RmUtils.LogMessage($" in drawGui.  Error:  {ex.Message} \n\n{ex.StackTrace}", "Error", true);
            }
        }
Пример #30
0
 internal static bool ActivateBlizzyToolBar()
 {
     if (RMSettings.EnableBlizzyToolbar)
     {
         try
         {
             if (ToolbarManager.ToolbarAvailable)
             {
                 if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT)
                 {
                     _rmRosterBlizzy             = ToolbarManager.Instance.Add("RosterManager", "Roster");
                     _rmRosterBlizzy.TexturePath = WindowSettings.ShowWindow ? TextureFolder + "Icon_On_24" : TextureFolder + "Icon_Off_24";
                     _rmRosterBlizzy.ToolTip     = Localizer.Format("#autoLOC_RM_1000"); // #autoLOC_RM_1000 = Roster Manager Roster Window
                     _rmRosterBlizzy.Visibility  = new GameScenesVisibility(GameScenes.SPACECENTER);
                     _rmRosterBlizzy.Visible     = true;
                     _rmRosterBlizzy.OnClick    += e =>
                     {
                         OnRMRosterToggle();
                     };
                 }
                 RmUtils.LogMessage("Blizzy Toolbar available!", "Info", RMSettings.VerboseLogging);
                 return(true);
             }
             RmUtils.LogMessage("Blizzy Toolbar not available!", "Info", RMSettings.VerboseLogging);
             return(false);
         }
         catch (Exception ex)
         {
             // Blizzy Toolbar instantiation error.
             RmUtils.LogMessage("Error in EnableBlizzyToolbar... Error:  " + ex, "Error", true);
             return(false);
         }
     }
     // No Blizzy Toolbar
     RmUtils.LogMessage("Blizzy Toolbar not Enabled...", "Info", RMSettings.VerboseLogging);
     return(false);
 }