void DoPaint(int x, int y, int z, byte color, PaintMode mode, Edit.Brush brush, int size) { for (int px = x - (size - 1); px <= x + (size - 1); px++) { for (int py = y - (size - 1); py <= y + (size - 1); py++) { for (int pz = z - (size - 1); pz <= z + (size - 1); pz++) { if (IsOutOfBounds(px, py, pz)) { continue; } if (mode == PaintMode.Filled && IsEmpty(px, py, pz)) { continue; } if (mode == PaintMode.Empty && !IsEmpty(px, py, pz)) { continue; } if (brush == Edit.Brush.Diamond && Mathf.Abs(px - x) + Mathf.Abs(py - y) + Mathf.Abs(pz - z) >= size) { continue; } if (brush == Edit.Brush.Sphere && Vector3.Distance(new Vector3(x, y, z), new Vector3(px, py, pz)) > size) { continue; } PreviewChunk.use.chunk.SetPaletteIndexAt(px, py, pz, color); edits[ToIndex(px, py, pz)] = color; } } } }
void Paint(int x, int y, int z, byte color, PaintMode mode) { if (IsOutOfBounds(x, y, z)) { return; } Edit.Brush brush = Edit.use.brush; int size = Edit.use.brushSize; foreach (int index in GetSymmetryPoints(x, y, z)) { int px, py, pz; FromIndex(index, out px, out py, out pz); DoPaint(px, py, pz, color, mode, brush, size); } }
public ChangeBrushAct(Edit.Brush brush) { this.brush = brush; }
public override void Do() { prevBrush = Edit.use.brush; Edit.use.brush = brush; }
void ToolOptions() { GUILayout.BeginVertical("box"); showToolOptions = GUILayout.Toggle(showToolOptions, "Tool Options", "boxhead"); if (showToolOptions) { if (Edit.use.bindPlaneLock.IsHeld()) { bool planeLock = !GUILayout.Toggle(!Edit.use.planeLock, "Plane Lock", "button"); if (planeLock != Edit.use.planeLock) { actQueue.Enqueue(new ChangePlaneLockAct(planeLock)); } } else { bool planeLock = GUILayout.Toggle(Edit.use.planeLock, "Plane Lock", "button"); if (planeLock != Edit.use.planeLock) { actQueue.Enqueue(new ChangePlaneLockAct(planeLock)); } } GUILayout.Label("Symmetry"); GUILayout.BeginHorizontal(); GUI.color = Color.Lerp(Color.red, Color.white, 0.5f); bool mirrorX = GUILayout.Toggle(Edit.use.mirrorX, "X", "button"); GUI.color = Color.Lerp(Color.green, Color.white, 0.5f); bool mirrorY = GUILayout.Toggle(Edit.use.mirrorY, "Y", "button"); GUI.color = Color.Lerp(Color.Lerp(Color.blue, Color.cyan, .5f), Color.white, 0.5f); bool mirrorZ = GUILayout.Toggle(Edit.use.mirrorZ, "Z", "button"); GUI.color = Color.white; if (mirrorX != Edit.use.mirrorX || mirrorY != Edit.use.mirrorY || mirrorZ != Edit.use.mirrorZ) { actQueue.Enqueue(new ChangeSymmetryAct(mirrorX, mirrorY, mirrorZ)); } GUILayout.EndHorizontal(); if (Edit.use.tool == Edit.Tool.Place || Edit.use.tool == Edit.Tool.Paint) { GUILayout.Label("Brush Type"); Edit.Brush brush = (Edit.Brush)GUILayout.SelectionGrid((int)ed.brush, new[] { "Cube", "Sphere", "Diamond" }, 1); if (brush != Edit.use.brush) { actQueue.Enqueue(new ChangeBrushAct(brush)); } GUILayout.Label("Brush Size"); GUILayout.BeginHorizontal(); GUI.enabled = ed.brushSize > 1; if (GUILayout.Button("-")) { actQueue.Enqueue(new ChangeBrushSizeAct(ed.brushSize - 1)); } GUI.enabled = true; int brushSize; if (int.TryParse(GUILayout.TextField(ed.brushSize.ToString()), out brushSize)) { if (brushSize != ed.brushSize) { actQueue.Enqueue(new ChangeBrushSizeAct(brushSize)); } } if (GUILayout.Button("+")) { actQueue.Enqueue(new ChangeBrushSizeAct(ed.brushSize + 1)); } GUILayout.EndHorizontal(); } if (Edit.use.tool == Edit.Tool.Fill) { bool fillDiagonals = GUILayout.Toggle(Edit.use.fillDiagonals, "Diagonals", "button"); if (fillDiagonals != Edit.use.fillDiagonals) { actQueue.Enqueue(new ChangeFillDiagonalsAct(fillDiagonals)); } } } GUILayout.EndVertical(); if (repaint) { boxRects.Add(GUILayoutUtility.GetLastRect()); } }