Beispiel #1
0
        private void Redraw()
        {
            var map = eyeManager.CurrentMap;

            VS.CanvasItemClear(ShadedCanvasItem);
            VS.CanvasItemClear(UnshadedCanvasItem);
            using (var shadedHandle = new DrawingHandleScreen(ShadedCanvasItem))
                using (var unshadedHandle = new DrawingHandleScreen(UnshadedCanvasItem))
                {
                    foreach (var effect in _Effects)
                    {
                        if (effect.Coordinates.MapID != map)
                        {
                            continue;
                        }

                        // NOTE TO FUTURE READERS:
                        // Yes, due to how this is implemented, unshaded is always on top of shaded.
                        // If you want to rework it to be properly defined, be my guest.
                        var handle = effect.Shaded ? shadedHandle : unshadedHandle;

                        handle.SetTransform(effect.Coordinates.ToWorld().Position *EyeManager.PIXELSPERMETER *new Vector2(1, -1), new Angle(-effect.Rotation), effect.Size);
                        var effectSprite = effect.EffectSprite;
                        handle.DrawTexture(effectSprite, -((Vector2)effectSprite.Size) / 2, ToColor(effect.Color));
                    }
                }
        }
Beispiel #2
0
        private void DrawJpsNodes(DrawingHandleScreen screenHandle, Box2 viewport)
        {
            foreach (var route in JpsRoutes)
            {
                foreach (var tile in route.JumpNodes)
                {
                    if ((route.Route.Contains(tile) && (Modes & PathfindingDebugMode.Route) != 0) ||
                        !viewport.Contains(tile))
                    {
                        continue;
                    }

                    var screenTile = _eyeManager.WorldToScreen(tile);
                    var box        = new UIBox2(
                        screenTile.X - 15.0f,
                        screenTile.Y - 15.0f,
                        screenTile.X + 15.0f,
                        screenTile.Y + 15.0f);

                    screenHandle.DrawRect(box, new Color(
                                              0.0f,
                                              1.0f,
                                              0.0f,
                                              0.2f));
                }
            }
        }
Beispiel #3
0
        private void _drawItem(
            DrawingHandleScreen handle, ref float vOffset, float hOffset, Item item,
            Font font, StyleBox itemSelected)
        {
            var itemHeight = font.GetHeight(UIScale) + itemSelected.MinimumSize.Y;
            var selected   = item.Index == _selectedIndex;

            if (selected)
            {
                itemSelected.Draw(handle, UIBox2.FromDimensions(hOffset, vOffset, PixelWidth - hOffset, itemHeight));
            }

            if (!string.IsNullOrWhiteSpace(item.Text))
            {
                var offset   = itemSelected.GetContentOffset(Vector2.Zero);
                var baseLine = offset + (hOffset, vOffset + font.GetAscent(UIScale));
                foreach (var chr in item.Text)
                {
                    baseLine += (font.DrawChar(handle, chr, baseLine, UIScale, Color.White), 0);
                }
            }

            vOffset += itemHeight;
            hOffset += 5;
            foreach (var child in item.Children)
            {
                _drawItem(handle, ref vOffset, hOffset, child, font, itemSelected);
            }
        }
Beispiel #4
0
        private void DrawAStarNodes(DrawingHandleScreen screenHandle, Box2 viewport)
        {
            foreach (var route in AStarRoutes)
            {
                var highestgScore = route.GScores.Values.Max();

                foreach (var(tile, score) in route.GScores)
                {
                    if ((route.Route.Contains(tile) && (Modes & PathfindingDebugMode.Route) != 0) ||
                        !viewport.Contains(tile))
                    {
                        continue;
                    }

                    var screenTile = _eyeManager.WorldToScreen(tile);
                    var box        = new UIBox2(
                        screenTile.X - 15.0f,
                        screenTile.Y - 15.0f,
                        screenTile.X + 15.0f,
                        screenTile.Y + 15.0f);

                    screenHandle.DrawRect(box, new Color(
                                              0.0f,
                                              score / highestgScore,
                                              1.0f - (score / highestgScore),
                                              0.1f));
                }
            }
        }
