internal TileMeshRenderer(BlockTileRenderer colorSource)
 {
     this.colorSource = colorSource;
     deactivated      = new List <Vector2I>(16);
     forceRebuild     = false;
     lastVisible      = new Extents(0, 0, 0, 0);
     renderInfo       = new Dictionary <BuildingDef, TileRenderInfo>(128);
     selectedCell     = Grid.InvalidCell;
     highlightCell    = Grid.InvalidCell;
     invalidPlaceCell = Grid.InvalidCell;
 }
        /// <summary>
        /// Removes a tile-like object from rendering.
        /// </summary>
        /// <param name="def">The building def to render.</param>
        /// <param name="isReplacement">true if replacing another item, or false otherwise.</param>
        /// <param name="element">The element used to build the def.</param>
        /// <param name="cell">The cell the building occupied.</param>
        public void RemoveBlock(BuildingDef def, bool isReplacement, SimHashes element,
                                int cell)
        {
            int             layer = (int)BlockTileRenderer.GetRenderInfoLayer(isReplacement, element);
            LayerRenderInfo info;

            if (renderInfo.TryGetValue(def, out TileRenderInfo infoForTile) && (info =
                                                                                    infoForTile.infos[layer]) != null)
            {
                info.RemoveCell(cell);
            }
        }
 public static void Postfix(int cell, SimHashes element, BlockTileRenderer __instance, ref Color __result)
 {
     try
     {
         var cellColor = State.TileColors[cell];
         if
         (
             State.Config.Enabled &&
             cellColor.HasValue
         )
         {
             __result *= cellColor.Value;
         }
     }
     catch (Exception e)
     {
         Common.Logger.LogOnce("EnterCell failed.", e);
     }
 }
