public override void Update() { int x1, x2, y1, y2; var intersecting = HashSetPool <Uprootable, PipPlantOverlay> .Allocate(); base.Update(); // SimDebugView is updated on a background thread, so since plant checking // must be done on the FG thread, it is updated here Grid.GetVisibleExtents(out Vector2I min, out Vector2I max); x1 = min.x; x2 = max.x; y1 = min.y; y2 = max.y; // Refresh plant list with plants on the screen RemoveOffscreenTargets(layerTargets, min, max, null); partition.GetAllIntersecting(new Vector2(x1, y1), new Vector2(x2, y2), intersecting); foreach (var uprootable in intersecting) { AddTargetIfVisible(uprootable, min, max, layerTargets, targetLayer); } for (int y = y1; y <= y2; y++) { for (int x = x1; x <= x2; x++) { int cell = Grid.XYToCell(x, y); if (Grid.IsValidCell(cell)) { cells[cell] = PipPlantOverlayTests.CheckCell(cell); } } } UpdateHighlightTypeOverlay(min, max, layerTargets, plants, conditions, OverlayModes.BringToFrontLayerSetting.Constant, targetLayer); intersecting.Recycle(); }
public PipPlantOverlay() { var colors = GlobalAssets.Instance.colorSet; int pc = PipPlantOverlayTests.PlantCount; // Plural forms are annoying PipPlantOverlayTests.UpdatePlantCriteria(); string plantCountText = string.Format((pc == 1) ? PPO.TOOLTIPS.PLANTCOUNT_1 : PPO.TOOLTIPS.PLANTCOUNT, pc, PipPlantOverlayTests.PlantRadius); cameraLayerMask = LayerMask.GetMask(new string[] { "MaskedOverlay", "MaskedOverlayBG" }); cells = new PipPlantFailedReasons[Grid.CellCount]; for (int i = 0; i < Grid.CellCount; i++) { // Avoid a big green screen flash on first load cells[i] = PipPlantFailedReasons.NoPlantablePlot; } conditions = new OverlayModes.ColorHighlightCondition[] { new OverlayModes.ColorHighlightCondition(GetHighlightColor, ShouldHighlight) }; layerTargets = new HashSet <Uprootable>(); legendFilters = CreateDefaultFilters(); Instance = this; pipPlantLegend = new List <LegendEntry> { new LegendEntry(PPO.CANPLANT, PPO.TOOLTIPS.CANPLANT, colors.cropGrown), new LegendEntry(PPO.HARDNESS, string.Format(PPO.TOOLTIPS.HARDNESS, GameUtil.Hardness.NEARLY_IMPENETRABLE), colors.cropHalted), new LegendEntry(PPO.PLANTCOUNT, plantCountText, colors.cropGrowing), new LegendEntry(PPO.PRESSURE, string.Format(PPO.TOOLTIPS.PRESSURE, GameUtil.GetFormattedMass(PipPlantOverlayTests.PRESSURE_THRESHOLD)), colors.heatflowThreshold0), new LegendEntry(PPO.TEMPERATURE, string.Format(PPO.TOOLTIPS.TEMPERATURE, GameUtil.GetFormattedTemperature(PipPlantOverlayTests.TEMP_MIN), GameUtil.GetFormattedTemperature(PipPlantOverlayTests.TEMP_MAX)), colors.cropHalted) }; partition = null; plants = new HashSet <Tag>(Assets.GetPrefabTagsWithComponent <Uprootable>()); selectionMask = LayerMask.GetMask(new string[] { "MaskedOverlay" }); targetLayer = LayerMask.NameToLayer("MaskedOverlay"); }
/// <summary> /// Calculates if the specified plant should be tinted. /// </summary> /// <param name="plant">The plant that was found.</param> /// <returns>Whether the plant is in range of the cell under the cursor.</returns> private bool ShouldHighlight(KMonoBehaviour plant) { bool hl = false; int plantCell; if (plant != null && Grid.IsValidCell(plantCell = Grid.PosToCell(plant))) { // Same method as used by the decor overlay int mouseCell = Grid.PosToCell(CameraController.Instance.baseCamera. ScreenToWorldPoint(KInputManager.GetMousePos())); // It goes from [x - radius, y - radius] to (x + radius, y + radius) if (Grid.IsValidCell(mouseCell) && cells[mouseCell] != PipPlantFailedReasons. NoPlantablePlot) { int radius = PipPlantOverlayTests.PlantRadius, below = radius, above = radius; var area = plant.GetComponent <OccupyArea>(); Grid.CellToXY(mouseCell, out int mouseX, out int mouseY); Grid.CellToXY(plantCell, out int x, out int y); int startX = x, startY = y; // Need to expand the test area by the plant's size since the top tile is // just as valid of an obstruction as the bottom if (area != null) { var extents = area.GetExtents(); startX = extents.x; startY = extents.y; x = extents.x + extents.width - 1; y = extents.y + extents.height - 1; } if (PipPlantOverlayTests.SymmetricalRadius) { startX--; startY--; } // Pips check the foundation tile, not the plant tile, so find out if top // or bottom is valid and adjust the highlight radius bool solidBelow = PipPlantOverlayTests.IsAcceptableCell(Grid. CellBelow(mouseCell), ReceptacleDirection.Top); if (PipPlantOverlayTests.IsAcceptableCell(Grid.CellAbove(mouseCell), ReceptacleDirection.Bottom)) { above++; if (solidBelow) { below++; } else { below--; } } else if (solidBelow) { above--; below++; } // Symmetrical radius adds another tile on the right and top to match hl = mouseX > startX - radius && mouseX <= x + radius && mouseY > startY - above && mouseY <= y + below; } } return(hl); }