Ejemplo n.º 1
0
        public override void Draw()
        {
            if (world == null)
            {
                return;
            }

            var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight) / 2);
            var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);

            var rsr = Game.Renderer.RgbaSpriteRenderer;

            rsr.DrawSprite(terrainSprite, o, s);
            rsr.DrawSprite(customTerrainSprite, o, s);
            rsr.DrawSprite(actorSprite, o, s);
            rsr.DrawSprite(shroudSprite, o, s);

            // Draw viewport rect
            if (hasRadar)
            {
                var tl = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.TopLeft).ToCPos());
                var br = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.BottomRight).ToCPos());

                Game.Renderer.EnableScissor(mapRect);
                DrawRadarPings();
                Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
                Game.Renderer.DisableScissor();
            }
        }
        void ApplyOrders(World world, int2 xy, MouseInput mi)
        {
            if (world.OrderGenerator == null)
            {
                return;
            }

            var pos    = worldRenderer.Position(xy);
            var orders = world.OrderGenerator.Order(world, pos.ToCPos(), mi).ToArray();

            world.PlayVoiceForOrders(orders);

            var flashed = false;

            foreach (var order in orders)
            {
                var o = order;
                if (!flashed)
                {
                    if (o.TargetActor != null)
                    {
                        world.AddFrameEndTask(w => w.Add(new FlashTarget(o.TargetActor)));
                        flashed = true;
                    }
                    else if (o.Subject != world.LocalPlayer.PlayerActor && o.TargetLocation != CPos.Zero)                     // TODO: this filters building placement, but also suppport powers :(
                    {
                        world.AddFrameEndTask(w => w.Add(new MoveFlash(worldRenderer.Position(worldRenderer.Viewport.ViewToWorldPx(mi.Location)), world)));
                        flashed = true;
                    }
                }

                world.IssueOrder(o);
            }
        }
Ejemplo n.º 3
0
        static IEnumerable <IFinalizedRenderable> DrawZap(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, out float2 p, string palette)
        {
            var dist = to - from;
            var q    = new float2(-dist.Y, dist.X);
            var c    = -float2.Dot(from, q);
            var rs   = new List <IFinalizedRenderable>();
            var z    = from;
            var pal  = wr.Palette(palette);

            while ((to - z).X > 5 || (to - z).X < -5 || (to - z).Y > 5 || (to - z).Y < -5)
            {
                var step = steps.Where(t => (to - (z + new float2(t[0], t[1]))).LengthSquared < (to - z).LengthSquared)
                           .MinBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c));

                var pos = wr.Position((z + new float2(step[2], step[3])).ToInt2());
                rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, pal, 1f, true).PrepareRender(wr));

                z += new float2(step[0], step[1]);
                if (rs.Count >= 1000)
                {
                    break;
                }
            }

            p = z;

            return(rs);
        }
Ejemplo n.º 4
0
        public IEnumerable <IRenderable> Render(WorldRenderer wr)
        {
            if (!self.IsInWorld)
            {
                yield break;
            }

            if (self.IsDead)
            {
                yield break;
            }

            if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
            {
                yield break;
            }

            if (wr.World.FogObscures(self))
            {
                yield break;
            }

            var pos    = wr.ScreenPxPosition(self.CenterPosition);
            var bounds = self.Bounds;

            bounds.Offset(pos.X, pos.Y);

            var palette   = wr.Palette(paletteName);
            var offset    = (int)(4 / wr.Viewport.Zoom);
            var effectPos = wr.Position(new int2(bounds.Right - offset, bounds.Bottom - offset));

            yield return(new SpriteRenderable(anim.Image, effectPos, WVec.Zero, 0, palette, 1f / wr.Viewport.Zoom, true));
        }
Ejemplo n.º 5
0
        float GetIntensity()
        {
            var cp        = worldRenderer.Position(worldRenderer.Viewport.CenterLocation);
            var intensity = 100 * 1024 * 1024 * shakeEffects.Sum(
                e => (float)e.Intensity / (e.Position - cp).LengthSquared);

            return(Math.Min(intensity, 10));
        }
Ejemplo n.º 6
0
            public void RenderAfterWorld(WorldRenderer wr, World world)
            {
                var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();

                foreach (var unit in power.UnitsInRange(xy))
                {
                    wr.DrawSelectionBox(unit, Color.Red);
                }
            }