Beispiel #5
0
        private void DrawRegions(DrawingHandleScreen screenHandle, Box2 viewport)
        {
            var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity;

            if (attachedEntity == null || !Regions.TryGetValue(attachedEntity.Transform.GridID, out var entityRegions))
            {
                return;
            }

            foreach (var(chunk, regions) in entityRegions)
            {
                foreach (var(region, nodes) in regions)
                {
                    foreach (var tile in nodes)
                    {
                        if (!viewport.Contains(tile))
                        {
                            continue;
                        }

                        var screenTile = _eyeManager.WorldToScreen(tile);
                        var box        = new UIBox2(
                            screenTile.X - 15.0f,
                            screenTile.Y - 15.0f,
                            screenTile.X + 15.0f,
                            screenTile.Y + 15.0f);

                        screenHandle.DrawRect(box, _regionColors[attachedEntity.Transform.GridID][chunk][region]);
                    }
                }
            }
        }
        private void DrawGraph(DrawingHandleScreen screenHandle)
        {
            var eyeManager = IoCManager.Resolve <IEyeManager>();
            var viewport   = IoCManager.Resolve <IEyeManager>().GetWorldViewport();

            foreach (var(chunk, nodes) in Graph)
            {
                foreach (var tile in nodes)
                {
                    if (!viewport.Contains(tile))
                    {
                        continue;
                    }

                    var screenTile = eyeManager.WorldToScreen(tile);

                    var box = new UIBox2(
                        screenTile.X - 15.0f,
                        screenTile.Y - 15.0f,
                        screenTile.X + 15.0f,
                        screenTile.Y + 15.0f);

                    screenHandle.DrawRect(box, _graphColors[chunk]);
                }
            }
        }
        protected override void Draw(DrawingHandleScreen handle)
        {
            if (!TryGetHands(out IHandsComponent hands))
            {
                return;
            }

            var leftActive = hands.ActiveIndex == "left";

            handle.DrawStyleBox(handBox, leftActive ? handL : handR);
            handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);

            /*
             * if (LeftHand.Entity != null && LeftHand.HeldSprite != null)
             * {
             *  var bounds = LeftHand.HeldSprite.Size;
             *  handle.DrawTextureRect(LeftHand.HeldSprite,
             *      UIBox2i.FromDimensions(handL.Left + (int)(handL.Width / 2f - bounds.X / 2f),
             *                      handL.Top + (int)(handL.Height / 2f - bounds.Y / 2f),
             *                      (int)bounds.X, (int)bounds.Y), tile: false);
             * }
             *
             * if (RightHand.Entity != null && RightHand.HeldSprite != null)
             * {
             *  var bounds = RightHand.HeldSprite.Size;
             *  handle.DrawTextureRect(RightHand.HeldSprite,
             *      UIBox2i.FromDimensions(handR.Left + (int)(handR.Width / 2f - bounds.Y / 2f),
             *                      handR.Top + (int)(handR.Height / 2f - bounds.Y / 2f),
             *                      (int)bounds.X, (int)bounds.Y), tile: false);
             * }
             */
        }
        private void DrawJpsRoutes(DrawingHandleScreen screenHandle)
        {
            var eyeManager = IoCManager.Resolve <IEyeManager>();
            var viewport   = eyeManager.GetWorldViewport();

            foreach (var route in JpsRoutes)
            {
                // Draw box on each tile of route
                foreach (var position in route.Route)
                {
                    if (!viewport.Contains(position))
                    {
                        continue;
                    }
                    var screenTile = eyeManager.WorldToScreen(position);
                    // worldHandle.DrawLine(position, nextWorld.Value, Color.Blue);
                    var box = new UIBox2(
                        screenTile.X - 15.0f,
                        screenTile.Y - 15.0f,
                        screenTile.X + 15.0f,
                        screenTile.Y + 15.0f);
                    screenHandle.DrawRect(box, Color.Orange.WithAlpha(0.25f));
                }
            }
        }
