RegisterTexture() static private method

Registeres a texture and returns a handle to the texture.
Be sure not to dispose of the bitmap after calling this function.
static private RegisterTexture ( Bitmap bitmap ) : Texture
bitmap System.Drawing.Bitmap The bitmap that contains the texture.
return Texture
Esempio n. 1
0
        //
        // INIT LOADING RESOURCES
        //
        /// <summary>Initializes the textures used for the loading screen</summary>
        internal static void InitLoading()
        {
            customLoadScreen = false;
            string Path = Program.FileSystem.GetDataFolder("In-game");

            if (TextureLoadingBkg == null)
            {
                int    bkgNo          = Program.RandomNumberGenerator.Next(numOfLoadingBkgs);
                string backgroundFile = OpenBveApi.Path.CombineFile(Path, "loadingbkg_" + bkgNo + ".png");
                if (System.IO.File.Exists(backgroundFile))
                {
                    Textures.RegisterTexture(backgroundFile, out TextureLoadingBkg);
                }
            }
            if (Renderer.TextureLogo == null)
            {
                // choose logo size according to screen width
                string fName;

                /*if (Screen.Width > 2048)		fName	= LogoFileName[2];
                 * else if (Screen.Width > 1024)	fName	= LogoFileName[1];
                 * else							fName	= LogoFileName[0];*/
                fName = "logo.png";
                string logoFile = OpenBveApi.Path.CombineFile(Path, fName);
                if (System.IO.File.Exists(logoFile))
                {
                    Textures.RegisterTexture(logoFile, out TextureLogo);
                }
            }
        }
Esempio n. 2
0
        //
        // INIT LOADING RESOURCES
        //
        /// <summary>Initializes the textures used for the loading screen</summary>
        internal static void InitLoading()
        {
            customLoadScreen = false;
            string Path = Program.FileSystem.GetDataFolder("In-game");

            if (TextureLoadingBkg == null)
            {
                int bkgNo = Program.RandomNumberGenerator.Next(numOfLoadingBkgs);
                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Path, "loadingbkg_" + bkgNo + ".png"),
                                         out TextureLoadingBkg);
            }
            if (Renderer.TextureLogo == null)
            {
                // choose logo size according to screen width
                string fName;
                if (Screen.Width > 2048)
                {
                    fName = LogoFileName[2];
                }
                else if (Screen.Width > 1024)
                {
                    fName = LogoFileName[1];
                }
                else
                {
                    fName = LogoFileName[0];
                }
                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Path, fName), out TextureLogo);
            }
        }
Esempio n. 3
0
            internal void Apply(out ObjectManager.StaticObject Object)
            {
                Object = new ObjectManager.StaticObject();
                if (faces.Count != 0)
                {
                    int mf = Object.Mesh.Faces.Length;
                    int mm = Object.Mesh.Materials.Length;
                    int mv = Object.Mesh.Vertices.Length;
                    Array.Resize(ref Object.Mesh.Faces, mf + faces.Count);
                    Array.Resize(ref Object.Mesh.Materials, mm + materials.Count);
                    Array.Resize(ref Object.Mesh.Vertices, mv + verticies.Count);
                    for (int i = 0; i < verticies.Count; i++)
                    {
                        Object.Mesh.Vertices[mv + i] = new OpenBveApi.Objects.Vertex(verticies[i].Coordinates, verticies[i].TextureCoordinates);
                    }

                    for (int i = 0; i < faces.Count; i++)
                    {
                        Object.Mesh.Faces[i]          = new MeshFace(faces[i].Vertices);
                        Object.Mesh.Faces[i].Material = (ushort)faces[i].Material;
                        for (int k = 0; k < faces[i].Vertices.Length; k++)
                        {
                            Object.Mesh.Faces[i].Vertices[k].Normal = verticies[faces[i].Vertices[k]].Normal;
                        }

                        for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
                        {
                            Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
                        }

                        Object.Mesh.Faces[mf + i].Material += (ushort)mm;
                    }

                    for (int i = 0; i < materials.Count; i++)
                    {
                        Object.Mesh.Materials[mm + i].Flags            = 0;
                        Object.Mesh.Materials[mm + i].Color            = materials[i].Color;
                        Object.Mesh.Materials[mm + i].TransparentColor = Color24.Black;
                        Object.Mesh.Materials[mm + i].BlendMode        = MeshMaterialBlendMode.Normal;
                        if (materials[i].DaytimeTexture != null)
                        {
                            OpenBveApi.Textures.Texture tday;
                            Textures.RegisterTexture(materials[i].DaytimeTexture, out tday);
                            Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
                        }
                        else
                        {
                            Object.Mesh.Materials[mm + i].DaytimeTexture = null;
                        }

                        Object.Mesh.Materials[mm + i].EmissiveColor         = materials[i].EmissiveColor;
                        Object.Mesh.Materials[mm + i].NighttimeTexture      = null;
                        Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
                        Object.Mesh.Materials[mm + i].GlowAttenuationData   = materials[i].GlowAttenuationData;
                        Object.Mesh.Materials[mm + i].WrapMode = materials[i].WrapMode;
                    }
                }
            }
Esempio n. 4
0
        private static void Init()
        {
            Initialized = true;
            string Folder = OpenBveApi.Path.CombineDirectory(Program.FileSystem.GetDataFolder(), "RouteViewer");

            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "background.png"), out BackgroundChangeTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "brightness.png"), out BrightnessChangeTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "transponder.png"), out TransponderTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "section.png"), out SectionTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "limit.png"), out LimitTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "station_start.png"), out StationStartTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "station_end.png"), out StationEndTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "stop.png"), out StopTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "buffer.png"), out BufferTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "sound.png"), out SoundTexture);
            Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "switchsound.png"), out PointSoundTexture);
        }
Esempio n. 5
0
 /// <summary>Registers a texture and returns a handle to the texture.</summary>
 /// <param name="path">The path to the file or folder that contains the texture.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 /// <param name="handle">Receives the handle to the texture.</param>
 /// <returns>Whether loading the texture was successful.</returns>
 public override bool RegisterTexture(string path, TextureParameters parameters, out Texture handle)
 {
     if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
     {
         Texture data;
         if (Textures.RegisterTexture(path, parameters, out data))
         {
             handle = data;
             return(true);
         }
     }
     else
     {
         ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
     }
     handle = null;
     return(false);
 }
Esempio n. 6
0
        //
        // INIT LOADING RESOURCES
        //
        /// <summary>Initializes the textures used for the loading screen</summary>
        internal static void InitLoading()
        {
            customLoadScreen = false;
            string Path  = Program.FileSystem.GetDataFolder("In-game");
            int    bkgNo = Game.Generator.Next(numOfLoadingBkgs);

            if (TextureLoadingBkg == null)
            {
                string file = OpenBveApi.Path.CombineFile(Path, "loadingbkg_" + bkgNo + ".png");
                if (System.IO.File.Exists(file))
                {
                    Textures.RegisterTexture(file, out TextureLoadingBkg);
                }
            }

            // choose logo size according to screen width
            string fName;

            if (Renderer.ScreenWidth > 2048)
            {
                fName = LogoFileName[2];
            }
            else if (Renderer.ScreenWidth > 1024)
            {
                fName = LogoFileName[1];
            }
            else
            {
                fName = LogoFileName[0];
            }

            fName = OpenBveApi.Path.CombineFile(Path, fName);
            if (System.IO.File.Exists(fName))
            {
                if (System.IO.File.Exists(fName))
                {
                    Textures.RegisterTexture(fName, out TextureLogo);
                }
            }
        }