Ejemplo n.º 7
0
        public IEnumerable <IRenderable> Render(Actor self, WorldRenderer wr)
        {
            if (IsTraitDisabled)
            {
                yield break;
            }

            if (self.IsDead || !self.IsInWorld)
            {
                yield break;
            }

            if (anim == null)
            {
                yield break;
            }

            var allied = self.Owner.IsAlliedWith(self.World.RenderPlayer);

            if (!allied && !info.ShowToEnemies)
            {
                yield break;
            }

            if (allied && !info.ShowToAllies)
            {
                yield break;
            }

            if (!ShouldRender(self))
            {
                yield break;
            }

            if (self.World.FogObscures(self))
            {
                yield break;
            }

            var pxPos       = wr.ScreenPxPosition(self.CenterPosition);
            var actorBounds = self.Bounds;

            actorBounds.Offset(pxPos.X, pxPos.Y);
            pxPos = new int2(actorBounds.Left, actorBounds.Top);

            var img     = anim.Image;
            var imgSize = img.Size.ToInt2();

            pxPos = pxPos.WithX(pxPos.X + imgSize.X / 2).WithY(pxPos.Y + imgSize.Y / 2);

            pxPos += info.Offset;
            var renderPos = wr.Position(pxPos);

            anim.Tick();

            yield return(new SpriteRenderable(img, renderPos, WVec.Zero, info.ZOffset, wr.Palette(info.Palette), info.Scale, true));
        }
        public void RenderAfterWorld(WorldRenderer wr, World world)
        {
            var position = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
            var topLeft  = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo);

            var actorInfo = Rules.Info[Building];

            foreach (var dec in actorInfo.Traits.WithInterface <IPlaceBuildingDecoration>())
            {
                dec.Render(wr, world, actorInfo, position.CenterPosition);                      /* hack hack */
            }
            var cells = new Dictionary <CPos, bool>();

            // Linebuild for walls.
            // Assumes a 1x1 footprint; weird things will happen for other footprints
            if (Rules.Info[Building].Traits.Contains <LineBuildInfo>())
            {
                foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, Building, BuildingInfo))
                {
                    cells.Add(t, BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, t));
                }
            }
            else
            {
                if (!initialized)
                {
                    var rbi     = Rules.Info[Building].Traits.Get <RenderBuildingInfo>();
                    var palette = rbi.Palette ?? (Producer.Owner != null ?
                                                  rbi.PlayerPalette + Producer.Owner.InternalName : null);

                    preview     = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette));
                    initialized = true;
                }

                var offset = topLeft.CenterPosition + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero;
                foreach (var r in preview)
                {
                    r.OffsetBy(offset).Render(wr);
                }

                var res           = world.WorldActor.Trait <ResourceLayer>();
                var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
                foreach (var t in FootprintUtils.Tiles(Building, BuildingInfo, topLeft))
                {
                    cells.Add(t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null);
                }
            }

            var pal = wr.Palette("terrain");

            foreach (var c in cells)
            {
                var tile = c.Value ? buildOk : buildBlocked;
                new SpriteRenderable(tile, c.Key.CenterPosition,
                                     WVec.Zero, -511, pal, 1f, true).Render(wr);
            }
        }
Ejemplo n.º 9
0
        public override void Draw()
        {
            if (world == null)
            {
                return;
            }

            if (renderShroud != null)
            {
                foreach (var cell in dirtyShroudCells)
                {
                    UpdateShroudCell(cell);
                }
                dirtyShroudCells.Clear();
            }

            radarSheet.CommitBufferedData();

            var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight) / 2);
            var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);

            var rsr = Game.Renderer.RgbaSpriteRenderer;

            rsr.DrawSprite(terrainSprite, o, s);
            rsr.DrawSprite(actorSprite, o, s);

            if (renderShroud != null)
            {
                rsr.DrawSprite(shroudSprite, o, s);
            }

            // Draw viewport rect
            if (hasRadar)
            {
                var tl = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.TopLeft)));
                var br = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.BottomRight)));

                Game.Renderer.EnableScissor(mapRect);
                DrawRadarPings();
                Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
                Game.Renderer.DisableScissor();
            }
        }
Ejemplo n.º 10
0
            public IEnumerable <IRenderable> Render(WorldRenderer wr, World world)
            {
                var xy  = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
                var pal = wr.Palette("terrain");

                foreach (var t in world.FindTilesInCircle(xy, range))
                {
                    yield return(new SpriteRenderable(tile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true));
                }
            }
Ejemplo n.º 11
0
        public IEnumerable <IRenderable> Render(Actor self, WorldRenderer wr)
        {
            var pos    = wr.ScreenPxPosition(self.CenterPosition);
            var bounds = self.Bounds.Value;

            bounds.Offset(pos.X, pos.Y);
            var spaceBuffer = (int)(10 / wr.Viewport.Zoom);
            var effectPos   = wr.Position(new int2(pos.X, bounds.Y - spaceBuffer));

            yield return(new TextRenderable(font, effectPos, 0, color, name));
        }
