void AddTextWithShadow(GuiRenderer renderer, Font font, string text, Vec2 position,
                               HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, ColorValue color)
        {
            Vec2 shadowOffset = 1.0f / renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

            renderer.AddText(font, text, position + shadowOffset, horizontalAlign, verticalAlign,
                             new ColorValue(0, 0, 0, color.Alpha / 2));
            renderer.AddText(font, text, position, horizontalAlign, verticalAlign, color);
        }
        void AddTextWithShadow(GuiRenderer renderer, string text, Vec2 position,
                               HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, ColorValue color)
        {
            Vec2 shadowOffset = 2.0f / RendererWorld.Instance.DefaultViewport.DimensionsInPixels.Size.ToVec2();

            renderer.AddText(text, position + shadowOffset, horizontalAlign, verticalAlign,
                             new ColorValue(0, 0, 0, color.Alpha / 2));
            renderer.AddText(text, position, horizontalAlign, verticalAlign, color);
        }
Example #3
0
        void renderTargetUserControl1_RenderUI(RenderTargetUserControl sender, GuiRenderer renderer)
        {
            string text = "NeoAxis Engine " + EngineVersionInformation.Version;

            renderer.AddText(text, new Vec2(.01f, .01f), HorizontalAlign.Left,
                             VerticalAlign.Top, new ColorValue(1, 1, 1));

            renderer.AddText("Camera control: W A S D, right mouse", new Vec2(.99f, .99f),
                             HorizontalAlign.Right, VerticalAlign.Bottom, new ColorValue(1, 1, 1));
        }
Example #4
0
        void renderTargetUserControl1_RenderUI(GuiRenderer renderer)
        {
            string text = "NeoAxis Engine " + EngineVersionInformation.Version;

            renderer.AddText(text, new Vec2(.01f, .01f), HorizontalAlign.Left,
                             VerticalAlign.Top, new ColorValue(1, 1, 1));
        }
Example #5
0
 protected override void OnRenderUI(GuiRenderer renderer)
 {
     //base.OnRenderUI(renderer);
     // The version without clipping works when running in a game. In the editor, UpdateText set averageCharWidth to a guess!
     // With clipping it looks ok in the editor.
     renderer.AddText(textDisplay, this.GetScreenPosition());
     //renderer.AddText(textDisplay, this.GetScreenPosition(), HorizontalAlign.Left, VerticalAlign.Top, this.TextColor, clip);
     //renderer.AddRectangle(this.GetScreenRectangle(), this.TextColor, clip);
     //Log.Info("GetScreenRectangle {0}, GetScreenPosition {1}, GetScreenSize {2}", this.GetScreenRectangle().ToString(), this.GetScreenPosition().ToString(), this.GetScreenSize().ToString());
 }
Example #6
0
        public override void OnRenderScreenUI(GuiRenderer renderer)
        {
            base.OnRenderScreenUI(renderer);

            if (drawTextOnScreen)
            {
                renderer.AddText("Add-on Example!", new Vec2(.5f, .9f), HorizontalAlign.Center, VerticalAlign.Top,
                                 new ColorValue(1, 0, 0));
                renderer.AddQuad(new Rect(.3f, .94f, .7f, .95f), new ColorValue(1, 1, 0));
            }
        }
        void PerspectiveViewControl_RenderUI(GuiRenderer renderer)
        {
            if (_camera != null)
                Nameplates.RenderObjectsTips(renderer, _camera);
            string text = "FPS: " + Perspective.Fps
                        + "    loc: " + renderTarget.CameraPosition.ToString(0)
                        + "    dir: " + renderTarget.CameraDirection.ToString(0)
                        + "    mouse: " + _mouseIntersection.ToString(2)
                        + "    over: " + _worldViewModel.MouseOverEntity;

            renderer.AddText(text, new Vec2(.01f, .01f), HorizontalAlign.Left,
                VerticalAlign.Top, new ColorValue(1, 1, 1));
        }
Example #8
0
        public void DrawDebug(Rect r, GuiRenderer renderer)
        {
            Rect[] rs = new Rect[5];
            rs[0] = new Rect(Utils.TR(r, new Vec2(0.05f, 0.375f)), Utils.TR(r, new Vec2(0.30f, 0.625f)));
            rs[4] = new Rect(Utils.TR(r, new Vec2(0.05f, 0.05f)), Utils.TR(r, new Vec2(0.30f, 0.30f)));
            rs[2] = new Rect(Utils.TR(r, new Vec2(0.05f, 0.70f)), Utils.TR(r, new Vec2(0.30f, 0.95f)));
            rs[3] = new Rect(Utils.TR(r, new Vec2(0.375f, 0.375f)), Utils.TR(r, new Vec2(0.625f, 0.625f)));
            rs[1] = new Rect(Utils.TR(r, new Vec2(0.70f, 0.375f)), Utils.TR(r, new Vec2(0.95f, 0.625f)));

            for (int i = 0; i < aerofoils.Length; i++)
                aerofoils[i].DrawDebug(rs[i], renderer);

            float speed = awesomeAircraft.mainBody.LinearVelocity.Length();
            renderer.AddText("speed:" + speed.ToString(), r.LeftTop);
        }
        void PerspectiveViewControl_RenderUI(GuiRenderer renderer)
        {
            if (_camera != null)
            {
                Nameplates.RenderObjectsTips(renderer, _camera);
            }
            string text = "FPS: " + Perspective.Fps
                          + "    loc: " + renderTarget.CameraPosition.ToString(0)
                          + "    dir: " + renderTarget.CameraDirection.ToString(0)
                          + "    mouse: " + _mouseIntersection.ToString(2)
                          + "    over: " + _worldViewModel.MouseOverEntity;

            renderer.AddText(text, new Vec2(.01f, .01f), HorizontalAlign.Left,
                             VerticalAlign.Top, new ColorValue(1, 1, 1));
        }
        /// <summary>
        /// To draw some information of a player
        /// </summary>
        /// <param name="renderer"></param>
        void DrawPlayerInformation( GuiRenderer renderer )
        {
            if( GetRealCameraType() == CameraType.Free )
                return;

            if( IsCutSceneEnabled() )
                return;

            //debug draw an influences.
            {
                float posy = .8f;

                foreach( Entity entity in GetPlayerUnit().Children )
                {
                    Influence influence = entity as Influence;
                    if( influence == null )
                        continue;

                    renderer.AddText( influence.Type.Name, new Vec2( .7f, posy ),
                        HorizontalAlign.Left, VerticalAlign.Center );

                    int count = (int)( (float)influence.RemainingTime * 2.5f );
                    if( count > 50 )
                        count = 50;
                    string str = "";
                    for( int n = 0; n < count; n++ )
                        str += "I";

                    renderer.AddText( str, new Vec2( .85f, posy ),
                        HorizontalAlign.Left, VerticalAlign.Center );

                    posy -= .025f;
                }
            }
        }
        protected override void OnRenderUI( GuiRenderer renderer )
        {
            base.OnRenderUI( renderer );

            //Draw some HUD information
            if( GetPlayerUnit() != null )
            {
                if( GetRealCameraType() != CameraType.Free && !IsCutSceneEnabled() &&
                    GetActiveObserveCameraArea() == null )
                {
                    DrawTarget( renderer );
                }

                DrawPlayerInformation( renderer );

                bool activeConsole = EngineConsole.Instance != null && EngineConsole.Instance.Active;

                if( EngineApp.Instance.IsKeyPressed( EKeys.Tab ) && !activeConsole )
                    DrawPlayersStatistics( renderer );

                if( GameNetworkServer.Instance != null || GameNetworkClient.Instance != null )
                {
                    renderer.AddText( "\"Tab\" for players statistics", new Vec2( .01f, .1f ),
                        HorizontalAlign.Left, VerticalAlign.Top, new ColorValue( 1, 1, 1, .5f ) );
                }
            }

            //Game is paused on server
            if( EntitySystemWorld.Instance.IsClientOnly() && !EntitySystemWorld.Instance.Simulation )
            {
                renderer.AddText( "Game is paused on server", new Vec2( .5f, .5f ),
                    HorizontalAlign.Center, VerticalAlign.Center, new ColorValue( 1, 0, 0 ) );
            }
        }
        public void DoRenderUI( GuiRenderer renderer )
        {
            if( transparency == 0.0f )
                return;

            if( firstRender )
            {
                texture = TextureManager.Instance.Load( "Gui\\Various\\Console.dds",
                    Texture.Type.Type2D, 0 );
                font = FontManager.Instance.LoadFont( "Default", .025f );

                firstRender = false;
            }

            if( font == null )
                return;

            Rect textureRect = new Rect( 0, 0, 1, 1 );
            textureRect += textureOffset;

            renderer.AddQuad( new Rect( 0, 0, 1, .5f ), textureRect, texture,
                new ColorValue( 1, 1, 1, transparency ), false, new Rect( 0, 0, 1, 1 ) );
            renderer.AddQuad( new Rect( 0, .495f, 1, .5f ),
                new ColorValue( .8f, .8f, .8f, transparency ) );

            string staticText = "Version " + EngineVersionInformation.Version;
            if( staticText != null && staticText != "" )
            {
                renderer.AddText( font, staticText, new Vec2( .99f, .5f - font.Height ),
                    HorizontalAlign.Right, VerticalAlign.Center, new ColorValue( 1, 1, 1, transparency ) );
            }

            float fontheight = font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;
            if( stringDownPosition != strings.Count - 1 )
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                    " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                    " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                    " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                    " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
                str = currentString + "_";

            renderer.AddText( font, str, new Vec2( x, y ), HorizontalAlign.Left,
                VerticalAlign.Center, new ColorValue( 1, 1, 1, transparency ) );

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;
            if( startpos > strings.Count - 1 )
                startpos = strings.Count - 1;
            for( int n = startpos; n >= 0 && y - fontheight > 0; n-- )
            {
                renderer.AddText( font, strings[ n ].text, new Vec2( x, y ), HorizontalAlign.Left,
                    VerticalAlign.Center, strings[ n ].color * new ColorValue( 1, 1, 1, transparency ) );
                y -= fontheight;
            }
        }
