Example #1
0
        public TileVisual(BuildingConfig buildingConfig, int cell)
        {
            Offset = buildingConfig.Offset;
            this.buildingConfig = buildingConfig;
            hasReplacementLayer = buildingConfig.BuildingDef.ReplacementLayer != ObjectLayer.NumLayers;

            Vector3 positionCBC = Grid.CellToPosCBC(cell, Grid.SceneLayer.Building);

            Visualizer = GameUtil.KInstantiate(buildingConfig.BuildingDef.BuildingPreview, positionCBC, Grid.SceneLayer.Ore, "BlueprintModTileVisualizer", LayerMask.NameToLayer("Place"));
            Visualizer.transform.SetPosition(positionCBC);
            Visualizer.SetActive(true);

            if (Visualizer.GetComponent <Rotatable>() != null)
            {
                Visualizer.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
            }

            KBatchedAnimController batchedAnimController = Visualizer.GetComponent <KBatchedAnimController>();

            if (batchedAnimController != null)
            {
                batchedAnimController.visibilityType = KAnimControllerBase.VisibilityType.OffscreenUpdate;
                batchedAnimController.isMovable      = true;
                batchedAnimController.Offset         = buildingConfig.BuildingDef.GetVisualizerOffset() + buildingConfig.BuildingDef.placementPivot;
            }

            VisualsUtilities.SetVisualizerColor(cell, GetVisualizerColor(cell), Visualizer, buildingConfig);
            DirtyCell = cell;
            UpdateGrid(cell);
        }
Example #2
0
        public bool TryUse(int cell)
        {
            Clean();

            if (BlueprintsState.InstantBuild)
            {
                if (ValidCell(cell))
                {
                    Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                    GameObject building    = buildingConfig.BuildingDef.Create(positionCBC, null, buildingConfig.SelectedElements, buildingConfig.BuildingDef.CraftRecipe, 293.15F, buildingConfig.BuildingDef.BuildingComplete);
                    if (building == null)
                    {
                        return(false);
                    }

                    buildingConfig.BuildingDef.MarkArea(cell, buildingConfig.Orientation, buildingConfig.BuildingDef.TileLayer, building);
                    buildingConfig.BuildingDef.RunOnArea(cell, buildingConfig.Orientation, cell0 => TileVisualizer.RefreshCell(cell0, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer));

                    if (building.GetComponent <Deconstructable>() != null)
                    {
                        building.GetComponent <Deconstructable>().constructionElements = buildingConfig.SelectedElements.ToArray();
                    }

                    if (building.GetComponent <Rotatable>() != null)
                    {
                        building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                    }

                    VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                    return(true);
                }
            }

            else if (IsPlaceable(cell))
            {
                Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                GameObject building    = buildingConfig.BuildingDef.Instantiate(positionCBC, buildingConfig.Orientation, buildingConfig.SelectedElements);
                if (building == null)
                {
                    return(false);
                }

                if (building.GetComponent <Rotatable>() != null)
                {
                    building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                }

                if (Visualizer.GetComponent <KBatchedAnimController>() != null)
                {
                    Visualizer.GetComponent <KBatchedAnimController>().TintColour = BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT;
                }

                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                return(true);
            }

            return(false);
        }
Example #3
0
        public void MoveVisualizer(int cell)
        {
            if (cell != this.cell)
            {
                Visualizer.transform.SetPosition(Grid.CellToPosCBC(cell, Grid.SceneLayer.Building));
                VisualsUtilities.SetVisualizerColor(cell, GetVisualizerColor(cell), Visualizer, buildingConfig);

                this.cell = cell;
            }
        }
Example #4
0
        public UtilityVisual(BuildingConfig buildingConfig, int cell)
        {
            Offset = buildingConfig.Offset;
            this.buildingConfig = buildingConfig;
            this.cell           = cell;

            Vector3 positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);

            Visualizer = GameUtil.KInstantiate(buildingConfig.BuildingDef.BuildingPreview, positionCBC, Grid.SceneLayer.Ore, "BlueprintModUtilityVisualizer", LayerMask.NameToLayer("Place"));
            Visualizer.transform.SetPosition(positionCBC);
            Visualizer.SetActive(true);

            if (Visualizer.GetComponent <Rotatable>() != null)
            {
                Visualizer.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
            }

            KBatchedAnimController batchedAnimController = Visualizer.GetComponent <KBatchedAnimController>();

            if (batchedAnimController != null)
            {
                IUtilityNetworkMgr utilityNetworkManager = buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>().GetNetworkManager();

                if (utilityNetworkManager != null)
                {
                    string animation = utilityNetworkManager.GetVisualizerString((UtilityConnections)buildingConfig.Flags) + "_place";

                    if (batchedAnimController.HasAnimation(animation))
                    {
                        batchedAnimController.Play(animation);
                    }
                }

                batchedAnimController.visibilityType = KAnimControllerBase.VisibilityType.Always;
                batchedAnimController.isMovable      = true;
                batchedAnimController.Offset         = buildingConfig.BuildingDef.GetVisualizerOffset() + buildingConfig.BuildingDef.placementPivot;
                batchedAnimController.TintColour     = GetVisualizerColor(cell);

                batchedAnimController.SetLayer(LayerMask.NameToLayer("Place"));
            }

            else
            {
                Visualizer.SetLayerRecursively(LayerMask.NameToLayer("Place"));
            }

            VisualsUtilities.SetVisualizerColor(cell, GetVisualizerColor(cell), Visualizer, buildingConfig);
        }