Esempio n. 7
0
 private static void ApplyMeshBuilder(ref ObjectManager.StaticObject Object, MeshBuilder Builder)
 {
     if (Builder.Faces.Count != 0)
     {
         int mf = Object.Mesh.Faces.Length;
         int mm = Object.Mesh.Materials.Length;
         int mv = Object.Mesh.Vertices.Length;
         Array.Resize <World.MeshFace>(ref Object.Mesh.Faces, mf + Builder.Faces.Count);
         if (mm == 0)
         {
             if (Object.Mesh.Materials.Length == 0)
             {
                 /*
                  * If the object has no materials defined at all, we need to add one
                  */
                 Array.Resize(ref Object.Mesh.Materials, 1);
                 Object.Mesh.Materials[0]                  = new World.MeshMaterial();
                 Object.Mesh.Materials[0].Color            = new Color32(255, 255, 255);
                 Object.Mesh.Materials[0].Flags            = (byte)(0 | 0);
                 Object.Mesh.Materials[0].DaytimeTexture   = null;
                 Object.Mesh.Materials[0].NighttimeTexture = null;
                 mm++;
             }
         }
         if (Builder.Materials.Length > 0)
         {
             Array.Resize <World.MeshMaterial>(ref Object.Mesh.Materials, mm + Builder.Materials.Length);
         }
         else
         {
             /*
              * If no materials have been defined for this face group, use the last material
              */
             mm -= 1;
         }
         Array.Resize <VertexTemplate>(ref Object.Mesh.Vertices, mv + Builder.Vertices.Count);
         for (int i = 0; i < Builder.Vertices.Count; i++)
         {
             Object.Mesh.Vertices[mv + i] = new Vertex((Vertex)Builder.Vertices[i]);
         }
         for (int i = 0; i < Builder.Faces.Count; i++)
         {
             Object.Mesh.Faces[mf + i] = Builder.Faces[i];
             for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
             {
                 Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
             }
             Object.Mesh.Faces[mf + i].Material += (ushort)mm;
         }
         for (int i = 0; i < Builder.Materials.Length; i++)
         {
             Object.Mesh.Materials[mm + i].Flags            = (byte)((Builder.Materials[i].EmissiveColorUsed ? World.MeshMaterial.EmissiveColorMask : 0) | (Builder.Materials[i].TransparentColorUsed ? World.MeshMaterial.TransparentColorMask : 0));
             Object.Mesh.Materials[mm + i].Color            = Builder.Materials[i].Color;
             Object.Mesh.Materials[mm + i].TransparentColor = Builder.Materials[i].TransparentColor;
             if (Builder.Materials[i].DaytimeTexture != null)
             {
                 Textures.Texture tday;
                 if (Builder.Materials[i].TransparentColorUsed)
                 {
                     Textures.RegisterTexture(Builder.Materials[i].DaytimeTexture, new OpenBveApi.Textures.TextureParameters(null, new Color24(Builder.Materials[i].TransparentColor.R, Builder.Materials[i].TransparentColor.G, Builder.Materials[i].TransparentColor.B)), out tday);
                 }
                 else
                 {
                     Textures.RegisterTexture(Builder.Materials[i].DaytimeTexture, out tday);
                 }
                 Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
             }
             else
             {
                 Object.Mesh.Materials[mm + i].DaytimeTexture = null;
             }
             Object.Mesh.Materials[mm + i].EmissiveColor = Builder.Materials[i].EmissiveColor;
             if (Builder.Materials[i].NighttimeTexture != null)
             {
                 Textures.Texture tnight;
                 if (Builder.Materials[i].TransparentColorUsed)
                 {
                     Textures.RegisterTexture(Builder.Materials[i].NighttimeTexture, new OpenBveApi.Textures.TextureParameters(null, new Color24(Builder.Materials[i].TransparentColor.R, Builder.Materials[i].TransparentColor.G, Builder.Materials[i].TransparentColor.B)), out tnight);
                 }
                 else
                 {
                     Textures.RegisterTexture(Builder.Materials[i].NighttimeTexture, out tnight);
                 }
                 Object.Mesh.Materials[mm + i].NighttimeTexture = tnight;
             }
             else
             {
                 Object.Mesh.Materials[mm + i].NighttimeTexture = null;
             }
             Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
             Object.Mesh.Materials[mm + i].BlendMode             = Builder.Materials[i].BlendMode;
             Object.Mesh.Materials[mm + i].GlowAttenuationData   = Builder.Materials[i].GlowAttenuationData;
             Object.Mesh.Materials[mm + i].WrapMode = Textures.OpenGlTextureWrapMode.RepeatRepeat;
         }
     }
 }
Esempio n. 8
0
            // --- constructors ---
            /// <summary>Creates a new table of characters.</summary>
            /// <param name="font">The font.</param>
            /// <param name="offset">The offset from codepoint U+0000.</param>
            internal OpenGlFontTable(Font font, int offset)
            {
                /*
                 * Measure characters.
                 * */
                Size[]   physicalSizes    = new Size[256];
                Size[]   typographicSizes = new Size[256];
                Bitmap   bitmap           = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
                Graphics graphics         = Graphics.FromImage(bitmap);

                graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                for (int i = 0; i < 256; i++)
                {
                    SizeF physicalSize    = graphics.MeasureString(char.ConvertFromUtf32(offset + i), font, int.MaxValue, StringFormat.GenericDefault);
                    SizeF typographicSize = graphics.MeasureString(char.ConvertFromUtf32(offset + i), font, int.MaxValue, StringFormat.GenericTypographic);
                    physicalSizes[i]    = new Size((int)Math.Ceiling(physicalSize.Width), (int)Math.Ceiling(physicalSize.Height));
                    typographicSizes[i] = new Size((int)Math.Ceiling(typographicSize.Width == 0.0f ? physicalSize.Width : typographicSize.Width), (int)Math.Ceiling(typographicSize.Height == 0.0f ? physicalSize.Height : typographicSize.Height));
                }

                /*
                 * Find suitable bitmap dimensions.
                 * */
                const int width      = 256;
                const int border     = 1;
                int       x          = border;
                int       y          = border;
                int       lineHeight = 0;

                for (int i = 0; i < 256; i++)
                {
                    if (x + physicalSizes[i].Width + border > width)
                    {
                        x          = border;
                        y         += lineHeight;
                        lineHeight = 0;
                    }
                    else
                    {
                        x += physicalSizes[i].Width + 2 * border;
                    }
                    if (physicalSizes[i].Height + border > lineHeight)
                    {
                        lineHeight = physicalSizes[i].Height + 2 * border;
                    }
                }
                y += lineHeight;
                int height = (int)RoundToPowerOfTwo((uint)y);

                graphics.Dispose();
                bitmap.Dispose();

                /*
                 * Draw character to bitmap.
                 * */
                bitmap   = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                graphics = Graphics.FromImage(bitmap);
                graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                graphics.Clear(Color.Black);
                x               = border;
                y               = border;
                lineHeight      = 0;
                this.Characters = new OpenGlFontChar[256];
                for (int i = 0; i < 256; i++)
                {
                    if (x + physicalSizes[i].Width + border > width)
                    {
                        x          = border;
                        y         += lineHeight;
                        lineHeight = 0;
                    }
                    graphics.DrawString(char.ConvertFromUtf32(offset + i), font, Brushes.White, new PointF(x, y));
                    float x0 = (float)(x - border) / (float)width;
                    float x1 = (float)(x + physicalSizes[i].Width + border) / (float)width;
                    float y0 = (float)(y - border) / (float)height;
                    float y1 = (float)(y + physicalSizes[i].Height + border) / (float)height;
                    this.Characters[i] = new OpenGlFontChar(new RectangleF(x0, y0, x1 - x0, y1 - y0), new Size(physicalSizes[i].Width + 2 * border, physicalSizes[i].Height + 2 * border), typographicSizes[i]);
                    x += physicalSizes[i].Width + 2 * border;
                    if (physicalSizes[i].Height + border > lineHeight)
                    {
                        lineHeight = physicalSizes[i].Height + 2 * border;
                    }
                }
                graphics.Dispose();
                this.Texture = Textures.RegisterTexture(bitmap);
            }
