Exemple #1
0
        void DrawRegular(IMyTextSurface surface, ScreenData data)
        {
            Color background = surface.ScriptBackgroundColor;
            Color foreground = surface.ScriptForegroundColor;
            Color white      = new Color(230, 230, 230);
            //Color gray0 = new Color(200, 200, 200);
            Color gray1   = new Color(130, 130, 130);
            Color gray2   = new Color(15, 15, 15);
            Color darken  = new Color(50, 50, 50, 200);
            Color darken2 = new Color(0, 0, 0, 150);

            white = foreground;
            var hsv = ColorExtensions.ColorToHSV(foreground);

            hsv.Y *= 0.6f;
            hsv.Z *= 0.6f;
            gray1  = ColorExtensions.HSVtoColor(hsv);

            //Canvas canvas = new Canvas((surface.TextureSize - surface.TextureSize * 1f) * 0.5f, surface.TextureSize * 1f);
            Canvas canvas = new Canvas((surface.TextureSize - Vec(surface.SurfaceSize.Y * 1f)) * 0.5f, Vec(surface.SurfaceSize.Y * 1f));

            //if (background.ColorToHSV().Z < 0.01)
            //{
            //	white = new Color(230, 230, 230);
            //	darken = new Color(200, 200, 200, 10);
            //	darken2 = new Color(200, 200, 200, 20);
            //	gray0 = new Color(50, 50, 50);
            //	gray1 = new Color(25, 25, 25);
            //}

            using (var frame = surface.DrawFrame())
            {
                //Inner circle
                frame.Add(canvas.Circle(Vec(0, 0), Vec(0.95f), darken));
                frame.Add(canvas.Rect(Vec(0, -0.136f), Vec(0.95f, 0.9f), background));
                frame.Add(canvas.CircleHollow(Vec(0, 0), Vec(1f), gray2));
                frame.Add(canvas.CircleHollow(Vec(0, 0), Vec(0.95f), gray1));



                //Right progress bg
                frame.Add(canvas.Rect(Vec(0.3f, 0), Vec(0.055f, 0.3f), darken));
                frame.Add(canvas.Progress(Vec(0.3f, 0), Vec(0.3f, 0.055f), Color.Orange, data.thrustOverrideH2, rotation: 4.71239f));
                frame.Add(canvas.TriangleRight(Vec(0.3f, -0.13f), Vec(0.06f, 0.04f), background, rotation: MathHelper.ToRadians(180)));
                frame.Add(canvas.TriangleRight(Vec(0.3f, 0.13f), Vec(0.04f, 0.06f), background, rotation: MathHelper.ToRadians(-90)));
                frame.Add(canvas.Rect(Vec(0.3f, 0), Vec(0.06f, 0.008f), background));



                //Left progress bg
                frame.Add(canvas.Rect(Vec(-0.3f, 0), Vec(0.055f, 0.3f), darken));
                frame.Add(canvas.Progress(Vec(-0.3f, 0), Vec(0.3f, 0.055f), Color.Blue, data.thrustOverridePW, rotation: 4.71239f));
                frame.Add(canvas.TriangleRight(Vec(-0.3f, -0.13f), Vec(0.04f, 0.06f), background, rotation: MathHelper.ToRadians(90)));
                frame.Add(canvas.TriangleRight(Vec(-0.3f, 0.13f), Vec(0.06f, 0.04f), background));
                frame.Add(canvas.Rect(Vec(0 - .3f, 0), Vec(0.06f, 0.008f), background));


                //Icons
                frame.Add(canvas.Sprite("IconHydrogen", Vec(0.3f, -0.2f), Vec(0.08f, 0.08f), white, Anchor.Center));
                frame.Add(canvas.Sprite("IconEnergy", Vec(-0.3f, -0.2f), Vec(0.1f, 0.1f), white, Anchor.Center));

                //Thrust text
                frame.Add(canvas.Text((data.cruiseEnabled ? string.Format("{0:0%}", data.thrustOverrideH2) : ""), Vec(0.30f, 0.185f), 0.08f, white));
                frame.Add(canvas.Text((data.cruiseEnabled ? string.Format("{0:0%}", data.thrustOverridePW) : ""), Vec(-0.30f, 0.185f), 0.08f, white));



                //Speedometer
                double speedAngle = ((Math.Abs(data.targetSpeed) / data.maxSpeed) * 4.71238898) + 0.785398163;
                frame.Add(canvas.Triangle(Vec(0, 0), Vec(0.04f), gray2, rotation: (float)speedAngle, offset: Vec(0, 0.46f)));

                speedAngle = ((Math.Abs(data.speed) / data.maxSpeed) * 4.71238898) + 0.785398163;                 //percent * 270 degrees + 45 degrees offset.
                frame.Add(canvas.Rect(Vec(0, 0), Vec(0.01f, 0.1f), white, rotation: (float)speedAngle, offset: Vec(0, 0.435f)));



                //Speedometer ticks
                frame.Add(canvas.Triangle(Vec(0, 0), Vec(0.01f, 0.06f), white, rotation: (float)Math.PI, offset: Vec(0, 0.468f)));
                frame.Add(canvas.Triangle(Vec(0, 0), Vec(0.01f, 0.06f), white, rotation: (float)Math.PI * 0.625f, offset: Vec(0, 0.468f)));
                frame.Add(canvas.Triangle(Vec(0, 0), Vec(0.01f, 0.06f), white, rotation: (float)Math.PI * 0.25f, offset: Vec(0, 0.468f)));

                frame.Add(canvas.Triangle(Vec(0, 0), Vec(0.01f, 0.06f), white, rotation: (float)Math.PI * -0.625f, offset: Vec(0, 0.468f)));
                frame.Add(canvas.Triangle(Vec(0, -0), Vec(0.01f, 0.06f), white, rotation: (float)Math.PI * -0.25f, offset: Vec(0, 0.468f)));



                frame.Add(canvas.Text(data.speed.ToString("n0"), Vec(0, -0.20f), 0.16f, white));
                frame.Add(canvas.Text($"[{data.targetSpeed.ToString("n0")}]", Vec(0, -0.09f), 0.14f, white));
                frame.Add(canvas.Text("m/s", Vec(0, 0), 0.1f, gray1));

                //frame.Add(canvas.Rect(Vec(-0.15f, 0.20f), Vec(0.01f, 0.16f), darken2));
                //frame.Add(canvas.Rect(Vec(0.15f, 0.20f), Vec(0.01f, 0.16f), darken2));


                frame.Add(canvas.Text("Cruise", Vec(0, 0.15f), 0.1f, gray1));
                frame.Add(canvas.Text("Align", Vec(0, 0.25f), 0.1f, gray1));

                if (data.cruiseEnabled)
                {
                    frame.Add(canvas.Rect(Vec(-0.15f, 0.15f), Vec(0.02f, 0.06f), Color.Green));
                }
                else
                {
                    frame.Add(canvas.Rect(Vec(-0.15f, 0.15f), Vec(0.02f, 0.06f), Color.Red));
                }

                if (data.alignEnabled)
                {
                    frame.Add(canvas.Rect(Vec(-0.15f, 0.25f), Vec(0.02f, 0.06f), Color.Green));
                }
                else
                {
                    frame.Add(canvas.Rect(Vec(-0.15f, 0.25f), Vec(0.02f, 0.06f), Color.Red));
                }

                //Create angle on indicators
                frame.Add(canvas.Triangle(Vec(-0.13f, 0.10f), Vec(0.08f), background, rotation: 1.57079633f));
                frame.Add(canvas.Triangle(Vec(-0.13f, 0.20f), Vec(0.08f), background, rotation: 1.57079633f));
                frame.Add(canvas.TriangleRight(Vec(-0.13f, 0.284f), Vec(0.08f, 0.04f), background));



                //Arrow max
                //frame.Add(canvas.Rect(Vec(0, -0.392f), Vec(0.02f), gray1, Anchor.Center));
                frame.Add(canvas.Triangle(Vec(0, -0.41f), Vec(0.04f, 0.06f), gray1, Anchor.Center));
                frame.Add(canvas.Rect(Vec(0, -0.426f), Vec(0.04f, 0.01f), gray1, Anchor.Center));

                //Arrow min
                //frame.Add(canvas.Rect(Vec(0, 0.392f), Vec(0.02f), gray1, Anchor.Center));
                frame.Add(canvas.Triangle(Vec(0, 0.41f), Vec(0.04f, 0.06f), gray1, Anchor.Center, rotation: (float)Math.PI));
                frame.Add(canvas.Rect(Vec(0, 0.426f), Vec(0.04f, 0.01f), gray1, Anchor.Center));

                //Max alt text
                if (data.maxAlt == double.MaxValue)
                {
                    frame.Add(canvas.Text("--", Vec(0, -0.35f), 0.07f, gray1));
                }
                else
                {
                    frame.Add(canvas.Text(data.maxAlt.ToString("n0") + "m", Vec(0, -0.35f), 0.07f, gray1));
                }
                frame.Add(canvas.Text(data.minAlt.ToString("n1") + "m", Vec(0, 0.35f), 0.07f, gray1));
            }
        }
        public static SerializableVector3 ToSandboxHsvColor(this System.Windows.Media.Color color)
        {
            var vColor = ColorExtensions.ColorToHSV(new Color(color.R, color.G, color.B));

            return(new SerializableVector3(vColor.X, vColor.Y * 2f - 1f, vColor.Z * 2f - 1f));
        }
Exemple #3
0
 /// <summary>
 /// Byte RGB to game's color mask (0-1/-1-1/-1-1).
 /// </summary>
 public static Vector3 RGBToColorMask(Color rgb)
 {
     return(HSVToColorMask(ColorExtensions.ColorToHSV(rgb)));
 }