Example #13
0
        public void DoRenderUI()
        {
            GuiRenderer renderer = EngineApp.Instance.ScreenGuiRenderer;

            if (transparency == 0.0f)
            {
                return;
            }

            //load backgrouund texture and font
            if (texture != null && texture.IsDisposed())
            {
                needLoadTextureAndFont = true;
            }
            if (needLoadTextureAndFont)
            {
                texture = TextureManager.Instance.Load("GUI\\Textures\\Console.png", Texture.Type.Type2D, 0);
                font    = FontManager.Instance.LoadFont("Default", .025f);
                needLoadTextureAndFont = false;
            }

            if (font == null)
            {
                return;
            }

            Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();
            Vec2 shadowOffset = new Vec2(1, 1) / viewportSize;

            //draw background
            Rect textureRect = new Rect(0, 0, 10 * renderer.AspectRatio, 10 / 2);

            textureRect -= textureOffset;
            renderer.AddQuad(new Rect(0, 0, 1, .5f), textureRect, texture, new ColorValue(1, 1, 1, transparency), false);

            //draw border line
            renderer.AddQuad(new Rect(0, .5f, 1, .508f), new ColorValue(0.29f, 0.6f, 0.86f, 0.9f * transparency));

            //draw background info
            string staticText = string.Format(
                "NeoAxis 3D Engine {0}\r\nPress \"~\" to hide console\r\nPress \"Ctrl + ~\" to hide and disable auto opening",
                EngineVersionInformation.Version);

            renderer.AddTextWordWrap(staticText, new Rect(0, 0, .995f, .495f), HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                                     new ColorValue(.5f, .5f, .6f, transparency));

            float fontheight = font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

            if (stringDownPosition != strings.Count - 1)
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
            {
                str = currentString + "_";
            }

            renderer.PushClipRectangle(new Rect(0, 0, .975f, 1));
            renderer.AddText(font, str, new Vec2(x, y) + shadowOffset, HorizontalAlign.Left,
                             VerticalAlign.Center, new ColorValue(0, 0, 0, transparency / 2));
            renderer.AddText(font, str, new Vec2(x, y), HorizontalAlign.Left,
                             VerticalAlign.Center, new ColorValue(1, 1, 1, transparency));
            renderer.PopClipRectangle();

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;

            if (startpos > strings.Count - 1)
            {
                startpos = strings.Count - 1;
            }
            for (int n = startpos; n >= 0 && y - fontheight > 0; n--)
            {
                renderer.AddText(font, strings[n].text, new Vec2(x, y) + shadowOffset, HorizontalAlign.Left,
                                 VerticalAlign.Center, strings[n].color * new ColorValue(0, 0, 0, transparency / 2));
                renderer.AddText(font, strings[n].text, new Vec2(x, y), HorizontalAlign.Left,
                                 VerticalAlign.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight;
            }
        }
        protected override void OnRenderScreenUI(GuiRenderer renderer)
        {
            base.OnRenderScreenUI(renderer);

            if (Map.Instance != null)
                Map.Instance.DoRenderUI(renderer);

            if (MultiViewRenderingManager.Instance != null)
                MultiViewRenderingManager.Instance.RenderScreenUI(renderer);

            controlManager.DoRenderUI(renderer);

            //screenMessages
            {
                Viewport viewport = RendererWorld.Instance.DefaultViewport;
                Vec2 shadowOffset = 2.0f / viewport.DimensionsInPixels.Size.ToVec2();

                Vec2 pos = new Vec2(.03f, .75f);

                for (int n = screenMessages.Count - 1; n >= 0; n--)
                {
                    ScreenMessage message = screenMessages[n];

                    float alpha = message.timeRemaining;
                    if (alpha > 1)
                        alpha = 1;
                    renderer.AddText(message.text, pos + shadowOffset, HorizontalAlign.Left,
                        VerticalAlign.Bottom, new ColorValue(0, 0, 0, alpha / 2));
                    renderer.AddText(message.text, pos, HorizontalAlign.Left, VerticalAlign.Bottom,
                        new ColorValue(1, 1, 1, alpha));

                    pos.Y -= renderer.DefaultFont.Height;
                }
            }

            //fading in, out
            RenderFadingOut(renderer);
            RenderFadingIn(renderer);

            if (EngineConsole.Instance != null)
                EngineConsole.Instance.DoRenderUI();
        }
Example #15
0
        protected override void OnRenderUI( GuiRenderer renderer )
        {
            base.OnRenderUI( renderer );

            Vec2I size = GetNeededSize();

            if( browser == null )
                CreateBrowser();

            //update brower engine and texture
            if( browser != null )
            {
                if( viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized( oldSize, viewSize );
                }

                //create texture
                if( texture == null || textureSize != size )
                {
                    if( texture != null )
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    string textureName = TextureManager.Instance.GetUniqueName( "WebBrowserControl" );
                    texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                        1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable );
                    forceUpdateTexture = true;
                }

                //update texture
                if( /*browser.IsDirty ||*/ forceUpdateTexture )
                {
                    if( texture != null )
                        UpdateTexture();
                    forceUpdateTexture = false;
                }
            }

            //draw texture
            {
                bool backColorZero = BackColor == new ColorValue( 0, 0, 0, 0 );

                ColorValue color = backColorZero ? new ColorValue( 1, 1, 1 ) : BackColor;
                if( texture == null )
                    color = new ColorValue( 0, 0, 0, color.Alpha );
                color *= GetTotalColorMultiplier();

                color.Clamp( new ColorValue( 0, 0, 0, 0 ), new ColorValue( 1, 1, 1, 1 ) );

                Rect rect;
                GetScreenRectangle( out rect );

                if( renderer.IsScreen && !renderer._OutGeometryTransformEnabled )
                {
                    //screen per pixel accuracy

                    Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

                    Vec2 leftTop = rect.LeftTop;
                    leftTop *= viewportSize;
                    leftTop = new Vec2( (int)( leftTop.X + .9999f ), (int)( leftTop.Y + .9999f ) );
                    if( RenderSystem.Instance.IsDirect3D() )
                        leftTop -= new Vec2( .5f, .5f );
                    leftTop /= viewportSize;

                    Vec2 rightBottom = rect.RightBottom;
                    rightBottom *= viewportSize;
                    rightBottom = new Vec2( (int)( rightBottom.X + .9999f ), (int)( rightBottom.Y + .9999f ) );
                    if( RenderSystem.Instance.IsDirect3D() )
                        rightBottom -= new Vec2( .5f, .5f );
                    rightBottom /= viewportSize;

                    Rect fixedRect = new Rect( leftTop, rightBottom );

                    renderer.AddQuad( fixedRect, new Rect( 0, 0, 1, 1 ), texture, color, true );
                }
                else
                {
                    renderer.AddQuad( rect, new Rect( 0, 0, 1, 1 ), texture, color, true );
                }
            }

            if( !IsSupportedByThisPlatform() )
            {
                renderer.AddText( string.Format( "WebBrowserControl: {0} is not supported.", PlatformInfo.Platform ),
                    new Vec2( .5f, .5f ), Renderer.HorizontalAlign.Center, Renderer.VerticalAlign.Center, new ColorValue( 1, 0, 0 ) );
            }
        }