Esempio n. 9
0
 private static void ApplyMeshBuilder(ref ObjectManager.StaticObject Object, MeshBuilder Builder, ObjectManager.ObjectLoadMode LoadMode, bool ForceTextureRepeatX, bool ForceTextureRepeatY)
 {
     if (Builder.Faces.Length != 0)
     {
         int mf = Object.Mesh.Faces.Length;
         int mm = Object.Mesh.Materials.Length;
         int mv = Object.Mesh.Vertices.Length;
         Array.Resize <World.MeshFace>(ref Object.Mesh.Faces, mf + Builder.Faces.Length);
         Array.Resize <World.MeshMaterial>(ref Object.Mesh.Materials, mm + Builder.Materials.Length);
         Array.Resize <World.Vertex>(ref Object.Mesh.Vertices, mv + Builder.Vertices.Length);
         for (int i = 0; i < Builder.Vertices.Length; i++)
         {
             Object.Mesh.Vertices[mv + i] = Builder.Vertices[i];
         }
         for (int i = 0; i < Builder.Faces.Length; i++)
         {
             Object.Mesh.Faces[mf + i] = Builder.Faces[i];
             for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
             {
                 Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
             }
             Object.Mesh.Faces[mf + i].Material += (ushort)mm;
         }
         for (int i = 0; i < Builder.Materials.Length; i++)
         {
             Object.Mesh.Materials[mm + i].Flags            = (byte)((Builder.Materials[i].EmissiveColorUsed ? World.MeshMaterial.EmissiveColorMask : 0) | (Builder.Materials[i].TransparentColorUsed ? World.MeshMaterial.TransparentColorMask : 0));
             Object.Mesh.Materials[mm + i].Color            = Builder.Materials[i].Color;
             Object.Mesh.Materials[mm + i].TransparentColor = Builder.Materials[i].TransparentColor;
             Textures.OpenGlTextureWrapMode WrapX, WrapY;
             if (ForceTextureRepeatX)
             {
                 WrapX = Textures.OpenGlTextureWrapMode.RepeatRepeat;
             }
             else
             {
                 WrapX = Textures.OpenGlTextureWrapMode.ClampClamp;
             }
             if (ForceTextureRepeatY)
             {
                 WrapY = Textures.OpenGlTextureWrapMode.RepeatRepeat;
             }
             else
             {
                 WrapY = Textures.OpenGlTextureWrapMode.ClampClamp;
             }
             if (WrapX != Textures.OpenGlTextureWrapMode.RepeatRepeat | WrapY != Textures.OpenGlTextureWrapMode.RepeatRepeat)
             {
                 for (int j = 0; j < Builder.Vertices.Length; j++)
                 {
                     if (Builder.Vertices[j].TextureCoordinates.X <0.0 | Builder.Vertices[j].TextureCoordinates.X> 1.0)
                     {
                         WrapX = Textures.OpenGlTextureWrapMode.RepeatRepeat;
                     }
                     if (Builder.Vertices[j].TextureCoordinates.Y <0.0 | Builder.Vertices[j].TextureCoordinates.Y> 1.0)
                     {
                         WrapY = Textures.OpenGlTextureWrapMode.RepeatRepeat;
                     }
                 }
             }
             if (Builder.Materials[i].DaytimeTexture != null)
             {
                 Textures.Texture tday;
                 if (Builder.Materials[i].TransparencyTexture != null)
                 {
                     Bitmap Main = new Bitmap(Builder.Materials[i].DaytimeTexture);
                     Main = ResizeImage(Main, Main.Size.Width, Main.Size.Height);
                     Bitmap Alpha = new Bitmap(Builder.Materials[i].TransparencyTexture);
                     if (Alpha.Size != Main.Size)
                     {
                         Alpha = ResizeImage(Alpha, Main.Size.Width, Main.Size.Height);
                     }
                     Bitmap texture = MergeAlphaBitmap(Main, Alpha);
                     //Dispose of both main and alpha
                     Main.Dispose();
                     Alpha.Dispose();
                     tday = Textures.RegisterTexture(texture);
                 }
                 else
                 {
                     Textures.RegisterTexture(Builder.Materials[i].DaytimeTexture, new TextureParameters(null, Builder.Materials[i].TransparentColor), out tday);
                 }
                 Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
             }
             else
             {
                 Object.Mesh.Materials[mm + i].DaytimeTexture = null;
             }
             Object.Mesh.Materials[mm + i].EmissiveColor = Builder.Materials[i].EmissiveColor;
             if (Builder.Materials[i].NighttimeTexture != null)
             {
                 Textures.Texture tnight;
                 Textures.RegisterTexture(Builder.Materials[i].NighttimeTexture, new TextureParameters(null, Builder.Materials[i].TransparentColor), out tnight);
                 Object.Mesh.Materials[mm + i].DaytimeTexture = tnight;
             }
             else
             {
                 Object.Mesh.Materials[mm + i].NighttimeTexture = null;
             }
             Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
             Object.Mesh.Materials[mm + i].BlendMode             = Builder.Materials[i].BlendMode;
             Object.Mesh.Materials[mm + i].GlowAttenuationData   = Builder.Materials[i].GlowAttenuationData;
         }
     }
 }
Esempio n. 10
0
 /// <summary>Registers a texture and returns a handle to the texture.</summary>
 /// <param name="texture">The texture data.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 /// <param name="handle">Receives the handle to the texture.</param>
 /// <returns>Whether loading the texture was successful.</returns>
 public override bool RegisterTexture(Texture texture, TextureParameters parameters, out Texture handle)
 {
     texture = texture.ApplyParameters(parameters);
     handle  = Textures.RegisterTexture(texture);
     return(true);
 }
Esempio n. 11
0
 //
 // SET CUSTOM LOADING SCREEN BACKGROUND
 //
 /// <summary>Sets the loading screen background to a custom image</summary>
 internal static void SetLoadingBkg(string fileName)
 {
     Textures.RegisterTexture(fileName, out TextureLoadingBkg);
     customLoadScreen = true;
 }
