public override float Apply(PaintLayer layer, Color color, byte glow, PaintBrushSize brushSize, float pressurePercent, int randSeed, int worldX, int worldY) { var mymod = BetterPaintMod.Instance; int iterRange = (int)((brushSize == PaintBrushSize.Small ? 1 : 3) * mymod.Config.BrushSizeMultiplier); float radius = (brushSize == PaintBrushSize.Small ? 0.5f : 3f) * mymod.Config.BrushSizeMultiplier; int tileX = worldX / 16; int tileY = worldY / 16; float uses = 0; for (int i = -iterRange; i <= iterRange; i++) { for (int j = -iterRange; j <= iterRange; j++) { float dist = (float)Math.Sqrt((double)((i * i) + (j * j))); if (dist > radius) { continue; } uses += this.PaintAt(layer, color, glow, pressurePercent, (ushort)(tileX + i), (ushort)(tileY + j)); } } return(uses); }
public void Remove(PaintLayer layer) { int index = _layers.IndexOf(layer); if (index == -1) { return; } if (CurrentLayer == layer) { if (_layers.Count == 1) { _currentLayerIndex = -1; } else { _currentLayerIndex = index == 0 ? 1 : index - 1; } } _layers.Remove(layer); Destroy(layer.gameObject); UpdateLayerOrder(); }
public override float Apply(PaintLayer layer, Color _, byte __, PaintBrushSize brushSize, float pressurePercent, int randSeed, int worldX, int worldY) { var mymod = BetterPaintMod.Instance; int diameter = brushSize == PaintBrushSize.Small ? 1 : 6; diameter = (int)((float)diameter * mymod.Config.BrushSizeMultiplier); int iterRange = Math.Max(1, diameter / 2); float radius = (float)diameter / 2f; int tileX = worldX / 16; int tileY = worldY / 16; for (int i = -iterRange; i <= iterRange; i++) { for (int j = -iterRange; j <= iterRange; j++) { float dist = (float)Math.Sqrt((double)((i * i) + (j * j))); if (dist > radius) { continue; } this.EraseAt(layer, pressurePercent, (ushort)(tileX + i), (ushort)(tileY + j)); } } return(0); }
public float PaintAt(PaintLayer layer, Color color, byte glow, float pressurePercent, ushort tileX, ushort tileY) { if (!layer.CanPaintAt(Main.tile[tileX, tileY])) { return(0f); } Color?oldColor; byte oldGlow; Color blendedColor = PaintBrush.GetBlendedColor(layer, color, pressurePercent, tileX, tileY, out oldColor); byte blendedGlow = PaintBrush.GetBlendedGlow(layer, glow, pressurePercent, tileX, tileY, out oldGlow); layer.SetRawColorAt(blendedColor, tileX, tileY); layer.SetGlowAt(blendedGlow, tileX, tileY); float diff = PaintBrush.ComputeChangePercent(oldColor, blendedColor, oldGlow, blendedGlow); if (diff <= 0.01f) { pressurePercent = 0f; } return(pressurePercent); //return PaintBrush.ComputeColorChangePercent( existing_color, lerped_color ); }
public void EraseAt(PaintLayer layer, float pressurePercent, ushort tileX, ushort tileY) { if (!layer.CanPaintAt(Main.tile[tileX, tileY])) { return; } if (!layer.HasColorAt(tileX, tileY)) { return; } int tolerance = (int)(pressurePercent * 255f); Color?oldColor; byte oldGlow; Color blendedColor = PaintBrush.GetErasedColor(layer, pressurePercent, tileX, tileY, out oldColor); byte blendedGlow = PaintBrush.GetBlendedGlow(layer, 0, pressurePercent, tileX, tileY, out oldGlow); float diff = PaintBrush.ComputeChangePercent(oldColor, blendedColor, oldGlow, blendedGlow); if (diff <= 0.01f) { layer.RemoveRawColorAt(tileX, tileY); layer.RemoveGlowAt(tileX, tileY); } else { layer.SetRawColorAt(blendedColor, tileX, tileY); layer.SetGlowAt(blendedGlow, tileX, tileY); } }
public float PaintAt(PaintLayer layer, Color color, byte glow, float pressurePercent, float brushRadius, float dist, ushort tileX, ushort tileY) { if (!layer.CanPaintAt(Main.tile[tileX, tileY])) { return(0f); } float distPressurePercent = MathHelper.Clamp(pressurePercent * (1f - (dist / brushRadius)), 0f, 1f); Color?oldColor; byte oldGlow; Color blendedColor = PaintBrush.GetBlendedColor(layer, color, distPressurePercent, tileX, tileY, out oldColor); byte blendedGlow = PaintBrush.GetBlendedGlow(layer, glow, distPressurePercent, tileX, tileY, out oldGlow); layer.SetRawColorAt(blendedColor, tileX, tileY); layer.SetGlowAt(blendedGlow, tileX, tileY); float diff = PaintBrush.ComputeChangePercent(oldColor, blendedColor, oldGlow, blendedGlow); if (diff <= 0.01f) { distPressurePercent = 0f; } return(distPressurePercent); }
//////////////// public static Color GetBlendedColor(PaintLayer layer, Color rgbColor, float pressurePercent, ushort tileX, ushort tileY, out Color?oldColor) { Color blendedColor; float oldPressurePercent; oldColor = layer.GetRawColorAt(tileX, tileY); if (oldColor != null) { Color oldRgbColor = (Color)oldColor; oldPressurePercent = oldRgbColor.A / 255f; float oldPressurePercentOffset = (1f - pressurePercent) * oldPressurePercent; blendedColor = Color.Lerp(rgbColor, oldRgbColor, oldPressurePercentOffset); } else { oldPressurePercent = 0f; blendedColor = rgbColor; } blendedColor.A = (byte)(MathHelper.Lerp(oldPressurePercent, 1f, pressurePercent) * 255f); return(blendedColor); }
public void MergeDown(PaintLayer layer) { int index = _layers.IndexOf(layer); if (index < 1) { return; } Graphics.Blit(layer.RenderTexture, _layers[index - 1].RenderTexture, layer.Material); Remove(layer); }
public static Color GetErasedColor(PaintLayer layer, float pressurePercent, ushort tileX, ushort tileY, out Color?oldColor) { oldColor = layer.GetRawColorAt(tileX, tileY); if (oldColor == null) { return(Color.Transparent); } Color blendedColor = (Color)oldColor; blendedColor.A = (byte)(MathHelper.Lerp(blendedColor.A, 0f, pressurePercent) * 255f); return(blendedColor); }
public void StopPainting() { if (!_isPainting) { return; } CurrentTool.Up(_paintLayer.RenderTexture, GetPaintParameters()); Layers.MergeDown(_paintLayer); _paintLayer = null; _isPainting = false; RecordUndo(); }
public bool EditHexagon(Vector3 initialWorldCoordinate, Vector3 endWorldCoordinate, int typeID, float height, PaintLayer paintLayer) { bool isDirty = false; Vector2i initialGridCoordinate = HexagonUtils.ConvertOrthonormalToHexaSpace(initialWorldCoordinate); Vector2i endGridCoordinate = HexagonUtils.ConvertOrthonormalToHexaSpace(endWorldCoordinate); IEnumerable <Vector2i> line = HexagonUtils.GetLine(initialGridCoordinate, endGridCoordinate); foreach (Vector2i gridCoordinate in line) { isDirty |= EditHexagon(gridCoordinate, typeID, height, paintLayer); } return(isDirty); }
public override void OnInspectorGUI() { GUILayout.Space(15.0f); GUI.enabled = TargetMap.IsValid; _paintLayer = (PaintLayer)EditorGUILayout.MaskField("Painted layer: ", (int)_paintLayer, new[] { "Type", "Height" }); // HexaType picker GUI.enabled = TargetMap.IsValid && _paintLayer.Contain(PaintLayer.Type); _typeIdBrush = EditorGUILayout.Popup("Brush type: ", _typeIdBrush, GUI.enabled ? TargetMap.Types.GetNames() : new[] { "" }); // Height picker GUI.enabled = TargetMap.IsValid && _paintLayer.Contain(PaintLayer.Height); _heightBrush = EditorGUILayout.Slider("Brush height: ", _heightBrush, 0, 20); // Space GUILayout.Space(5.0f); // Enable edit mode buton GUI.enabled = TargetMap.IsValid; GUI.color = IsEditModeEnabled ? Color.green : Color.yellow; if (GUILayout.Button(EditModeButtonString)) { IsEditModeEnabled = !IsEditModeEnabled; } GUI.color = Color.white; GUILayout.Label(IsEditModeEnabled ? "Edit mode hide scene view handlers!" : ""); // Rebuild button. if (GUILayout.Button("Force rebuild")) { TargetMap.ForceRebuild(); } GUILayout.Space(15.0f); // Set Data GUI.enabled = true; TargetMap.HexData = EditorGUILayout.ObjectField("HexTerrain data:", TargetMap.HexData, typeof(HexTerrainData), false) as HexTerrainData; TargetMap.Types = EditorGUILayout.ObjectField("Types data:", TargetMap.Types, typeof(HexagonTypeData), false) as HexagonTypeData; }
public static byte GetBlendedGlow(PaintLayer layer, byte glow, float pressurePercent, ushort tileX, ushort tileY, out byte oldGlow) { byte blendedGlow; oldGlow = layer.GetGlowAt(tileX, tileY); if (glow != 0) { byte pressuredGlow = (byte)((float)glow * pressurePercent); blendedGlow = (byte)MathHelper.Lerp((float)oldGlow, 255f, (float)pressuredGlow / 255f); } else { blendedGlow = (byte)MathHelper.Lerp((float)oldGlow, 0f, pressurePercent); } return(blendedGlow); }
public void StartPainting() { if (CurrentTool == null) { return; } if (_isPainting) { return; } _isPainting = true; _paintLayer = Layers.Create("Paint", ImageSize, true); _paintLayer.Opacity = CurrentTool.Opacity; RenderTexture.active = _paintLayer.RenderTexture; GL.Clear(false, true, Color.clear); RenderTexture.active = null; CurrentTool.Down(_paintLayer.RenderTexture, GetPaintParameters(), Layers); }
bool EditHexagon(Vector2i gridCoordinate, int typeID, float height, PaintLayer paintLayer) { //Debug.Log("gridCoordinate: " + gridCoordinate); bool isDirty = false; if (HexData.Contains(gridCoordinate)) { if (paintLayer.Contain(PaintLayer.Type) && HexData[gridCoordinate].TypeID != typeID) { HexData[gridCoordinate].TypeID = typeID; isDirty |= true; } if (paintLayer.Contain(PaintLayer.Height) && HexData[gridCoordinate].Height != height) { HexData[gridCoordinate].Height = height; isDirty |= true; } _chunks[gridCoordinate.y / chunkLength * ChunkRow + gridCoordinate.x / chunkWidth].IsDirty |= isDirty; } return(isDirty); }
public override float Apply(PaintLayer layer, Color color, byte glow, PaintBrushSize brushSize, float pressurePercent, int randSeed, int worldX, int worldY) { var mymod = BetterPaintMod.Instance; int diameter = brushSize == PaintBrushSize.Small ? 3 : 8; diameter = (int)((float)diameter * mymod.Config.BrushSizeMultiplier); int iterRange = diameter / 2; float maxRange = (float)diameter / 2f; float uses = 0; int tileX = worldX / 16; int tileY = worldY / 16; double tileOffsetX = (double)(worldX % 16) / 16f; double tileOffsetY = (double)(worldY % 16) / 16f; for (int i = -iterRange; i <= iterRange; i++) { for (int j = -iterRange; j <= iterRange; j++) { double iOff = i + tileOffsetX; double jOff = j + tileOffsetY; float dist = (float)Math.Sqrt((iOff * iOff) + (jOff * jOff)); if (dist > maxRange) { continue; } ushort x = (ushort)(tileX + i); ushort y = (ushort)(tileY + j); uses += this.PaintAt(layer, color, glow, pressurePercent, maxRange, dist, x, y); } } return(uses); }
public override float Apply(PaintLayer layer, Color color, byte glow, PaintBrushSize brushSize, float pressurePercent, int randSeed, int worldX, int worldY) { var mymod = BetterPaintMod.Instance; var rand = new Random(randSeed); int tileX = worldX / 16; int tileY = worldY / 16; float uses = 0; int diameter = brushSize == PaintBrushSize.Small ? 3 : 6; diameter = (int)((float)diameter * mymod.Config.BrushSizeMultiplier); int spats = (int)((float)(diameter * diameter) * mymod.Config.BrushSpatterDensity); int minRadius = Math.Max(1, diameter / 3); int extendedRadiusRange = diameter - minRadius; for (int i = 0; i < spats; i++) { int extendedRadius = rand.Next(extendedRadiusRange); int radius = minRadius + extendedRadius; int xOff = rand.Next(-radius, radius); radius = minRadius + extendedRadius; int yOff = rand.Next(-radius, radius); float randPercent = pressurePercent * (1f - (float)rand.NextDouble()); if (randPercent >= 0.01f) { uses += this.PaintAt(layer, color, glow, randPercent, (ushort)(tileX + xOff), (ushort)(tileY + yOff)); } } return(uses); }
public bool EditHexagon(Vector3 worldCoordinate, int typeID, float height, PaintLayer paintLayer) { Vector2i gridCoordinate = HexagonUtils.ConvertOrthonormalToHexaSpace(worldCoordinate); return(EditHexagon(gridCoordinate, typeID, height, paintLayer)); }
//////////////// public abstract float Apply(PaintLayer layer, Color color, byte glow, PaintBrushSize brushSize, float pressurePercent, int randSeed, int worldX, int worldY);