Example #16
0
        //Tank specific
        void DrawTankGunTarget( GuiRenderer renderer )
        {
            Tank tank = GetPlayerUnit() as Tank;
            if( tank == null )
                return;

            Gun gun = tank.MainGun;
            if( gun == null )
                return;

            Vec3 gunPosition = gun.GetInterpolatedPosition();
            Vec3 gunDirection = gun.GetInterpolatedRotation() * new Vec3( 1, 0, 0 );

            RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(
                new Ray( gunPosition, gunDirection * 1000 ),
                (int)ContactGroup.CastOnlyContact );

            bool finded = false;
            Vec3 pos = Vec3.Zero;

            foreach( RayCastResult result in piercingResult )
            {
                bool ignore = false;

                MapObject obj = MapSystemWorld.GetMapObjectByBody( result.Shape.Body );

                Dynamic dynamic = obj as Dynamic;
                if( dynamic != null && dynamic.GetParentUnit() == tank )
                    ignore = true;

                if( !ignore )
                {
                    finded = true;
                    pos = result.Position;
                    break;
                }
            }

            if( !finded )
                pos = gunPosition + gunDirection * 1000;

            Vec2 screenPos = RendererWorld.Instance.DefaultCamera.ProjectToScreenCoordinates( pos );
            renderer.AddText( "+", screenPos,
                HorizontalAlign.Center, VerticalAlign.Center, new ColorValue( 0, 1, 0 ) );
        }
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            UpdateHUD();

            //render user names for moving pieces by users
            foreach (Entity entity in Map.Instance.Children)
            {
                JigsawPuzzlePiece piece = entity as JigsawPuzzlePiece;
                if (piece != null)
                {
                    string userName = null;

                    if (EntitySystemWorld.Instance.IsServer())
                    {
                        if (piece.Server_MovingByUser != null)
                        {
                            userName = piece.Server_MovingByUser.Name;
                        }
                    }
                    if (EntitySystemWorld.Instance.IsClientOnly())
                    {
                        if (piece.Client_MovingByUser != null)
                        {
                            userName = piece.Client_MovingByUser.Name;
                        }
                    }

                    if (!string.IsNullOrEmpty(userName))
                    {
                        Vec2 screenPosition;
                        if (RendererWorld.Instance.DefaultCamera.ProjectToScreenCoordinates(
                                piece.Position, out screenPosition))
                        {
                            renderer.AddText(userName,
                                             screenPosition, HorizontalAlign.Left, VerticalAlign.Top,
                                             new ColorValue(0, 1, 0, .75f));
                        }
                    }
                }
            }

            //show list of users
            if (GameNetworkServer.Instance != null || GameNetworkClient.Instance != null)
            {
                List <string> lines = new List <string>();

                lines.Add("Players:");

                if (GameNetworkServer.Instance != null)
                {
                    UserManagementServerNetworkService userService =
                        GameNetworkServer.Instance.UserManagementService;

                    foreach (UserManagementServerNetworkService.UserInfo user in userService.Users)
                    {
                        string line = "  " + user.Name;
                        if (user == userService.ServerUser)
                        {
                            line += " (you)";
                        }
                        lines.Add(line);
                    }
                }

                if (GameNetworkClient.Instance != null)
                {
                    UserManagementClientNetworkService userService =
                        GameNetworkClient.Instance.UserManagementService;

                    foreach (UserManagementClientNetworkService.UserInfo user in userService.Users)
                    {
                        string line = "  " + user.Name;
                        if (user == userService.ThisUser)
                        {
                            line += " (you)";
                        }
                        lines.Add(line);
                    }
                }

                renderer.AddTextLines(lines, new Vec2(.01f, .15f), HorizontalAlign.Left, VerticalAlign.Top,
                                      0, new ColorValue(1, 1, 0));
            }

            //screenMessages
            {
                Vec2 pos = new Vec2(.01f, .9f);
                for (int n = screenMessages.Count - 1; n >= 0; n--)
                {
                    ScreenMessage message = screenMessages[n];

                    ColorValue color = new ColorValue(1, 1, 1, message.timeRemaining);
                    if (color.Alpha > 1)
                    {
                        color.Alpha = 1;
                    }

                    renderer.AddText(message.text, pos, HorizontalAlign.Left, VerticalAlign.Top,
                                     color);
                    pos.Y -= renderer.DefaultFont.Height;
                }
            }

            //Game is paused on server
            if (EntitySystemWorld.Instance.IsClientOnly() && !EntitySystemWorld.Instance.Simulation)
            {
                renderer.AddText("Game is paused on server", new Vec2(.5f, .5f),
                                 HorizontalAlign.Center, VerticalAlign.Center, new ColorValue(1, 0, 0));
            }
        }
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            //Draw some HUD information
            if (GetPlayerUnit() != null)
            {
                UpdateHuds();

                if (GetRealCameraType() != CameraType.Free && !IsCutSceneEnabled() &&
                    GetActiveObserveCameraArea() == null)
                {
                    DrawTarget(renderer);

                    if (GetPlayerUnit() as AKunit != null || GetPlayerUnit() as Unit != null || GetPlayerUnit() as PlayerCharacter != null)
                    {
                        drawRadar(renderer);
                        UpdateAKunitHUD(renderer);
                    }
                }

                DrawPlayerInformation(renderer);

                if (EngineApp.Instance.IsKeyPressed(EKeys.F1) && !EngineConsole.Instance.Active)
                    DrawPlayersStatistics(renderer);

                if (GameNetworkServer.Instance != null || GameNetworkClient.Instance != null)
                {
                    renderer.AddText("\"F1\" for players statistics", new Vec2(.01f, .1f),
                        HorizontalAlign.Left, VerticalAlign.Top, new ColorValue(1, 1, 1, .5f));
                }
            }

            //Game is paused on server
            if (EntitySystemWorld.Instance.IsClientOnly() && !EntitySystemWorld.Instance.Simulation)
            {
                renderer.AddText("Game is paused on server", new Vec2(.5f, .5f),
                    HorizontalAlign.Center, VerticalAlign.Center, new ColorValue(1, 0, 0));
            }

            //screenMessages
            {
                Vec2 pos = new Vec2(.01f, .65f);
                for (int n = screenMessages.Count - 1; n >= 0; n--)
                {
                    ScreenMessage message = screenMessages[n];

                    ColorValue color = new ColorValue(1, 1, 1, message.timeRemaining);
                    if (color.Alpha > 1)
                        color.Alpha = 1;

                    renderer.AddText(message.text, pos, HorizontalAlign.Left, VerticalAlign.Top,
                        color);
                    pos.Y -= renderer.DefaultFont.Height;
                }
            }
        }
        /// <summary>
        /// Draw a target at center of screen
        /// </summary>
        /// <param name="renderer"></param>
        private void DrawTarget(GuiRenderer renderer)
        {
            AKunit akunit = GetPlayerUnit() as AKunit;
            Unit playerunit = GetPlayerUnit() as Unit;
            //Draw icons over every friendly and enemy unit in viewport but not in RE or ME
            if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor && (akunit != null || playerunit as PlayerCharacter != null))
            {
                //PlayerCharacter player = (PlayerCharacter) playerunit;

                if (akunit != null)
                    akunit.VisibleUnits = new List<Unit>();
                else if (playerunit != null)
                    playerunit.VisibleUnits = new List<Unit>();

                bool stillOnScreen = false;

                Map.Instance.GetObjectsByScreenRectangle(new Rect(0.0f, 0.0f, 1.0f, 1.0f), MapObjectSceneGraphGroups.UnitGroupMask, delegate(MapObject candidateMapObject)
                {
                    Unit unit = candidateMapObject as Unit;
                    if (unit != null && akunit != null && akunit as Unit != unit && unit as PlayerCharacter == null)
                    {
                        float dist = (unit.Position - akunit.Position).Length();
                        if (dist < AKunitRadarRange)
                        {
                            akunit.VisibleUnits.Add(unit);
                            if (akunit.CurrentReticuleTarget == null) akunit.CurrentReticuleTarget = unit;

                            Texture texture = unit.Intellect != null && akunit.Intellect.Faction == unit.Intellect.Faction ? textureGood : textureWhite;

                            if (akunit.CurrentReticuleTarget == unit)
                            {
                                stillOnScreen = true;
                                DisplayTextureOverPosition(akunit.CurrentReticuleTarget.Position, textureBad, renderer, new ColorValue(1f, 1f, 1f));
                            }
                            else
                            {
                                DisplayTextureOverPosition(unit.Position, texture, renderer, new ColorValue(1f, 1f, 1f));
                            }
                            if (akunit.CurrentMissileTarget != null && unit == akunit.CurrentMissileTarget)
                            {
                                DisplayTextureOverPosition(unit.Position, missileLockDone, renderer, new ColorValue(1f, 1f, 1f));
                            }
                        }
                    }
                    else if (unit != null && playerunit != null && playerunit as Unit != unit && unit as PlayerCharacter == null)
                    {
                        float dist = (unit.Position - playerunit.Position).Length();
                        if (dist < AKunitRadarRange)
                        {
                            playerunit.VisibleUnits.Add(unit);
                            if (playerunit.CurrentReticuleTarget == null) playerunit.CurrentReticuleTarget = unit;

                            Texture texture = unit.Intellect != null && playerunit.Intellect.Faction == unit.Intellect.Faction ? textureGood : textureWhite;

                            if (playerunit.CurrentReticuleTarget == unit)
                            {
                                stillOnScreen = true;
                                DisplayTextureOverPosition(playerunit.CurrentReticuleTarget.Position, textureBad, renderer, new ColorValue(1f, 1f, 1f));
                            }
                            else
                            {
                                DisplayTextureOverPosition(unit.Position, texture, renderer, new ColorValue(1f, 1f, 1f));
                            }
                            if (playerunit.CurrentMissileTarget != null && unit == playerunit.CurrentMissileTarget)
                            {
                                DisplayTextureOverPosition(unit.Position, missileLockDone, renderer, new ColorValue(1f, 1f, 1f));
                            }
                        }
                    }
                });

                if (!stillOnScreen && akunit != null) akunit.CurrentReticuleTarget = null;
                else if (!stillOnScreen && playerunit != null) playerunit.CurrentReticuleTarget = null;
                // do this here, coz you can't have multiple GetObjectsByScreenRectangle inside each other
                DrawTargetLock(renderer);
            }

            Ray lookRay = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(
                new Vec2(.5f, .5f));

            //Vec3 lookTo;
            Body body = null;

            Vec3 lookFrom = lookRay.Origin;
            Vec3 lookDir = Vec3.Normalize(lookRay.Direction);
            float distance = 1000.0f;// RendererWorld.Instance.DefaultCamera.FarClipDistance;

            Unit playerUnit = GetPlayerUnit();

            RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(
                new Ray(lookFrom, lookDir * distance), (int)ContactGroup.CastOnlyContact);

            foreach (RayCastResult result in piercingResult)
            {
                bool ignore = false;

                MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);

                Dynamic dynamic = obj as Dynamic;
                Unit Dunit = obj as Unit;
                if (dynamic != null && playerUnit != null && dynamic.GetParentUnit() == GetPlayerUnit())
                    ignore = true;

                if (dynamic != null && dynamic.GetParentUnit() != GetPlayerUnit())
                {
                    targetgizmo(true);
                    if (Dunit != null && akunit != null)
                    {
                        if ((Dunit.Intellect != null && Dunit.Intellect.Faction != akunit.Intellect.Faction)
                           || (EngineApp.Instance.IsKeyPressed(EKeys.Q))

                           )
                            akunit.CurrentReticuleTarget = Dunit;
                    }
                    else if (Dunit != null && playerunit != null)
                    {
                        if ((Dunit.Intellect != null && Dunit.Intellect.Faction != playerunit.Intellect.Faction)
                           || (EngineApp.Instance.IsKeyPressed(EKeys.Q))

                           )
                            playerunit.CurrentReticuleTarget = Dunit;
                    }
                }
                else
                {
                    targetgizmo(false);
                }

                if (!ignore)
                {
                    body = result.Shape.Body;
                    break;
                }
            }

            if (akunit == null)
            {
                renderer.AddText("¤", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);
                renderer.AddText("(  )", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);
            }

            if (playerunit == null)
            {
                renderer.AddText("¤", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);
                renderer.AddText("(  )", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);
            }

            //if (body != null)
            //{
            //    MapObject obj = MapSystemWorld.GetMapObjectByBody(body);
            //    if (obj != null && (obj as GameGuiObject) == null)
            //    {
            //        renderer.AddText(obj.Type.Name, new Vec2(.5f, .525f),
            //            HorizontalAlign.Center, VerticalAlign.Center);

            //        Dynamic dynamic = obj as Dynamic;
            //        if (dynamic != null)
            //        {
            //            if (dynamic.Type.LifeMax != 0)
            //            {
            //                float lifecoef = dynamic.Life / dynamic.Type.LifeMax;

            //                renderer.AddText("||||||||||", new Vec2(.5f - .04f, .55f), HorizontalAlign.Left,
            //                    VerticalAlign.Center, new ColorValue(.5f, .5f, .5f, .5f));

            //                float count = lifecoef * 10;
            //                String s = "";
            //                for (int n = 0; n < count; n++)
            //                    s += "|";

            //                renderer.AddText(s, new Vec2(.5f - .04f, .55f),
            //                    HorizontalAlign.Left, VerticalAlign.Center, new ColorValue(0, 1, 0, 1));
            //            }
            //            // we dont need to show mass

            //            //if (dynamic.PhysicsModel != null)
            //            //{
            //            //    float mass = 0;
            //            //    foreach (Body s in dynamic.PhysicsModel.Bodies)
            //            //        mass += s.Mass;
            //            //    string ss = string.Format("mass {0}", mass);
            //            //    renderer.AddText(ss, new Vec2(.5f - .04f, .6f),
            //            //        HorizontalAlign.Left, VerticalAlign.Center, new ColorValue(0, 1, 0, 1));
            //            //}
            //        }
            //    }
            //}

            //Tank specific
            DrawTankGunTarget(renderer);

            //AKunit spesific
            //DrawAKunitGunTarget(renderer);
        }