Esempio n. 12
0
        // render data
        private static void RenderData(ref Table Table)
        {
            // prepare timetable
            int   w = 384, h = 192;
            int   offsetx           = 0;
            int   actualheight      = h;
            float descriptionwidth  = 256;
            float descriptionheight = 16;
            float stationnamewidth  = 16;

            for (int k = 0; k < 2; k++)
            {
                Bitmap   b = new Bitmap(w, h);
                Graphics g = Graphics.FromImage(b);
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                g.Clear(Color.Transparent);
                g.FillRectangle(Brushes.White, new RectangleF(offsetx, 0, w, actualheight));
                Font f   = new Font(FontFamily.GenericSansSerif, 13.0f, GraphicsUnit.Pixel);
                Font fs  = new Font(FontFamily.GenericSansSerif, 11.0f, GraphicsUnit.Pixel);
                Font fss = new Font(FontFamily.GenericSansSerif, 9.0f, GraphicsUnit.Pixel);
                // draw timetable
                string t; SizeF s;
                // description
                float x0 = offsetx + 8;
                float y0 = 8;
                if (k == 1)
                {
                    t = DefaultTimetableDescription;
                    g.DrawString(t, f, Brushes.Black, new RectangleF(x0, 6, descriptionwidth, descriptionheight + 8));
                    y0 += descriptionheight + 2;
                }
                // highest speed
                t = Translations.GetInterfaceString("timetable_highestspeed");
                s = g.MeasureString(t, fs);
                g.DrawString(t, fs, Brushes.Black, x0, y0);
                float y0a = y0 + s.Height + 2;
                float x1  = x0 + s.Width + 4;
                for (int i = 0; i < Table.Tracks.Length; i++)
                {
                    float y = y0a + 18 * i;
                    t = Table.Tracks[i].Speed;
                    g.DrawString(t, f, Brushes.Black, x0, y);
                    s = g.MeasureString(t, f);
                    float x = x0 + s.Width + 4;
                    if (x > x1)
                    {
                        x1 = x;
                    }
                }
                g.DrawLine(Pens.LightGray, new PointF(x1 - 2, 4 + descriptionheight), new PointF(x1 - 2, y0a + 18 * Table.Tracks.Length - 1));
                // driving time
                t = Translations.GetInterfaceString("timetable_drivingtime");
                s = g.MeasureString(t, fs);
                g.DrawString(t, fs, Brushes.Black, x1, y0);
                float x2 = x1 + s.Width + 4;
                for (int i = 0; i < Table.Tracks.Length; i++)
                {
                    float y = y0a + 18 * i;
                    if (Table.Tracks[i].Time.Hour.Length != 0)
                    {
                        t = Table.Tracks[i].Time.Hour;
                        g.DrawString(t, fss, Brushes.Black, x1, y + 2);
                    }
                    else
                    {
                        t = "0";
                    }
                    s = g.MeasureString(t, fss, 9999, StringFormat.GenericTypographic);
                    float x = x1 + s.Width - 1;
                    if (Table.Tracks[i].Time.Minute.Length != 0)
                    {
                        t = Table.Tracks[i].Time.Minute;
                        g.DrawString(t, fs, Brushes.Black, x, y + 2);
                    }
                    else
                    {
                        t = "00:";
                    }
                    s  = g.MeasureString(t, fs, 9999, StringFormat.GenericTypographic);
                    x += s.Width + 1;
                    t  = Table.Tracks[i].Time.Second;
                    g.DrawString(t, fss, Brushes.Black, x, y + 2);
                    s  = g.MeasureString(t, fss, 9999, StringFormat.GenericTypographic);
                    x += s.Width + 8;
                    if (x > x2)
                    {
                        x2 = x;
                    }
                }
                for (int i = 0; i < Table.Tracks.Length; i++)
                {
                    float y = y0a + 18 * i;
                    g.DrawLine(Pens.LightGray, new PointF(offsetx + 4, y - 1), new PointF(x2 - 2, y - 1));
                }
                g.DrawLine(Pens.LightGray, new PointF(x2 - 2, 4 + descriptionheight), new PointF(x2 - 2, y0a + 18 * Table.Tracks.Length - 1));
                // station name
                float y2 = y0;
                t = Translations.GetInterfaceString("timetable_stationname");
                s = g.MeasureString(t, f);
                g.DrawString(t, f, Brushes.Black, x2, y2);
                float x3 = x2 + s.Width + 4;
                for (int i = 0; i < Table.Stations.Length; i++)
                {
                    float y = y0 + 18 * (i + 1) + 2;
                    g.DrawLine(Pens.LightGray, new PointF(x2 - 2, y - 1), new PointF(w - 4, y - 1));
                    t = Table.Stations[i].Name;
                    if (Table.Stations[i].NameJapanese & Table.Stations[i].Name.Length > 1)
                    {
                        float[] sizes     = new float[t.Length];
                        float   totalsize = 0.0f;
                        for (int j = 0; j < t.Length; j++)
                        {
                            sizes[j]   = g.MeasureString(new string(t[j], 1), f, 9999, StringFormat.GenericTypographic).Width;
                            totalsize += sizes[j];
                        }
                        float space = (stationnamewidth - totalsize) / (float)(t.Length - 1);
                        float x     = 0.0f;
                        for (int j = 0; j < t.Length; j++)
                        {
                            g.DrawString(new string(t[j], 1), f, Brushes.Black, x2 + x, y);
                            x += sizes[j] + space;
                        }
                    }
                    else
                    {
                        g.DrawString(t, f, Brushes.Black, x2, y);
                    }
                    s = g.MeasureString(t, f);
                    {
                        float x = x2 + s.Width + 4;
                        if (x > x3)
                        {
                            x3 = x;
                        }
                    }
                }
                g.DrawLine(Pens.LightGray, new PointF(x3 - 2, 4 + descriptionheight), new PointF(x3 - 2, y0 + 18 * (Table.Stations.Length + 1)));
                if (k == 0)
                {
                    stationnamewidth = x3 - x2 - 6;
                }
                // arrival time
                t = Translations.GetInterfaceString("timetable_arrivaltime");
                s = g.MeasureString(t, f);
                g.DrawString(t, f, Brushes.Black, x3, y2);
                float x4 = x3 + s.Width + 4;
                for (int i = 0; i < Table.Stations.Length; i++)
                {
                    float y = y0 + 18 * (i + 1) + 2;
                    if (Table.Stations[i].Pass)
                    {
                        t = "00";
                        s = g.MeasureString(t, fs);
                        float x = x3 + s.Width;
                        t = "   ↓";
                        g.DrawString(t, f, Brushes.Black, x, y);
                        s  = g.MeasureString(t, f);
                        x += +s.Width + 4;
                        if (x > x4)
                        {
                            x4 = x;
                        }
                    }
                    else
                    {
                        if (Table.Stations[i].Arrival.Hour.Length != 0)
                        {
                            t = Table.Stations[i].Arrival.Hour;
                            g.DrawString(t, fs, Brushes.Black, x3, y);
                        }
                        else
                        {
                            t = "00";
                        }
                        s = g.MeasureString(t, fs);
                        float x = x3 + s.Width;
                        if (Table.Stations[i].Arrival.Minute.Length != 0 & Table.Stations[i].Arrival.Second.Length != 0)
                        {
                            t = Table.Stations[i].Arrival.Minute + ":" + Table.Stations[i].Arrival.Second;
                        }
                        else
                        {
                            t = "";
                        }
                        g.DrawString(t, f, Brushes.Black, x, y);
                        s  = g.MeasureString(t, f);
                        x += s.Width + 4;
                        if (x > x4)
                        {
                            x4 = x;
                        }
                    }
                }
                g.DrawLine(Pens.LightGray, new PointF(x4 - 2, 4 + descriptionheight), new PointF(x4 - 2, y0 + 18 * (Table.Stations.Length + 1)));
                // departure time
                t = Translations.GetInterfaceString("timetable_departuretime");
                s = g.MeasureString(t, f);
                g.DrawString(t, f, Brushes.Black, x4, y2);
                float x5 = x4 + s.Width + 4;
                for (int i = 0; i < Table.Stations.Length; i++)
                {
                    float y = y0 + 18 * (i + 1) + 2;
                    if (Table.Stations[i].Terminal)
                    {
                        t = "00";
                        s = g.MeasureString(t, fs);
                        float       x  = x4 + s.Width;
                        const float c0 = 4;
                        const float c1 = 32;
                        g.DrawLine(Pens.Black, new PointF(x + c0, y + 6), new PointF(x + c1, y + 6));
                        g.DrawLine(Pens.Black, new PointF(x + c0, y + 10), new PointF(x + c1, y + 10));
                        x += c1 + 4;
                        if (x > x5)
                        {
                            x5 = x;
                        }
                    }
                    else
                    {
                        if (Table.Stations[i].Departure.Hour.Length != 0)
                        {
                            t = Table.Stations[i].Departure.Hour;
                            g.DrawString(t, fs, Brushes.Black, x4, y);
                        }
                        else
                        {
                            t = "00";
                        }
                        s = g.MeasureString(t, fs);
                        float x = x4 + s.Width;
                        if (Table.Stations[i].Departure.Minute.Length != 0 & Table.Stations[i].Departure.Second.Length != 0)
                        {
                            t = Table.Stations[i].Departure.Minute + ":" + Table.Stations[i].Departure.Second;
                        }
                        else
                        {
                            t = "";
                        }
                        g.DrawString(t, f, Brushes.Black, x, y);
                        s  = g.MeasureString(t, f);
                        x += s.Width + 4;
                        if (x > x5)
                        {
                            x5 = x;
                        }
                    }
                }
                for (int i = 0; i < Table.Stations.Length; i++)
                {
                    float y = y0 + 18 * (i + 1) + 2;
                    g.DrawLine(Pens.LightGray, new PointF(x2 - 2, y - 1), new PointF(w - 4, y - 1));
                }
                // border
                if (k == 1)
                {
                    g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4), new PointF(offsetx + 4, y0a + 18 * Table.Tracks.Length - 1));
                    g.DrawLine(Pens.Black, new PointF(offsetx + 4, y0a + 18 * Table.Tracks.Length - 1), new PointF(x2 - 2, y0a + 18 * Table.Tracks.Length - 1));
                    g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4), new PointF(w - 4, 4));
                    g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4 + descriptionheight), new PointF(w - 4, 4 + descriptionheight));
                    g.DrawLine(Pens.Black, new PointF(x2 - 2, y0 + 18 * (Table.Stations.Length + 1)), new PointF(w - 4, y0 + 18 * (Table.Stations.Length + 1)));
                    g.DrawLine(Pens.Black, new PointF(w - 4, 4), new PointF(w - 4, y0 + 18 * (Table.Stations.Length + 1)));
                    g.DrawLine(Pens.Black, new PointF(x2 - 2, y0a + 18 * Table.Tracks.Length - 1), new PointF(x2 - 2, y0 + 18 * (Table.Stations.Length + 1)));
                }
                // measure
                w = (int)Math.Ceiling((double)(x5 + 1));
                h = (int)Math.Ceiling((double)(y0 + 18 * (Table.Stations.Length + 1) + 4));
                // description
                if (k == 0)
                {
                    t = DefaultTimetableDescription;
                    s = g.MeasureString(t, f, w - 16);
                    descriptionwidth  = s.Width;
                    descriptionheight = s.Height + 2;
                    h += (int)Math.Ceiling((double)s.Height) + 4;
                }
                // finish
                if (k == 0)
                {
                    // measures
                    int nw = Textures.RoundUpToPowerOfTwo(w);
                    offsetx      = nw - w;
                    w            = nw;
                    actualheight = h;
                    h            = Textures.RoundUpToPowerOfTwo(h);
                }
                else
                {
                    // create texture
                    g.Dispose();
                    DefaultTimetableTexture = Textures.RegisterTexture(b);
                }
            }
        }
