/// <summary>
            /// This converts the ARPResourceList actual object to a new dictionary for consumption
            /// </summary>
            /// <param name="actualResourceList"></param>
            /// <returns></returns>
            private ARPResourceList ExtractARPResourceList(Object actualResourceList)
            {
                ARPResourceList ListToReturn = new ARPResourceList();

                try {
                    //iterate each "value" in the dictionary
                    foreach (var item in (IDictionary)actualResourceList)
                    {
                        PropertyInfo pi   = item.GetType().GetProperty("Value");
                        object       oVal = pi.GetValue(item, null);
                        ARPResource  r1   = new ARPResource(oVal);
                        ListToReturn.Add(r1.ResourceDef.id, r1);
                    }
                } catch (Exception) {
                    //
                }
                return(ListToReturn);
            }
Esempio n. 2
0
 //        void lstResourcesVessel_OnMonitorStateChange(ARPResource sender, ARPResource.MonitorStateEnum alarmType, bool TurnedOn,Boolean AlarmAcknowledged)
 void lstResourcesVessel_OnMonitorStateChanged(ARPResource sender, ARPResource.MonitorStateEnum oldValue, ARPResource.MonitorStateEnum newValue,ARPResource.AlarmStateEnum AlarmState)
 {
     LogFormatted_DebugOnly("ARP-{0}:{1}->{2} ({3})", sender.ResourceDef.name, oldValue, newValue,sender.AlarmState);
     //Play a sound if necessary
     //if (TurnedOn && !AlarmAcknowledged && settings.AlarmsEnabled && settings.Resources[sender.ResourceDef.id].AlarmEnabled)
     if (newValue!= ARPResource.MonitorStateEnum.None && AlarmState== ARPResource.AlarmStateEnum.Unacknowledged && settings.AlarmsEnabled && settings.Resources[sender.ResourceDef.id].AlarmEnabled)
         {
         switch (newValue)
         {
             case ARPResource.MonitorStateEnum.Alert:
                 if (clipAlarmsAlert != null)
                     KSPAlternateResourcePanel.audioController.Play(clipAlarmsAlert, settings.AlarmsAlertRepeats);
                 break;
             case ARPResource.MonitorStateEnum.Warn:
                 //dont play the sound if we are coming down from alert
                 if (oldValue != ARPResource.MonitorStateEnum.Alert && clipAlarmsAlert != null)
                     KSPAlternateResourcePanel.audioController.Play(clipAlarmsWarning, settings.AlarmsWarningRepeats);
                 break;
         }
     }
 }
