Exemplo n.º 1
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (!Enabled)
            {
                graphics.FillRectangle(RenderBounds, DisabledBackground);
            }
            else
            {
                if (Focused)
                {
                    graphics.FillRectangle(RenderBounds, FocusedBackground);

                    if (FocusOutlineThickness != Thickness.Zero)
                    {
                        graphics.DrawRectangle(RenderBounds, FocusOutlineColor, FocusOutlineThickness, true);
                    }
                }

                if (Highlighted)
                {
                    graphics.FillRectangle(RenderBounds, HighlightedBackground);

                    if (HighlightOutlineThickness != Thickness.Zero)
                    {
                        graphics.DrawRectangle(RenderBounds, HighlightOutlineColor, HighlightOutlineThickness, true);
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            if (_isPending)
            {
                graphics.FillRectangle(RenderBounds, _connectingStateTextures[_animationFrame], TextureRepeatMode.NoScaleCenterSlice);
            }
            else
            {
                base.OnDraw(graphics, gameTime);

                //graphics.FillRectangle(RenderBounds, Background,  TextureRepeatMode.NoScaleCenterSlice);

                if (_renderLatency)
                {
                    string text = $"{_ping}ms";

                    if (!string.IsNullOrWhiteSpace(_version))
                    {
                        text = $"Server Ping: {text}\nGame Version: {_version.Trim()}";
                    }

                    var size     = graphics.Font.MeasureString(text);
                    var position = _cursorPosition + new Point(5, 5);

                    graphics.SpriteBatch.FillRectangle(new Rectangle(position, size.ToPoint()), Color.Black * 0.5f);
                    graphics.DrawString(position.ToVector2(), text, TextColor.White, FontStyle.None, 1f);
                }
            }
        }
Exemplo n.º 3
0
        public GuiManager(Game game, IServiceProvider serviceProvider, InputManager inputManager, IGuiRenderer guiRenderer, IOptionsProvider optionsProvider)
        {
            Game             = game;
            ServiceProvider  = serviceProvider;
            InputManager     = inputManager;
            ScaledResolution = new GuiScaledResolution(game)
            {
                GuiScale = optionsProvider.AlexOptions.VideoOptions.GuiScale
            };
            ScaledResolution.ScaleChanged += ScaledResolutionOnScaleChanged;

            FocusManager = new GuiFocusHelper(this, InputManager, game.GraphicsDevice);

            GuiRenderer = guiRenderer;
            guiRenderer.ScaledResolution = ScaledResolution;
            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);

            GuiSpriteBatch = new GuiSpriteBatch(guiRenderer, Game.GraphicsDevice, SpriteBatch);
            GuiRenderArgs  = new GuiRenderArgs(Game.GraphicsDevice, SpriteBatch, ScaledResolution, GuiRenderer, new GameTime());

            //  DebugHelper = new GuiDebugHelper(this);

            optionsProvider.AlexOptions.VideoOptions.GuiScale.Bind((value, newValue) =>
            {
                ScaledResolution.GuiScale = newValue;
            });
        }
Exemplo n.º 4
0
        //	private void Draw(GuiSpriteBatch graphics, )

        /// <inheritdoc />
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (_add)
            {
                _progress += gameTime.ElapsedGameTime.TotalSeconds;
                _progress  = Math.Clamp(_progress, 0d, 1d);

                if (_progress >= 1d)
                {
                    _add = false;
                }
            }
            else
            {
                _progress -= gameTime.ElapsedGameTime.TotalSeconds;
                _progress  = Math.Clamp(_progress, 0d, 1d);

                if (_progress <= 0d)
                {
                    _add = true;
                }
            }

            graphics.FillRectangle(RenderBounds, BackgroundColor);
            var xOffset = (_progress * RenderBounds.Width);

            graphics.FillRectangle(new Rectangle(RenderBounds.X + (int)xOffset, RenderBounds.Y, RenderBounds.Height, RenderBounds.Height), ForegroundColor);
        }
Exemplo n.º 5
0
 protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
 {
     if (_hidden)
     {
         return;
     }
     base.OnDraw(graphics, gameTime);
 }