Esempio n. 13
0
        internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
        {
            double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0);

            switch (e.Key)
            {
            case Key.ShiftLeft:
            case Key.ShiftRight:
                ShiftPressed = true;
                break;

            case Key.ControlLeft:
            case Key.ControlRight:
                ControlPressed = true;
                break;

            case Key.LAlt:
            case Key.RAlt:
                AltPressed = true;
                break;

            case Key.F5:
                if (CurrentRoute != null && CurrentlyLoading == false)
                {
                    Bitmap bitmap = null;
                    CurrentlyLoading         = true;
                    Renderer.OptionInterface = false;
                    if (!Interface.CurrentOptions.LoadingBackground)
                    {
                        Renderer.RenderScene(0.0);
                        currentGameWindow.SwapBuffers();
                        bitmap = new Bitmap(Renderer.ScreenWidth, Renderer.ScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        BitmapData bData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                        GL.ReadPixels(0, 0, Renderer.ScreenWidth, Renderer.ScreenHeight, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0);
                        bitmap.UnlockBits(bData);
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        Renderer.TextureLoadingBkg = Textures.RegisterTexture(bitmap, new TextureParameters(null, null));
                    }
                    World.CameraAlignment a = World.CameraCurrentAlignment;
                    if (LoadRoute())
                    {
                        World.CameraCurrentAlignment = a;
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
                        World.CameraAlignmentDirection = new World.CameraAlignment();
                        World.CameraAlignmentSpeed     = new World.CameraAlignment();
                        ObjectManager.UpdateVisibility(a.TrackPosition, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    }

                    CurrentlyLoading         = false;
                    Renderer.OptionInterface = true;
                    Textures.UnloadTexture(Renderer.TextureLoadingBkg);
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                }
                break;

            case Key.F7:
                if (CurrentlyLoading == true)
                {
                    break;
                }
                OpenFileDialog Dialog = new OpenFileDialog();
                Dialog.CheckFileExists = true;
                Dialog.Filter          = @"CSV/RW files|*.csv;*.rw|All files|*";
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    CurrentlyLoading = true;
                    CurrentRoute     = Dialog.FileName;
                    LoadRoute();
                    ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    CurrentlyLoading = false;
                    UpdateCaption();
                }
                else
                {
                    if (Program.CurrentlyRunOnMono)
                    {
                        //HACK: Dialog doesn't close properly when pressing the ESC key under Mono
                        //Avoid calling Application.DoEvents() unless absolutely necessary though!
                        Application.DoEvents();
                    }
                }
                Dialog.Dispose();
                break;

            case Key.F8:
                if (Program.CurrentlyLoading == true)
                {
                    //Don't allow the user to update the settings during loading, bad idea....
                    break;
                }
                if (formOptions.ShowOptions() == DialogResult.OK)
                {
                    UpdateGraphicsSettings();
                }
                Application.DoEvents();
                break;

            case Key.F9:
                if (Interface.MessageCount != 0)
                {
                    formMessages.ShowMessages();
                    Application.DoEvents();
                }
                break;

            case Key.F10:
                Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
                break;

            case Key.A:
            case Key.Keypad4:
                World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad2:
                World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad8:
                World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Left:
                World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Right:
                World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Up:
                World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Down:
                World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadDivide:
                World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadMultiply:
                World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad0:
                World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadPeriod:
                World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad1:
                Game.ApplyPointOfInterest(-1, true);
                CpuReducedMode = false;
                break;

            case Key.Keypad7:
                Game.ApplyPointOfInterest(1, true);
                CpuReducedMode = false;
                break;

            case Key.PageUp:
                JumpToStation(1);
                CpuReducedMode = false;
                break;

            case Key.PageDown:
                JumpToStation(-1);
                CpuReducedMode = false;
                break;

            case Key.Keypad5:
                World.CameraCurrentAlignment.Yaw      = 0.0;
                World.CameraCurrentAlignment.Pitch    = 0.0;
                World.CameraCurrentAlignment.Roll     = 0.0;
                World.CameraCurrentAlignment.Position = new Vector3(0.0, 2.5, 0.0);
                World.CameraCurrentAlignment.Zoom     = 0.0;
                World.CameraAlignmentDirection        = new World.CameraAlignment();
                World.CameraAlignmentSpeed            = new World.CameraAlignment();
                World.VerticalViewingAngle            = World.OriginalVerticalViewingAngle;
                UpdateViewport();
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                CpuReducedMode = false;
                break;

            case Key.F:
                Renderer.OptionWireframe = !Renderer.OptionWireframe;
                CpuReducedMode           = false;
                if (Renderer.OptionWireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                }
                else
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                }
                break;

            case Key.N:
                Renderer.OptionNormals = !Renderer.OptionNormals;
                CpuReducedMode         = false;
                break;

            case Key.E:
                Renderer.OptionEvents = !Renderer.OptionEvents;
                CpuReducedMode        = false;
                break;

            case Key.C:
                CpuAutomaticMode = !CpuAutomaticMode;
                CpuReducedMode   = false;
                break;

            case Key.I:
                Renderer.OptionInterface = !Renderer.OptionInterface;
                CpuReducedMode           = false;
                break;

            case Key.M:
                //SoundManager.Mute = !SoundManager.Mute;
                break;

            case Key.Plus:
            case Key.KeypadPlus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "+";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Minus:
            case Key.KeypadMinus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "-";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Number0:
            case Key.Number1:
            case Key.Number2:
            case Key.Number3:
            case Key.Number4:
            case Key.Number5:
            case Key.Number6:
            case Key.Number7:
            case Key.Number8:
            case Key.Number9:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = string.Empty;
                }
                JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0);
                CpuReducedMode       = false;
                break;

            case Key.Period:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "0.";
                }
                else if (JumpToPositionValue.IndexOf('.') == -1)
                {
                    JumpToPositionValue += ".";
                }
                CpuReducedMode = false;
                break;

            case Key.BackSpace:
                if (JumpToPositionEnabled && JumpToPositionValue.Length != 0)
                {
                    JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1);
                    CpuReducedMode      = false;
                }
                break;

            case Key.Enter:
                if (JumpToPositionEnabled)
                {
                    if (JumpToPositionValue.Length != 0)
                    {
                        int direction;
                        if (JumpToPositionValue[0] == '-')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = -1;
                        }
                        else if (JumpToPositionValue[0] == '+')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = 1;
                        }
                        else
                        {
                            direction = 0;
                        }
                        double value;
                        if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture,
                                            out value))
                        {
                            if (value < TrackManager.CurrentTrack.Elements[TrackManager.CurrentTrack.Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100)
                            {
                                if (direction != 0)
                                {
                                    value = World.CameraTrackFollower.TrackPosition + (double)direction * value;
                                }
                                TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false);
                                World.CameraCurrentAlignment.TrackPosition = value;
                                World.UpdateAbsoluteCamera(0.0);
                                World.UpdateViewingDistances();
                            }
                        }
                    }
                }
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;

            case Key.Escape:
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;
            }
        }
