Exemplo n.º 1
0
 private static void RenameFile(Blueprint blueprint, string newName)
 {
     DeleteXML(blueprint);
     blueprint.name = newName;
     SaveToXML(blueprint);
 }
Exemplo n.º 2
0
 private static void DeleteXML(Blueprint blueprint)
 {
     File.Delete(FullFilePath(blueprint.name));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add a blueprint to the folder.
 /// </summary>
 /// <param name="blueprint">The blueprint to add</param>
 public void AddBlueprint(Blueprint blueprint)
 {
     contents.Add(blueprint);
     SelectedBlueprintIndex = contents.Count - 1;
 }
        public override void DesignateMultiCell(IEnumerable <IntVec3> cells)
        {
            // bail out if empty
            if (cells == null || cells.Count() == 0)
            {
                Messages.Message("Fluffy.Blueprints.CannotCreateBluePrint_NothingSelected".Translate(), MessageSound.RejectInput);
                return;
            }

            // get list of buildings in the cells, note that this includes frames and blueprints, and so _may include floors!_
            List <Thing> things = new List <Thing>(cells.SelectMany(cell => cell.GetThingList(Map)
                                                                    .Where(thing => thing.IsValidBlueprintThing()))
                                                   .Distinct());

            // get list of creatable terrains
            List <Pair <TerrainDef, IntVec3> > terrains = new List <Pair <TerrainDef, IntVec3> >();

            terrains.AddRange(cells.Select(cell => new Pair <TerrainDef, IntVec3>(cell.GetTerrain(Map), cell))
                              .Where(p => p.First.IsValidBlueprintTerrain()));

            // get edges of blueprint area
            // (might be bigger than selected region, but never smaller).
            var allCells = cells.Concat(things.SelectMany(thing => thing.OccupiedRect().Cells));

            int left   = allCells.Min(cell => cell.x);
            int top    = allCells.Max(cell => cell.z);
            int right  = allCells.Max(cell => cell.x);
            int bottom = allCells.Min(cell => cell.z);

            // total size ( +1 because x = 2 ... x = 4 => 4 - 2 + 1 cells )
            IntVec2 size = new IntVec2(right - left + 1, top - bottom + 1);

            // fetch origin for default (North) orientation
            IntVec3 origin = Resources.CenterPosition(new IntVec3(left, 0, bottom), size, Rot4.North);

            // create list of buildables
            List <BuildableInfo> buildables = new List <BuildableInfo>();

            foreach (var thing in things)
            {
                buildables.Add(new BuildableInfo(thing, origin));
            }
            foreach (var terrain in terrains)
            {
                buildables.Add(new BuildableInfo(terrain.First, terrain.Second, origin));
            }

            // try to get a decent default name: check if selection contains only a single room - if so, that's a decent name.
            Room   room        = origin.GetRoom(Map);
            string defaultName = null;

            if (room != null && room.Role != RoomRoleDefOf.None)
            {
                defaultName = room.Role.LabelCap;
            }
            // TODO: multiple (same) rooms, etc.

            // add to controller - controller handles adding to designations
            Blueprint blueprint = new Blueprint(buildables, size, defaultName);

            Controller.Add(blueprint);

#if DEBUG
            blueprint.Debug();
#endif
        }
Exemplo n.º 5
0
        public static Blueprint CreateBlueprint(Vector2I topLeft, Vector2I bottomRight, FilteredDragTool originTool = null)
        {
            Blueprint blueprint       = new Blueprint("unnamed", "");
            int       blueprintHeight = (topLeft.y - bottomRight.y);

            for (int x = topLeft.x; x <= bottomRight.x; ++x)
            {
                for (int y = bottomRight.y; y <= topLeft.y; ++y)
                {
                    int cell = Grid.XYToCell(x, y);

                    if (Grid.IsVisible(cell))
                    {
                        bool emptyCell = true;

                        for (int layer = 0; layer < Grid.ObjectLayers.Length; ++layer)
                        {
                            if (layer == 7)
                            {
                                continue;
                            }

                            GameObject gameObject = Grid.Objects[cell, layer];
                            Building   building;

                            if (gameObject != null && (building = gameObject.GetComponent <Building>()) != null && building.Def.IsBuildable() && (originTool == null || originTool.IsActiveLayer(originTool.GetFilterLayerFromGameObject(gameObject))))
                            {
                                PrimaryElement primaryElement;

                                if ((primaryElement = building.GetComponent <PrimaryElement>()) != null)
                                {
                                    Vector2I centre = Grid.CellToXY(GameUtil.NaturalBuildingCell(building));

                                    BuildingConfig buildingConfig = new BuildingConfig {
                                        Offset      = new Vector2I(centre.x - topLeft.x, blueprintHeight - (topLeft.y - centre.y)),
                                        BuildingDef = building.Def,
                                        Orientation = building.Orientation
                                    };

                                    buildingConfig.SelectedElements.Add(primaryElement.ElementID.CreateTag());
                                    if (building.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null)
                                    {
                                        buildingConfig.Flags = (int)building.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>().GetNetworkManager()?.GetConnections(cell, false);
                                    }

                                    if (!blueprint.BuildingConfiguration.Contains(buildingConfig))
                                    {
                                        blueprint.BuildingConfiguration.Add(buildingConfig);
                                    }
                                }

                                emptyCell = false;
                            }
                        }

                        if (emptyCell && (!Grid.IsSolidCell(cell) || Grid.Objects[cell, 7] != null && Grid.Objects[cell, 7].name == "DigPlacer"))
                        {
                            Vector2I digLocation = new Vector2I(x - topLeft.x, blueprintHeight - (topLeft.y - y));

                            if (!blueprint.DigLocations.Contains(digLocation))
                            {
                                blueprint.DigLocations.Add(digLocation);
                            }
                        }
                    }
                }
            }

            return(blueprint);
        }
Exemplo n.º 6
0
 public BuildableInfo(Blueprint blueprint)
 {
     this.blueprint = blueprint;
     // rest is filled in by scribe.
 }