Beispiel #9
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            for (var i = 0; i < TrackedFrames; i++)
            {
                var currentFrameIndex = MathHelper.Mod(_frameIndex - 1 - i, TrackedFrames);
                var frameTime         = _frameTimes[currentFrameIndex];
                var x           = FrameWidth * UserInterfaceManager.UIScale * (TrackedFrames - 1 - i);
                var frameHeight = FrameHeight * (frameTime / (1f / TargetFrameRate));
                var rect        = new UIBox2(x, PixelHeight - frameHeight, x + FrameWidth * UserInterfaceManager.UIScale, PixelHeight);

                Color color;
                if (frameTime > 1f / (TargetFrameRate / 2 - 1))
                {
                    color = Color.Red;
                }
                else if (frameTime > 1f / (TargetFrameRate - 1))
                {
                    color = Color.Yellow;
                }
                else
                {
                    color = Color.Lime;
                }

                handle.DrawRect(rect, color);
            }
        }
        private static readonly Color CompletedColor = new Color(0.0f, 0.8f, 0.27f);   // green

        protected override void Draw(DrawingHandleScreen handle)
        {
            Span <float> x = stackalloc float[10];
            Color        color;

            var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes

            if (Progress >= 0f)
            {
                color = new Color(
                    EndColor.R + (StartColor.R - EndColor.R) * Progress,
                    EndColor.G + (StartColor.G - EndColor.G) * Progress,
                    EndColor.B + (StartColor.B - EndColor.B) * Progress,
                    EndColor.A);
            }
            else
            {
                var alpha = MathHelper.Clamp(0.5f * lerp, 0f, 0.5f);
                color = CompletedColor.WithAlpha(alpha);
            }

            _shader.SetParameter("progress", Progress);
            handle.UseShader(_shader);
            handle.DrawRect(PixelSizeBox, color);
        }
    protected override void Draw(DrawingHandleScreen handle)
    {
        foreach (var layer in _parallaxManager.ParallaxLayers)
        {
            var tex     = layer.Texture;
            var texSize = tex.Size * layer.Config.Scale.Floored();
            var ourSize = PixelSize;

            if (layer.Config.Tiled)
            {
                // Multiply offset by slowness to match normal parallax
                var scaledOffset = (Offset * layer.Config.Slowness).Floored();

                // Then modulo the scaled offset by the size to prevent drawing a bunch of offscreen tiles for really small images.
                scaledOffset.X %= texSize.X;
                scaledOffset.Y %= texSize.Y;

                // Note: scaledOffset must never be below 0 or there will be visual issues.
                // It could be allowed to be >= texSize on a given axis but that would be wasteful.

                for (var x = -scaledOffset.X; x < ourSize.X; x += texSize.X)
                {
                    for (var y = -scaledOffset.Y; y < ourSize.Y; y += texSize.Y)
                    {
                        handle.DrawTextureRect(tex, UIBox2.FromDimensions((x, y), texSize));
                    }
                }
            }
            else
            {
                var origin = ((ourSize - texSize) / 2) + layer.Config.ControlHomePosition;
                handle.DrawTextureRect(tex, UIBox2.FromDimensions(origin, texSize));
            }
        }
    }
 protected override void Draw(DrawingHandleScreen handle)
 {
     base.Draw(handle);
     if (UserInterfaceManager.CurrentlyHovered == this)
     {
         OnMouseHovering?.Invoke();
     }
 }
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            var style = _getStyleBox();

            style?.Draw(handle, PixelSizeBox);
        }
Beispiel #14
0
        protected override void Draw(DrawingHandleScreen handle)
        {
            var dims = Texture != null?GetDrawDimensions(Texture) : UIBox2.FromDimensions(Vector2.Zero, PixelSize);

            dims.Top = Math.Max(dims.Bottom - dims.Bottom * Progress, 0);
            handle.DrawRect(dims, DoAfterHelpers.GetProgressColor(Progress));

            base.Draw(handle);
        }
