Exemple #1
0
        private void DrawView()
        {
            if (!(DrawView_Enabled && IsGLInitialized))
            {
                return;
            }

            if (GraphicsContext.CurrentContext != OpenGLControl.Context)
            {
                OpenGLControl.MakeCurrent();
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            var map = MainMap;

            if (map == null)
            {
                GL.Flush();
                OpenGLControl.SwapBuffers();
                Refresh();
                return;
            }

            var xyInt        = new XYInt();
            var unrotatedPos = new XYDouble();
            var texCoord0    = new XYDouble();
            var texCoord1    = new XYDouble();
            var texCoord2    = new XYDouble();
            var texCoord3    = new XYDouble();

            GL.MatrixMode(MatrixMode.Projection);
            var temp_mat = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, GLSize.Y, 0.0F, -1.0F, 1.0F);

            GL.LoadMatrix(ref temp_mat);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            if (map.Tileset != null)
            {
                TileUtil.GetTileRotatedTexCoords(App.TextureOrientation, ref texCoord0, ref texCoord1, ref texCoord2, ref texCoord3);

                GL.Enable(EnableCap.Texture2D);
                GL.Color4(0.0F, 0.0F, 0.0F, 1.0F);

                var x   = 0;
                var y   = 0;
                var num = 0;
                var a   = 0;
                for (y = 0; y <= TextureCount.Y - 1; y++)
                {
                    for (x = 0; x <= TextureCount.X - 1; x++)
                    {
                        num = (TextureYOffset + y) * TextureCount.X + x;
                        if (num >= map.Tileset.TileCount)
                        {
                            goto EndOfTextures1;
                        }
                        a = map.Tileset.Tiles[num].GlTextureNum;
                        GL.BindTexture(TextureTarget.Texture2D, a);
                        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal);
                        GL.Begin(BeginMode.Quads);
                        GL.TexCoord2(texCoord0.X, texCoord0.Y);
                        GL.Vertex2(x * 64, y * 64);           // Top Left
                        GL.TexCoord2(texCoord1.X, texCoord1.Y);
                        GL.Vertex2(x * 64 + 64, y * 64);      // Bottom Left
                        GL.TexCoord2(texCoord3.X, texCoord3.Y);
                        GL.Vertex2(x * 64 + 64, y * 64 + 64); // Bottom right
                        GL.TexCoord2(texCoord2.X, texCoord2.Y);
                        GL.Vertex2(x * 64, y * 64 + 64);      // Top right

                        GL.End();
                    }
                }

EndOfTextures1:

                GL.Disable(EnableCap.Texture2D);

                if (DisplayTileTypes)
                {
                    GL.Begin(BeginMode.Quads);
                    for (y = 0; y <= TextureCount.Y - 1; y++)
                    {
                        for (x = 0; x <= TextureCount.X - 1; x++)
                        {
                            num = (TextureYOffset + y) * TextureCount.X + x;
                            if (num >= map.Tileset.TileCount)
                            {
                                goto EndOfTextures2;
                            }
                            a = map.TileTypeNum[num];
                            GL.Color3(App.TileTypes[a].DisplayColour.Red, App.TileTypes[a].DisplayColour.Green, App.TileTypes[a].DisplayColour.Blue);
                            GL.Vertex2(x * 64 + 24, y * 64 + 24);
                            GL.Vertex2(x * 64 + 24, y * 64 + 40);
                            GL.Vertex2(x * 64 + 40, y * 64 + 40);
                            GL.Vertex2(x * 64 + 40, y * 64 + 24);
                        }
                    }
EndOfTextures2:
                    GL.End();
                }

                if (App.DisplayTileOrientation)
                {
                    GL.Disable(EnableCap.CullFace);

                    unrotatedPos.X = 0.25F;
                    unrotatedPos.Y = 0.25F;
                    var vertex0 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos);
                    unrotatedPos.X = 0.5F;
                    unrotatedPos.Y = 0.25F;
                    var vertex1 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos);
                    unrotatedPos.X = 0.5F;
                    unrotatedPos.Y = 0.5F;
                    var vertex2 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos);

                    GL.Begin(BeginMode.Triangles);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    for (y = 0; y <= TextureCount.Y - 1; y++)
                    {
                        for (x = 0; x <= TextureCount.X - 1; x++)
                        {
                            num = (TextureYOffset + y) * TextureCount.X + x;
                            if (num >= map.Tileset.TileCount)
                            {
                                goto EndOfTextures3;
                            }
                            GL.Vertex2(x * 64 + vertex0.X * 64, y * 64 + vertex0.Y * 64);
                            GL.Vertex2(x * 64 + vertex2.X * 64, y * 64 + vertex2.Y * 64);
                            GL.Vertex2(x * 64 + vertex1.X * 64, y * 64 + vertex1.Y * 64);
                        }
                    }