Exemple #4
0
 public static void Postfix(int cell, SimHashes element, BlockTileRenderer __instance, ref Color __result)
 {
     try
     {
         if
         (
             State.ConfiguratorState.Enabled &&
             ColorHelper.TileColors.Length > cell &&
             ColorHelper.TileColors[cell].HasValue
         )
         {
             __result *= ColorHelper.TileColors[cell].Value;
         }
     }
     catch (Exception e)
     {
         State.Logger.Log("EnterCell failed.");
         State.Logger.Log(e);
     }
 }
        /// <summary>
        /// Adds a tile-like object to render.
        /// </summary>
        /// <param name="renderLayer">The layer to use for rendering.</param>
        /// <param name="def">The building def to render.</param>
        /// <param name="isReplacement">true if replacing another item, or false otherwise.</param>
        /// <param name="element">The element used to build the def.</param>
        /// <param name="cell">The cell the building will occupy.</param>
        public void AddBlock(int renderLayer, BuildingDef def, bool isReplacement,
                             SimHashes element, int cell)
        {
            int layer = (int)BlockTileRenderer.GetRenderInfoLayer(isReplacement, element);

            // If building never seen before
            if (!renderInfo.TryGetValue(def, out TileRenderInfo infoForTile))
            {
                renderInfo.Add(def, infoForTile = new TileRenderInfo());
            }
            int queryLayer = (int)(isReplacement ? def.ReplacementLayer : def.TileLayer);
            var infos      = infoForTile.infos;
            // Create the layer if not yet populated
            var info = infos[layer];

            if (info == null)
            {
                info         = new LayerRenderInfo(queryLayer, renderLayer, def, element);
                infos[layer] = info;
            }
            info.AddCell(cell);
        }
            public static bool Prefix(int cell, SimHashes element, BlockTileRenderer __instance, ref Color __result)
            {
                try
                {
                    Color tileColor;

                    if (State.ConfiguratorState.Enabled)
                    {
                        if (State.ConfiguratorState.LegacyTileColorHandling)
                        {
                            switch (State.ConfiguratorState.ColorMode)
                            {
                            case ColorMode.Json:
                                tileColor = ColorHelper.GetCellColorJson(cell);
                                break;

                            case ColorMode.DebugColor:
                                tileColor = ColorHelper.GetCellColorDebug(cell);
                                break;

                            default:
                                tileColor = ColorHelper.DefaultCellColor;
                                break;
                            }
                        }
                        else
                        {
                            if (ColorHelper.TileColors.Length > cell && ColorHelper.TileColors[cell].HasValue)
                            {
                                tileColor = ColorHelper.TileColors[cell].Value;
                            }
                            else
                            {
                                //if (cell == __instance.invalidPlaceCell)
                                if (cell == (int)GetField(__instance, "invalidPlaceCell"))
                                {
                                    __result = ColorHelper.InvalidCellColor;
                                    return(false);
                                }

                                tileColor = ColorHelper.DefaultCellColor;
                            }
                        }
                    }
                    else
                    {
                        tileColor = ColorHelper.DefaultCellColor;
                    }

                    //if (cell == __instance.selectedCell)
                    if (cell == (int)GetField(__instance, "selectedCell"))
                    {
                        __result = tileColor * 1.5f;
                        return(false);
                    }

                    //if (cell == __instance.highlightCell)
                    if (cell == (int)GetField(__instance, "highlightCell"))
                    {
                        __result = tileColor * 1.25f;
                        return(false);
                    }

                    __result = tileColor;
                    return(false);
                }
                catch (Exception e)
                {
                    State.Logger.Log("EnterCell failed.");
                    State.Logger.Log(e);
                }

                return(true);
            }
    private void UpdateVis(Vector3 pos)
    {
        bool flag  = def.IsValidPlaceLocation(visualizer, pos, buildingOrientation, out string _);
        bool flag2 = def.IsValidReplaceLocation(pos, buildingOrientation, def.ReplacementLayer, def.ObjectLayer);

        flag = (flag || flag2);
        if ((Object)visualizer != (Object)null)
        {
            Color c        = Color.white;
            float strength = 0f;
            if (!flag)
            {
                c        = Color.red;
                strength = 1f;
            }
            SetColor(visualizer, c, strength);
        }
        int num = Grid.PosToCell(pos);

        if ((Object)def != (Object)null)
        {
            Vector3 vector = Grid.CellToPosCBC(num, def.SceneLayer);
            visualizer.transform.SetPosition(vector);
            base.transform.SetPosition(vector - Vector3.up * 0.5f);
            if (def.IsTilePiece)
            {
                ClearTilePreview();
                if (Grid.IsValidBuildingCell(num))
                {
                    GameObject gameObject = Grid.Objects[num, (int)def.TileLayer];
                    if ((Object)gameObject == (Object)null)
                    {
                        Grid.Objects[num, (int)def.TileLayer] = visualizer;
                    }
                    if (def.isKAnimTile)
                    {
                        GameObject x = null;
                        if (def.ReplacementLayer != ObjectLayer.NumLayers)
                        {
                            x = Grid.Objects[num, (int)def.ReplacementLayer];
                        }
                        if ((Object)gameObject == (Object)null || ((Object)gameObject.GetComponent <Constructable>() == (Object)null && (Object)x == (Object)null))
                        {
                            TileVisualizer.RefreshCell(num, def.TileLayer, def.ReplacementLayer);
                            if ((Object)def.BlockTileAtlas != (Object)null)
                            {
                                int renderLayer = LayerMask.NameToLayer("Overlay");
                                BlockTileRenderer blockTileRenderer = World.Instance.blockTileRenderer;
                                blockTileRenderer.SetInvalidPlaceCell(num, !flag);
                                if (lastCell != num)
                                {
                                    blockTileRenderer.SetInvalidPlaceCell(lastCell, false);
                                }
                                blockTileRenderer.AddBlock(renderLayer, def, flag2, SimHashes.Void, num);
                            }
                        }
                    }
                }
            }
            if (lastCell != num)
            {
                lastCell = num;
            }
        }
    }
 /// <summary>
 /// Creates the singleton instance of this class.
 /// </summary>
 /// <param name="colorSource">The tile renderer to use for tile colors.</param>
 internal static void CreateInstance(BlockTileRenderer colorSource)
 {
     DestroyInstance();
     Instance = new TileMeshRenderer(colorSource);
 }