Esempio n. 1
0
        public static Texture2D CombineTextures(Texture2D aBaseTexture, Texture2D aToCopyTexture)
        {
            GravityTurner.Log("CombineTextures");
            Texture2D baseTexture = ReadTexture(aBaseTexture);

            if (baseTexture == null)
            {
                GravityTurner.Log("read texture failed");
                return(aBaseTexture);
            }

            int       aWidth         = aBaseTexture.width;
            int       aHeight        = aBaseTexture.height;
            Texture2D aReturnTexture = new Texture2D(aWidth, aHeight, TextureFormat.RGBA32, false);

            GravityTurner.Log("create arrays {0}:{1} {2}", aWidth.ToString(), aHeight.ToString(), aToCopyTexture.width);
            Color[] aBaseTexturePixels = baseTexture.GetPixels();
            Color[] aCopyTexturePixels = aToCopyTexture.GetPixels();
            Color[] aColorList         = new Color[aBaseTexturePixels.Length];
            int     aPixelLength       = aBaseTexturePixels.Length;

            for (int p = 0; p < aPixelLength; p++)
            {
                aColorList[p] = Color.Lerp(aBaseTexturePixels[p], aCopyTexturePixels[p], aCopyTexturePixels[p].a);
            }

            GravityTurner.Log("SetPixels");
            aReturnTexture.SetPixels(aColorList);
            aReturnTexture.Apply(false);

            return(aReturnTexture);
        }
Esempio n. 2
0
        public static Texture2D ReadTexture(Texture2D texture)
        {
            GravityTurner.Log("ReadTexture");
            // Create a temporary RenderTexture of the same size as the texture
            RenderTexture tmp = RenderTexture.GetTemporary(
                texture.width,
                texture.height,
                0,
                RenderTextureFormat.Default,
                RenderTextureReadWrite.Linear);

            GravityTurner.Log("  Blit");
            // Blit the pixels on texture to the RenderTexture
            Graphics.Blit(texture, tmp);
            // Backup the currently set RenderTexture
            RenderTexture previous = RenderTexture.active;

            // Set the current RenderTexture to the temporary one we created
            RenderTexture.active = tmp;
            // Create a new readable Texture2D to copy the pixels to it
            Texture2D myTexture2D = new Texture2D(texture.width, texture.width);

            // Copy the pixels from the RenderTexture to the new Texture
            GravityTurner.Log("  Readpixels");
            myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
            myTexture2D.Apply();
            // Reset the active RenderTexture
            RenderTexture.active = previous;
            // Release the temporary RenderTexture
            GravityTurner.Log("  Release");
            RenderTexture.ReleaseTemporary(tmp);

            // "myTexture2D" now has the same pixels from "texture" and it's readable.
            return(myTexture2D);
        }
Esempio n. 3
0
 public HelpWindow(GravityTurner inTurner, int inWindowID)
     : base(inTurner, inWindowID)
 {
     WindowTitle    = "GravityTurn Help";
     windowPos.left = Screen.width - (windowPos.width + 40);
     windowPos.top  = 30;
 }
Esempio n. 4
0
 public StatsWindow(GravityTurner turner, int WindowID)
     : base(turner, WindowID)
 {
     WindowTitle      = "GravityTurn Statistics Window";
     windowPos.height = 200;
     windowPos.width  = 310;
 }
Esempio n. 5
0
 public MainWindow(GravityTurner inTurner, int inWindowID)
     : base(inTurner,inWindowID)
 {
     turner = inTurner;
     helpWindow = new HelpWindow(inTurner,inWindowID+1);
     stagesettings = new StageSettings(inTurner, inWindowID + 2,helpWindow);
 }
Esempio n. 6
0
 public StageSettings(GravityTurner turner, int WindowID, HelpWindow inhelpWindow)
     : base(turner, WindowID)
 {
     helpWindow      = inhelpWindow;
     WindowTitle     = "GravityTurn Stage & Cache Settings";
     windowPos.width = 300;
 }
Esempio n. 7
0
 public FlightMapWindow(GravityTurner turner, int inWindowID, int width = 800, int height = 400)
     : base(turner, inWindowID)
 {
     windowPos   = new Rect(Screen.width / 2 - width / 2, 100, width, height);
     flightMap   = new FlightMap(turner, width, height);
     WindowTitle = "FlightMap";
 }