Beispiel #15
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            if (Sprite == null)
            {
                return;
            }

            handle.DrawEntity(Sprite.Owner, GlobalPixelPosition + PixelSize / 2);
        }
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            var style   = ActualStyleBox;
            var drawBox = PixelSizeBox;

            style.Draw(handle, drawBox);
        }
        protected override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (UserInterfaceManager.CurrentlyHovered == this)
            {
                handle.DrawRect(PixelSizeBox, HoverColor);
            }
        }
        private static void DrawString(DrawingHandleScreen handle, Font font, Vector2 pos, string str, Color color)
        {
            var baseLine = new Vector2(pos.X, font.GetAscent(1) + pos.Y);

            foreach (var chr in str)
            {
                var advance = font.DrawChar(handle, chr, baseLine, 1, color);
                baseLine += new Vector2(advance, 0);
            }
        }
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (!VisibleInTree)
            {
                return;
            }

            handle.DrawRect(_uiBox, Color.Red, false);
        }
Beispiel #20
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (_message == null)
            {
                return;
            }

            _entry.Draw(handle, _getFont(), SizeBox, 0, UIScale, _getFontColor());
        }
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (_message == null)
            {
                return;
            }

            _entry.Draw(handle, _getFont(), SizeBox, 0, new Stack <FormattedMessage.Tag>(), UIScale);
        }
Beispiel #22
0
        protected override void Draw(DrawingHandleScreen handle)
        {
            if (!TryGetHands(out IHandsComponent hands))
            {
                return;
            }

            var leftActive = hands.ActiveIndex == "left";

            handle.DrawStyleBox(handBox, leftActive ? handL : handR);
            handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);
        }
        private void DrawScreen(DrawingHandleScreen screen)
        {
            var viewport = _eyeManager.GetWorldViewport();

            var ent = _playerManager.LocalPlayer?.ControlledEntity;

            if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent sus) != true)
            {
                return;
            }

            foreach (var(_, uid) in sus.Allies)
            {
                // Otherwise the entity can not exist yet
                if (!_entityManager.TryGetEntity(uid, out var ally))
                {
                    return;
                }

                if (!ally.TryGetComponent(out IPhysicsComponent physics))
                {
                    return;
                }

                if (!ExamineSystemShared.InRangeUnOccluded(ent.Transform.MapPosition, ally.Transform.MapPosition, 15,
                                                           entity => entity == ent || entity == ally))
                {
                    return;
                }

                // all entities have a TransformComponent
                var transform = physics.Entity.Transform;

                // if not on the same map, continue
                if (transform.MapID != _eyeManager.CurrentMap || !transform.IsMapTransform)
                {
                    continue;
                }

                var worldBox = physics.WorldAABB;

                // if not on screen, or too small, continue
                if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
                {
                    continue;
                }

                var screenCoordinates = _eyeManager.WorldToScreen(physics.WorldAABB.TopLeft + (0, 0.5f));
                DrawString(screen, _font, screenCoordinates, _traitorText, Color.OrangeRed);
            }
        }
Beispiel #24
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (!Debug)
            {
                return;
            }

            var(pSizeX, pSizeY) = PixelSize;
            foreach (var child in Children)
            {
                if (!child.GetValue(DebugProperty))
                {
                    continue;
                }

                var rect = CalcChildRect(Size, UIScale, child, out var anchorSize);

                var left   = rect.Left * UIScale;
                var right  = rect.Right * UIScale;
                var top    = rect.Top * UIScale;
                var bottom = rect.Bottom * UIScale;

                DrawVLine(anchorSize.Left, Color.Pink);
                DrawVLine(anchorSize.Right, Color.Green);
                DrawHLine(anchorSize.Top, Color.Pink);
                DrawHLine(anchorSize.Bottom, Color.Green);

                /*
                 * DrawVLine(left, Color.Orange);
                 * DrawVLine(right, Color.Blue);
                 * DrawHLine(top, Color.Orange);
                 * DrawHLine(bottom, Color.Blue);
                 */

                handle.DrawRect(new UIBox2(left, top, right, bottom), Color.Red, false);
            }

            void DrawVLine(float x, Color color)
            {
                handle.DrawLine((x, 0), (x, pSizeY), color);
            }

            void DrawHLine(float y, Color color)
            {
                handle.DrawLine((0, y), (pSizeX, y), color);
            }
        }