Example #20
0
        public static void RenderObjectsTips(GuiRenderer renderer, Camera camera)
        {
            Contract.Requires<ArgumentNullException>(camera != null);
            Contract.Requires<ArgumentNullException>(renderer != null);

            if (!showObjectsTips)
                return;

            Vec3 cameraPosition = camera.Position;

            //generate visible objects list 
            Map.Instance.GetObjectsByScreenRectangle(camera, new Rect(0, 0, 1, 1), delegate(MapObject obj)
            {
                if (!obj.Visible)
                    return;
                if (!obj.EditorSelectable)
                    return;

                float lengthSqr = (obj.Position - cameraPosition).LengthSqr();
                if (lengthSqr > visibleDistance * visibleDistance)
                    return;

                TempObjects.Add(obj);
            });

            //sort objects by distance 
            //_tempObjects.Sort( delegate( MapObject obj1, MapObject obj2 ) 
            ListUtils.SelectionSort(TempObjects, delegate(MapObject obj1, MapObject obj2)
            {
                float distanceSqr1 = (obj1.Position - cameraPosition).LengthSqr();
                float distanceSqr2 = (obj2.Position - cameraPosition).LengthSqr();

                if (distanceSqr1 < distanceSqr2)
                    return 1;
                if (distanceSqr1 > distanceSqr2)
                    return -1;
                return 0;
            });

            //render objects 
            foreach (MapObject obj in TempObjects.Where(x => !string.IsNullOrEmpty(x.TextUserData)))
            {
                Vec2 screenPos;
                camera.ProjectToScreenCoordinates(obj.Position + new Vec3(0, 0, obj.MapBounds.GetSize().Z + 0.2f), out screenPos);
                if (!new Rect(.001f, .001f, .999f, .999f).IsContainsPoint(screenPos))
                    continue;

                float length = (obj.Position - cameraPosition).LengthFast();

                float alpha = 1;
                if (length > visibleDistance * .9f)
                    alpha = (visibleDistance - length) / (visibleDistance * .1f);

                var textColor = new ColorValue(0.8f, 0.8f, 1, 1);
                textColor.Alpha *= alpha;

                Font font = FontManager.Instance.LoadFont("Default", 0.02f) ?? renderer.DefaultFont;

                string text = obj.TextUserData;
                if (text.Length != 0)
                {
                    float textLength = font.GetTextLength(renderer, text) / renderer.AspectRatio;

                    if (screenPos.X < textLength * .5f)
                    {
                        float visibleArea = 1.0f - (textLength * .5f - screenPos.X) /
                           (textLength * .5f);
                        MathFunctions.Clamp(ref visibleArea, 0, 1);
                        textColor.Alpha *= visibleArea;
                        alpha *= visibleArea;
                    }
                    if (screenPos.X > 1.0f - textLength * .5f)
                    {
                        float visibleArea = 1.0f - (screenPos.X - (1.0f - textLength * .5f)) /
                           (textLength * .5f);
                        MathFunctions.Clamp(ref visibleArea, 0, 1);
                        textColor.Alpha *= visibleArea;
                        alpha *= visibleArea;
                    }

                    renderer.AddText(font, text, screenPos, HorizontalAlign.Center,
                       VerticalAlign.Center, textColor);
                }

                /*** icon rendering
                 * outside loop float aspectRatioInv = 1.0f / camera.AspectRatio;
                if (!string.IsNullOrEmpty(tipItem.Icon))
                {
                    Vec2 size = new Vec2(tipItem.IconSize * aspectRatioInv, tipItem.IconSize);
                    Rect rectangle = new Rect(screenPos - size * .5f, screenPos + size * .5f);

                    if (textLength == 0)
                    {
                        if (rectangle.Right < size.X)
                        {
                            float v = (rectangle.Right - size.X * .5f) / (size.X * .5f);
                            MathFunctions.Clamp(ref v, 0, 1);
                            alpha *= v;
                        }
                        if (rectangle.Left > 1.0 - size.X)
                        {
                            float v = ((1.0f - rectangle.Left) - size.X * .5f) / (size.X * .5f);
                            MathFunctions.Clamp(ref v, 0, 1);
                            alpha *= v;
                        }
                        if (rectangle.Top < size.Y)
                        {
                            float v = (rectangle.Top - size.Y * .5f) / (size.Y * .5f);
                            MathFunctions.Clamp(ref v, 0, 1);
                            alpha *= v;
                        }
                        if (rectangle.Bottom > 1.0 - size.Y)
                        {
                            float v = ((1.0f - rectangle.Bottom) - size.Y * .5f) / (size.Y * .5f);
                            MathFunctions.Clamp(ref v, 0, 1);
                            alpha *= v;
                        }
                    }

                    if (textLength != 0)
                        rectangle -= new Vec2(textLength * .5f + size.X * .5f, 0);

                    Texture texture = TextureManager.Instance.Load(tipItem.Icon);

                    ColorValue color = tipItem.IconColor;
                    color *= alpha;

                    if (texture != null)
                        renderer.AddQuad(rectangle, new Rect(0, 0, 1, 1), texture, color, true);
                }
                 */

            }

            TempObjects.Clear();
        }