Esempio n. 8
0
 public FlightMapWindow(GravityTurner turner, int inWindowID, int width = 800, int height = 400)
     : base(turner, inWindowID)
 {
     windowPos = new Rect(Screen.width / 2 - width / 2, 100, width, height);
     flightMap = new FlightMap(turner, width, height);
     WindowTitle = "FlightMap";
 }
Esempio n. 9
0
 public BaseWindow(GravityTurner turner, int inWindowID)
 {
     this.turner = turner;
     turner.windowManager.Register(this);
     WindowID = inWindowID;
     filename = IOUtils.GetFilePathFor(turner.GetType(), string.Format("gt_window_{0}.cfg", WindowID));
     Load();
 }
Esempio n. 10
0
        public MainWindow(GravityTurner inTurner, int inWindowID)
            : base(inTurner, inWindowID)
        {
            turner           = inTurner;
            helpWindow       = new HelpWindow(inTurner, inWindowID + 1);
            stagesettings    = new StageSettings(inTurner, inWindowID + 2, helpWindow);
            windowPos.width  = 300;
            windowPos.height = 100;
            Version v = typeof(GravityTurner).Assembly.GetName().Version;

            WindowTitle = String.Format("GravityTurn V {0}.{1}.{2}", v.Major, v.Minor, v.Build);
        }
Esempio n. 11
0
 public void Load()
 {
     try
     {
         ConfigNode root = ConfigNode.Load(filename);
         if (root != null)
         {
             ConfigNode.LoadObjectFromConfig(this, root);
         }
     }
     catch (Exception ex)
     {
         GravityTurner.Log("Window Load error {0}", ex.ToString());
     }
 }
Esempio n. 12
0
        public MainWindow(GravityTurner inTurner, int inWindowID)
            : base(inTurner, inWindowID)
        {
            turner        = inTurner;
            helpWindow    = new HelpWindow(inTurner, inWindowID + 1);
            stagesettings = new StageSettings(inTurner, inWindowID + 2, helpWindow);

            windowPos.width  = 300;
            windowPos.height = 100;
            windowPos.left   = Screen.width - (windowPos.width + 40);
            windowPos.top    = 30;
            Version v = typeof(GravityTurner).Assembly.GetName().Version;

            WindowTitle = String.Format("GravityTurn");
        }
Esempio n. 13
0
 public BaseWindow(GravityTurner turner, int inWindowID)
 {
     this.turner = turner;
     turner.windowManager.Register(this);
     WindowID = inWindowID;
     filename = LaunchDB.GetBaseFilePath(turner.GetType(), string.Format("gt_window_{0}.cfg", WindowID));
     Load();
     if (windowPos.left + windowPos.width > Screen.width)
     {
         windowPos.left = Screen.width - windowPos.width;
     }
     if (windowPos.top + windowPos.height > Screen.height)
     {
         windowPos.top = Screen.height - windowPos.height;
     }
     if (windowPos.top < 0)
     {
         windowPos.top = 0;
     }
 }
Esempio n. 14
0
 public StageSettings(GravityTurner turner, int WindowID, HelpWindow inhelpWindow)
     : base(turner, WindowID)
 {
     helpWindow = inhelpWindow;
     WindowTitle = "GravityTurn Stage Settings";
 }
