Exemple #1
0
 public static InputTask BlueprintFactory(InputMode mode, Func <Cell, Constructable> construct)
 {
     return(new InputTask(mode, (cells, selected) => {
         foreach (Cell cell in cells)
         {
             Blueprint blueprint = new Blueprint(cell.World, construct(cell));
             if (blueprint != null && cell.World.ValidatePlacement(cell.X, cell.Y, blueprint))
             {
                 if (blueprint.Construct is Structure)
                 {
                     cell.StructureBlueprint = blueprint;
                 }
                 else if (blueprint.Construct is Floor)
                 {
                     cell.FloorBlueprint = blueprint;
                 }
                 ConstructionJob job = new ConstructionJob(cell, blueprint);
                 cell.World.JobManager.AddJob(job);
                 blueprint.job = job;
             }
         }
     }, (cell, spriteBatch) => {
         Blueprint preview = new Blueprint(cell.World, construct(cell));
         bool validPlacement = cell.World.ValidatePlacement(cell.X, cell.Y, preview);
         preview.Draw(spriteBatch, cell.X, cell.Y, validPlacement ? Blueprint.BlueprintState.Preview : Blueprint.BlueprintState.Invalid);
     }, (cells) => {
         foreach (Cell cell in cells)
         {
             cell.CancelJobs();
         }
     }, (cell) => {
         return cell.HasBlueprints;
     }));
 }
Exemple #2
0
        public void Draw()
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, viewportManager.Camera.Transform);

            if (currentTask != null && currentTask.Preview != null)
            {
                if (isDragging)
                {
                    for (int x = dragAreaCells.Left; x <= dragAreaCells.Right; x++)
                    {
                        for (int y = dragAreaCells.Top; y <= dragAreaCells.Bottom; y++)
                        {
                            Cell cell = world.GetCellAt(x, y);
                            if (cell != null)
                            {
                                currentTask.Preview(cell, spriteBatch);
                            }
                        }
                    }
                }
                else if (CellUnderMouse != null)
                {
                    currentTask.Preview(CellUnderMouse, spriteBatch);
                }
            }

            if (isDraggingRight)
            {
                ShapeManager.DrawRectangle(spriteBatch, dragAreaRight, Color.Transparent, Color.Red);
                for (int x = dragAreaCellsRight.Left; x <= dragAreaCellsRight.Right; x++)
                {
                    for (int y = dragAreaCellsRight.Top; y <= dragAreaCellsRight.Bottom; y++)
                    {
                        Cell cell = world.GetCellAt(x, y);
                        if (cell != null && (currentTask != null && currentTask.CanCancel != null && currentTask.CanCancel(cell)))
                        {
                            Blueprint preview = new Blueprint(cell.World, new Floor(cell, FloorType.Concrete));
                            preview.Draw(spriteBatch, cell.X, cell.Y, Blueprint.BlueprintState.Invalid);
                        }
                    }
                }
            }

            if (isDragging && currentTask == null)
            {
                ShapeManager.DrawRectangle(spriteBatch, dragArea, Color.Transparent, Color.GreenYellow);
            }

            spriteBatch.End();
        }
Exemple #3
0
 public static InputTask BulldozeFactory()
 {
     return(new InputTask(InputMode.Area, (cells, selected) => {
         foreach (Cell cell in cells)
         {
             if (cell.Floor != null)
             {
                 DestroyJob job = new DestroyJob(cell, cell.Floor);
                 cell.World.JobManager.AddJob(job);
             }
             else if (cell.Structure != null)
             {
                 DestroyJob job = new DestroyJob(cell, cell.Structure);
                 cell.World.JobManager.AddJob(job);
             }
         }
     }, (cell, spriteBatch) => {
         Blueprint preview = new Blueprint(cell.World, new Floor(cell, FloorType.Concrete));
         preview.Draw(spriteBatch, cell.X, cell.Y, Blueprint.BlueprintState.Invalid);
     }));
 }