/// <summary>
        /// Display user interface to force refresh all plops associated with a tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="system"/> is <c>null</c>.
        /// </exception>
        internal static void Command_RefreshPlops(TileSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            if (!EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Refresh Plops"),
                    string.Format(
                        /* 0: name of tile system */
                        TileLang.Text("Do you want to force refresh all plops associated with '{0}'?"),
                        system.name
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                return;
            }

            // Refresh all plops which are associated with tile system.
            foreach (var plop in UnityEngine.Resources.FindObjectsOfTypeAll <PlopInstance>())
            {
                if (plop.Owner == system && plop.Brush != null)
                {
                    PlopUtility.RefreshPlop(system, plop);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raised by <see cref="OnTool"/> to perform painting upon pressing left or right mouse button.
        /// </summary>
        /// <param name="e">Tool event data.</param>
        /// <param name="context">Context that tool is being used in.</param>
        protected virtual void OnPaint(ToolEvent e, IToolContext context)
        {
            var brush = e.IsLeftButtonPressed
                ? ToolUtility.SelectedBrush
                : ToolUtility.SelectedBrushSecondary;

            // Like with the regular paint tool, null brush is the eraser!
            if (brush != null && !PlopUtility.CanPlopWithBrush(brush))
            {
                return;
            }

            if (brush == null)
            {
                if (ToolUtility.ActivePlop != null)
                {
                    PlopUtility.ErasePlop(ToolUtility.ActivePlop);
                    ToolUtility.ActivePlop = null;
                }
            }
            else
            {
                if (!this.allowOverpaint && ToolUtility.ActivePlop != null)
                {
                    // Cycle to next variation if replacing plop with same brush.
                    int nextVariation = ToolUtility.ActivePlop.VariationIndex;
                    if (brush == ToolUtility.ActivePlop.Brush)
                    {
                        ++nextVariation;
                    }

                    ToolUtility.ActivePlop = PlopUtility.CyclePlop(context.TileSystem, ToolUtility.ActivePlop, brush, ToolUtility.Rotation, nextVariation);
                }
                else
                {
                    var args = this.GetPaintingArgs(brush);
                    if (args.variation == Brush.RANDOM_VARIATION)
                    {
                        args.variation = this.PreRandomizeVariation(brush, 0);
                        this.RandomizeVariationShift();
                    }
                    int nextVariation = args.ResolveVariation(0);

                    var plop = PlopUtility.PaintPlop(context.TileSystem, this.ApplySnapping(this.localMousePoint), brush, ToolUtility.Rotation, nextVariation);
                    ToolUtility.ActivePlop        = plop;
                    ToolUtility.PreviouslyPlopped = plop;
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override void OnDrawGizmos(TileSystem system)
        {
            // We need to populate properties of `IBrushContext` for preview generation.
            var brush = (PreviousToolEvent != null && PreviousToolEvent.IsRightButtonPressed)
                ? ToolUtility.SelectedBrushSecondary
                : ToolUtility.SelectedBrush;

            if (!PlopUtility.CanPlopWithBrush(brush))
            {
                return;
            }

            // Do not draw immediate preview when mouse is positioned over a plop
            // unless overpainting is permitted.
            if (!this.allowOverpaint && ToolUtility.ActivePlop != null)
            {
                return;
            }

            // Offset preview against mouse position.
            Vector3 placementPoint = PlopUtility.PositionFromPlopPoint(system, this.ApplySnapping(this.localMousePoint));

            ImmediatePreviewUtility.Matrix = system.transform.localToWorldMatrix * MathUtility.TranslationMatrix(placementPoint);

            this._fakeContext.TileSystem = system;
            this._fakeContext.Brush      = brush;

            // Pretend to paint tile so that we can see its data beforehand!
            var previewTile = ImmediatePreviewUtility.GetPreviewTileData(this._fakeContext, brush, ToolUtility.Rotation);

            // Plop tool does not support orientations.
            previewTile.orientationMask = 0;

            var args = GetPaintingArgs(brush);

            if (args.variation == Brush.RANDOM_VARIATION)
            {
                args.variation = this.PreRandomizeVariation(brush, 0);
            }
            previewTile.variationIndex = (byte)args.ResolveVariation(0);

            brush.OnDrawImmediatePreview(this._fakeContext, previewTile, ImmediatePreviewUtility.PreviewMaterial, brush);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override void OnTool(ToolEvent e, IToolContext context)
        {
            switch (e.Type)
            {
            case EventType.MouseDown:
                // Note: Left button for next; right button for previous.
                int offset = 0;
                if (e.IsLeftButtonPressed)
                {
                    offset = -1;
                }
                else if (e.IsRightButtonPressed)
                {
                    offset = +1;
                }

                if (ToolUtility.ActivePlop != null)
                {
                    // Variation index to use next?
                    int nextVariation = ToolUtility.ActivePlop.VariationIndex + offset;
                    // Cycle through plop variations.
                    ToolUtility.ActivePlop = PlopUtility.CyclePlop(context.TileSystem, ToolUtility.ActivePlop, ToolUtility.ActivePlop.Brush, ToolUtility.ActivePlop.PaintedRotation, nextVariation);
                }
                else
                {
                    // Get tile at pointer
                    var tile = context.TileSystem.GetTile(e.MousePointerTileIndex);
                    if (tile == null || tile.brush == null)
                    {
                        return;
                    }

                    // Variation index to use next?
                    int nextVariation = tile.variationIndex + offset;
                    // Cycle through tile variations.
                    tile.brush.CycleWithSimpleRotation(context.TileSystem, e.MousePointerTileIndex, tile.PaintedRotation, nextVariation);
                }
                break;
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public override void OnSceneGUI(ToolEvent e, IToolContext context)
        {
            if (!IsEditorNearestControl)
            {
                return;
            }

            // "Hide wireframe outline"
            if (this.HideWireframeOutline)
            {
                bool willErase = (ToolUtility.SelectedBrush == null && ToolUtility.ActivePlop != null);
                bool willCycle = (!this.allowOverpaint && ToolUtility.ActivePlop != null && PlopUtility.CanPlopWithBrush(ToolUtility.SelectedBrush));
                bool disableImmediatePreview = (ToolUtility.SelectedBrush != null && ToolUtility.SelectedBrush.disableImmediatePreview);
                if (!willErase && !willCycle && !disableImmediatePreview)
                {
                    return;
                }
            }

            // Outline plop with wire cube!
            Vector3 wirePoint = (!this.allowOverpaint && ToolUtility.ActivePlop != null)
                ? ToolUtility.ActivePlop.PlopPoint
                : this.ApplySnapping(this.localMousePoint);

            Vector3 snapCellSize = context.TileSystem.CellSize;

            snapCellSize.x = this.SnapAxisX.Resolve(snapCellSize.x);
            snapCellSize.y = this.SnapAxisY.Resolve(snapCellSize.y);

            ToolHandleUtility.DrawWireBox(wirePoint, snapCellSize);
        }