Example #5
0
        private void UpdateGrid(int cell)
        {
            Clean();

            if (Grid.IsValidBuildingCell(cell))
            {
                bool visualizerSeated = false;

                if (Grid.Objects[cell, (int)buildingConfig.BuildingDef.TileLayer] == null)
                {
                    Grid.Objects[cell, (int)buildingConfig.BuildingDef.TileLayer] = Visualizer;
                    visualizerSeated = true;
                }

                if (buildingConfig.BuildingDef.isKAnimTile)
                {
                    GameObject tileLayerObject        = Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.TileLayer];
                    GameObject replacementLayerObject = hasReplacementLayer ? Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] : null;

                    if (tileLayerObject == null || tileLayerObject.GetComponent <Constructable>() == null && replacementLayerObject == null)
                    {
                        if (buildingConfig.BuildingDef.BlockTileAtlas != null)
                        {
                            if (!ValidCell(cell))
                            {
                                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                            }

                            bool replacing = hasReplacementLayer && CanReplace(cell);
                            World.Instance.blockTileRenderer.AddBlock(LayerMask.NameToLayer("Overlay"), buildingConfig.BuildingDef, replacing, SimHashes.Void, cell);
                            if (replacing && !visualizerSeated && Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] == null)
                            {
                                Grid.Objects[cell, (int)buildingConfig.BuildingDef.ReplacementLayer] = Visualizer;
                            }
                        }
                    }

                    TileVisualizer.RefreshCell(cell, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer);
                }

                DirtyCell = cell;
            }
        }
Example #6
0
        public bool TryUse(int cell)
        {
            if (BlueprintsState.InstantBuild)
            {
                if (ValidCell(cell))
                {
                    Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                    GameObject building    = buildingConfig.BuildingDef.Create(positionCBC, null, buildingConfig.SelectedElements, buildingConfig.BuildingDef.CraftRecipe, 293.15F, buildingConfig.BuildingDef.BuildingComplete);
                    if (building == null)
                    {
                        return(false);
                    }

                    buildingConfig.BuildingDef.MarkArea(cell, buildingConfig.Orientation, buildingConfig.BuildingDef.TileLayer, building);
                    buildingConfig.BuildingDef.RunOnArea(cell, buildingConfig.Orientation, cell0 => TileVisualizer.RefreshCell(cell0, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer));

                    if (building.GetComponent <Rotatable>() != null)
                    {
                        building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                    }

                    if (buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && building.GetComponent <KAnimGraphTileVisualizer>() != null)
                    {
                        building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections((UtilityConnections)buildingConfig.Flags);
                    }

                    VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                    return(true);
                }
            }

            else if (IsPlaceable(cell))
            {
                Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                GameObject building    = buildingConfig.BuildingDef.Instantiate(positionCBC, buildingConfig.Orientation, buildingConfig.SelectedElements);

                if (building == null)
                {
                    return(false);
                }

                if (building.GetComponent <Rotatable>() != null)
                {
                    building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                }

                if (buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && building.GetComponent <KAnimGraphTileVisualizer>() != null)
                {
                    building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections((UtilityConnections)buildingConfig.Flags);
                }

                if (ToolMenu.Instance != null)
                {
                    building.FindOrAddComponent <Prioritizable>().SetMasterPriority(ToolMenu.Instance.PriorityScreen.GetLastSelectedPriority());
                }

                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                return(true);
            }

            return(false);
        }
Example #7
0
 public void MoveVisualizer(int cell)
 {
     Visualizer.transform.SetPosition(Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer));
     VisualsUtilities.SetVisualizerColor(cell, GetVisualizerColor(cell), Visualizer, buildingConfig);
     UpdateGrid(cell);
 }