Example #21
0
        void DrawPlayersStatistics( GuiRenderer renderer )
        {
            if( IsCutSceneEnabled() )
                return;

            if( PlayerManager.Instance == null )
                return;

            renderer.AddQuad( new Rect( .1f, .2f, .9f, .8f ), new ColorValue( 0, 0, 1, .5f ) );

            renderer.AddText( "Players statistics", new Vec2( .5f, .25f ),
                HorizontalAlign.Center, VerticalAlign.Center );

            if( EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle() )
            {
                float posy = .3f;
                ICollection<Entity> icol = Entities.Instance.EntitiesCollection;
                String fact = "";
                foreach( PlayerManager.ServerOrSingle_Player player in
                    PlayerManager.Instance.ServerOrSingle_Players )
                {
                    foreach (Entity ent in icol)
                    {
                        Console.WriteLine(ent.UIN + " : "+ent.NetworkUIN+" : "+ent.Name);
                        Console.WriteLine(player.Identifier + " : " + " : " + player.User.Identifier + " : " + player.Name);

                        if (ent.Name.ToString().Contains("Human"))
                        {
                            fact = "Human";
                        }
                        if (ent.Name.ToString().Contains("Statue") && ent.NetworkUIN.Equals(player.User.Identifier))
                        {
                            fact = "Statue";
                        }

                    }

                    string text = string.Format("{0},   Frags: {1},  Faction: {3},  Ping: {2} ms", player.Name,
                        player.Frags, (int)( player.Ping * 1000 ), fact );
                    renderer.AddText( text, new Vec2( .2f, posy ), HorizontalAlign.Left,
                        VerticalAlign.Center );

                    posy += .025f;
                }
            }

            if( EntitySystemWorld.Instance.IsClientOnly() )
            {
                float posy = .3f;
                ICollection<Entity> icol = Entities.Instance.EntitiesCollection;
                String fact = "";
                foreach( PlayerManager.Client_Player player in PlayerManager.Instance.Client_Players )
                {
                    foreach (Entity ent in icol)
                    {
                        if (ent.Name.ToString().Contains("Human") && ent.UIN.Equals(player.User.Identifier))
                        {
                            fact = "Human";
                        }
                        if (ent.Name.ToString().Contains("Statue") && ent.UIN.Equals(player.User.Identifier))
                        {
                            fact = "Statue";
                        }
                    }

                    string text = string.Format("{0},   Frags: {1},  Faction: {3}, ID: {4}, Ping: {2} ms", player.Name,
                        player.Frags, (int)( player.Ping * 1000 ),  fact, player.Identifier );
                    renderer.AddText( text, new Vec2( .2f, posy ), HorizontalAlign.Left,
                        VerticalAlign.Center );

                    posy += .025f;
                }
            }
        }
