Ejemplo n.º 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);

            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));
            }
        }