Exemplo n.º 6
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            //if (OutlineColor == Color.Transparent || OutlineSize == Thickness.Zero) return;

            //graphics.DrawRectangle(Bounds, OutlineColor, OutlineSize);
        }
Exemplo n.º 7
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (Texture != null)
            {
                graphics.FillRectangle(RenderBounds, Texture, RepeatMode);
            }
        }
Exemplo n.º 8
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            var bounds = RenderBounds;

            bounds.Inflate(1f, 1f);
            graphics.DrawRectangle(bounds, BorderColor, BorderThickness);
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            if (ParentState is IGuiElement gui)
            {
                gui.Draw(graphics, gameTime);
            }

            base.OnDraw(graphics, gameTime);
        }
Exemplo n.º 10
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (_mapTexture == null)
            {
                return;
            }
        }
Exemplo n.º 11
0
        public void Init(GraphicsDevice graphicsDevice, IServiceProvider serviceProvider)
        {
            GraphicsDevice = graphicsDevice;
            SpriteBatch    = new SpriteBatch(graphicsDevice);
            GuiRenderer.Init(graphicsDevice, serviceProvider);

            GuiSpriteBatch?.Dispose();
            GuiSpriteBatch = new GuiSpriteBatch(GuiRenderer, graphicsDevice, SpriteBatch);
            GuiRenderArgs  = new GuiRenderArgs(GraphicsDevice, SpriteBatch, ScaledResolution, GuiRenderer, new GameTime());
        }
Exemplo n.º 12
0
 protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
 {
     if (_isPending)
     {
         graphics.FillRectangle(RenderBounds, _connectingStateTextures[_animationFrame], TextureRepeatMode.NoScaleCenterSlice);
     }
     else
     {
         base.OnDraw(graphics, gameTime);
     }
 }
Exemplo n.º 13
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (IsSelected)
            {
                var bounds = RenderBounds;
                bounds.Inflate(1, 1);
                graphics.FillRectangle(bounds, SelectedBackground, TextureRepeatMode.NoRepeat);
            }
        }
Exemplo n.º 14
0
        private void DrawChatLine(GuiSpriteBatch graphics, string text, float alpha, ref Vector2 offset)
        {
            var size = Font.MeasureString(text);

            var renderPos = Bounds.BottomLeft() + offset;

            graphics.FillRectangle(new Rectangle(renderPos.ToPoint(), new Point(Width, (int)Math.Ceiling(size.Y + 2))),
                                   new Color(Color.Black, alpha * 0.5f));

            Font.DrawString(graphics.SpriteBatch, text, renderPos + new Vector2(0, 2), TextColor.White, opacity: alpha);
            offset.Y -= (size.Y + 2);
        }
Exemplo n.º 15
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            var bounds = RenderBounds;

            var fillWidth = bounds.Width - 2 * _spriteSheetSegmentWidth;

            base.OnDraw(graphics, gameTime);

            bounds = new Rectangle(bounds.X + _spriteSheetSegmentWidth, bounds.Y, Math.Max(1, (int)(fillWidth * Percent)), bounds.Height);
            graphics.FillRectangle(bounds, Highlight);

            //	args.SpriteBatch.DrawString(FontRenderer, Text, RenderBounds.Center.ToVector2() - (TextSize / 2f), Color.Black, 0f, Vector2.Zero, TextScale, SpriteEffects.None, 0f);
        }
Exemplo n.º 16
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (_mapTexture == null)
            {
                return;
            }

            var device = graphics.Context.GraphicsDevice;

            device.SetRenderTarget(_mapTexture);

            RenderMiniMap(device, graphics.SpriteBatch, gameTime);

            device.SetRenderTarget(null);
        }
Exemplo n.º 17
0
        public GuiManager(Game game, InputManager inputManager, IGuiRenderer guiRenderer)
        {
            Game             = game;
            InputManager     = inputManager;
            ScaledResolution = new GuiScaledResolution(game);
            ScaledResolution.ScaleChanged += ScaledResolutionOnScaleChanged;

            FocusManager = new GuiFocusHelper(this, InputManager, game.GraphicsDevice);

            GuiRenderer = guiRenderer;
            guiRenderer.ScaledResolution = ScaledResolution;
            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);

            GuiSpriteBatch = new GuiSpriteBatch(guiRenderer, Game.GraphicsDevice, SpriteBatch);
            GuiRenderArgs  = new GuiRenderArgs(Game.GraphicsDevice, SpriteBatch, ScaledResolution, GuiRenderer, new GameTime());

            //  DebugHelper = new GuiDebugHelper(this);
        }