Esempio n. 14
0
        public static bool ReadMarkerXML(string fileName, ref CsvRwRouteParser.Marker marker)
        {
            //The current XML file to load
            XmlDocument currentXML = new XmlDocument();

            //Load the marker's XML file
            currentXML.Load(fileName);
            string Path = System.IO.Path.GetDirectoryName(fileName);

            if (currentXML.DocumentElement != null)
            {
                bool        iM            = false;
                XmlNodeList DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/TextMarker");

                if (DocumentNodes == null || DocumentNodes.Count == 0)
                {
                    DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/ImageMarker");
                    iM            = true;
                }
                if (DocumentNodes == null || DocumentNodes.Count == 0)
                {
                    Interface.AddMessage(MessageType.Error, false, "No marker nodes defined in XML file " + fileName);
                    return(false);
                }
                //marker = new CsvRwRouteParser.Marker();
                foreach (XmlNode n in DocumentNodes)
                {
                    if (n.ChildNodes.OfType <XmlElement>().Any())
                    {
                        bool     EarlyDefined = false, LateDefined = false;
                        string   EarlyText = null, Text = null, LateText = null;
                        string[] Trains = null;
                        Texture  EarlyTexture = null, Texture = null, LateTexture = null;
                        double   EarlyTime = 0.0, LateTime = 0.0, TimeOut = Double.PositiveInfinity, EndingPosition = Double.PositiveInfinity;
                        OpenBveApi.Colors.MessageColor EarlyColor = MessageColor.White, OnTimeColor = MessageColor.White, LateColor = MessageColor.White;
                        foreach (XmlNode c in n.ChildNodes)
                        {
                            switch (c.Name.ToLowerInvariant())
                            {
                            case "early":
                                if (!c.ChildNodes.OfType <XmlElement>().Any())
                                {
                                    Interface.AddMessage(MessageType.Error, false,
                                                         "No paramaters defined for the early message in " + fileName);
                                }
                                foreach (XmlNode cc in c.ChildNodes)
                                {
                                    switch (cc.Name.ToLowerInvariant())
                                    {
                                    case "text":
                                        EarlyText = cc.InnerText;
                                        break;

                                    case "texture":
                                    case "image":
                                        string f;
                                        try
                                        {
                                            f = OpenBveApi.Path.CombineFile(Path, cc.InnerText);
                                        }
                                        catch
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageEarlyTexture path was malformed in file " + fileName);
                                            break;
                                        }
                                        if (System.IO.File.Exists(f))
                                        {
                                            if (!Textures.RegisterTexture(f, out EarlyTexture))
                                            {
                                                Interface.AddMessage(MessageType.Error, false, "Loading MessageEarlyTexture " + f + " failed.");
                                            }
                                        }
                                        else
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageEarlyTexture " + f + " does not exist.");
                                        }
                                        break;

                                    case "time":
                                        if (!Interface.TryParseTime(cc.InnerText, out EarlyTime))
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "Early message time invalid in " + fileName);
                                        }
                                        EarlyDefined = true;
                                        break;

                                    case "color":
                                        EarlyColor = ParseColor(cc.InnerText, fileName);
                                        break;
                                    }
                                }
                                break;

                            case "ontime":
                                if (!c.ChildNodes.OfType <XmlElement>().Any())
                                {
                                    Interface.AddMessage(MessageType.Error, false,
                                                         "No paramaters defined for the on-time message in " + fileName);
                                }
                                foreach (XmlNode cc in c.ChildNodes)
                                {
                                    switch (cc.Name.ToLowerInvariant())
                                    {
                                    case "text":
                                        Text = cc.InnerText;
                                        break;

                                    case "texture":
                                    case "image":
                                        string f;
                                        try
                                        {
                                            f = OpenBveApi.Path.CombineFile(Path, cc.InnerText);
                                        }
                                        catch
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageTexture path was malformed in file " + fileName);
                                            break;
                                        }
                                        if (System.IO.File.Exists(f))
                                        {
                                            if (!Textures.RegisterTexture(f, out Texture))
                                            {
                                                Interface.AddMessage(MessageType.Error, false, "Loading MessageTexture " + f + " failed.");
                                            }
                                        }
                                        else
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageTexture " + f + " does not exist.");
                                        }
                                        break;

                                    case "color":
                                        OnTimeColor = ParseColor(cc.InnerText, fileName);
                                        break;

                                    case "time":
                                        Interface.AddMessage(MessageType.Error, false, "OnTime should not contain a TIME declaration in " + fileName);
                                        break;
                                    }
                                }
                                break;

                            case "late":
                                if (!c.ChildNodes.OfType <XmlElement>().Any())
                                {
                                    Interface.AddMessage(MessageType.Error, false,
                                                         "No paramaters defined for the late message in " + fileName);
                                }

                                foreach (XmlNode cc in c.ChildNodes)
                                {
                                    switch (cc.Name.ToLowerInvariant())
                                    {
                                    case "text":
                                        LateText = cc.InnerText;
                                        break;

                                    case "texture":
                                    case "image":
                                        string f;
                                        try
                                        {
                                            f = OpenBveApi.Path.CombineFile(Path, cc.InnerText);
                                        }
                                        catch
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageLateTexture path was malformed in file " + fileName);
                                            break;
                                        }
                                        if (System.IO.File.Exists(f))
                                        {
                                            if (!Textures.RegisterTexture(f, out LateTexture))
                                            {
                                                Interface.AddMessage(MessageType.Error, false, "Loading MessageLateTexture " + f + " failed.");
                                            }
                                        }
                                        else
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "MessageLateTexture " + f + " does not exist.");
                                        }
                                        break;

                                    case "time":
                                        if (!Interface.TryParseTime(cc.InnerText, out LateTime))
                                        {
                                            Interface.AddMessage(MessageType.Error, false, "Early message time invalid in " + fileName);
                                        }
                                        LateDefined = true;
                                        break;

                                    case "color":
                                        LateColor = ParseColor(cc.InnerText, fileName);
                                        break;
                                    }
                                }
                                break;

                            case "timeout":
                                if (!NumberFormats.TryParseDouble(c.InnerText, new[] { 1.0 }, out TimeOut))
                                {
                                    Interface.AddMessage(MessageType.Error, false, "Marker timeout invalid in " + fileName);
                                }
                                break;

                            case "distance":
                                if (!NumberFormats.TryParseDouble(c.InnerText, new[] { 1.0 }, out EndingPosition))
                                {
                                    Interface.AddMessage(MessageType.Error, false, "Marker distance invalid in " + fileName);
                                }
                                break;

                            case "trains":
                                Trains = c.InnerText.Split(';');
                                break;
                            }
                        }
                        //Check this marker is valid
                        if (TimeOut == Double.PositiveInfinity && EndingPosition == Double.PositiveInfinity)
                        {
                            Interface.AddMessage(MessageType.Error, false, "No marker timeout or distance defined in marker XML " + fileName);
                            return(false);
                        }
                        if (EndingPosition != Double.PositiveInfinity)
                        {
                            if (Math.Abs(EndingPosition) == EndingPosition)
                            {
                                //Positive
                                marker.EndingPosition = marker.StartingPosition + EndingPosition;
                            }
                            else
                            {
                                //Negative
                                marker.EndingPosition    = marker.StartingPosition;
                                marker.StartingPosition -= EndingPosition;
                            }
                        }
                        MessageManager.TextureMessage t = new MessageManager.TextureMessage();
                        MessageManager.GeneralMessage m = new MessageManager.GeneralMessage();
                        //Add variants

                        if (EarlyDefined)
                        {
                            if (iM)
                            {
                                if (EarlyTexture != null)
                                {
                                    t.MessageEarlyTime    = EarlyTime;
                                    t.MessageEarlyTexture = EarlyTexture;
                                }
                                else
                                {
                                    Interface.AddMessage(MessageType.Warning, false, "An early time was defined, but no message was specified in MarkerXML " + fileName);
                                }
                            }
                            else
                            {
                                if (EarlyText != null)
                                {
                                    m.MessageEarlyTime  = EarlyTime;
                                    m.MessageEarlyText  = EarlyText;
                                    m.MessageEarlyColor = EarlyColor;
                                }
                                else
                                {
                                    Interface.AddMessage(MessageType.Warning, false, "An early time was defined, but no message was specified in MarkerXML " + fileName);
                                }
                            }
                        }
                        if (LateDefined)
                        {
                            if (iM)
                            {
                                if (LateTexture != null)
                                {
                                    t.MessageLateTime    = LateTime;
                                    t.MessageLateTexture = LateTexture;
                                }
                                else
                                {
                                    Interface.AddMessage(MessageType.Warning, false, "A late time was defined, but no message was specified in MarkerXML " + fileName);
                                }
                            }
                            else
                            {
                                if (LateText != null)
                                {
                                    m.MessageLateTime  = LateTime;
                                    m.MessageLateText  = LateText;
                                    m.MessageLateColor = LateColor;
                                }
                                else
                                {
                                    Interface.AddMessage(MessageType.Warning, false, "An early time was defined, but no message was specified in MarkerXML " + fileName);
                                }
                            }
                        }
                        //Final on-time message
                        if (iM)
                        {
                            t.Trains = Trains;
                            if (Texture != null)
                            {
                                t.MessageOnTimeTexture = Texture;
                            }
                        }
                        else
                        {
                            m.Trains = Trains;
                            if (Text != null)
                            {
                                m.MessageOnTimeText = Text;
                                m.Color             = OnTimeColor;
                            }
                        }
                        if (iM)
                        {
                            marker.Message = t;
                        }
                        else
                        {
                            marker.Message = m;
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 15
0
        //Parses an XML background definition
        public static BackgroundManager.BackgroundHandle ReadBackgroundXML(string fileName)
        {
            List <BackgroundManager.StaticBackground> Backgrounds = new List <BackgroundManager.StaticBackground>();
            //The current XML file to load
            XmlDocument currentXML = new XmlDocument();

            //Load the object's XML file
            currentXML.Load(fileName);
            string Path = System.IO.Path.GetDirectoryName(fileName);

            double[] UnitOfLength = { 1.0 };
            //Check for null
            if (currentXML.DocumentElement != null)
            {
                XmlNodeList DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/Background");
                //Check this file actually contains OpenBVE light definition nodes
                if (DocumentNodes != null)
                {
                    foreach (XmlNode n in DocumentNodes)
                    {
                        if (n.ChildNodes.OfType <XmlElement>().Any())
                        {
                            double DisplayTime = -1;
                            //The time to transition between backgrounds in seconds
                            double TransitionTime = 0.8;
                            //The texture to use (if static)
                            Textures.Texture t = null;
                            //The object to use (if object based)
                            ObjectManager.StaticObject o = null;
                            //The transition mode between backgrounds
                            BackgroundManager.BackgroundTransitionMode mode = BackgroundManager.BackgroundTransitionMode.FadeIn;
                            //The number of times the texture is repeated around the viewing frustrum (if appropriate)
                            double repetitions = 6;
                            foreach (XmlNode c in n.ChildNodes)
                            {
                                string[] Arguments = c.InnerText.Split(',');
                                switch (c.Name.ToLowerInvariant())
                                {
                                case "mode":
                                    switch (c.InnerText.ToLowerInvariant())
                                    {
                                    case "fadein":
                                        mode = BackgroundManager.BackgroundTransitionMode.FadeIn;
                                        break;

                                    case "fadeout":
                                        mode = BackgroundManager.BackgroundTransitionMode.FadeOut;
                                        break;

                                    case "none":
                                        mode = BackgroundManager.BackgroundTransitionMode.None;
                                        break;

                                    default:
                                        Interface.AddMessage(Interface.MessageType.Error, true, c.InnerText + "is not a valid background fade mode in file " + fileName);
                                        break;
                                    }
                                    break;

                                case "object":
                                    string f = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(fileName), c.InnerText);
                                    if (!System.IO.File.Exists(f))
                                    {
                                        Interface.AddMessage(Interface.MessageType.Error, true, "FileName " + f + " not found in file " + fileName);
                                    }
                                    else
                                    {
                                        ObjectManager.UnifiedObject b = ObjectManager.LoadObject(f, System.Text.Encoding.Default, ObjectManager.ObjectLoadMode.Normal, false, false, false);
                                        o = (ObjectManager.StaticObject)b;
                                    }
                                    break;

                                case "repetitions":
                                    if (!NumberFormats.TryParseDoubleVb6(Arguments[0], UnitOfLength, out repetitions))
                                    {
                                        Interface.AddMessage(Interface.MessageType.Error, false, c.InnerText + " does not parse to a valid number of repetitions in " + fileName);
                                    }
                                    break;

                                case "texture":
                                    var file = OpenBveApi.Path.CombineFile(Path, c.InnerText);
                                    if (!System.IO.File.Exists(file))
                                    {
                                        Interface.AddMessage(Interface.MessageType.Error, false, "The background texture file " + c.InnerText + " does not exist in " + fileName);
                                    }
                                    else
                                    {
                                        Textures.RegisterTexture(file, out t);
                                    }
                                    break;

                                case "time":
                                    if (!Interface.TryParseTime(Arguments[0].Trim(), out DisplayTime))
                                    {
                                        Interface.AddMessage(Interface.MessageType.Error, false, c.InnerText + " does not parse to a valid time in file " + fileName);
                                    }
                                    break;

                                case "transitiontime":
                                    if (!NumberFormats.TryParseDoubleVb6(Arguments[0], UnitOfLength, out TransitionTime))
                                    {
                                        Interface.AddMessage(Interface.MessageType.Error, false, c.InnerText + " is not a valid background transition time in " + fileName);
                                    }
                                    break;
                                }
                            }
                            //Create background if texture is not null
                            if (t != null && o == null)
                            {
                                Backgrounds.Add(new BackgroundManager.StaticBackground(t, repetitions, false, TransitionTime, mode, DisplayTime));
                            }
                            if (t == null && o != null)
                            {
                                //All other parameters are ignored if an object has been defined
                                //TODO: Error message stating they have been ignored
                                return(new BackgroundManager.BackgroundObject(o));
                            }
                        }
                    }
                    if (Backgrounds.Count == 1)
                    {
                        return(Backgrounds[0]);
                    }
                    if (Backgrounds.Count > 1)
                    {
                        //Sort list- Not worried about when they start or end, so use simple LINQ
                        Backgrounds = Backgrounds.OrderBy(o => o.Time).ToList();
                        //If more than 2 backgrounds, convert to array and return a new dynamic background
                        return(new BackgroundManager.DynamicBackground(Backgrounds.ToArray()));
                    }
                }
            }
            //We couldn't find any valid XML, so return false
            throw new InvalidDataException();
        }
