public void TimeWarpWindow(int id)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

            scrollPos = GUILayout.BeginScrollView(scrollPos);

            editToggle = GUILayout.Toggle(editToggle, "Create", skin.button);
            selected   = GUILayout.SelectionGrid(selected, names, 1, smallButtonStyle);

            currentRates = customWarps.Find(r => r.Name == names[selected] ||
                                            (names[selected].Contains("<") && names[selected].Split('<', '>')[2] == r.Name)
                                            );

            if (currentRates == null)
            {
                currentRates = StandardWarp;
            }

            GUILayout.EndScrollView();

            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            scrollPos2 = GUILayout.BeginScrollView(scrollPos2);

            if (editToggle)
            {
                bool canExport = true;

                GUILayout.BeginVertical(GUILayout.ExpandHeight(true));

                warpName = GUILayout.TextField(warpName);
                for (int i = 1; i < 8; i++)
                {
                    if (i < 4 || !physics)
                    {
                        w[i] = GUILayout.TextField(w[i]);
                    }
                }
#if false
                w1 = GUILayout.TextField(w1);
                w2 = GUILayout.TextField(w2);
                w3 = GUILayout.TextField(w3);
                if (!physics)
                {
                    w4 = GUILayout.TextField(w4);
                    w5 = GUILayout.TextField(w5);
                    w6 = GUILayout.TextField(w6);
                    w7 = GUILayout.TextField(w7);
                }
#endif
                physics = GUILayout.Toggle(physics, "Physics Warp?");

                GUILayout.EndVertical();

                if (GUILayout.Button("Save"))
                {
                    float[] rates;
                    if (physics)
                    {
                        rates = new float[4];
                    }
                    else
                    {
                        rates = new float[8];
                    }

                    rates[0] = 1f;

                    float pw;
                    for (int i = 1; i < 8; i++)
                    {
                        if (i < 4 || !physics)
                        {
                            if (float.TryParse(w[i], out pw))
                            {
                                rates[i] = pw;
                            }
                            else
                            {
                                canExport = false;
                            }
                        }
                    }
#if false
                    float pw1;
                    if (float.TryParse(w1, out pw1))
                    {
                        rates[1] = pw1;
                    }
                    else
                    {
                        canExport = false;
                    }
                    float pw2;
                    if (float.TryParse(w2, out pw2))
                    {
                        rates[2] = pw2;
                    }
                    else
                    {
                        canExport = false;
                    }
                    float pw3;
                    if (float.TryParse(w3, out pw3))
                    {
                        rates[3] = pw3;
                    }
                    else
                    {
                        canExport = false;
                    }
                    if (!physics)
                    {
                        float pw4;
                        if (float.TryParse(w4, out pw4))
                        {
                            rates[4] = pw4;
                        }
                        else
                        {
                            canExport = false;
                        }
                        float pw5;
                        if (float.TryParse(w5, out pw5))
                        {
                            rates[5] = pw5;
                        }
                        else
                        {
                            canExport = false;
                        }
                        float pw6;
                        if (float.TryParse(w6, out pw6))
                        {
                            rates[6] = pw6;
                        }
                        else
                        {
                            canExport = false;
                        }
                        float pw7;
                        if (float.TryParse(w7, out pw7))
                        {
                            rates[7] = pw7;
                        }
                        else
                        {
                            canExport = false;
                        }
                    }
#endif
                    if (canExport)
                    {
                        TimeWarpRates timeWarpRates = new TimeWarpRates(warpName, rates, physics);
                        customWarps.Add(timeWarpRates);
                        SaveCustomWarpRates();
                        editToggle = false;
                        //SetWarpRates (timeWarpRates);
                        warpName = "Name";
                        physics  = false;
                        InitW();
#if false
                        w[1] = "10";
                        w[2] = "100";
                        w[3] = "1000";
                        w[4] = "10000";
                        w[5] = "100000";
                        w[6] = "1000000";
                        w[7] = "10000000";
#endif
                    }
                    else
                    {
                        //PopupDialog.SpawnPopupDialog (new MultiOptionDialog("Cannot save because there are non-numbers in the editing fields", "Error", null), false, null);
                        var dialog = new MultiOptionDialog("btw1", "Cannot save because there are non-numbers in the editing fields", "Error", HighLogic.UISkin, new DialogGUIBase[] {
                            new DialogGUIButton("OK", () => { })
                        });
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, true);
                    }
                    //save the settings, so if they have been regenerated, it exsists and wont cause errors
                    BetterTimeWarp.SettingsNode.Save(BetterTimeWarpInitializer.BTW_CFG_FILE);
                }
                if (GUILayout.Button("Cancel", smallButtonStyle))
                {
                    editToggle = false;
                    warpName   = "Name";
                    physics    = false;
                    InitW();
#if false
                    w[1] = "10";
                    w[2] = "100";
                    w[3] = "1000";
                    w[4] = "10000";
                    w[5] = "100000";
                    w[6] = "1000000";
                    w[7] = "10000000";
#endif
                }
            }
            else
            {
                GUILayout.BeginVertical(GUILayout.ExpandHeight(true));
                for (int i = 1; i <= 8; i++)
                {
                    if (i <= 4 || !currentRates.Physics)
                    {
                        var f = currentRates.Rates[i - 1];
                        GUILayout.Label("<b><color=lime>" + i.ToString() + ":</color></b> <color=white>" + f.ToString(TimeWarpRates.rateFmt(f)) + "x</color>");
                    }
                }
#if false
                GUILayout.Label("<b><color=lime>1:</color></b> <color=white>" + currentRates.Rates[0].ToString(TimeWarpRates.rateFmt(currentRates.Rates[0]) + "x</color>");
                                GUILayout.Label("<b><color=lime>2:</color></b> <color=white>" + currentRates.Rates[1].ToString("N0") + "x</color>");
                                GUILayout.Label("<b><color=lime>3:</color></b> <color=white>" + currentRates.Rates[2].ToString("N0") + "x</color>");
                                GUILayout.Label("<b><color=lime>4:</color></b> <color=white>" + currentRates.Rates[3].ToString("N0") + "x</color>");
                                if (!currentRates.Physics)
                {
                    GUILayout.Label("<b><color=lime>5:</color></b> <color=white>" + currentRates.Rates[4].ToString("N0") + "x</color>");
                    GUILayout.Label("<b><color=lime>6:</color></b> <color=white>" + currentRates.Rates[5].ToString("N0") + "x</color>");
                    GUILayout.Label("<b><color=lime>7:</color></b> <color=white>" + currentRates.Rates[6].ToString("N0") + "x</color>");
                    GUILayout.Label("<b><color=lime>8:</color></b> <color=white>" + currentRates.Rates[7].ToString("N0") + "x</color>");
                }
#endif
                GUILayout.EndVertical();

                GUILayout.Space(15f);
                if (GUILayout.Button("Select"))
                {
                    SetWarpRates(currentRates);
                }
                if (currentRates != StandardWarp && currentRates != StandardPhysWarp && GUILayout.Button("Edit", smallButtonStyle))
                {
                    if (currentRates != StandardWarp && currentRates != StandardPhysWarp)
                    {
                        if (!currentRates.Physics)
                        {
                            SetWarpRates(StandardWarp, false);
                        }
                        else
                        {
                            SetWarpRates(StandardPhysWarp, false);
                        }
                        customWarps.Remove(currentRates);
                        editToggle = true;
                        warpName   = currentRates.Name;
                        physics    = currentRates.Physics;

                        for (int i = 1; i < 8; i++)
                        {
                            if (i < 4 || !physics)
                            {
                                w[i] = currentRates.Rates[i].ToString(TimeWarpRates.rateFmt(currentRates.Rates[i]));
                            }
                        }
#if false
                        w1 = currentRates.Rates[1].ToString(TimeWarpRates.rateFmt(currentRates.Rates[1]));
                        w2 = currentRates.Rates[2].ToString(TimeWarpRates.rateFmt(currentRates.Rates[2]));
                        w3 = currentRates.Rates[3].ToString(TimeWarpRates.rateFmt(currentRates.Rates[3]));
                        if (!physics)
                        {
                            w4 = currentRates.Rates[4].ToString(TimeWarpRates.rateFmt(currentRates.Rates[4]));
                            w5 = currentRates.Rates[5].ToString(TimeWarpRates.rateFmt(currentRates.Rates[5]));
                            w6 = currentRates.Rates[6].ToString(TimeWarpRates.rateFmt(currentRates.Rates[6]));
                            w7 = currentRates.Rates[7].ToString(TimeWarpRates.rateFmt(currentRates.Rates[7]));
                        }
#endif
                        selected = 0;
                    }
                    else
                    {
                        //PopupDialog.SpawnPopupDialog (new MultiOptionDialog("Cannot edit standard warp rates", "Better Time Warp", null), true, null);

                        var dialog = new MultiOptionDialog("btw2", "Cannot edit standard warp rates", "Better Time Warp", HighLogic.UISkin, new DialogGUIBase[] {
                            new DialogGUIButton("OK", () => { })
                        });
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, true);
                    }
                }
                if (currentRates != StandardWarp && currentRates != StandardPhysWarp && GUILayout.Button("Delete", smallButtonStyle))
                {
                    if (currentRates != StandardWarp && currentRates != StandardPhysWarp)
                    {
                        customWarps.Remove(currentRates);
                        selected = 0;
                        SaveCustomWarpRates();
                        //	PopupDialog.SpawnPopupDialog (new MultiOptionDialog("Deleted " + currentRates.Name + " time warp rates", "Better Time Warp", null), true, null);



                        var dialog = new MultiOptionDialog("btw3", "Deleted " + currentRates.Name + " time warp rates", "Better Time Warp", HighLogic.UISkin, new DialogGUIBase[] {
                            new DialogGUIButton("OK", () => {
                                // winState = winContent.close;
                            })
                        });
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, true);
                        // winState = winContent.dialog;



                        SetWarpRates(StandardWarp, false);
                    }
                    else
                    {
                        //PopupDialog.SpawnPopupDialog (new MultiOptionDialog("Cannot delete standard warp rates", "Better Time Warp", null), true, null);

                        var dialog = new MultiOptionDialog("btw4", "Cannot delete standard warp rates", "Better Time Warp", HighLogic.UISkin, new DialogGUIBase[] {
                            new DialogGUIButton("OK", () => { })
                        });
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, true);
                    }
                }
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Simple", GUILayout.ExpandWidth(true)))
            {
                advWindowOpen = false;
            }
            showPhysicsSettings = GUILayout.Toggle(showPhysicsSettings, "<color=lime>Physics Settings</color>", skin.button, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            if (!lockWindow())
            {
                GUI.DragWindow();
            }
        }
        private void SaveCustomWarpRates()
        {
            if (!SettingsNode.HasNode("BetterTimeWarp"))
            {
                SettingsNode.AddNode("BetterTimeWarp");
            }

            ConfigNode node = SettingsNode.GetNode("BetterTimeWarp");

            node.SetValue("ScaleCameraSpeed", ScaleCameraSpeed.ToString(), true);
            node.SetValue("UseLosslessPhysics", UseLosslessPhysics.ToString(), true);
            node.SetValue("LosslessUpperThreshold", LosslessUpperThreshold.ToString(), true);

            node.RemoveNodes("CustomWarpRate");
            foreach (var rates in customWarps)
            {
                if (rates != StandardWarp && rates != StandardPhysWarp)
                {
                    ConfigNode rateNode = new ConfigNode("CustomWarpRate");
                    rateNode.AddValue("name", rates.Name);
                    for (int i = 1; i < 8; i++)
                    {
                        if (i < 4 || !rates.Physics)
                        {
                            rateNode.AddValue("warpRate" + i.ToString(), rates.Rates[i].ToString(TimeWarpRates.rateFmt(rates.Rates[i])));
                        }
                    }
#if false
                    rateNode.AddValue("warpRate1", rates.Rates[1]);
                    rateNode.AddValue("warpRate2", rates.Rates[2]);
                    rateNode.AddValue("warpRate3", rates.Rates[3]);
                    if (!rates.Physics)
                    {
                        rateNode.AddValue("warpRate4", rates.Rates[4]);
                        rateNode.AddValue("warpRate5", rates.Rates[5]);
                        rateNode.AddValue("warpRate6", rates.Rates[6]);
                        rateNode.AddValue("warpRate7", rates.Rates[7]);
                    }
#endif
                    rateNode.AddValue("physics", rates.Physics);
                    node.AddNode(rateNode);
                }
            }

            if (CurrentWarp == null)
            {
                CurrentWarp = StandardWarp;
                Log.Info("CurrentWarp set to StandardWarp  3");
            }
            if (CurrentPhysWarp == null)
            {
                CurrentPhysWarp = StandardPhysWarp;
            }

            node.SetValue("CurrentTimeWarp", CurrentWarp.Name, true);
            node.SetValue("CurrentPhysWarp", CurrentPhysWarp.Name, true);
        }