EndOfTextures3:
                    GL.End();

                    GL.Enable(EnableCap.CullFace);
                }

                if (DisplayTileNumbers && App.UnitLabelFont != null)   //TextureViewFont IsNot Nothing Then
                {
                    GL.Enable(EnableCap.Texture2D);
                    for (y = 0; y <= TextureCount.Y - 1; y++)
                    {
                        for (x = 0; x <= TextureCount.X - 1; x++)
                        {
                            num = (TextureYOffset + y) * TextureCount.X + x;
                            if (num >= map.Tileset.TileCount)
                            {
                                goto EndOfTextures4;
                            }
                            clsTextLabel textLabel = new clsTextLabel();
                            textLabel.Text         = num.ToStringInvariant();
                            textLabel.SizeY        = 24.0F;
                            textLabel.Colour.Red   = 1.0F;
                            textLabel.Colour.Green = 1.0F;
                            textLabel.Colour.Blue  = 0.0F;
                            textLabel.Colour.Alpha = 1.0F;
                            textLabel.Pos.X        = x * 64;
                            textLabel.Pos.Y        = y * 64;
                            textLabel.TextFont     = App.UnitLabelFont; //TextureViewFont
                            textLabel.Draw();
                        }
                    }
EndOfTextures4:
                    GL.Disable(EnableCap.Texture2D);
                }

                if (App.SelectedTextureNum >= 0 & TextureCount.X > 0)
                {
                    a       = App.SelectedTextureNum - TextureYOffset * TextureCount.X;
                    xyInt.X = a - a / TextureCount.X * TextureCount.X;
                    xyInt.Y = a / TextureCount.X;
                    GL.Begin(BeginMode.LineLoop);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    GL.Vertex2(xyInt.X * 64, xyInt.Y * 64);
                    GL.Vertex2(xyInt.X * 64, xyInt.Y * 64.0D + 64);
                    GL.Vertex2(xyInt.X * 64 + 64, xyInt.Y * 64 + 64);
                    GL.Vertex2(xyInt.X * 64 + 64, xyInt.Y * 64);
                    GL.End();
                }
            }

            GL.Flush();
            OpenGLControl.SwapBuffers();

            Refresh();
        }
        public override void ActionPerform()
        {
            if (!Started)
            {
                Debugger.Break();
                return;
            }

            var Unit             = default(Unit);
            var Sector           = Map.Sectors[PosNum.X, PosNum.Y];
            var DrawUnitLabel    = default(bool);
            var ViewInfo         = Map.ViewInfo;
            var MouseOverTerrain = ViewInfo.GetMouseOverTerrain();
            var TextLabel        = default(clsTextLabel);
            var XYZ_dbl          = default(XYZDouble);
            var XYZ_dbl2         = default(XYZDouble);
            var ScreenPos        = new XYInt();
            var Connection       = default(clsUnitSectorConnection);

            foreach (var tempLoopVar_Connection in Sector.Units)
            {
                Connection = tempLoopVar_Connection;
                Unit       = Connection.Unit;
                if (!UnitDrawn[Unit.MapLink.ArrayPosition])
                {
                    UnitDrawn[Unit.MapLink.ArrayPosition] = true;
                    XYZ_dbl.X     = Unit.Pos.Horizontal.X - ViewInfo.ViewPos.X;
                    XYZ_dbl.Y     = Unit.Pos.Altitude - ViewInfo.ViewPos.Y;
                    XYZ_dbl.Z     = -Unit.Pos.Horizontal.Y - ViewInfo.ViewPos.Z;
                    DrawUnitLabel = false;
                    if (Unit.TypeBase.IsUnknown)
                    {
                        DrawUnitLabel = true;
                    }
                    else
                    {
                        GL.PushMatrix();
                        GL.Translate(XYZ_dbl.X, XYZ_dbl.Y, Convert.ToDouble(-XYZ_dbl.Z));
                        Unit.TypeBase.GLDraw(Unit.Rotation);
                        GL.PopMatrix();
                        if (Unit.TypeBase.Type == UnitType.PlayerDroid)
                        {
                            if (((DroidDesign)Unit.TypeBase).AlwaysDrawTextLabel)
                            {
                                DrawUnitLabel = true;
                            }
                        }
                        if (MouseOverTerrain != null)
                        {
                            if (MouseOverTerrain.Units.Count > 0)
                            {
                                if (MouseOverTerrain.Units[0] == Unit)
                                {
                                    DrawUnitLabel = true;
                                }
                            }
                        }
                    }
                    if (DrawUnitLabel && !UnitTextLabels.AtMaxCount())
                    {
                        Matrix3DMath.VectorRotationByMatrix(ViewInfo.ViewAngleMatrixInverted, XYZ_dbl, ref XYZ_dbl2);
                        if (ViewInfo.PosGetScreenXY(XYZ_dbl2, ref ScreenPos))
                        {
                            if (ScreenPos.X >= 0 & ScreenPos.X <= ViewInfo.MapViewControl.GLSize.X & ScreenPos.Y >= 0 & ScreenPos.Y <= ViewInfo.MapViewControl.GLSize.Y)
                            {
                                TextLabel              = new clsTextLabel();
                                TextLabel.TextFont     = App.UnitLabelFont;
                                TextLabel.SizeY        = SettingsManager.Settings.FontSize;
                                TextLabel.Colour.Red   = 1.0F;
                                TextLabel.Colour.Green = 1.0F;
                                TextLabel.Colour.Blue  = 1.0F;
                                TextLabel.Colour.Alpha = 1.0F;
                                TextLabel.Pos.X        = ScreenPos.X + 32;
                                TextLabel.Pos.Y        = ScreenPos.Y;
                                TextLabel.Text         = Unit.TypeBase.GetDisplayTextCode();
                                UnitTextLabels.Add(TextLabel);
                            }
                        }
                    }
                }
            }
        }
        private void DrawView()
        {
            if ( !(DrawView_Enabled && IsGLInitialized) )
            {
                return;
            }

            if ( GraphicsContext.CurrentContext != OpenGLControl.Context )
            {
                OpenGLControl.MakeCurrent();
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            clsMap Map = MainMap;

            if ( Map == null )
            {
                GL.Flush();
                OpenGLControl.SwapBuffers();
                Refresh();
                return;
            }

            int X = 0;
            int Y = 0;
            int Num = 0;
            sXY_int XY_int = new sXY_int();
            int A = 0;
            sXY_sng Vertex0 = new sXY_sng();
            sXY_sng Vertex1 = new sXY_sng();
            sXY_sng Vertex2 = new sXY_sng();
            sXY_sng UnrotatedPos = new sXY_sng();
            sXY_sng TexCoord0 = new sXY_sng();
            sXY_sng TexCoord1 = new sXY_sng();
            sXY_sng TexCoord2 = new sXY_sng();
            sXY_sng TexCoord3 = new sXY_sng();

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 temp_mat = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, GLSize.Y, 0.0F, -1.0F, 1.0F);
            GL.LoadMatrix(ref temp_mat);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            if ( Map.Tileset != null )
            {
                TileUtil.GetTileRotatedTexCoords(App.TextureOrientation, TexCoord0, TexCoord1, TexCoord2, TexCoord3);

                GL.Enable(EnableCap.Texture2D);
                GL.Color4(0.0F, 0.0F, 0.0F, 1.0F);

                for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                {
                    for ( X = 0; X <= TextureCount.X - 1; X++ )
                    {
                        Num = (TextureYOffset + Y) * TextureCount.X + X;
                        if ( Num >= Map.Tileset.TileCount )
                        {
                            goto EndOfTextures1;
                        }
                        A = Map.Tileset.Tiles[Num].TextureView_GL_Texture_Num;
                        if ( A == 0 )
                        {
                            GL.BindTexture(TextureTarget.Texture2D, 0);
                        }
                        else
                        {
                            GL.BindTexture(TextureTarget.Texture2D, A);
                        }
                        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal);
                        GL.Begin(BeginMode.Quads);
                        GL.TexCoord2(TexCoord0.X, TexCoord0.Y);
                        GL.Vertex2(X * 64, Y * 64);
                        GL.TexCoord2(TexCoord2.X, TexCoord2.Y);
                        GL.Vertex2(X * 64, Y * 64 + 64);
                        GL.TexCoord2(TexCoord3.X, TexCoord3.Y);
                        GL.Vertex2(X * 64 + 64, Y * 64 + 64);
                        GL.TexCoord2(TexCoord1.X, TexCoord1.Y);
                        GL.Vertex2(X * 64 + 64, Y * 64);
                        GL.End();
                    }
                }

                EndOfTextures1:

                GL.Disable(EnableCap.Texture2D);

                if ( DisplayTileTypes )
                {
                    GL.Begin(BeginMode.Quads);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures2;
                            }
                            A = Map.Tile_TypeNum[Num];
                            GL.Color3(App.TileTypes[A].DisplayColour.Red, App.TileTypes[A].DisplayColour.Green, App.TileTypes[A].DisplayColour.Blue);
                            GL.Vertex2(X * 64 + 24, Y * 64 + 24);
                            GL.Vertex2(X * 64 + 24, Y * 64 + 40);
                            GL.Vertex2(X * 64 + 40, Y * 64 + 40);
                            GL.Vertex2(X * 64 + 40, Y * 64 + 24);
                        }
                    }
                    EndOfTextures2:
                    GL.End();
                }

                if ( App.DisplayTileOrientation )
                {
                    GL.Disable(EnableCap.CullFace);

                    UnrotatedPos.X = 0.25F;
                    UnrotatedPos.Y = 0.25F;
                    Vertex0 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.25F;
                    Vertex1 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.5F;
                    Vertex2 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);

                    GL.Begin(BeginMode.Triangles);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures3;
                            }
                            GL.Vertex2(X * 64 + Vertex0.X * 64, Y * 64 + Vertex0.Y * 64);
                            GL.Vertex2(X * 64 + Vertex2.X * 64, Y * 64 + Vertex2.Y * 64);
                            GL.Vertex2(X * 64 + Vertex1.X * 64, Y * 64 + Vertex1.Y * 64);
                        }
                    }
                    EndOfTextures3:
                    GL.End();

                    GL.Enable(EnableCap.CullFace);
                }

                if ( DisplayTileNumbers && App.UnitLabelFont != null ) //TextureViewFont IsNot Nothing Then
                {
                    clsTextLabel TextLabel = default(clsTextLabel);
                    GL.Enable(EnableCap.Texture2D);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures4;
                            }
                            TextLabel = new clsTextLabel();
                            TextLabel.Text = IOUtil.InvariantToString(Num);
                            TextLabel.SizeY = 24.0F;
                            TextLabel.Colour.Red = 1.0F;
                            TextLabel.Colour.Green = 1.0F;
                            TextLabel.Colour.Blue = 0.0F;
                            TextLabel.Colour.Alpha = 1.0F;
                            TextLabel.Pos.X = X * 64;
                            TextLabel.Pos.Y = Y * 64;
                            TextLabel.TextFont = App.UnitLabelFont; //TextureViewFont
                            TextLabel.Draw();
                        }
                    }
                    EndOfTextures4:
                    GL.Disable(EnableCap.Texture2D);
                }

                if ( App.SelectedTextureNum >= 0 & TextureCount.X > 0 )
                {
                    A = App.SelectedTextureNum - TextureYOffset * TextureCount.X;
                    XY_int.X = A - ((int)(Conversion.Int(A / TextureCount.X))) * TextureCount.X;
                    XY_int.Y = (int)(Conversion.Int(A / TextureCount.X));
                    GL.Begin(BeginMode.LineLoop);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64.0D + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64 + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64);
                    GL.End();
                }
            }

            GL.Flush();
            OpenGLControl.SwapBuffers();

            Refresh();
        }