Esempio n. 16
0
        internal void Apply(ref ObjectManager.StaticObject Object)
        {
            if (TransformMatrix != Matrix4D.NoTransformation)
            {
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Vertices[i].Coordinates.Transform(TransformMatrix);
                }
            }
            if (Faces.Length != 0)
            {
                int mf = Object.Mesh.Faces.Length;
                int mm = Object.Mesh.Materials.Length;
                int mv = Object.Mesh.Vertices.Length;
                Array.Resize <MeshFace>(ref Object.Mesh.Faces, mf + Faces.Length);
                Array.Resize <MeshMaterial>(ref Object.Mesh.Materials, mm + Materials.Length);
                Array.Resize <VertexTemplate>(ref Object.Mesh.Vertices, mv + Vertices.Length);
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Object.Mesh.Vertices[mv + i] = Vertices[i];
                }

                for (int i = 0; i < Faces.Length; i++)
                {
                    Object.Mesh.Faces[mf + i] = Faces[i];
                    for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
                    {
                        Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
                    }

                    Object.Mesh.Faces[mf + i].Material += (ushort)mm;
                }

                for (int i = 0; i < Materials.Length; i++)
                {
                    Object.Mesh.Materials[mm + i].Flags            = (byte)((Materials[i].EmissiveColorUsed ? MeshMaterial.EmissiveColorMask : 0) | (Materials[i].TransparentColorUsed ? MeshMaterial.TransparentColorMask : 0));
                    Object.Mesh.Materials[mm + i].Color            = Materials[i].Color;
                    Object.Mesh.Materials[mm + i].TransparentColor = Materials[i].TransparentColor;
                    if (Materials[i].DaytimeTexture != null || Materials[i].Text != null)
                    {
                        Texture tday;
                        if (Materials[i].Text != null)
                        {
                            Bitmap bitmap = null;
                            if (Materials[i].DaytimeTexture != null)
                            {
                                bitmap = new Bitmap(Materials[i].DaytimeTexture);
                            }

                            Bitmap texture = TextOverlay.AddTextToBitmap(bitmap, Materials[i].Text, Materials[i].Font, 12, Materials[i].BackgroundColor, Materials[i].TextColor, Materials[i].TextPadding);
                            tday = Textures.RegisterTexture(texture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)));
                        }
                        else
                        {
                            if (Materials[i].TransparentColorUsed)
                            {
                                Textures.RegisterTexture(Materials[i].DaytimeTexture,
                                                         new TextureParameters(null,
                                                                               new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G,
                                                                                           Materials[i].TransparentColor.B)), out tday);
                            }
                            else
                            {
                                Textures.RegisterTexture(Materials[i].DaytimeTexture, out tday);
                            }
                        }

                        Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].DaytimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].EmissiveColor = Materials[i].EmissiveColor;
                    if (Materials[i].NighttimeTexture != null)
                    {
                        Texture tnight;
                        if (Materials[i].TransparentColorUsed)
                        {
                            Textures.RegisterTexture(Materials[i].NighttimeTexture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)), out tnight);
                        }
                        else
                        {
                            Textures.RegisterTexture(Materials[i].NighttimeTexture, out tnight);
                        }

                        Object.Mesh.Materials[mm + i].NighttimeTexture = tnight;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].NighttimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
                    Object.Mesh.Materials[mm + i].BlendMode             = Materials[i].BlendMode;
                    Object.Mesh.Materials[mm + i].GlowAttenuationData   = Materials[i].GlowAttenuationData;
                    Object.Mesh.Materials[mm + i].WrapMode = Materials[i].WrapMode;
                }
            }
        }