Beispiel #25
0
        protected override void Draw(DrawingHandleScreen handle)
        {
            if (!TryGetHands(out IHandsComponent hands))
            {
                return;
            }

            var leftActive = hands.ActiveIndex == "left";

            var handL = new UIBox2(_handL.TopLeft * UIScale, _handL.BottomRight * UIScale);
            var handR = new UIBox2(_handR.TopLeft * UIScale, _handR.BottomRight * UIScale);

            handle.DrawStyleBox(handBox, leftActive ? handL : handR);
            handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);
        }
        protected override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            handle.UseShader(Shader);

            var leftOffset = 2 * HealthBarScale;
            var box        = new UIBox2i(
                leftOffset,
                -2 + 2 * HealthBarScale,
                leftOffset + (int)(XPixelDiff * Ratio * UIScale),
                -2);

            handle.DrawRect(box, Color);
        }
Beispiel #27
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            var offset = 0;
            var icon   = _getIcon();

            if (icon != null)
            {
                offset += _getIcon().Width + _getHSeparation();
                var vOffset = (PixelHeight - _getIcon().Height) / 2;
                handle.DrawTextureRect(icon, UIBox2.FromDimensions((0, vOffset), icon.Size * UIScale), false);
            }

            var box = new UIBox2(offset, 0, PixelWidth, PixelHeight);

            DrawTextInternal(handle, box);
        }
Beispiel #28
0
        public void Draw(
            DrawingHandleScreen handle,
            IFontLibrary font,
            UIBox2 drawBox,
            float verticalOffset,
            float uiScale,
            Color defColor)
        {
            var flib = font.StartFont();

            foreach (var wd in _ld)
            {
                var s        = Message.Sections[wd.section];
                var baseLine = drawBox.TopLeft + new Vector2((float)wd.x, verticalOffset + (float)wd.y);

                foreach (var rune in s
                         .Content[wd.charOffs..(wd.charOffs + wd.length)]
Beispiel #29
0
        protected internal override void Draw(DrawingHandleScreen handle)
        {
            base.Draw(handle);

            if (!VisibleInTree)
            {
                return;
            }

            var(x, y) = GlobalPixelPosition;
            var renderBox = new UIBox2(
                _uiBox.Left - x,
                _uiBox.Top - y,
                _uiBox.Right - x,
                _uiBox.Bottom - y);

            handle.DrawRect(renderBox, Color.Red, false);
        }
Beispiel #30
0
        private void DrawScreen(DrawingHandleScreen screen)
        {
            var viewport = _eyeManager.GetWorldViewport();

            foreach (var uid in _allies)
            {
                // Otherwise the entity can not exist yet
                if (!_entityManager.TryGetEntity(uid, out var ally))
                {
                    return;
                }

                if (!ally.TryGetComponent(out ICollidableComponent collidable))
                {
                    return;
                }

                if (!ExamineSystemShared.InRangeUnOccluded(_user.Transform.MapPosition, ally.Transform.MapPosition, 15,
                                                           entity => entity == _user || entity == ally))
                {
                    return;
                }

                // all entities have a TransformComponent
                var transform = collidable.Entity.Transform;

                // if not on the same map, continue
                if (transform.MapID != _eyeManager.CurrentMap || !transform.IsMapTransform)
                {
                    continue;
                }

                var worldBox = collidable.WorldAABB;

                // if not on screen, or too small, continue
                if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
                {
                    continue;
                }

                var screenCoordinates = _eyeManager.WorldToScreen(collidable.WorldAABB.TopLeft + (0, 0.5f));
                DrawString(screen, _font, screenCoordinates, _traitorText, Color.OrangeRed);
            }
        }