Esempio n. 15
0
        public override void WindowGUI(int windowID)
        {
            base.WindowGUI(windowID);
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            ItemLabel("Fairing Pressure");
            turner.FairingPressure.setValue(GUILayout.TextField(string.Format("{0:0}", turner.FairingPressure), GUILayout.Width(60)));
            turner.FairingPressure.locked = GuiUtils.LockToggle(turner.FairingPressure.locked);
            helpWindow.Button("Dynamic pressure where we pop the procedural fairings.  Higher values will pop lower in the atmosphere, which saves weight, but can cause overheating.  Fairings are heavy, so it's definitely a good idea to pop them as soon as possible.");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            ItemLabel("Stage Post Delay");
            turner.autostagePostDelay.setValue(GUILayout.TextField(string.Format("{0:0}", turner.autostagePostDelay), GUILayout.Width(60)));
            turner.autostagePostDelay.locked = GuiUtils.LockToggle(turner.autostagePostDelay.locked);
            helpWindow.Button("Delay after a stage event before we consider the next stage.");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            ItemLabel("Stage Pre Delay");
            turner.autostagePreDelay.setValue(GUILayout.TextField(string.Format("{0:0}", turner.autostagePreDelay), GUILayout.Width(60)));
            turner.autostagePreDelay.locked = GuiUtils.LockToggle(turner.autostagePreDelay.locked);
            helpWindow.Button("Delay after running out of fuel before we activate the next stage.");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            ItemLabel("Stage Limit");
            turner.autostageLimit.setValue(GUILayout.TextField(string.Format("{0:0}", turner.autostageLimit), GUILayout.Width(60)));
            turner.autostageLimit.locked = GuiUtils.LockToggle(turner.autostageLimit.locked);
            helpWindow.Button("Stop at this stage number");
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Clear Cache", GUILayout.Width(90)))
            {
                // Need to clear the cache directory
                // gt_launchdb*
                // gt_vessel*

                foreach (string f in Directory.EnumerateFiles(LaunchDB.GetBaseFilePath(this.GetType(), ""), "gt_vessel_*"))
                {
                    File.Delete(f);
                }
                foreach (string f in Directory.EnumerateFiles(LaunchDB.GetBaseFilePath(this.GetType(), ""), "gt_launchdb"))
                {
                    File.Delete(f);
                }
            }
#if false
            if (!turner.IsLaunchDBEmpty())
            {
                if (GUILayout.Button("Reset Guess", GUILayout.ExpandWidth(false)))
                {
                    if (File.Exists(GravityTurner.ConfigFilename(GravityTurner.getVessel)))
                    {
                        File.Delete(GravityTurner.ConfigFilename(GravityTurner.getVessel));
                    }

                    if (File.Exists(turner.launchdb.GetFilename()))
                    {
                        File.Delete(turner.launchdb.GetFilename());
                    }
                    turner.ClearLaunchDB();
                }
            }
#endif
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
Esempio n. 16
0
        public override void WindowGUI(int windowID)
        {
            base.WindowGUI(windowID);
            if (!WindowVisible && turner.toolbarControl.enabled)
            {
                turner.toolbarControl.SetFalse(false);
                turner.SaveParameters();
            }
            GUILayout.BeginVertical();
            UiStartSpeed();
            UiTurnAngle();
            UiAPTimeStart();
            UiAPTimeFinish();
            UiSensitivity();
            UiDestinationHeight();
            UiRoll();
            UiInclination();
            UiPressureCutoff();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Setup", GUILayout.ExpandWidth(false)))
            {
                stagesettings.WindowVisible = !stagesettings.WindowVisible;
                stagesettings.InitPos();
            }

            turner.EnableStageManager = GUILayout.Toggle(turner.EnableStageManager, "Auto Stage");
            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.Label("   ");
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.FlexibleSpace();
            }
            turner.EnableSpeedup = GUILayout.Toggle(turner.EnableSpeedup, "Use Timewarp");

            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.Label("            ");
                GUILayout.FlexibleSpace();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            turner.flightMapWindow.WindowVisible = GUILayout.Toggle(turner.flightMapWindow.WindowVisible, "Show Launch Map", GUILayout.ExpandWidth(false));
            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.Label("   ");
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.FlexibleSpace();
            }
            turner.EnableStats = GUILayout.Toggle(turner.EnableStats, "Show Stats", GUILayout.ExpandWidth(false));
            if (HighLogic.CurrentGame.Parameters.CustomParams <GT>().useStock)
            {
                GUILayout.FlexibleSpace();
            }

            if (turner.statsWindow.WindowVisible != turner.EnableStats)
            {
                turner.statsWindow.WindowVisible = turner.EnableStats;
                turner.statsWindow.Save();
                if (!turner.statsWindow.WindowVisible)
                {
                    turner.statsWindow.windowPos.height = 200;
                    GravityTurner.DebugShow             = false;
                }
                else
                {
                    turner.statsWindow.InitPos();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            // when not landed and not launching we are in orbit. allow to save.
            if (!GravityTurner.getVessel.Landed && !turner.Launching)
            {
                if (turner.program >= GravityTurner.AscentProgram.InCircularisation)
                {
                    GUILayout.Label("Launch success! ", GUILayout.ExpandWidth(false));
                }

                if (GUILayout.Button(GuiUtils.saveIcon, GUILayout.ExpandWidth(false), GUILayout.MinWidth(18), GUILayout.MinHeight(21)))
                {
                    turner.SaveDefaultParameters();
                }
            }
            else
            {
                GUILayout.Label(string.Format("{0}, time to match: {1:0.0} s", GetAscentPhaseString(turner.program), turner.HoldAPTime), GUILayout.ExpandWidth(false));
            }
            GUILayout.EndHorizontal();

            // landed, not launched yet. Allow configuration
            if (GravityTurner.getVessel.Landed && !turner.Launching)
            {
                GUILayout.BeginHorizontal();
                string guess = turner.IsLaunchDBEmpty() ? "First Guess" : "Improve Guess";
                if (GUILayout.Button(guess, GUILayout.ExpandWidth(false)))
                {
                    turner.CalculateSettings(GravityTurner.getVessel);
                }

                if (!turner.IsLaunchDBEmpty() && GUILayout.Button("Previous Best", GUILayout.ExpandWidth(false)))
                {
                    turner.CalculateSettings(GravityTurner.getVessel, true);
                }

                if (GUILayout.Button("C", GUILayout.ExpandWidth(false)))
                {
                    if (File.Exists(GravityTurner.ConfigFilename(GravityTurner.getVessel)))
                    {
                        File.Delete(GravityTurner.ConfigFilename(GravityTurner.getVessel));
                    }

                    if (File.Exists(turner.launchdb.GetFilename()))
                    {
                        File.Delete(turner.launchdb.GetFilename());
                    }
                    turner.ClearLaunchDB();
                }


                helpWindow.Button("Improve Guess will try to extrapolate the best settings based on previous launches.  This may end in fiery death, but it won't happen the same way twice.  Be warned, sometimes launches get worse before they get better.  But they do get better.  To reset, click the <bold>C</bold> button");
                if (GUILayout.Button(GuiUtils.saveIcon, GUILayout.ExpandWidth(false), GUILayout.MinWidth(18), GUILayout.MinHeight(21)))
                {
                    turner.SaveDefaultParameters();
                }
                GUILayout.EndHorizontal();
            }
            // while landed, show launch button
            if (GravityTurner.getVessel.Landed && !turner.Launching && GUILayout.Button("Launch!", GUILayout.ExpandWidth(true), GUILayout.MinHeight(30)))
            {
                Debug.Log("Launch button pressed again");
                turner.Launch();
            }
            // while launching, show launch button
            if (turner.Launching && GUILayout.Button("Abort!", GUILayout.MinHeight(30)))
            {
                turner.Kill();
                turner.RecordAbortedLaunch();
            }
#if DEBUG
            // GUILayout.Label(GravityTurner.DebugMessage, GUILayout.ExpandWidth(true), GUILayout.MinHeight(200));
#endif

            GUILayout.EndVertical();
            double StopHeight = GravityTurner.getVessel.mainBody.atmosphereDepth;
            if (StopHeight <= 0)
            {
                StopHeight = turner.DestinationHeight * 1000;
            }
            turner.HoldAPTime = turner.APTimeStart + ((float)GravityTurner.getVessel.altitude / (float)StopHeight * (turner.APTimeFinish - turner.APTimeStart));
            if (turner.HoldAPTime > Math.Max(turner.APTimeFinish, turner.APTimeStart))
            {
                turner.HoldAPTime = Math.Max(turner.APTimeFinish, turner.APTimeStart);
            }
            if (turner.HoldAPTime < Math.Min(turner.APTimeFinish, turner.APTimeStart))
            {
                turner.HoldAPTime = Math.Min(turner.APTimeFinish, turner.APTimeStart);
            }
            Rect  r         = GUILayoutUtility.GetLastRect();
            float minHeight = r.height + r.yMin + 10;
            if (windowPos.height != minHeight && minHeight > 20)
            {
                windowPos.height = minHeight;
                Save();
            }
            GUI.DragWindow();
        }
Esempio n. 17
0
 public StageSettings(GravityTurner turner, int WindowID, HelpWindow inhelpWindow)
     : base(turner, WindowID)
 {
     helpWindow  = inhelpWindow;
     WindowTitle = "GravityTurn Stage Settings";
 }
Esempio n. 18
0
 public HelpWindow(GravityTurner inTurner, int inWindowID)
     : base(inTurner,inWindowID)
 {
     WindowTitle = "GravityTurn Help";
 }
Esempio n. 19
0
 public HelpWindow(GravityTurner inTurner, int inWindowID)
     : base(inTurner, inWindowID)
 {
     WindowTitle = "GravityTurn Help";
 }