Exemplo n.º 18
0
        public void Draw(GameTime gameTime)
        {
            try
            {
                GuiSpriteBatch.Begin();

                ForEachScreen(screen =>
                {
                    screen.Draw(GuiSpriteBatch, gameTime);

                    DrawScreen?.Invoke(this, new GuiDrawScreenEventArgs(screen, gameTime));
                    //  DebugHelper.DrawScreen(screen);
                });
            }
            finally
            {
                GuiSpriteBatch.End();
            }
        }
Exemplo n.º 19
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            var item = _item;

            if (item == null || item.Renderer == null)
            {
                return;
            }

            // graphics.Context.GraphicsDevice.SetRenderTarget(RenderTarget);
            // graphics.Context.GraphicsDevice.Clear(Color.White);
            try
            {
                var renderArgs = new RenderArgs()
                {
                    GraphicsDevice = graphics.SpriteBatch.GraphicsDevice,
                    SpriteBatch    = graphics.SpriteBatch,
                    GameTime       = gameTime,
                    Camera         = Camera,
                };

                //var viewport = args.Graphics.Viewport;
                //args.Graphics.Viewport = new Viewport(RenderBounds);
                //graphics.End();

                using (var context = graphics.BranchContext(BlendState.AlphaBlend, DepthStencilState.Default,
                                                            RasterizerState.CullClockwise, SamplerState.PointWrap))
                {
                    var bounds = RenderBounds;

                    bounds.Inflate(-3, -3);

                    var p  = graphics.Project(bounds.Location.ToVector2());
                    var p2 = graphics.Project(bounds.Location.ToVector2() + bounds.Size.ToVector2());

                    var newViewport = Camera.Viewport;
                    newViewport.X      = (int)p.X;
                    newViewport.Y      = (int)p.Y;
                    newViewport.Width  = (int)(p2.X - p.X);
                    newViewport.Height = (int)(p2.Y - p.Y);

                    Camera.Viewport = newViewport;

                    context.Viewport = Camera.Viewport;

                    graphics.Begin();

                    Item.Renderer.Render(renderArgs);
                    // Entity.Render(renderArgs);
                    //  EntityModelRenderer?.Render(renderArgs, EntityPosition);

                    graphics.End();
                }
            }
            finally
            {
                //   graphics.Context.GraphicsDevice.SetRenderTarget(null);
            }

            // graphics.SpriteBatch.Draw(RenderTarget, new Rectangle(0, 0, 256, 256), Color.White);
        }
Exemplo n.º 20
0
 protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
 {
     //	base.OnDraw(graphics, gameTime);
     graphics.DrawLine(new Vector2(RenderBounds.Left, RenderBounds.Height / 2f), RenderBounds.Width, 0f, TextColor.DarkGray.ForegroundColor, 1);
 }
Exemplo n.º 21
0
 protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
 {
     _graphicsDevice = graphics.SpriteBatch.GraphicsDevice;
     base.OnDraw(graphics, gameTime);
 }