Example #22
0
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vec2I size = GetNeededSize();

            if (browser == null)
            {
                CreateBrowser();
            }

            //update brower engine and texture
            if (browser != null)
            {
                if (viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized(oldSize, viewSize);
                }

                //create texture
                if (texture == null || textureSize != size || needRecreateTexture)
                {
                    if (texture != null)
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    string textureName = TextureManager.Instance.GetUniqueName("WebBrowserControl");

                    bool mipmaps = false;
                    if (GetControlManager() != null && GetControlManager() is In3dControlManager)
                    {
                        mipmaps = inGame3DGuiMipmaps;
                    }

                    if (mipmaps)
                    {
                        texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                                 1, -1, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable | Texture.Usage.AutoMipmap);
                    }
                    else
                    {
                        texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                                 1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable);
                    }

                    needUpdateTexture   = true;
                    needRecreateTexture = false;
                }

                if (needInvalidate)
                {
                    browserHost.SetZoomLevel(zoom);
                    browserHost.Invalidate(CefPaintElementType.View);
                    //browserHost.Invalidate( new CefRectangle( 0, 0, 100000, 100000 ), CefPaintElementType.View );
                    needInvalidate = false;
                }

                //update texture
                if (/*browser.IsDirty ||*/ needUpdateTexture)
                {
                    if (texture != null)
                    {
                        UpdateTexture();
                    }
                    needUpdateTexture = false;
                }
            }

            //draw texture
            if (browser != null)
            {
                bool backColorZero = BackColor == new ColorValue(0, 0, 0, 0);

                ColorValue color = backColorZero ? new ColorValue(1, 1, 1) : BackColor;
                if (texture == null)
                {
                    color = new ColorValue(0, 0, 0, color.Alpha);
                }
                color *= GetTotalColorMultiplier();

                color.Clamp(new ColorValue(0, 0, 0, 0), new ColorValue(1, 1, 1, 1));

                Rect rect;
                GetScreenRectangle(out rect);

                if (renderer.IsScreen && !renderer._OutGeometryTransformEnabled)
                {
                    //screen per pixel accuracy

                    Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

                    Vec2 leftTop = rect.LeftTop;
                    leftTop *= viewportSize;
                    leftTop  = new Vec2((int)(leftTop.X + .9999f), (int)(leftTop.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        leftTop -= new Vec2(.5f, .5f);
                    }
                    leftTop /= viewportSize;

                    Vec2 rightBottom = rect.RightBottom;
                    rightBottom *= viewportSize;
                    rightBottom  = new Vec2((int)(rightBottom.X + .9999f), (int)(rightBottom.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        rightBottom -= new Vec2(.5f, .5f);
                    }
                    rightBottom /= viewportSize;

                    Rect fixedRect = new Rect(leftTop, rightBottom);

                    renderer.AddQuad(fixedRect, new Rect(0, 0, 1, 1), texture, color, true);
                }
                else
                {
                    renderer.AddQuad(rect, new Rect(0, 0, 1, 1), texture, color, true);
                }
            }

            if (cefRuntimeUnableToLoad)
            {
                renderer.AddTextWordWrap(
                    string.Format("WebBrowserControl: Unable to initialize web browser control. Error: {0}", cefRuntimeUnableToLoadError),
                    GetScreenRectangle(), Renderer.HorizontalAlign.Center, false, Renderer.VerticalAlign.Center, 0, new ColorValue(1, 0, 0));
            }
            else if (!IsSupportedByThisPlatform())
            {
                renderer.AddText(string.Format("WebBrowserControl: {0} is not supported.", PlatformInfo.Platform),
                                 new Vec2(.5f, .5f), Renderer.HorizontalAlign.Center, Renderer.VerticalAlign.Center, new ColorValue(1, 0, 0));
            }
        }
        void DrawPlayersStatistics( GuiRenderer renderer )
        {
            if( IsCutSceneEnabled() )
                return;

            if( PlayerManager.Instance == null )
                return;

            renderer.AddQuad( new Rect( .1f, .2f, .9f, .8f ), new ColorValue( 0, 0, 1, .5f ) );

            renderer.AddText( "Players statistics", new Vec2( .5f, .25f ),
                HorizontalAlign.Center, VerticalAlign.Center );

            if( EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle() )
            {
                float posy = .3f;

                foreach( PlayerManager.ServerOrSingle_Player player in
                    PlayerManager.Instance.ServerOrSingle_Players )
                {
                    string text = string.Format( "{0},   Frags: {1},   Ping: {2} ms", player.Name,
                        player.Frags, (int)( player.Ping * 1000 ) );
                    renderer.AddText( text, new Vec2( .2f, posy ), HorizontalAlign.Left,
                        VerticalAlign.Center );

                    posy += .025f;
                }
            }

            if( EntitySystemWorld.Instance.IsClientOnly() )
            {
                float posy = .3f;

                foreach( PlayerManager.Client_Player player in PlayerManager.Instance.Client_Players )
                {
                    string text = string.Format( "{0},   Frags: {1},   Ping: {2} ms", player.Name,
                        player.Frags, (int)( player.Ping * 1000 ) );
                    renderer.AddText( text, new Vec2( .2f, posy ), HorizontalAlign.Left,
                        VerticalAlign.Center );

                    posy += .025f;
                }
            }
        }
Example #24
0
        public static void RenderObjectsTips(GuiRenderer renderer, Camera camera)
        {
            Contract.Requires <ArgumentNullException>(camera != null);
            Contract.Requires <ArgumentNullException>(renderer != null);

            if (!showObjectsTips)
            {
                return;
            }

            Vec3 cameraPosition = camera.Position;

            //generate visible objects list
            Map.Instance.GetObjectsByScreenRectangle(camera, new Rect(0, 0, 1, 1), delegate(MapObject obj)
            {
                if (!obj.Visible)
                {
                    return;
                }
                if (!obj.EditorSelectable)
                {
                    return;
                }

                float lengthSqr = (obj.Position - cameraPosition).LengthSqr();
                if (lengthSqr > visibleDistance * visibleDistance)
                {
                    return;
                }

                TempObjects.Add(obj);
            });

            //sort objects by distance
            //_tempObjects.Sort( delegate( MapObject obj1, MapObject obj2 )
            ListUtils.SelectionSort(TempObjects, delegate(MapObject obj1, MapObject obj2)
            {
                float distanceSqr1 = (obj1.Position - cameraPosition).LengthSqr();
                float distanceSqr2 = (obj2.Position - cameraPosition).LengthSqr();

                if (distanceSqr1 < distanceSqr2)
                {
                    return(1);
                }
                if (distanceSqr1 > distanceSqr2)
                {
                    return(-1);
                }
                return(0);
            });

            //render objects
            foreach (MapObject obj in TempObjects.Where(x => !string.IsNullOrEmpty(x.TextUserData)))
            {
                Vec2 screenPos;
                camera.ProjectToScreenCoordinates(obj.Position + new Vec3(0, 0, obj.MapBounds.GetSize().Z + 0.2f), out screenPos);
                if (!new Rect(.001f, .001f, .999f, .999f).IsContainsPoint(screenPos))
                {
                    continue;
                }

                float length = (obj.Position - cameraPosition).LengthFast();

                float alpha = 1;
                if (length > visibleDistance * .9f)
                {
                    alpha = (visibleDistance - length) / (visibleDistance * .1f);
                }

                var textColor = new ColorValue(0.8f, 0.8f, 1, 1);
                textColor.Alpha *= alpha;

                Font font = FontManager.Instance.LoadFont("Default", 0.02f) ?? renderer.DefaultFont;

                string text = obj.TextUserData;
                if (text.Length != 0)
                {
                    float textLength = font.GetTextLength(renderer, text) / renderer.AspectRatio;

                    if (screenPos.X < textLength * .5f)
                    {
                        float visibleArea = 1.0f - (textLength * .5f - screenPos.X) /
                                            (textLength * .5f);
                        MathFunctions.Clamp(ref visibleArea, 0, 1);
                        textColor.Alpha *= visibleArea;
                        alpha           *= visibleArea;
                    }
                    if (screenPos.X > 1.0f - textLength * .5f)
                    {
                        float visibleArea = 1.0f - (screenPos.X - (1.0f - textLength * .5f)) /
                                            (textLength * .5f);
                        MathFunctions.Clamp(ref visibleArea, 0, 1);
                        textColor.Alpha *= visibleArea;
                        alpha           *= visibleArea;
                    }

                    renderer.AddText(font, text, screenPos, HorizontalAlign.Center,
                                     VerticalAlign.Center, textColor);
                }

                /*** icon rendering
                 * outside loop float aspectRatioInv = 1.0f / camera.AspectRatio;
                 * if (!string.IsNullOrEmpty(tipItem.Icon))
                 * {
                 *  Vec2 size = new Vec2(tipItem.IconSize * aspectRatioInv, tipItem.IconSize);
                 *  Rect rectangle = new Rect(screenPos - size * .5f, screenPos + size * .5f);
                 *
                 *  if (textLength == 0)
                 *  {
                 *      if (rectangle.Right < size.X)
                 *      {
                 *          float v = (rectangle.Right - size.X * .5f) / (size.X * .5f);
                 *          MathFunctions.Clamp(ref v, 0, 1);
                 *          alpha *= v;
                 *      }
                 *      if (rectangle.Left > 1.0 - size.X)
                 *      {
                 *          float v = ((1.0f - rectangle.Left) - size.X * .5f) / (size.X * .5f);
                 *          MathFunctions.Clamp(ref v, 0, 1);
                 *          alpha *= v;
                 *      }
                 *      if (rectangle.Top < size.Y)
                 *      {
                 *          float v = (rectangle.Top - size.Y * .5f) / (size.Y * .5f);
                 *          MathFunctions.Clamp(ref v, 0, 1);
                 *          alpha *= v;
                 *      }
                 *      if (rectangle.Bottom > 1.0 - size.Y)
                 *      {
                 *          float v = ((1.0f - rectangle.Bottom) - size.Y * .5f) / (size.Y * .5f);
                 *          MathFunctions.Clamp(ref v, 0, 1);
                 *          alpha *= v;
                 *      }
                 *  }
                 *
                 *  if (textLength != 0)
                 *      rectangle -= new Vec2(textLength * .5f + size.X * .5f, 0);
                 *
                 *  Texture texture = TextureManager.Instance.Load(tipItem.Icon);
                 *
                 *  ColorValue color = tipItem.IconColor;
                 *  color *= alpha;
                 *
                 *  if (texture != null)
                 *      renderer.AddQuad(rectangle, new Rect(0, 0, 1, 1), texture, color, true);
                 * }
                 */
            }

            TempObjects.Clear();
        }
Example #25
0
        public void DoRenderUI(GuiRenderer renderer)
        {
            if (transparency == 0.0f)
            {
                return;
            }

            if (firstRender)
            {
                texture = TextureManager.Instance.Load("Gui\\Various\\Console.dds",
                                                       Texture.Type.Type2D, 0);
                font = FontManager.Instance.LoadFont("Default", .025f);

                firstRender = false;
            }

            if (font == null)
            {
                return;
            }

            Rect textureRect = new Rect(0, 0, 1, 1);

            textureRect += textureOffset;

            renderer.PushClipRectangle(new Rect(0, 0, 1, 1));
            renderer.AddQuad(new Rect(0, 0, 1, .5f), textureRect, texture,
                             new ColorValue(1, 1, 1, transparency), false);
            renderer.PopClipRectangle();
            renderer.AddQuad(new Rect(0, .495f, 1, .5f),
                             new ColorValue(.8f, .8f, .8f, transparency));

            string staticText = "Version " + EngineVersionInformation.Version;

            if (staticText != null && staticText != "")
            {
                renderer.AddText(font, staticText, new Vec2(.99f, .5f - font.Height),
                                 HorizontalAlign.Right, VerticalAlign.Center, new ColorValue(1, 1, 1, transparency));
            }

            float fontheight = font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

            if (stringDownPosition != strings.Count - 1)
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
            {
                str = currentString + "_";
            }

            renderer.AddText(font, str, new Vec2(x, y), HorizontalAlign.Left,
                             VerticalAlign.Center, new ColorValue(1, 1, 1, transparency));

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;

            if (startpos > strings.Count - 1)
            {
                startpos = strings.Count - 1;
            }
            for (int n = startpos; n >= 0 && y - fontheight > 0; n--)
            {
                renderer.AddText(font, strings[n].text, new Vec2(x, y), HorizontalAlign.Left,
                                 VerticalAlign.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight;
            }
        }
Example #26
0
        void DrawArea_RenderUI( Control sender, GuiRenderer renderer )
        {
            Rect rectangle = sender.GetScreenRectangle();
            bool clipRectangle = true;
            ColorValue[] colors = new ColorValue[]{
                new ColorValue( 1 ,0, 0 ),
                new ColorValue( 0, 1, 0 ),
                new ColorValue( 0, 0, 1 ),
                new ColorValue( 1, 1, 0 ),
                new ColorValue( 1, 1, 1 )};

            if( clipRectangle )
                renderer.PushClipRectangle( rectangle );

            //draw triangles
            if( GetDrawAreaMode() == DrawAreaModes.Triangles )
            {
                float distance = rectangle.GetSize().X / 2;

                List<GuiRenderer.TriangleVertex> triangles = new List<GuiRenderer.TriangleVertex>( 256 );

                Radian angle = -EngineApp.Instance.Time;

                const int steps = 30;
                Vec2 lastPosition = Vec2.Zero;
                for( int step = 0; step < steps + 1; step++ )
                {
                    Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio );

                    if( step != 0 )
                    {
                        ColorValue color = colors[ step % colors.Length ];
                        ColorValue color2 = color;
                        color2.Alpha = 0;
                        triangles.Add( new GuiRenderer.TriangleVertex( rectangle.GetCenter(), color ) );
                        triangles.Add( new GuiRenderer.TriangleVertex( lastPosition, color2 ) );
                        triangles.Add( new GuiRenderer.TriangleVertex( pos, color2 ) );
                    }

                    angle += ( MathFunctions.PI * 2 ) / steps;
                    lastPosition = pos;
                }

                renderer.AddTriangles( triangles );
            }

            //draw quads
            if( GetDrawAreaMode() == DrawAreaModes.Quads )
            {
                //draw background
                {
                    Texture texture = TextureManager.Instance.Load( "Gui\\Various\\Logo.png" );
                    renderer.AddQuad( rectangle, new Rect( 0, -.3f, 1, 1.4f ), texture,
                        new ColorValue( 1, 1, 1 ), true );
                }

                //draw bars
                {
                    float time = EngineApp.Instance.Time;

                    EngineRandom random = new EngineRandom( 0 );

                    int count = 15;
                    float stepOffset = rectangle.GetSize().X / count;
                    float size = stepOffset * .9f;
                    for( int n = 0; n < count; n++ )
                    {
                        float v = MathFunctions.Cos( time * random.NextFloat() );
                        float v2 = ( v + 1 ) / 2;

                        ColorValue color = colors[ n % colors.Length ];
                        Rect rect = new Rect(
                            rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y * v2,
                            rectangle.Left + stepOffset * n + size, rectangle.Bottom );
                        renderer.AddQuad( rect, color );
                    }
                }
            }

            //draw lines
            if( GetDrawAreaMode() == DrawAreaModes.Lines )
            {
                float maxDistance;
                {
                    Vec2 s = rectangle.GetSize() / 2;
                    maxDistance = MathFunctions.Sqrt( s.X * s.X + s.Y * s.Y );
                }

                int step = 0;
                float distance = 0;
                Radian angle = -EngineApp.Instance.Time;
                Vec2 lastPosition = Vec2.Zero;

                while( distance < maxDistance )
                {
                    Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio );

                    if( step != 0 )
                    {
                        ColorValue color = colors[ step % colors.Length ];
                        renderer.AddLine( lastPosition, pos, color );
                    }

                    step++;
                    angle += MathFunctions.PI / 10;
                    distance += .001f;
                    lastPosition = pos;
                }
            }

            //draw text
            if( GetDrawAreaMode() == DrawAreaModes.Text )
            {
                //draw text with specified font.
                renderer.AddText( drawAreaBigFont, "Big Font Sample", rectangle.LeftTop, HorizontalAlign.Left,
                    VerticalAlign.Top, new ColorValue( 1, 1, 1 ) );

                //draw text with word wrap.
                string text = "Test Test Test.\n\nThe expandable user interface system is a unified system " +
                    "for the creation of end-user controls, menus, dialogues, windows and HUD screens. " +
                    "With the help of this system the end-user exercises control over the application.";
                renderer.AddTextWordWrap( text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                    new ColorValue( 1, 1, 0 ) );
            }

            if( clipRectangle )
                renderer.PopClipRectangle();
        }