Esempio n. 3
0
 void lstResourcesVessel_OnAlarmStateChanged(ARPResource sender, ARPResource.AlarmStateEnum oldValue, ARPResource.AlarmStateEnum newValue,ARPResource.MonitorStateEnum MonitorState)
 {
     LogFormatted_DebugOnly("ARP-{0}:{1}->{2} ({3})", sender.ResourceDef.name, oldValue, newValue, sender.MonitorState);
     if (newValue != ARPResource.AlarmStateEnum.Unacknowledged)
         KSPAlternateResourcePanel.audioController.Stop();
 }
        internal static void DrawUsage(Rect rectStart, ARPResource Res, Boolean ShowRates, Boolean IgnoreInstants = false)
        {
            Rect rectTemp = new Rect(rectStart) { y = rectStart.y - 1, height = 18 };

            if (ShowRates && !IgnoreInstants && (rectStart.width < 180)) rectTemp.width = (rectTemp.width * 2 / 3);

            String strUsageString = String.Format("{0} / {1}", Res.AmountFormatted, Res.MaxAmountFormatted);;
            switch (Res.ResourceConfig.DisplayValueAs)
            {
                case ResourceSettings.DisplayUnitsEnum.Units:                                       break;
                case ResourceSettings.DisplayUnitsEnum.Tonnes:      strUsageString += " T";         break;
                case ResourceSettings.DisplayUnitsEnum.Kilograms:   strUsageString += " Kg";        break;
                case ResourceSettings.DisplayUnitsEnum.Liters:      strUsageString += " L";         break;
                default:                                                                            break;
            }
            GUI.Label(rectTemp, strUsageString, Styles.styleBarText);
        }
        internal static void DrawTimeRemaining(Rect rectStart, ARPResource Res)
        {
            Rect rectTemp = new Rect(rectStart) { y = rectStart.y - 1, height = 18 };

            if (Res.Rate < 0) {
                GUI.Label(rectTemp, Resources.texRateUp, Styles.styleBarRateText);

                Double TimeRemaining = Math.Abs((Res.MaxAmount - Res.Amount) / Res.Rate);
                String strTime = FormatTime(TimeRemaining);
                GUI.Label(rectTemp, strTime, Styles.styleBarText);
            }
            else if (Res.Rate > 0) {
                GUI.Label(rectTemp, Resources.texRateDown, Styles.styleBarRateText);

                Double TimeRemaining = Math.Abs(Res.Amount / Res.Rate);
                String strTime = FormatTime(TimeRemaining);
                GUI.Label(rectTemp, strTime, Styles.styleBarText);
            }
            else
            {
                GUI.Label(rectTemp, "---", Styles.styleBarText);
            }

            //GUI.Label(rectTemp, string.Format("{0} / {1}", Res.AmountFormatted, Res.MaxAmountFormatted), Styles.styleBarText);
        }
        internal static Boolean DrawResourceBar(Rect rectBar, ARPResource Res, GUIStyle styleBack, GUIStyle styleFront, GUIStyle styleFrontThin, Boolean ShowRates, Boolean Highlight, GUIStyle HighlightStyle)
        {
            Boolean blnReturn = false;
            Single fltBarRemainRatio = (float)Res.Amount / (float)Res.MaxAmount;

            //drawhighlight border
            if (Highlight)
            {
                Rect rectHighlight = new Rect(rectBar);
                rectHighlight.x -= 2; rectHighlight.y -= 2;
                rectHighlight.width += 4; rectHighlight.height += 4;
                GUI.Box(rectHighlight, "", HighlightStyle);
            }

            //blnReturn = Drawing.DrawBar(styleBack, out rectBar, Width);
            blnReturn = GUI.Button(rectBar, "", styleBack);

            if ((rectBar.width * fltBarRemainRatio) > 1)
                Drawing.DrawBarScaled(rectBar, Res ,styleFront, styleFrontThin, fltBarRemainRatio);

            if (!KSPAlternateResourcePanel.settings.ShowTimeRem)
            {
                ////add amounts
                Drawing.DrawUsage(rectBar, Res, ShowRates);
                ////add rate
                if (ShowRates) Drawing.DrawRate(rectBar, Res);
            }
            else
            {
                Drawing.DrawTimeRemaining(rectBar, Res);
            }

            return blnReturn;
        }
        //internal static Double RatePercent;
        internal static void DrawRate(Rect rectStart, ARPResource Res)
        {
            Rect rectTemp = new Rect(rectStart) { width = rectStart.width - 2, height = 18,y = rectStart.y - 1 };
            String strLabel = "";
            switch (KSPAlternateResourcePanel.settings.RateDisplayType)
            {
                case Settings.RateDisplayEnum.Default:
                    GUI.Label(rectTemp, string.Format("({0})", Res.RateFormatted), Styles.styleBarRateText);
                    break;
                case Settings.RateDisplayEnum.LeftRight:
                    //Int32 Arrows=1;
                    //RatePercent = Math.Abs(Res.Rate) / Res.MaxAmount * 100;
                    //if (RatePercent < KSPAlternateResourcePanel.APIInstance.windowDebug.intTest1)
                    //    Arrows = 1;
                    //else if (RatePercent < KSPAlternateResourcePanel.APIInstance.windowDebug.intTest2)
                    //    Arrows = 2;
                    //else if (RatePercent < KSPAlternateResourcePanel.APIInstance.windowDebug.intTest2)
                    //    Arrows = 3;
                    //else
                    //    Arrows = 4;

                    //if (Res.Rate < 0)
                    //    strLabel = new String('>', Arrows);
                    //else if (Res.Rate == 0)
                    //    strLabel = "---";
                    //else
                    //    strLabel = new String('<', Arrows);

                    if (Res.Rate < 0)
                        strLabel = ">>>";
                    else if (Res.Rate == 0)
                        strLabel = "---";
                    else
                        strLabel = "<<<";
                    GUI.Label(rectTemp, string.Format("{0}", strLabel), Styles.styleBarRateText);
                    break;
                case Settings.RateDisplayEnum.LeftRightPlus:
                    strLabel = Res.RateFormattedAbs;
                    if (Res.Rate < 0)
                        strLabel += " >";
                    else if (Res.Rate == 0)
                        strLabel = "---";
                    else
                        strLabel = "< " + strLabel;
                    GUI.Label(rectTemp, string.Format("{0}", strLabel), Styles.styleBarRateText);
                    break;
                case Settings.RateDisplayEnum.UpDown:
                case Settings.RateDisplayEnum.UpDownPlus:
                    if (Res.Rate < 0)
                        GUI.Label(rectTemp, Resources.texRateUp, Styles.styleBarRateText);
                    else if (Res.Rate > 0)
                        GUI.Label(rectTemp, Resources.texRateDown, Styles.styleBarRateText);

                    if (KSPAlternateResourcePanel.settings.RateDisplayType == Settings.RateDisplayEnum.UpDownPlus)
                    {
                        rectTemp = new Rect(rectTemp) { width = rectTemp.width - 10 };
                        GUI.Label(rectTemp, string.Format("{0}", Res.RateFormattedAbs), Styles.styleBarRateText);
                    }
                    break;
                default:
                    GUI.Label(rectTemp, string.Format("({0})", Res.RateFormatted), Styles.styleBarRateText);
                    break;
            }
        }
 //internal static Boolean DrawBar(GUIStyle Style, out Rect BarRect, int Width = 0, int Height = 0)
 //{
 //    Boolean blnReturn = false;
 //    List<GUILayoutOption> Options = new List<GUILayoutOption>();
 //    if (Width == 0) Options.Add(GUILayout.ExpandWidth(true));
 //    else Options.Add(GUILayout.Width(Width));
 //    if (Height != 0) Options.Add(GUILayout.Height(Height));
 //    //GUILayout.Label("", Style, Options.ToArray());
 //    if (GUILayout.Button("", Style, Options.ToArray()))
 //        blnReturn = true;
 //    BarRect = GUILayoutUtility.GetLastRect();
 //    return blnReturn;
 //}
 //private void DrawBar(Rect rectStart, int Row, GUIStyle Style)
 //{
 //    GUI.Label(rectStart, "", Style);
 //}
 internal static void DrawBarScaled(Rect rectStart, ARPResource Res, GUIStyle Style, GUIStyle StyleNarrow, float Scale)
 {
     Rect rectTemp = new Rect(rectStart);
     rectTemp.width = (float)Math.Ceiling(rectTemp.width = rectTemp.width * Scale);
     if (rectTemp.width <= 2) Style = StyleNarrow;
     GUI.Label(rectTemp, "", Style);
 }
Esempio n. 9
0
 //Raise the API event with the aggregated eventargs object
 void API_lstResourcesVessel_OnMonitorStateChanged(ARPResource sender, ARPResource.MonitorStateEnum oldValue, ARPResource.MonitorStateEnum newValue,ARPResource.AlarmStateEnum AlarmState)
 {
     if (onMonitorStateChanged != null)
         onMonitorStateChanged(new MonitorStateChangedEventArgs(sender, oldValue,newValue,AlarmState));
 }
Esempio n. 10
0
 public MonitorStateChangedEventArgs(ARPResource sender, ARPResource.MonitorStateEnum oldValue, ARPResource.MonitorStateEnum newValue, ARPResource.AlarmStateEnum AlarmState)
 {
     this.sender = sender;
     this.oldValue = oldValue;
     this.newValue = newValue;
     this.AlarmState = AlarmState;
 }