Esempio n. 17
0
        /// <summary>Loads the current HUD</summary>
        internal static void LoadHUD()
        {
            CultureInfo Culture = CultureInfo.InvariantCulture;
            string      Folder  = Program.FileSystem.GetDataFolder("In-game", Interface.CurrentOptions.UserInterfaceFolder);
            string      File    = OpenBveApi.Path.CombineFile(Folder, "interface.cfg");

            CurrentHudElements = new Element[16];
            int Length = 0;

            if (System.IO.File.Exists(File))
            {
                string[] Lines = System.IO.File.ReadAllLines(File, new System.Text.UTF8Encoding());
                for (int i = 0; i < Lines.Length; i++)
                {
                    int j = Lines[i].IndexOf(';');
                    if (j >= 0)
                    {
                        Lines[i] = Lines[i].Substring(0, j).Trim();
                    }
                    else
                    {
                        Lines[i] = Lines[i].Trim();
                    }
                    if (Lines[i].Length != 0)
                    {
                        if (!Lines[i].StartsWith(";", StringComparison.Ordinal))
                        {
                            if (Lines[i].Equals("[element]", StringComparison.OrdinalIgnoreCase))
                            {
                                Length++;
                                if (Length > CurrentHudElements.Length)
                                {
                                    Array.Resize <Element>(ref CurrentHudElements, CurrentHudElements.Length << 1);
                                }

                                CurrentHudElements[Length - 1] = new Element();
                            }
                            else if (Length == 0)
                            {
                                MessageBox.Show("Line outside of [element] structure encountered at line " + (i + 1).ToString(Culture) + " in " + File);
                            }
                            else
                            {
                                j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                                if (j >= 0)
                                {
                                    string   Command   = Lines[i].Substring(0, j).TrimEnd();
                                    string[] Arguments = Lines[i].Substring(j + 1).TrimStart().Split(new char[] { ',' }, StringSplitOptions.None);
                                    for (j = 0; j < Arguments.Length; j++)
                                    {
                                        Arguments[j] = Arguments[j].Trim();
                                    }
                                    switch (Command.ToLowerInvariant())
                                    {
                                    case "subject":
                                        if (Arguments.Length == 1)
                                        {
                                            CurrentHudElements[Length - 1].Subject = Arguments[0];
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "position":
                                        if (Arguments.Length == 2)
                                        {
                                            float x, y;
                                            if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x))
                                            {
                                                MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y))
                                            {
                                                MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].Position.X = x;
                                                CurrentHudElements[Length - 1].Position.Y = y;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "alignment":
                                        if (Arguments.Length == 2)
                                        {
                                            int x, y;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out x))
                                            {
                                                MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out y))
                                            {
                                                MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].Alignment.X = Math.Sign(x);
                                                CurrentHudElements[Length - 1].Alignment.Y = Math.Sign(y);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "topleft":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopLeft.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopLeft.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "topmiddle":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopMiddle.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopMiddle.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "topright":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopRight.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopRight.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "centerleft":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterLeft.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterLeft.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "centermiddle":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterMiddle.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterMiddle.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "centerright":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterRight.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterRight.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "bottomleft":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomLeft.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomLeft.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "bottommiddle":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomMiddle.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomMiddle.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "bottomright":
                                        if (Arguments.Length == 2)
                                        {
                                            if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomRight.BackgroundTexture);
                                            }

                                            if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Textures.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomRight.OverlayTexture);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "backcolor":
                                        if (Arguments.Length == 4)
                                        {
                                            int r, g, b, a;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r))
                                            {
                                                MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g))
                                            {
                                                MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b))
                                            {
                                                MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a))
                                            {
                                                MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                r = r < 0 ? 0 : r > 255 ? 255 : r;
                                                g = g < 0 ? 0 : g > 255 ? 255 : g;
                                                b = b < 0 ? 0 : b > 255 ? 255 : b;
                                                a = a < 0 ? 0 : a > 255 ? 255 : a;
                                                CurrentHudElements[Length - 1].BackgroundColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a);
                                            }

                                            break;
                                        }
                                        MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        break;

                                    case "overlaycolor":
                                        if (Arguments.Length == 4)
                                        {
                                            int r, g, b, a;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r))
                                            {
                                                MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g))
                                            {
                                                MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b))
                                            {
                                                MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a))
                                            {
                                                MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                r = r < 0 ? 0 : r > 255 ? 255 : r;
                                                g = g < 0 ? 0 : g > 255 ? 255 : g;
                                                b = b < 0 ? 0 : b > 255 ? 255 : b;
                                                a = a < 0 ? 0 : a > 255 ? 255 : a;
                                                CurrentHudElements[Length - 1].OverlayColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a);
                                            }

                                            break;
                                        }
                                        MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        break;

                                    case "textcolor":
                                        if (Arguments.Length == 4)
                                        {
                                            int r, g, b, a;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r))
                                            {
                                                MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g))
                                            {
                                                MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b))
                                            {
                                                MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a))
                                            {
                                                MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                r = r < 0 ? 0 : r > 255 ? 255 : r;
                                                g = g < 0 ? 0 : g > 255 ? 255 : g;
                                                b = b < 0 ? 0 : b > 255 ? 255 : b;
                                                a = a < 0 ? 0 : a > 255 ? 255 : a;
                                                CurrentHudElements[Length - 1].TextColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a);
                                            }

                                            break;
                                        }
                                        MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        break;

                                    case "textposition":
                                        if (Arguments.Length == 2)
                                        {
                                            float x, y;
                                            if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x))
                                            {
                                                MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y))
                                            {
                                                MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].TextPosition.X = x;
                                                CurrentHudElements[Length - 1].TextPosition.Y = y;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "textalignment":
                                        if (Arguments.Length == 2)
                                        {
                                            int x, y;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out x))
                                            {
                                                MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out y))
                                            {
                                                MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].TextAlignment.X = Math.Sign(x);
                                                CurrentHudElements[Length - 1].TextAlignment.Y = Math.Sign(y);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "textsize":
                                        if (Arguments.Length == 1)
                                        {
                                            int s;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out s))
                                            {
                                                MessageBox.Show("SIZE is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                switch (s)
                                                {
                                                case 0:
                                                    CurrentHudElements[Length - 1].Font = Fonts.VerySmallFont;
                                                    break;

                                                case 1:
                                                    CurrentHudElements[Length - 1].Font = Fonts.SmallFont;
                                                    break;

                                                case 2:
                                                    CurrentHudElements[Length - 1].Font = Fonts.NormalFont;
                                                    break;

                                                case 3:
                                                    CurrentHudElements[Length - 1].Font = Fonts.LargeFont;
                                                    break;

                                                case 4:
                                                    CurrentHudElements[Length - 1].Font = Fonts.VeryLargeFont;
                                                    break;

                                                default:
                                                    CurrentHudElements[Length - 1].Font = Fonts.NormalFont;
                                                    break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "textshadow":
                                        if (Arguments.Length == 1)
                                        {
                                            int s;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out s))
                                            {
                                                MessageBox.Show("SHADOW is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].TextShadow = s != 0;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "text":
                                        if (Arguments.Length == 1)
                                        {
                                            CurrentHudElements[Length - 1].Text = Arguments[0];
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "value":
                                        if (Arguments.Length == 1)
                                        {
                                            int n;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out n))
                                            {
                                                MessageBox.Show("VALUE1 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].Value1 = n;
                                            }
                                        }
                                        else if (Arguments.Length == 2)
                                        {
                                            float a, b;
                                            if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out a))
                                            {
                                                MessageBox.Show("VALUE1 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out b))
                                            {
                                                MessageBox.Show("VALUE2 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].Value1 = a;
                                                CurrentHudElements[Length - 1].Value2 = b;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "transition":
                                        if (Arguments.Length == 1)
                                        {
                                            int n;
                                            if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out n))
                                            {
                                                MessageBox.Show("TRANSITION is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].Transition = (HUD.Transition)n;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }
                                        break;

                                    case "transitionvector":
                                        if (Arguments.Length == 2)
                                        {
                                            float x, y;
                                            if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x))
                                            {
                                                MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y))
                                            {
                                                MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                            }
                                            else
                                            {
                                                CurrentHudElements[Length - 1].TransitionVector.X = x;
                                                CurrentHudElements[Length - 1].TransitionVector.Y = y;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File);
                                        }

                                        break;

                                    default:
                                        MessageBox.Show("Invalid command encountered at line " + (i + 1).ToString(Culture) + " in " + File);
                                        break;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Invalid statement encountered at line " + (i + 1).ToString(Culture) + " in " + File);
                                }
                            }
                        }
                    }
                }
            }

            Array.Resize <Element>(ref CurrentHudElements, Length);
        }
Esempio n. 18
0
 /// <summary>Registers a texture and returns a handle to the texture.</summary>
 /// <param name="texture">The texture data.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 /// <param name="handle">Receives the handle to the texture.</param>
 /// <returns>Whether loading the texture was successful.</returns>
 public override bool RegisterTexture(OpenBveApi.Textures.Texture texture, OpenBveApi.Textures.TextureParameters parameters, out OpenBveApi.Textures.TextureHandle handle)
 {
     texture = texture.ApplyParameters(parameters);
     handle  = Textures.RegisterTexture(texture);
     return(true);
 }