Ejemplo n.º 12
0
        static void Tick(OrderManager orderManager)
        {
            if (orderManager.Connection.ConnectionState != lastConnectionState)
            {
                lastConnectionState = orderManager.Connection.ConnectionState;
                ConnectionStateChanged(orderManager);
            }

            TickInner(orderManager);
            if (worldRenderer != null && orderManager.world != worldRenderer.world)
            {
                TickInner(worldRenderer.world.orderManager);
            }

            using (new PerfSample("render"))
            {
                ++RenderFrame;

                // worldRenderer is null during the initial install/download screen
                if (worldRenderer != null)
                {
                    Renderer.BeginFrame(worldRenderer.Viewport.TopLeft, worldRenderer.Viewport.Zoom);
                    Sound.SetListenerPosition(worldRenderer.Position(worldRenderer.Viewport.CenterLocation));
                    worldRenderer.Draw();
                }
                else
                {
                    Renderer.BeginFrame(int2.Zero, 1f);
                }

                using (new PerfSample("render_widgets"))
                {
                    Ui.Draw();
                    if (modData != null && modData.CursorProvider != null)
                    {
                        var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default";
                        modData.CursorProvider.DrawCursor(Renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame);
                    }
                }

                using (new PerfSample("render_flip"))
                {
                    Renderer.EndFrame(new DefaultInputHandler(orderManager.world));
                }
            }

            PerfHistory.items["render"].Tick();
            PerfHistory.items["batches"].Tick();
            PerfHistory.items["render_widgets"].Tick();
            PerfHistory.items["render_flip"].Tick();

            delayedActions.PerformActions();
        }
Ejemplo n.º 13
0
            public void RenderAfterWorld(WorldRenderer wr, World world)
            {
                var xy          = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
                var targetUnits = power.UnitsInRange(xy);

                foreach (var unit in targetUnits)
                {
                    if (manager.self.Owner.Shroud.IsTargetable(unit) || manager.self.Owner.HasFogVisibility())
                    {
                        wr.DrawSelectionBox(unit, Color.Red);
                    }
                }
            }
        void ApplyOrders(World world, int2 xy, MouseInput mi)
        {
            if (world.OrderGenerator == null)
            {
                return;
            }

            var pos    = worldRenderer.Position(xy);
            var orders = world.OrderGenerator.Order(world, world.Map.CellContaining(pos), mi).ToArray();

            world.PlayVoiceForOrders(orders);

            var flashed = false;

            foreach (var order in orders)
            {
                var o = order;
                if (o == null)
                {
                    continue;
                }

                if (!flashed && !o.SuppressVisualFeedback)
                {
                    if (o.TargetActor != null)
                    {
                        world.AddFrameEndTask(w => w.Add(new FlashTarget(o.TargetActor)));
                        flashed = true;
                    }
                    else if (o.TargetLocation != CPos.Zero)
                    {
                        world.AddFrameEndTask(w => w.Add(new SpriteEffect(worldRenderer.Position(worldRenderer.Viewport.ViewToWorldPx(mi.Location)), world, "moveflsh", "moveflash")));
                        flashed = true;
                    }
                }

                world.IssueOrder(o);
            }
        }
Ejemplo n.º 15
0
            public IEnumerable <IRenderable> Render(WorldRenderer wr, World world)
            {
                var xy  = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
                var pal = wr.Palette("terrain");

                // Source tiles
                foreach (var t in world.FindTilesInCircle(sourceLocation, range))
                {
                    yield return(new SpriteRenderable(sourceTile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true));
                }

                // Destination tiles
                foreach (var t in world.FindTilesInCircle(xy, range))
                {
                    yield return(new SpriteRenderable(sourceTile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true));
                }

                // Unit previews
                foreach (var unit in power.UnitsInRange(sourceLocation))
                {
                    var offset = (xy - sourceLocation).ToWVec();
                    if (manager.self.Owner.Shroud.IsTargetable(unit))
                    {
                        foreach (var r in unit.Render(wr))
                        {
                            yield return(r.OffsetBy(offset));
                        }
                    }
                }

                // Unit tiles
                foreach (var unit in power.UnitsInRange(sourceLocation))
                {
                    if (manager.self.Owner.Shroud.IsTargetable(unit))
                    {
                        var targetCell = unit.Location + (xy - sourceLocation);
                        var canEnter   = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility()) &&
                                          unit.Trait <Chronoshiftable>().CanChronoshiftTo(unit, targetCell));
                        var tile = canEnter ? validTile : invalidTile;
                        yield return(new SpriteRenderable(tile, targetCell.CenterPosition, WVec.Zero, -511, pal, 1f, true));
                    }
                }
            }
        public void UpdateMouseover()
        {
            TooltipType = WorldTooltipType.None;
            var cell = worldRenderer.Position(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();

            if (!world.Map.IsInMap(cell))
            {
                return;
            }

            if (world.ShroudObscures(cell))
            {
                TooltipType = WorldTooltipType.Unexplored;
                return;
            }

            var underCursor = world.ScreenMap.ActorsAt(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
                              .Where(a => !world.FogObscures(a) && a.HasTrait <IToolTip>())
                              .OrderByDescending(a => a.Info.SelectionPriority())
                              .FirstOrDefault();

            if (underCursor != null)
            {
                ActorTooltip = underCursor.TraitsImplementing <IToolTip>().First();
                TooltipType  = WorldTooltipType.Actor;
                return;
            }

            var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
                         .Where(a => a.TooltipName != null)
                         .OrderByDescending(a => a.Info.SelectionPriority())
                         .FirstOrDefault();

            if (frozen != null)
            {
                FrozenActorTooltip = frozen;
                TooltipType        = WorldTooltipType.FrozenActor;
            }
        }