Example #27
0
        void renderTargetUserControl1_RenderUI( RenderTargetUserControl sender, GuiRenderer renderer )
        {
            string text = "NeoAxis 3D Engine " + EngineVersionInformation.Version;
            renderer.AddText( text, new Vec2( .01f, .01f ), HorizontalAlign.Left,
                 VerticalAlign.Top, new ColorValue( 1, 1, 1 ) );

            renderer.AddText( "Camera control: W A S D, right mouse", new Vec2( .99f, .99f ),
                HorizontalAlign.Right, VerticalAlign.Bottom, new ColorValue( 1, 1, 1 ) );
        }
        private void AddTextWithShadow(GuiRenderer renderer, string text, Vec2 position, HorizontalAlign horizontalAlign,
            VerticalAlign verticalAlign, ColorValue color)
        {
            Vec2 shadowOffset = 2.0f / RendererWorld.Instance.DefaultViewport.DimensionsInPixels.Size.ToVec2();

            renderer.AddText(text, position + shadowOffset, horizontalAlign, verticalAlign,
                new ColorValue(0, 0, 0, color.Alpha / 2));
            renderer.AddText(text, position, horizontalAlign, verticalAlign, color);
        }
Example #29
0
        protected override void OnRenderUI( GuiRenderer renderer )
        {
            base.OnRenderUI( renderer );

            UpdateHUD();

            //render user names for moving pieces by users
            foreach( Entity entity in Map.Instance.Children )
            {
                JigsawPuzzlePiece piece = entity as JigsawPuzzlePiece;
                if( piece != null )
                {
                    string userName = null;

                    if( EntitySystemWorld.Instance.IsServer() )
                    {
                        if( piece.Server_MovingByUser != null )
                            userName = piece.Server_MovingByUser.Name;
                    }
                    if( EntitySystemWorld.Instance.IsClientOnly() )
                    {
                        if( piece.Client_MovingByUser != null )
                            userName = piece.Client_MovingByUser.Name;
                    }

                    if( !string.IsNullOrEmpty( userName ) )
                    {
                        Vec2 screenPosition;
                        if( RendererWorld.Instance.DefaultCamera.ProjectToScreenCoordinates(
                            piece.Position, out screenPosition ) )
                        {
                            renderer.AddText( userName,
                                screenPosition, HorizontalAlign.Left, VerticalAlign.Top,
                                new ColorValue( 0, 1, 0, .75f ) );
                        }
                    }
                }
            }

            //show list of users
            if( GameNetworkServer.Instance != null || GameNetworkClient.Instance != null )
            {
                List<string> lines = new List<string>();

                lines.Add( "Players:" );

                if( GameNetworkServer.Instance != null )
                {
                    UserManagementServerNetworkService userService =
                        GameNetworkServer.Instance.UserManagementService;

                    foreach( UserManagementServerNetworkService.UserInfo user in userService.Users )
                    {
                        string line = "  " + user.Name;
                        if( user == userService.ServerUser )
                            line += " (you)";
                        lines.Add( line );
                    }
                }

                if( GameNetworkClient.Instance != null )
                {
                    UserManagementClientNetworkService userService =
                        GameNetworkClient.Instance.UserManagementService;

                    foreach( UserManagementClientNetworkService.UserInfo user in userService.Users )
                    {
                        string line = "  " + user.Name;
                        if( user == userService.ThisUser )
                            line += " (you)";
                        lines.Add( line );
                    }
                }

                renderer.AddTextLines( lines, new Vec2( .01f, .15f ), HorizontalAlign.Left, VerticalAlign.Top,
                    0, new ColorValue( 1, 1, 0 ) );
            }

            //screenMessages
            {
                Vec2 pos = new Vec2( .01f, .9f );
                for( int n = screenMessages.Count - 1; n >= 0; n-- )
                {
                    ScreenMessage message = screenMessages[ n ];

                    ColorValue color = new ColorValue( 1, 1, 1, message.timeRemaining );
                    if( color.Alpha > 1 )
                        color.Alpha = 1;

                    renderer.AddText( message.text, pos, HorizontalAlign.Left, VerticalAlign.Top,
                        color );
                    pos.Y -= renderer.DefaultFont.Height;
                }
            }

            //Game is paused on server
            if( EntitySystemWorld.Instance.IsClientOnly() && !EntitySystemWorld.Instance.Simulation )
            {
                renderer.AddText( "Game is paused on server", new Vec2( .5f, .5f ),
                    HorizontalAlign.Center, VerticalAlign.Center, new ColorValue( 1, 0, 0 ) );
            }
        }