Exemplo n.º 22
0
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            var renderArgs = new RenderArgs()
            {
                GraphicsDevice = graphics.SpriteBatch.GraphicsDevice,
                SpriteBatch    = graphics.SpriteBatch,
                GameTime       = gameTime,
                Camera         = Camera,
            };
            //ClipToBounds = false;
            //graphics.End();
            //using (var context = graphics.BranchContext(BlendState.AlphaBlend, DepthStencilState.Default,RasterizerState.CullNone, SamplerState.PointWrap))
            {
                //var oldViewport = renderArgs.GraphicsDevice.Viewport;
                var oldBlendState        = renderArgs.GraphicsDevice.BlendState;
                var oldDepthStencilState = renderArgs.GraphicsDevice.DepthStencilState;
                var oldRasterizerState   = renderArgs.GraphicsDevice.RasterizerState;
                var oldSamplerState      = renderArgs.GraphicsDevice.SamplerStates[0];

                //renderArgs.GraphicsDevice.Viewport = Camera.Viewport;
                renderArgs.GraphicsDevice.BlendFactor       = Color.TransparentBlack;
                renderArgs.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
                renderArgs.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
                renderArgs.GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
                renderArgs.GraphicsDevice.SamplerStates[0]  = SamplerState.PointWrap;
                //renderArgs.GraphicsDevice.ScissorRectangle = Camera.Viewport.Bounds;

                //var bounds = RenderBounds;

                //bounds.Inflate(-3, -3);

                //var p = graphics.Project(bounds.Location.ToVector2());
                //var p2 = graphics.Project(bounds.Location.ToVector2() + bounds.Size.ToVector2());

                //var newViewport = Camera.Viewport;
                //newViewport.X      = (int)p.X;
                //newViewport.Y      = (int)p.Y;
                //newViewport.Width  = (int) (p2.X - p.X);
                //newViewport.Height = (int) (p2.Y - p.Y);

                //Camera.Viewport    = newViewport;
                Camera.UpdateProjectionMatrix();

                //context.Viewport = Camera.Viewport;

                // graphics.Begin();

                ModelExplorer.Render(graphics.Context, renderArgs);


                //renderArgs.GraphicsDevice.Viewport = oldViewport;
                renderArgs.GraphicsDevice.BlendState        = oldBlendState;
                renderArgs.GraphicsDevice.DepthStencilState = oldDepthStencilState;
                renderArgs.GraphicsDevice.RasterizerState   = oldRasterizerState;
                renderArgs.GraphicsDevice.SamplerStates[0]  = oldSamplerState;


                //   graphics.End();
            }
            //graphics.Begin();
        }
Exemplo n.º 23
0
        //private int _renderedC
        protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
        {
            base.OnDraw(graphics, gameTime);

            if (Focused)
            {
                var renderPos = (TextElement.RenderBounds.BottomLeft() - new Vector2(0, 8)).ToPoint();
                graphics.FillRectangle(new Rectangle(RenderBounds.X, (renderPos.Y) - 2, Width, 10), new Color(Color.Black, 0.5f));
            }

            KeyValuePair <DateTime, ChatObject>[] entries;
            lock (_lock)
            {
                entries = _chatEntries.ToArray();
            }

            if (entries.Length > 0)
            {
                int      renderedCount = 0;
                int      skipped       = 0;
                DateTime now           = DateTime.UtcNow;
                Vector2  offset        = new Vector2(0, -33);

                TextColor lastColor = TextColor.White;
                foreach (var msg in entries)
                {
                    var   elapse = now - msg.Key;
                    float alpha  = 1f;
                    if (!Focused)
                    {
                        if (elapse > _renderTimeout)
                        {
                            continue;
                        }

                        alpha = (float)(1f - ((elapse.TotalMilliseconds / _renderTimeout.TotalMilliseconds) * 1f));
                    }
                    else
                    {
                        if (_scrollValue > 0)
                        {
                            if (skipped < _scrollValue)
                            {
                                skipped++;
                                continue;
                            }
                        }
                    }

                    string message = msg.Value.RawMessage;

                    var lines = CalculateLines(message);
                    for (var index = 0; index < lines.Length; index++)
                    {
                        var line = lines[index];
                        if (lastColor != TextColor.White)
                        {
                            line = line + $"§{TextColor.Code}";
                        }

                        DrawChatLine(graphics, line, alpha, ref offset);

                        lastColor = FindLastColor(line);

                        renderedCount++;

                        if (renderedCount >= 10)
                        {
                            break;
                        }
                    }

                    //	if (!Focused)
                    {
                        if (renderedCount >= 10)
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
 /// <inheritdoc />
 protected override void OnDraw(GuiSpriteBatch graphics, GameTime gameTime)
 {
     ParentElement?.Draw(graphics, gameTime);
     base.OnDraw(graphics, gameTime);
 }