Beispiel #1
0
        protected override void Draw(SpriteBatch spriteBatch)
        {
            if (!Context.IsPlayerFree)
            {
                return;
            }

            // get on-screen tiles
            IEnumerable <Vector2> visibleTiles = TileHelper.GetTiles(
                x: Game1.viewport.X / Game1.tileSize,
                y: Game1.viewport.Y / Game1.tileSize,
                width: (int)(Game1.viewport.Width / (decimal)Game1.tileSize) + 2, // extend off-screen slightly to avoid overlay edges being visible
                height: (int)(Game1.viewport.Height / (decimal)Game1.tileSize) + 2
                );

            // draw each tile
            foreach (Vector2 tile in visibleTiles)
            {
                // get tile's screen coordinates
                float screenX  = tile.X * Game1.tileSize - Game1.viewport.X;
                float screenY  = tile.Y * Game1.tileSize - Game1.viewport.Y;
                int   tileSize = Game1.tileSize;

                // get machine group
                this.GroupTiles.TryGetValue(tile, out MachineGroup group);
                bool isGrouped = group != null;
                bool isActive  = isGrouped && group.HasInternalAutomation;

                // draw background
                {
                    Color color = Color.Black * 0.5f;
                    if (isActive)
                    {
                        color = Color.Green * 0.2f;
                    }
                    else if (isGrouped)
                    {
                        color = Color.Red * 0.2f;
                    }

                    spriteBatch.DrawLine(screenX + this.TileGap, screenY + this.TileGap, new Vector2(tileSize - this.TileGap * 2, tileSize - this.TileGap * 2), color);
                }

                // draw group edge borders
                if (group != null)
                {
                    this.DrawEdgeBorders(spriteBatch, group, tile, group.HasInternalAutomation ? Color.Green : Color.Red);
                }
            }

            // draw cursor
            this.DrawCursor();
        }
Beispiel #2
0
        protected override void DrawWorld(SpriteBatch spriteBatch)
        {
            if (!Context.IsPlayerFree)
            {
                return;
            }

            // draw each tile
            IReadOnlySet <Vector2> junimoChestTiles = this.JunimoGroup.GetTiles(this.LocationKey);

            foreach (Vector2 tile in TileHelper.GetVisibleTiles(expand: 1))
            {
                // get tile's screen coordinates
                float screenX  = tile.X * Game1.tileSize - Game1.viewport.X;
                float screenY  = tile.Y * Game1.tileSize - Game1.viewport.Y;
                int   tileSize = Game1.tileSize;

                // get machine group
                IMachineGroup?group = null;
                Color?        color = null;
                if (junimoChestTiles.Contains(tile))
                {
                    color = this.JunimoGroup.HasInternalAutomation
                        ? Color.Green * 0.2f
                        : Color.Red * 0.2f;
                    group = this.JunimoGroup;
                }
                else if (this.MachineData is not null)
                {
                    if (this.MachineData.ActiveTiles.TryGetValue(tile, out group))
                    {
                        color = Color.Green * 0.2f;
                    }
                    else if (this.MachineData.DisabledTiles.TryGetValue(tile, out group) || this.MachineData.OutdatedTiles.ContainsKey(tile))
                    {
                        color = Color.Red * 0.2f;
                    }
                }
                color ??= Color.Black * 0.5f;

                // draw background
                spriteBatch.DrawLine(screenX + this.TileGap, screenY + this.TileGap, new Vector2(tileSize - this.TileGap * 2, tileSize - this.TileGap * 2), color);

                // draw group edge borders
                if (group != null)
                {
                    this.DrawEdgeBorders(spriteBatch, group, tile, group.HasInternalAutomation ? Color.Green : Color.Red);
                }
            }

            // draw cursor
            this.DrawCursor();
        }
Beispiel #3
0
        protected override void Draw(SpriteBatch spriteBatch)
        {
            if (!Context.IsPlayerFree)
            {
                return;
            }

            // draw each tile
            foreach (Vector2 tile in TileHelper.GetVisibleTiles())
            {
                // get tile's screen coordinates
                float screenX  = tile.X * Game1.tileSize - Game1.viewport.X;
                float screenY  = tile.Y * Game1.tileSize - Game1.viewport.Y;
                int   tileSize = Game1.tileSize;

                // get machine group
                this.GroupTiles.TryGetValue(tile, out MachineGroup group);
                bool isGrouped = group != null;
                bool isActive  = isGrouped && group.HasInternalAutomation;

                // draw background
                {
                    Color color = Color.Black * 0.5f;
                    if (isActive)
                    {
                        color = Color.Green * 0.2f;
                    }
                    else if (isGrouped)
                    {
                        color = Color.Red * 0.2f;
                    }

                    spriteBatch.DrawLine(screenX + this.TileGap, screenY + this.TileGap, new Vector2(tileSize - this.TileGap * 2, tileSize - this.TileGap * 2), color);
                }

                // draw group edge borders
                if (group != null)
                {
                    this.DrawEdgeBorders(spriteBatch, group, tile, group.HasInternalAutomation ? Color.Green : Color.Red);
                }
            }

            // draw cursor
            this.DrawCursor();
        }
Beispiel #4
0
 /// <summary>Get the tile coordinates in the tile area.</summary>
 /// <param name="area">The tile area to search.</param>
 public static IEnumerable <Vector2> GetTiles(this Rectangle area)
 {
     return(TileHelper.GetTiles(area.X, area.Y, area.Width, area.Height));
 }
Beispiel #5
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get the tile coordinates in the game location.</summary>
        /// <param name="location">The game location to search.</param>
        public static IEnumerable <Vector2> GetTiles(this GameLocation location)
        {
            Layer layer = location.Map.Layers[0];

            return(TileHelper.GetTiles(0, 0, layer.LayerWidth, layer.LayerHeight));
        }