Example #30
0
        /// <summary>
        /// Draw a target at center of screen
        /// </summary>
        /// <param name="renderer"></param>
        void DrawTarget(GuiRenderer renderer)
        {
            renderer.AddText("o", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);

            Ray lookRay = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(
                new Vec2(.5f, .5f));

            Body body = null;

            Vec3 lookFrom = lookRay.Origin;
            Vec3 lookDir = Vec3.Normalize(lookRay.Direction);
            float distance = 1000.0f;

            Unit playerUnit = GetPlayerUnit();

            RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(
                new Ray(lookFrom, lookDir * distance), (int)ContactGroup.CastOnlyContact);

            foreach (RayCastResult result in piercingResult)
            {
                bool ignore = false;

                MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);

                Dynamic dynamic = obj as Dynamic;
                if (dynamic != null && playerUnit != null && dynamic.GetParentUnit() == GetPlayerUnit())
                    ignore = true;

                if (!ignore)
                {
                    body = result.Shape.Body;
                    break;
                }
            }

            //renderer.AddText("[  ]", new Vec2(.5f, .5f), HorizontalAlign.Center, VerticalAlign.Center);

            if (body != null && body == null)
            {
                MapObject obj = MapSystemWorld.GetMapObjectByBody(body);

                if (obj != null && !(obj is StaticMesh) && !(obj is GameGuiObject))
                {
                    renderer.AddText(obj.Type.Name, new Vec2(.5f, .525f),
                        HorizontalAlign.Center, VerticalAlign.Center);

                    Dynamic dynamic = obj as Dynamic;
                    if (dynamic != null)
                    {
                        if (dynamic.Type.LifeMax != 0)
                        {
                            renderer.AddText("XXXX", new Vec2(.5f - .04f, .55f), HorizontalAlign.Left,
                                VerticalAlign.Center, new ColorValue(.5f, .5f, .5f, .5f));

                            float lifecoef = dynamic.Life / dynamic.Type.LifeMax;

                            renderer.AddText("IIIIIIIIII", new Vec2(.5f - .04f, .55f), HorizontalAlign.Left,
                                VerticalAlign.Center, new ColorValue(.5f, .5f, .5f, .5f));

                            float count = lifecoef * 10;
                            String s = "";
                            for (int n = 0; n < count; n++)
                                s += "I";

                            renderer.AddText(s, new Vec2(.5f - .04f, .55f),
                                HorizontalAlign.Left, VerticalAlign.Center, new ColorValue(0, 1, 0, 1));
                        }

                        if (dynamic.PhysicsModel != null)
                        {
                            float mass = 0;
                            foreach (Body s in dynamic.PhysicsModel.Bodies)
                                mass += s.Mass;
                            string ss = string.Format("mass {0}", mass);
                            renderer.AddText(ss, new Vec2(.5f - .04f, .6f),
                                HorizontalAlign.Left, VerticalAlign.Center, new ColorValue(0, 1, 0, 1));
                        }
                    }
                }

            }
        }
		public override void OnRenderScreenUI( GuiRenderer renderer )
		{
			base.OnRenderScreenUI( renderer );

			if( drawTextOnScreen )
			{
				renderer.AddText( "Add-on Example!", new Vec2( .5f, .9f ), HorizontalAlign.Center, VerticalAlign.Top,
					new ColorValue( 1, 0, 0 ) );
				renderer.AddQuad( new Rect( .3f, .94f, .7f, .95f ), new ColorValue( 1, 1, 0 ) );
			}
		}
 private void renderTargetUserControl1_RenderUI(RenderTargetUserControl sender, GuiRenderer renderer)
 {
     string text = "NeoAxis 3D Engine " + EngineVersionInformation.Version;
     renderer.AddText(text, new Vec2(.01f, .01f), HorizontalAlign.Left,
          VerticalAlign.Top, new ColorValue(1, 1, 1));
 }
Example #33
0
		void AddTextWithShadow( GuiRenderer renderer, Engine.Renderer.Font font, string text, Vec2 position,
			HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, ColorValue color )
		{
			Vec2 shadowOffset = 2.0f / renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

			renderer.AddText( font, text, position + shadowOffset, horizontalAlign, verticalAlign,
				new ColorValue( 0, 0, 0, color.Alpha / 2 ) );
			renderer.AddText( font, text, position, horizontalAlign, verticalAlign, color );
		}
Example #34
0
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vec2I size = GetNeededSize();

            if (browser == null)
            {
                CreateBrowser();
            }

            //update brower engine and texture
            if (browser != null)
            {
                if (viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized(oldSize, viewSize);
                }

                //create texture
                if (texture == null || textureSize != size)
                {
                    if (texture != null)
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    string textureName = TextureManager.Instance.GetUniqueName("WebBrowserControl");
                    texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                             1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable);
                    forceUpdateTexture = true;
                }

                //update texture
                if (/*browser.IsDirty ||*/ forceUpdateTexture)
                {
                    if (texture != null)
                    {
                        UpdateTexture();
                    }
                    forceUpdateTexture = false;
                }
            }

            //draw texture
            {
                bool backColorZero = BackColor == new ColorValue(0, 0, 0, 0);

                ColorValue color = backColorZero ? new ColorValue(1, 1, 1) : BackColor;
                if (texture == null)
                {
                    color = new ColorValue(0, 0, 0, color.Alpha);
                }
                color *= GetTotalColorMultiplier();

                color.Clamp(new ColorValue(0, 0, 0, 0), new ColorValue(1, 1, 1, 1));

                Rect rect;
                GetScreenRectangle(out rect);

                if (renderer.IsScreen && !renderer._OutGeometryTransformEnabled)
                {
                    //screen per pixel accuracy

                    Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

                    Vec2 leftTop = rect.LeftTop;
                    leftTop *= viewportSize;
                    leftTop  = new Vec2((int)(leftTop.X + .9999f), (int)(leftTop.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        leftTop -= new Vec2(.5f, .5f);
                    }
                    leftTop /= viewportSize;

                    Vec2 rightBottom = rect.RightBottom;
                    rightBottom *= viewportSize;
                    rightBottom  = new Vec2((int)(rightBottom.X + .9999f), (int)(rightBottom.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        rightBottom -= new Vec2(.5f, .5f);
                    }
                    rightBottom /= viewportSize;

                    Rect fixedRect = new Rect(leftTop, rightBottom);

                    renderer.AddQuad(fixedRect, new Rect(0, 0, 1, 1), texture, color, true);
                }
                else
                {
                    renderer.AddQuad(rect, new Rect(0, 0, 1, 1), texture, color, true);
                }
            }

            if (!IsSupportedByThisPlatform())
            {
                renderer.AddText(string.Format("WebBrowserControl: {0} is not supported.", PlatformInfo.Platform),
                                 new Vec2(.5f, .5f), Renderer.HorizontalAlign.Center, Renderer.VerticalAlign.Center, new ColorValue(1, 0, 0));
            }
        }