Beispiel #1
0
 private static void SetFilterToBuilding(FilteredDragTool __instance, Dictionary <string, ToolParameterMenu.ToggleState> filters)
 {
     if (__instance is DeconstructTool)
     {
         Debug.Log("DeconstructToolDefault is BUILDINGS!");
         filters[ToolParameterMenu.FILTERLAYERS.ALL]       = ToolParameterMenu.ToggleState.Off;
         filters[ToolParameterMenu.FILTERLAYERS.BUILDINGS] = ToolParameterMenu.ToggleState.On;
         // DebugOutput("deconstruct", filters);
     }
 }
Beispiel #2
0
        public static Blueprint CreateBlueprint(Vector2I topLeft, Vector2I bottomRight, FilteredDragTool originTool = null)
        {
            Blueprint blueprint       = new Blueprint(Utilities.GetNewBlueprintLocation("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);
        }