Пример #1
0
        IEnumerator MonitorThread()
        {
            WaitForSeconds wfs = new WaitForSeconds(0.2f);

            Int32 intRate = TimeWarp.fetch.warpRates.Length - 1;

            while (intRate > 0 && (TimeWarp.fetch.warpRates[intRate]) > TimeWarp.CurrentRate)
            {
                intRate -= 1;
            }

            while (intRate >= 0)
            {
                TimeWarp.fetch.Mode = TimeWarp.Modes.HIGH;
                //Make sure we cancel autowarp if its engaged
                TimeWarp.fetch.CancelAutoWarp();
                TimeWarp.SetRate(intRate, false);

                float SecondsTillNextUpdate;
                float dWarpRate = 1;
                if (TimeWarp.fetch != null)
                {
                    dWarpRate = TimeWarp.CurrentRate;
                }
                SecondsTillNextUpdate = UpdateInterval * intRate;

                yield return(new WaitForSeconds(SecondsTillNextUpdate));

                intRate--;
            }
            JumpAndBackup.JumpToVessel(vessel);
            Destroy(this);
        }
Пример #2
0
        void ShowResourceGUIWindow(int windowId)
        {
            //Main.WIDTH = 583;
            Main.WIDTH = 613;

            previewWidth = 70;

            if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().altSkin)
            {
                Main.WIDTH -= 10;
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().compact)
            {
                Main.WIDTH -= 10;
            }

            int resourceWidth = 120;

            if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useIconsOnly)
            {
                resourceWidth = 38;
                Main.WIDTH    = Main.WIDTH - 120 + 38; // (120 - 38) ;
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useIconsAndText)
            {
                Main.WIDTH    += 40;
                resourceWidth += 40;
            }
            // Following to avoid flickering when moving the window with certain options specified
            if (Main.WIDTH + 40 != oldWidth)
            {
                oldWidth = Main.WIDTH + 40;
                ResourceAlertWindow.windowPosition.width = oldWidth;
            }
            toDel = null;
            Main.textFieldStyle.normal.textColor = Color.green;
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (HaystackWrapper.HaystackAvailable && HighLogic.CurrentGame.Parameters.CustomParams <RM_1>().useHaystackIfAvailable)
                {
                    GUILayout.BeginHorizontal(); // GUILayout.Width(Main.WIDTH));
                                                 // GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Haystack", btnStyle, GUILayout.Width(120)))
                    {
                        HaystackWrapper.ButtonClick();
                    }
                    GUILayout.FlexibleSpace();
                    if (HaystackWrapper.IsVisible)
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Get Vessel From Haystack", btnStyle, GUILayout.Width(240)))
                        {
                            Main.Log.Info("GetVesselFromHaystack");
                            if (HaystackWrapper.SelectedVessel != null)
                            {
                                Main.Log.Info("Vessel name: " + HaystackWrapper.SelectedVessel.vesselName);
                                JumpAndBackup.JumpToVessel(HaystackWrapper.SelectedVessel);
                            }
                        }
                    }
                    //GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal(); // GUILayout.Width(Main.WIDTH));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Common Resource Monitor Definition");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            var b = GUILayout.Toggle(Main.common, "Only allow common resources for new monitors", toggleStyle);

            if (b != Main.common)
            {
                Main.common = b;
                GetResourceList();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(); // GUILayout.Width(Main.WIDTH));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add Resource Monitor", btnStyle))
            {
                workingRMD.Add(new ResourceMonitorDef("ElectricCharge", "Alarm1", 5f, 1));

                resourceIndex = workingRMD.Count - 1; //sets index to last one
            }
            if (workingRMD.Count == 0 && HighLogic.LoadedSceneIsFlight)
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Apply Common Resource Monitor Settings", btnStyle))
                {
                    AddCommonResourceMonitors();
                    resourceIndex = workingRMD.Count - 1; //sets index to last one
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(25);
            if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useIconsOnly)
            {
                GUILayout.Label("Res", GUILayout.Width(resourceWidth));
            }
            else
            {
                GUILayout.Label("Resource", GUILayout.Width(resourceWidth));
            }
            GUILayout.Space(25);
            GUILayout.Label("Alarm Sound", GUILayout.Width(120));


            //GUILayout.Space(30);
            //GUILayout.Space(15);
            //GUILayout.Space(30);

            GUILayout.Space(75);
            GUILayout.Label("Amt or % ");
            //GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Width(Main.WIDTH + 20));

            for (int i = 0; i < workingRMD.Count; i++)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(Main.WIDTH + 20));
                resourceAlert = workingRMD[i];
                if (resourceAlert.Enabled)
                {
                    Main.buttonStyle.normal.textColor    = Color.green;
                    Main.toggleStyle.normal.textColor    = Color.green;
                    Main.textFieldStyle.normal.textColor = Color.green;
                }
                else
                {
                    Main.buttonStyle.normal.textColor    = Color.red;
                    Main.toggleStyle.normal.textColor    = Color.red;
                    Main.textFieldStyle.normal.textColor = Color.red;
                }
                int curResource = -1;


                // ****************************************************************************
                //                                                                            *
                GUIContent btn = null;

                if (!HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useTextOnly&& Main.icons.ContainsKey(resourceAlert.resname))
                {
                    if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useIconsOnly)
                    {
                        btn = new GUIContent(Main.icons[resourceAlert.resname]);
                    }
                    if (HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().useIconsAndText)
                    {
                        btn = new GUIContent(PartResourceLibrary.Instance.resourceDefinitions[resourceAlert.resname].displayName,
                                             Main.icons[resourceAlert.resname]);
                    }
                }
                else
                {
                    btn = new GUIContent(PartResourceLibrary.Instance.resourceDefinitions[resourceAlert.resname].displayName);
                }


                if (GUILayout.Button(btn, btnStyle, GUILayout.Width(resourceWidth)))
                {
                    resourceSelectionWindow = !resourceSelectionWindow;
                    if (resourceSelectionWindow)
                    {
                        lastSelectedResource = resourceAlert.resname;
                    }
                }

                GUILayout.Space(10);
                //                                                                            *
                // ****************************************************************************

                // ****************************************************************************
                //                                                                            *
                if (GUILayout.Button(resourceAlert.alarm, btnStyle, GUILayout.Width(120)))
                {
                    soundSelectionWindow = !soundSelectionWindow;
                    if (soundSelectionWindow)
                    {
                        lastSelectedSoundFile = resourceAlert.alarm;
                    }
                }

                GUILayout.Space(10);
                //                                                                            *
                // ****************************************************************************
                if (GUILayout.Button(resourceAlert.monitorHighValue ? ">" : "<", GUILayout.Width(20)))
                {
                    resourceAlert.monitorHighValue = !resourceAlert.monitorHighValue;
                }
                GUILayout.Space(10);
                var newMonitorByPercentage = GUILayout.Toggle(resourceAlert.monitorByPercentage, "", toggleStyle, GUILayout.Width(30));
                //GUILayout.Label("%", labelStyle, GUILayout.Width(20));
                if (newMonitorByPercentage)
                {
                    if (HighLogic.LoadedSceneIsFlight && !resourceAlert.monitorByPercentage)
                    {
                        //if (resourceAlert.percentage == 0 && resourceAlert.minAmt > 0)
                        {
                            var resource = PartResourceLibrary.Instance.GetDefinition(resourceAlert.resname);
                            FlightGlobals.ActiveVessel.rootPart.GetConnectedResourceTotals(resource.id, out double amount, out double maxAmount, true);
                            resourceAlert.percentage = (float)(100f * resourceAlert.minAmt / maxAmount);
                        }
                        resourceAlert.minAmt = 0;
                    }
                    float f = Math.Max(1f, Math.Min(resourceAlert.percentage, 99));

                    f = GUILayout.HorizontalSlider(f, 1f, 99f, horSliderStyle, thumbStyle, GUILayout.Width(100));
                    resourceAlert.percentage = (int)f;
                    string p = f.ToString("F0") + "%";
                    GUILayout.Label(p, GUILayout.Width(30));
                }
                else
                {
                    var labelStyleAmt = new GUIStyle(labelStyle);
                    labelStyleAmt.alignment = TextAnchor.MiddleRight;
                    GUILayout.Label("Amt:", labelStyleAmt, GUILayout.Width(40));
                    if (HighLogic.LoadedSceneIsFlight && resourceAlert.monitorByPercentage)
                    {
                        if (!newMonitorByPercentage && resourceAlert.percentage > 0 && resourceAlert.minAmt == 0)
                        {
                            var resource = PartResourceLibrary.Instance.GetDefinition(resourceAlert.resname);
                            FlightGlobals.ActiveVessel.rootPart.GetConnectedResourceTotals(resource.id, out double amount, out double maxAmount, true);
                            resourceAlert.minAmt = resourceAlert.percentage / 100f * maxAmount;
                        }
                        resourceAlert.percentage = 0;
                    }
                    string f = resourceAlert.minAmt.ToString("F1");
                    f = GUILayout.TextField(f, textFieldStyle, GUILayout.Width(90));
                    if (double.TryParse(f, out double d))
                    {
                        resourceAlert.minAmt = Math.Max(0.1, d);
                    }
                }
                resourceAlert.monitorByPercentage = newMonitorByPercentage;
                resourceAlert.Enabled             = GUILayout.Toggle(resourceAlert.Enabled, "", toggleStyle, GUILayout.Width(30));
                GUILayout.Space(5);
                //if (HighLogic.CurrentGame.Parameters.CustomParams<AlertMonitor>().altSkin)
                //    GUILayout.Space(10);
                if (GUILayout.Button("X", redBtnStyle, GUILayout.Width(23)))
                {
                    toDel = resourceAlert;
                }
                GUILayout.Space(5);
                if (previewSound != curResource || !soundplayer.SoundPlaying())
                {
                    if (GUILayout.Button("Preview", btnStyle, GUILayout.Width(previewWidth)))
                    {
                        previewSound = curResource;
                        Main.Log.Info("Preview: " + Main.SOUND_DIR + resourceAlert.alarm);
                        soundplayer.LoadNewSound(Main.SOUND_DIR + resourceAlert.alarm, HighLogic.CurrentGame.Parameters.CustomParams <RM_1>().resourceAlertRepetition);
                        soundplayer.SetVolume(HighLogic.CurrentGame.Parameters.CustomParams <RM_2>().masterVolume);

                        soundplayer.PlaySound(true); //Plays sound
                    }
                }
                else
                {
                    if (GUILayout.Button("Stop", GUILayout.Width(previewWidth)))
                    {
                        soundplayer.StopSound();
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (toDel != null)
            {
                workingRMD.Remove(toDel);
            }
            GUILayout.BeginHorizontal(); // GUILayout.Width(Main.WIDTH));

            if (HighLogic.LoadedSceneIsFlight)
            {
                if (GUILayout.Button("Close"))
                {
                    SaveSettings();
                    GuiOff();
                    soundSelectionWindow = false;
                }
            }
            else
            {
                if (GUILayout.Button("Save"))
                {
                    SaveSettings();
                    GuiOff();
                    soundSelectionWindow = false;
                }
                if (GUILayout.Button("Cancel"))
                {
                    GuiOff();
                    soundSelectionWindow = false;
                }
            }
            GUILayout.EndHorizontal();
            GUI.DragWindow();
        }