internal override void DrawWindow(Int32 id)
        {
            SetLocalVariables();

            try { GUILayout.BeginVertical(); }
            catch (Exception) { LogFormatted("DrawWindow: GUILayout not ready yet"); return; }

            if (mbARP.lstResourcesToDisplay.Count == 0)
            {
                GUILayout.Label("No current resources configured to display");
            }
            else
            {
                Int32 ResourceID;
                Rect  rectBar;
                for (int i = 0; i < mbARP.lstResourcesToDisplay.Count; i++)
                {
                    ResourceID = mbARP.lstResourcesToDisplay[i];
                    //Is it a separator - draw and skip?
                    if (ResourceID == 0)
                    {
                        GUILayout.Space(3 + settings.SpacerPadding);
                        GUILayout.Label("", Styles.styleSeparatorH, GUILayout.Width(WindowRect.width - 15), GUILayout.Height(2));
                        GUILayout.Space(settings.SpacerPadding);
                        continue;
                    }

                    //add space at top of window
                    if (i > 0)
                    {
                        GUILayout.Space(4);
                    }

                    GUILayout.BeginHorizontal();

                    //add title
                    Rect rectIcon = Drawing.DrawResourceIcon(lstResources[ResourceID].ResourceDef.name);

                    //If the global alarms setting is on
                    if (settings.AlarmsEnabled)
                    {
                        GUILayout.Space(1);
                        //work out the alarm ico to display
                        GUIContent contAlarm = new GUIContent(Resources.btnAlarm);
                        if (settings.Resources[ResourceID].AlarmEnabled)
                        {
                            contAlarm.image = Resources.btnAlarmEnabled;
                            switch (lstResources[ResourceID].MonitorState)
                            {
                            case ARPResource.MonitorStateEnum.Alert:
                                if (lstResources[ResourceID].AlarmState != ARPResource.AlarmStateEnum.Unacknowledged || DateTime.Now.Millisecond < 500)
                                {
                                    contAlarm.image = Resources.btnAlarmAlert;
                                }
                                break;

                            case ARPResource.MonitorStateEnum.Warn:
                                if (lstResources[ResourceID].AlarmState != ARPResource.AlarmStateEnum.Unacknowledged || DateTime.Now.Millisecond < 500)
                                {
                                    contAlarm.image = Resources.btnAlarmWarn;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        //Draw the button - if the alarm is unacknowledged then acknowledge, else toggle alarm status
                        if (GUILayout.Button(contAlarm, Styles.styleAlarmButton))
                        {
                            if (lstResources[ResourceID].AlarmState == ARPResource.AlarmStateEnum.Unacknowledged)
                            {
                                lstResources[ResourceID].SetAlarmAcknowledged();
                            }
                            else
                            {
                                settings.Resources[ResourceID].AlarmEnabled = !settings.Resources[ResourceID].AlarmEnabled;
                            }
                        }
                    }
                    //Is this resource selected
                    Boolean Highlight = SelectedResources.ContainsKey(ResourceID) && SelectedResources[ResourceID].AllVisible;

                    //For resources with no stage specifics - or the Resources is set to split display and values are different for all vessel and flow enabled ones
                    if (!settings.SplitLastStage || !lstResources[ResourceID].ResourceConfig.SplitLastStage || settings.ShowBase ||
                        (lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
                         lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) &&
                        ((!settings.Resources[ResourceID].ShowReserveLevels) ||
                         (!lstResourcesLastStage.ContainsKey(ResourceID)))
                        )
                    {
                        //full width bar
                        rectBar = Drawing.CalcBarRect(rectIcon, Icon2BarOffset_Left, 275, 15);  //was 245
                        if (Drawing.DrawResourceBar(rectBar, lstResources[ResourceID], Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                        {
                            //MonoBehaviourExtended.LogFormatted_DebugOnly("Clicked");
                            SelectedResources.TogglePartResourceVisible(ResourceID);
                        }
                    }
                    else
                    {
                        Int32 FullVesselBarOffset = settings.StageBarOnRight ? Icon2BarOffset_Left : Icon2BarOffset_Right;
                        Int32 StageBarOffset      = settings.StageBarOnRight ? Icon2BarOffset_Right : Icon2BarOffset_Left;

                        //need full Vessel and current stage bars
                        rectBar = Drawing.CalcBarRect(rectIcon, FullVesselBarOffset, 135, 15);  //was 120
                        if (Drawing.DrawResourceBar(rectBar, lstResources[ResourceID], Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                        {
                            SelectedResources.TogglePartResourceVisible(ResourceID);
                        }

                        //get last stage of this resource and set it
                        if (lstResourcesLastStage.ContainsKey(ResourceID))
                        {
                            Highlight = SelectedResources.ContainsKey(ResourceID) && SelectedResources[ResourceID].LastStageVisible;
                            rectBar   = Drawing.CalcBarRect(rectIcon, StageBarOffset, 135, 15); //was 120
                            if (Drawing.DrawResourceBar(rectBar, lstResourcesLastStage[ResourceID], Styles.styleBarBlue_Back, Styles.styleBarBlue, Styles.styleBarBlue_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                            {
                                SelectedResources.TogglePartResourceVisible(ResourceID, true);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.BeginHorizontal();
            ////STAGING STUFF
            if (settings.StagingEnabled)
            {
                ////Keyboard Stage Lock
                //GUIContent contLock = new GUIContent(Resources.btnUnlock, "Keyboard Staging Unlocked\r\nClick to toggle");
                //if (FlightInputHandler.fetch.stageLock)
                //    contLock = new GUIContent(Resources.btnLock, "Keyboard Staging Locked\r\nClick to toggle");
                //if (GUILayout.Button(contLock, Styles.styleAlarmButton))
                //    FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock;

                if (!settings.AutoStagingEnabled)
                {
                    //GUILayout.Label("Stage:", Styles.styleStageTextHead, GUILayout.Width(50));
                    if (GUILayout.Button("Stage:", Styles.styleStageTextHead, GUILayout.Width(50)))
                    {
                        settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
                    }
                    GUIStyle   styleStageNum = new GUIStyle(Styles.styleStageTextHead);
                    GUIContent contStageNum  = new GUIContent(Staging.CurrentStage.ToString());
                    //styleStageNum.normal.textColor=new Color(173,43,43);
                    //GUIContent contStageNum = new GUIContent(Staging.CurrentStage.ToString(),"NO Active Engines");
                    //if (THERE ARE ACTIVE ENGINES IN STAGE)
                    //{
                    //contStageNum.tooltip="Active Engines";
                    styleStageNum.normal.textColor = new Color(117, 206, 60);
                    //}

                    GUILayout.Label(contStageNum, styleStageNum, GUILayout.Width(20));

                    if (settings.StagingEnabledInMapView || !MapView.MapIsEnabled)
                    {
                        if (mbARP.blnVesselIsControllable)
                        {
                            if (GUILayout.Button("Activate Stage", "ButtonGeneral", GUILayout.Width(100)))
                            {
                                Staging.ActivateNextStage();
                            }
                            GUILayout.Space(21 + IconAlarmOffset);
                            //GUILayout.Space(51 + IconAlarmOffset);
                        }
                        else
                        {
                            GUILayout.Label("No Vessel Control", GUILayout.Width(120));
                            GUILayout.Space(1 + IconAlarmOffset);
                            //GUILayout.Space(31 + IconAlarmOffset);
                        }
                    }
                    //GUILayout.Space(48 + IconAlarmOffset);
                    //GUILayout.Space(21 + IconAlarmOffset);
                }
                else
                {
                    if (GUILayout.Button("Auto:", Styles.styleStageTextHead, GUILayout.Width(50)))
                    {
                        settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
                    }
                    GUILayout.Label(Staging.CurrentStage.ToString(), Styles.styleStageTextHead, GUILayout.Width(20));
                    GUILayout.Label("to", Styles.styleStageTextHead, GUILayout.Width(30));
                    GUILayout.Label(mbARP.AutoStagingTerminateAt.ToString(), Styles.styleStageTextHead, GUILayout.Width(30));
                    DrawHorizontalSlider(ref mbARP.AutoStagingTerminateAt, 0, mbARP.AutoStagingMaxStage);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();

                    String   strButtonArm = "Arm";
                    GUIStyle styleArm     = new GUIStyle(SkinsLibrary.CurrentSkin.button)
                    {
                        fontStyle = FontStyle.Bold
                    };
                    if (mbARP.AutoStagingArmed)
                    {
                        strButtonArm = "Disarm";
                        styleArm.normal.textColor = styleArm.hover.textColor = new Color32(207, 31, 31, 255);
                    }
                    else
                    {
                        styleArm.normal.textColor = styleArm.hover.textColor = new Color32(183, 254, 0, 255);
                    }

                    if (GUILayout.Button(strButtonArm, styleArm, GUILayout.Width(75)))
                    {
                        mbARP.AutoStagingArmed = !mbARP.AutoStagingArmed;
                    }

                    GUIStyle StatusStyle = new GUIStyle(SkinsLibrary.CurrentSkin.label);
                    StatusStyle.normal.textColor = mbARP.AutoStagingStatusColor;
                    //GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(147 + IconAlarmOffset));
                    GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(120 + IconAlarmOffset));
                    //GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(150 + IconAlarmOffset));
                }
            }
            else
            {
                //GUILayout.Space(234 + IconAlarmOffset);
                GUILayout.Space(207 + IconAlarmOffset);
                //GUILayout.Space(237 + IconAlarmOffset);
            }

            // ShowBase Button
            Boolean blnShowBase = settings.ShowBase;

            if (DrawToggle(ref blnShowBase, new GUIContent(Resources.btnViewBaseActive, blnShowBase ? "Back to Vessel Display" : "Show Base Display\r\nAll resource within 2km of active vessel"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                settings.ShowBase = blnShowBase;
            }
            //if (GUILayout.Button(new GUIContent(settings.ShowBase ? Resources.btnViewBaseActive : Resources.btnViewBase, "Toggle Vessel/Base Display"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    settings.ShowBase = !settings.ShowBase;
            //}

            // ShowTime Button
            Boolean blnShowTimeRem = settings.ShowTimeRem;

            if (DrawToggle(ref blnShowTimeRem, new GUIContent(Resources.btnViewTimes, blnShowTimeRem ? "Hide time Remianing": "Show Time Remaining"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                settings.ShowTimeRem = blnShowTimeRem;
            }
            //if (GUILayout.Button(new GUIContent(Resources.btnViewTimes, "Toggle Time Remaining"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    settings.ShowTimeRem = !settings.ShowTimeRem;
            //}

            // ShowAll Button
            Boolean blnToggleHidden = KSPAlternateResourcePanel.ShowAll;

            if (DrawToggle(ref blnToggleHidden, new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                KSPAlternateResourcePanel.ShowAll = blnToggleHidden;
            }
            //if (GUILayout.Button(new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    KSPAlternateResourcePanel.ShowAll = !KSPAlternateResourcePanel.ShowAll;
            //}

            //Settings Toggle button
            GUIContent btnMinMax = new GUIContent(Resources.btnChevronDown, "Show Settings...");

            if (windowSettings.Visible)
            {
                btnMinMax.image = Resources.btnChevronUp; btnMinMax.tooltip = "Hide Settings";
            }
            else if (settings.VersionAttentionFlag && DateTime.Now.Millisecond < 500)
            {
                btnMinMax.image = Resources.btnSettingsAttention;
            }

            if (settings.VersionAttentionFlag)
            {
                btnMinMax.tooltip = "Updated Version Available - " + btnMinMax.tooltip;
            }

            if (GUILayout.Button(btnMinMax, "ButtonSettings", GUILayout.Width(23)))
            {
                windowSettings.Visible = !windowSettings.Visible;
                if (windowSettings.Visible && settings.VersionAttentionFlag)
                {
                    windowSettings.ddlSettingsTab.SelectedIndex = (Int32)ARPWindowSettings.SettingsTabs.About;
                    settings.VersionAttentionFlag = false;
                }
                settings.Save();
            }

            GUILayout.EndHorizontal();

            //End window layout
            GUILayout.EndVertical();

            //If settings window is visible then position it accordingly
            if (mbARP.windowSettings.Visible)
            {
                mbARP.windowSettings.UpdateWindowRect();
            }
        }
示例#2
0
        internal override void DrawWindow(int id)
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Configure Resources", Styles.styleTextYellowBold);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close"))
            {
                this.Visible = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Space(2);
            GUILayout.Label("Icon", Styles.styleStageTextHead, GUILayout.Width(32));
            GUILayout.Label("Name", Styles.styleStageTextHead, GUILayout.Width(120));
            GUILayout.Label("Position", Styles.styleStageTextHead, GUILayout.Width(56));
            GUILayout.Space(6);
            GUILayout.Label("Visibility", Styles.styleStageTextHead, GUILayout.Width(80));
            GUILayout.Label("Monitor", Styles.styleStageTextHead, GUILayout.Width(60));
            GUILayout.EndHorizontal();

            Int32 SepToDelete = 0;

            Int32 NameWidth = 120;

            Styles.styleResourceSettingsArea.fixedWidth = ScrollAreaWidth - 23;

            ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, new GUIStyle(), GUILayout.Width(ScrollAreaWidth));
            //wrapper for preventing horiz scroll
            GUILayout.BeginVertical(GUILayout.Width(ScrollAreaWidth - 23));
            //foreach (PartResourceDefinition item in PartResourceLibrary.Instance.resourceDefinitions)

            if (Event.current.type == EventType.Repaint)
            {
                lstResPositions = new List <ResourcePosition>();
            }
            for (int i = 0; i < settings.Resources.Count; i++)
            {
                ResourceSettings item = settings.Resources.Values.ElementAt(i);
                if (ResourceToShowAlarm == item.id)
                {
                    GUILayout.Space(4);
                    GUILayout.BeginVertical(Styles.styleResourceSettingsArea);
                    NameWidth = 119;
                }
                GUILayout.BeginHorizontal();

                if (!item.IsSeparator)
                {
                    GUILayout.BeginVertical();
                    GUILayout.Space(6);
                    Drawing.DrawResourceIcon(item.name);

                    Rect IconRect;
                    if (Event.current.type == EventType.Repaint)
                    {
                        IconRect = GUILayoutUtility.GetLastRect();
                        //float intOffset = 0;
                        //if (lstResPositions.Count != 0)
                        //    intOffset = lstResPositions.Last().resourceRect.y + 22;
                        //Rect resResourcePos = new Rect(mbARP.windowDebug.intTest1, mbARP.windowDebug.intTest2 + intOffset, 0, 0);
                        lstResPositions.Add(new ResourcePosition(item.id, item.name, IconRect, ScrollAreaWidth - 20, (ResourceToShowAlarm == item.id)));
                    }
                    GUILayout.EndVertical();
                    //GUILayout.Label(item.name, GUILayout.Width(NameWidth));
                    if (GUILayout.Button(item.name, SkinsLibrary.CurrentSkin.label, GUILayout.Width(NameWidth)))
                    {
                        if (ResourceToShowAlarmChanger == item.id)
                        {
                            ResourceToShowAlarmChanger = 0;
                        }
                        else
                        {
                            ResourceToShowAlarmChanger      = item.id;
                            ddlMonType.SelectedIndex        = (Int32)settings.Resources[ResourceToShowAlarmChanger].MonitorDirection;
                            ddlDisplayValueAs.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].DisplayValueAs;
                        }
                        ResourceToShowAlarmChangeNeeded = true;
                    }
                }
                else
                {
                    GUILayout.BeginVertical();
                    GUILayout.Space(13);
                    GUILayout.Label("", Styles.styleSeparatorH, GUILayout.Width(120 + 36));
                    GUILayout.Space(7);
                    GUILayout.EndVertical();

                    if (Event.current.type == EventType.Repaint)
                    {
                        if (lstResPositions.Count > 0)
                        {
                            Rect IconRect = new Rect(lstResPositions.Last().iconRect)
                            {
                                y = lstResPositions.Last().iconRect.y + 22, width = 120 + 36
                            };
                            lstResPositions.Add(new ResourcePosition(item.id, "Separator", IconRect, ScrollAreaWidth - 20, (ResourceToShowAlarm == item.id)));
                        }
                    }
                }

                if (GUILayout.Button(new GUIContent("S", "Add Separator"), GUILayout.Width(21)))
                {
                    AddSeparatorAtEnd();
                    MoveResource(settings.Resources.Count - 1, i + 1);
                }

                //Move up and down
                if (i > 0)
                {
                    if (GUILayout.Button(new GUIContent("↑", "Move Up"), GUILayout.Width(21)))
                    {
                        SwapResource(i - 1, i);
                    }
                }
                else
                {
                    GUILayout.Space(21 + 4);
                }
                if (i < settings.Resources.Count - 1)
                {
                    if (GUILayout.Button("↓", GUILayout.Width(21)))
                    {
                        SwapResource(i, i + 1);
                    }
                }
                else
                {
                    GUILayout.Space(21 + 4);
                }

                //Move top and Bottom
                if (i > 0)
                {
                    if (GUILayout.Button(new GUIContent("↑↑", "Move to Top"), GUILayout.Width(27)))
                    {
                        MoveResource(i, 0);
                    }
                }
                else
                {
                    GUILayout.Space(27 + 4);
                }
                if (i < settings.Resources.Count - 1)
                {
                    if (GUILayout.Button(new GUIContent("↓↓", "Move to Bottom"), GUILayout.Width(27)))
                    {
                        MoveResource(i, settings.Resources.Count);
                    }
                }
                else
                {
                    GUILayout.Space(27 + 4);
                }

                // Visibility level and alarm values/Delete
                if (!item.IsSeparator)
                {
                    if (GUILayout.Button(settings.Resources[item.id].Visibility.ToString(), GUILayout.Width(75)))
                    {
                        settings.Resources[item.id].Visibility = settings.Resources[item.id].Visibility.Next();
                    }
                    if (GUILayout.Button(string.Format("{0}/{1}", settings.Resources[item.id].MonitorWarningLevel, settings.Resources[item.id].MonitorAlertLevel), GUILayout.Width(58)))
                    {
                        if (ResourceToShowAlarmChanger == item.id)
                        {
                            ResourceToShowAlarmChanger = 0;
                        }
                        else
                        {
                            ResourceToShowAlarmChanger      = item.id;
                            ddlMonType.SelectedIndex        = (Int32)settings.Resources[ResourceToShowAlarmChanger].MonitorDirection;
                            ddlDisplayValueAs.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].DisplayValueAs;
                        }
                        ResourceToShowAlarmChangeNeeded = true;
                    }
                }
                else
                {
                    if (GUILayout.Button("Delete", GUILayout.Width(75 + 58 + 4)))
                    {
                        SepToDelete = item.id;
                    }
                }
                GUILayout.FlexibleSpace();

                GUILayout.EndHorizontal();

                if (ResourceToShowAlarm == item.id)
                {
                    GUILayout.BeginVertical(GUILayout.Height(40), GUILayout.Width(ScrollAreaWidth - 20));
                    GUILayout.Space(8);//4

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Display As:", Styles.styleStageTextHead, GUILayout.Width(151));
                    //GUILayout.Label("Monitoring Type:", GUILayout.Width(mbARP.windowDebug.intTest1));
                    ddlDisplayValueAs.SetListBoxOffset(vectMonTypeOffset - ScrollPosition);
                    ddlDisplayValueAs.DrawButton();
                    GUILayout.Space(4);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Monitoring Levels:", Styles.styleStageTextHead, GUILayout.Width(151));
                    //GUILayout.Label("Monitoring Type:", GUILayout.Width(mbARP.windowDebug.intTest1));
                    ddlMonType.SetListBoxOffset(vectMonTypeOffset - ScrollPosition);
                    ddlMonType.DrawButton();
                    GUILayout.Space(4);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Warning Level:", GUILayout.Width(90));
                    settings.Resources[item.id].MonitorWarningLevel = (Int32)Math.Round(GUILayout.HorizontalSlider(settings.Resources[item.id].MonitorWarningLevel, 0, 100, GUILayout.Width(220)));
                    GUILayout.Label(settings.Resources[item.id].MonitorWarningLevel.ToString() + "%", GUILayout.Width(35));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Alert Level:", GUILayout.Width(90));
                    settings.Resources[item.id].MonitorAlertLevel = (Int32)Math.Round(GUILayout.HorizontalSlider(settings.Resources[item.id].MonitorAlertLevel, 0, 100, GUILayout.Width(220)));
                    GUILayout.Label(settings.Resources[item.id].MonitorAlertLevel.ToString() + "%", GUILayout.Width(35));
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();

                    if (settings.Resources[item.id].MonitorDirection == ResourceSettings.MonitorDirections.Low)
                    {
                        settings.Resources[item.id].MonitorWarningLevel = Mathf.Clamp(settings.Resources[item.id].MonitorWarningLevel,
                                                                                      settings.Resources[item.id].MonitorAlertLevel, 100);
                    }
                    else
                    {
                        settings.Resources[item.id].MonitorWarningLevel = Mathf.Clamp(settings.Resources[item.id].MonitorWarningLevel,
                                                                                      0, settings.Resources[item.id].MonitorAlertLevel);
                    }

                    GUIStyle temp = new GUIStyle(Styles.styleStageTextHead);
                    temp.padding.top = 0;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Alarms for this:", temp, GUILayout.Width(120));
                    DrawToggle(ref settings.Resources[item.id].AlarmEnabled, "Alarm Enabled", Styles.styleToggle);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Empty Behaviour:", temp, GUILayout.Width(120));
                    DrawToggle(ref settings.Resources[item.id].HideWhenEmpty, "Hide When Empty", Styles.styleToggle);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Full Behaviour:", temp, GUILayout.Width(120));
                    DrawToggle(ref settings.Resources[item.id].HideWhenFull, "Hide When Full", Styles.styleToggle);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Stage Bars:", temp, GUILayout.Width(120));
                    DrawToggle(ref settings.Resources[item.id].SplitLastStage, "Split Enabled", Styles.styleToggle);
                    GUILayout.EndHorizontal();
                    if (settings.Resources[item.id].SplitLastStage && (
                            PartResourceLibrary.Instance.resourceDefinitions[item.id].resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
                            PartResourceLibrary.Instance.resourceDefinitions[item.id].resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW)
                        )
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Split Behaviour:", temp, GUILayout.Width(120));
                        DrawToggle(ref settings.Resources[item.id].ShowReserveLevels, new GUIContent("Show Reserve Levels", "instead of Whole Vessel/Last Stage split"), Styles.styleToggle);
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.Space(3);
                    GUILayout.EndVertical();
                }
            }

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


            GUILayout.EndVertical();

            if (SepToDelete != 0)
            {
                settings.Resources.Remove(SepToDelete);
                List <ResourceSettings> lstTemp = settings.Resources.Values.ToList();
                settings.Resources = lstTemp.ToDictionary(x => x.id);
            }

            GUILayout.BeginHorizontal();
            if (DrawButton("Add Separator"))
            {
                AddSeparatorAtEnd();
            }
            if (DrawButton("Sort Groups"))
            {
                SortGroups();
            }

            if (DrawButton("Save"))
            {
                settings.Save();
            }
            GUILayout.EndHorizontal();

            if (ResourceToShowAlarmChangeNeeded)
            {
                ResourceToShowAlarmChangeNeeded = false;
                ResourceToShowAlarm             = ResourceToShowAlarmChanger;
            }

            // Draw the Yellow insertion strip
            if (DraggingResource && DropWillReorderList && resourceOver != null)
            {
                Single rectResMoveY;
                if (resourceInsertIndex < lstResPositions.Count)
                {
                    rectResMoveY = lstResPositions[resourceInsertIndex].resourceRect.y;
                }
                else
                {
                    rectResMoveY = lstResPositions[lstResPositions.Count - 1].resourceRect.y + lstResPositions[lstResPositions.Count - 1].resourceRect.height;
                }
                Rect rectResMove = new Rect(4,
                                            rectResMoveY + 49 - ScrollPosition.y,
                                            380, 9);
                GUI.Box(rectResMove, "", Styles.styleDragInsert);
            }

            //Do the mouse checks
            IconMouseEvents();

            //Disable the Window from dragging if we are dragging a resource
            DragEnabled = !DraggingResource;
        }
        internal override void DrawWindow(int id)
        {
            TransfersCount = 0;
            if (SkinsLibrary.CurrentSkin.name == "Unity")
            {
                GUI.Box(new Rect(0, 0, WindowWidthForBars - 1, WindowRect.height - 1), "", SkinsLibrary.CurrentSkin.window);
            }

            GUILayout.BeginVertical();
            GUI.Label(new Rect(0, 0, WindowWidthForBars + WindowWidthForFlowControl - 1, 18), this.PartRef.partInfo.title, Styles.stylePartWindowHead);
            GUILayout.Space(18);
            int i = 0;

            foreach (int key in this.ResourceList.Keys)
            {
                Boolean  TransferExists = mbARP.lstTransfers.ItemExists(this.PartID, key);
                Boolean  TransferActive = false;
                GUIStyle Highlight      = Styles.styleBarHighlight;
                if (TransferExists)
                {
                    if (mbARP.lstTransfers.GetItem(this.PartID, key).transferState == TransferStateEnum.In)
                    {
                        Highlight = Styles.styleBarHighlightGreen;
                    }
                    else if (mbARP.lstTransfers.GetItem(this.PartID, key).transferState == TransferStateEnum.Out)
                    {
                        Highlight = Styles.styleBarHighlightRed;
                    }

                    TransferActive = mbARP.lstTransfers.GetItem(this.PartID, key).Active;
                }

                GUILayout.Space(2);
                if (i > 0)
                {
                    GUILayout.Space(2);
                }
                GUILayout.BeginHorizontal();
                GUILayout.Space(5);
                //add title
                Rect rectIcon = Drawing.DrawResourceIcon(this.ResourceList[key].ResourceDef.name);
                GUILayout.Space(2);

                Rect rectBar = Drawing.CalcBarRect(rectIcon, Icon2BarOffset, 120, 15);
                if (Drawing.DrawResourceBar(rectBar, this.ResourceList[key],
                                            Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin,
                                            settings.ShowRatesForParts, TransferActive, Highlight))
                {
                    //if (this.ResourceList[key].ResourceDef.resourceTransferMode != ResourceTransferMode.NONE)
                    if (this.ResourceList[key].ResourceDef.resourceTransferMode != ResourceTransferMode.NONE &&
                        (
                            HighLogic.CurrentGame.Mode != Game.Modes.CAREER ||
                            GameVariables.Instance.UnlockedFuelTransfer(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment))
                        )
                        )
                    {
                        //toggle the transfer line
                        if (TransferExists)
                        {
                            mbARP.lstTransfers.RemoveItem(this.PartID, key);
                            TransferExists = false;
                        }
                        else
                        {
                            mbARP.lstTransfers.AddItem(this.PartRef, this.ResourceList[key].ResourceDef, TransferStateEnum.None);
                        }
                    }
                }

                if (this.ResourceList[key].ResourceDef.resourceFlowMode != ResourceFlowMode.NO_FLOW)
                {
                    if (Drawing.DrawFlowControlButton(rectBar, this.PartRef.Resources.Get(key).flowState))
                    {
                        this.PartRef.Resources.Get(key).flowState = !this.PartRef.Resources.Get(key).flowState;
                    }
                }

                GUILayout.EndHorizontal();

                if (TransferExists)
                {
                    TransfersCount++;
                    ARPTransfer tmpTransfer = mbARP.lstTransfers.GetItem(this.PartID, key);
                    GUILayout.Space(1);
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(8);
                    GUIStyle styleTransfer = new GUIStyle(SkinsLibrary.CurrentSkin.label);
                    styleTransfer.fixedHeight    = 19;
                    styleTransfer.padding.top    = -8;
                    styleTransfer.padding.bottom = 0;
                    //GUILayout.Label("Transfer: " + tmpTransfer.transferState, styleTransfer);
                    GUILayout.Label("Transfer: ", styleTransfer);

                    GUILayout.Space(21);


                    GUIStyle styleTransferButton = new GUIStyle(SkinsLibrary.CurrentSkin.button);
                    styleTransferButton.fixedHeight = 19;
                    styleTransferButton.fixedWidth  = 40;
                    styleTransferButton.onNormal    = styleTransferButton.active;
                    styleTransferButton.padding     = new RectOffset(0, 0, 0, 0);
                    styleTransferButton.margin      = new RectOffset(0, 0, 0, 0);


                    String  strOut     = (tmpTransfer.transferState == TransferStateEnum.Out && tmpTransfer.Active) ? "Stop" : "Out";
                    String  strIn      = (tmpTransfer.transferState == TransferStateEnum.In && tmpTransfer.Active) ? "Stop" : "In";
                    Boolean blnTempOut = GUILayout.Toggle(tmpTransfer.transferState == TransferStateEnum.Out, strOut, styleTransferButton);
                    Boolean blnTempIn  = GUILayout.Toggle(tmpTransfer.transferState == TransferStateEnum.In, strIn, styleTransferButton);

                    if (blnTempOut && (tmpTransfer.transferState != TransferStateEnum.Out))
                    {
                        //if there are any transfers in place for this resource then turn off the Out
                        //if (mbARP.lstTransfers.Any(x => x.ResourceID == key && x.Active))
                        //    mbARP.lstTransfers.SetStateNone(key);
                        //else
                        //    mbARP.lstTransfers.SetStateNone(key, TransferStateEnum.Out);

                        tmpTransfer.transferState = TransferStateEnum.Out;
                    }
                    else if (blnTempIn && (tmpTransfer.transferState != TransferStateEnum.In))
                    {
                        //if there are any transfers in place for this resource then turn off the In
                        //if (mbARP.lstTransfers.Any(x => x.ResourceID == key && x.Active))
                        //    mbARP.lstTransfers.SetStateNone(key);
                        //else
                        //    mbARP.lstTransfers.SetStateNone(key, TransferStateEnum.In);

                        tmpTransfer.transferState = TransferStateEnum.In;
                    }
                    else if (!blnTempIn && !blnTempOut && (tmpTransfer.transferState != TransferStateEnum.None))
                    {
                        tmpTransfer.transferState = TransferStateEnum.None;
                    }

                    //if (tmpTransfer.Active)
                    //{
                    //    GUILayout.Space(20);
                    //    if (GUILayout.Button("Stop", styleTransferButton))
                    //    {
                    //        //mbARP.lstTransfers.SetStateNone(key);
                    //        mbARP.lstTransfers.SetStateNone(key);
                    //    }
                    //}
                    //else
                    //{
                    //    //if (GUILayout.Button("Out", styleTransferButton)) { tmpTransfer.transferState = TransferStateEnum.Out; }
                    //    //if (GUILayout.Button("In", styleTransferButton)) { tmpTransfer.transferState = TransferStateEnum.In; }
                    //    //if (GUILayout.Button("None", styleTransferButton)) { tmpTransfer.transferState = TransferStateEnum.None; }
                    //    Boolean blnTempOut = GUILayout.Toggle(tmpTransfer.transferState == TransferStateEnum.Out, "Out", styleTransferButton);
                    //    Boolean blnTempIn = GUILayout.Toggle(tmpTransfer.transferState == TransferStateEnum.In, "In", styleTransferButton);
                    //    if (blnTempOut && (tmpTransfer.transferState != TransferStateEnum.Out))
                    //    {
                    //        if (mbARP.lstTransfers.Any(x=>x.transferState== TransferStateEnum.In))
                    //            mbARP.lstTransfers.SetStateNone(key);
                    //        else
                    //            mbARP.lstTransfers.SetStateNone(key, TransferStateEnum.Out);

                    //        tmpTransfer.transferState = TransferStateEnum.Out;
                    //    }
                    //    else if (blnTempIn && (tmpTransfer.transferState != TransferStateEnum.In))
                    //    {
                    //        if (mbARP.lstTransfers.Any(x => x.transferState == TransferStateEnum.Out))
                    //            mbARP.lstTransfers.SetStateNone(key);
                    //        else
                    //            mbARP.lstTransfers.SetStateNone(key, TransferStateEnum.In);

                    //        tmpTransfer.transferState = TransferStateEnum.In;
                    //    }
                    //    else if (!blnTempIn && !blnTempOut && (tmpTransfer.transferState != TransferStateEnum.None))
                    //        tmpTransfer.transferState = TransferStateEnum.None;
                    //}
                    GUILayout.EndHorizontal();
                }

                i++;
            }
        }