示例#1
0
    const int WINDOW_HEIGHT = 280;  // ウィンドウの高さ
    //-----------------------------------------------------
    //  PaintWindow
    //-----------------------------------------------------
    void PaintingWindow(int id)
    {
        // paint mode
        paintMode      = (PaintModes)GUI.Toolbar(new Rect(WINDOW_LEFT, WINDOW_UP, WINDOW_WIDTH, 30), (int)paintMode, new[] { "Brush", "Fill" });
        brush.Rotation = GUI.Toolbar(new Rect(WINDOW_LEFT + 50, WINDOW_UP + 40, 130, 20), brush.Rotation, new[] { "0", "90", "180", "270" });
        brush.FlipX    = GUI.Toggle(new Rect(WINDOW_LEFT + 50, WINDOW_UP + 65, 90, 20), brush.FlipX, "FLIP X");
        brush.FlipY    = GUI.Toggle(new Rect(WINDOW_LEFT + 115, WINDOW_UP + 65, 90, 20), brush.FlipY, "FLIP Y");

        // empty tile
        if (DrawPaletteTile(new Rect(WINDOW_LEFT, WINDOW_UP + 40, 40, 40), null, brush.Hidden))
        {
            brush.Hidden = true;
        }

        // tiles
        if (tiler.MeshTexture == null)
        {
            GUI.Label(new Rect(WINDOW_LEFT, WINDOW_UP + 95, WINDOW_WIDTH, 80), "Requires a Material\nwith a Texture");
        }
        else
        {
            SelectPanel(0, 95, tiler.MeshTexture);
        }

        // repaint
        var e = Event.current;

        if (e.type == EventType.MouseMove || e.type == EventType.MouseDown)
        {
            Repaint();
        }
    }
示例#2
0
        // this should probably be in its own file somehow? not sure
        void PaintingWindow(int id)
        {
            const int left  = 10;
            const int width = 180;

            // paint mode
            paintMode = (PaintModes)GUI.Toolbar(new Rect(left, 25, width, 30), (int)paintMode,
                                                new[] { "Brush", "Fill" });
            brush.Rotation = GUI.Toolbar(new Rect(left + 50, 65, 130, 20), brush.Rotation,
                                         new[] { "0", "90", "180", "270" });
            brush.FlipX = GUI.Toggle(new Rect(left + 50, 90, 90, 20), brush.FlipX, "FLIP X");
            brush.FlipY = GUI.Toggle(new Rect(left + 115, 90, 90, 20), brush.FlipY, "FLIP Y");

            // empty tile
            if (DrawPaletteTile(new Rect(left, 65, 40, 40), null, brush.Hidden))
            {
                brush.Hidden = true;
            }

            // tiles
            if (tiler.Texture == null)
            {
                GUI.Label(new Rect(left, 120, width, 80), "Requires a Material\nwith a Texture");
            }
            else
            {
                var columns    = tiler.Texture.width / tiler.TileWidth;
                var rows       = tiler.Texture.height / tiler.TileHeight;
                var tileWidth  = width / columns;
                var tileHeight = (tiler.TileHeight / (float)tiler.TileWidth) * tileWidth;

                for (int x = 0; x < columns; x++)
                {
                    for (int y = 0; y < rows; y++)
                    {
                        var rect = new Rect(left + x * tileWidth, 120 + y * tileHeight, tileWidth, tileHeight);
                        var tile = new Vector2Int(x, rows - 1 - y);
                        if (DrawPaletteTile(rect, tile, brush.Tile == tile && !brush.Hidden))
                        {
                            brush.Tile   = tile;
                            brush.Hidden = false;
                        }
                    }
                }
            }

            // repaint
            var e = Event.current;

            if (e.type == EventType.MouseMove || e.type == EventType.MouseDown)
            {
                Repaint();
            }
        }
示例#3
0
    public void Dig(DestinationMarkerEventArgs args)
    {
        // TODO: improve by using raycast to dig marker height
        Vector3 target = new Vector3(args.destinationPosition.x, DigMarkerWorldPositionY, args.destinationPosition.z);

        // Debug.LogWarning("START DIG");

        IsDigging = true;

        LevelTile tile = LevelHelpers.GetTileAtWorldPos(LevelController.Instance.Model, target);

        paintMode = tile.MarkedForDigging ? PaintModes.ERASE : PaintModes.PAINT;

        if (TileIsDiggable(tile))
        {
            PaintDig(args);
        }
    }
示例#4
0
 private void EraseBtn_Click(object sender, RoutedEventArgs e)
 {
     DrawBtn.IsChecked  = false;
     EraseBtn.IsChecked = true;
     PaintMode          = PaintModes.Erase;
 }
示例#5
0
 protected abstract Task <PaintContext> PaintInternal(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth);
示例#6
0
        /// <summary>
        /// Draws the XML element on the screen
        /// </summary>
        public async Task <PaintContext> Paint(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth)
        {
            if (this.disposed)
            {
                return(paintContext);
            }
            if (this.XmlNode == null)
            {
                return(paintContext);
            }
            if (this.xmlEditor == null)
            {
                return(paintContext);
            }

            paintContext = await PaintInternal(paintContext, cursorBlinkOn, cursor, gfx, paintMode, depth);

            if (this.cursorPaintPos != null && cursorBlinkOn)
            {
                this.PaintCursor(gfx);
            }
            return(paintContext);
        }
示例#7
0
        protected override async Task <PaintContext> PaintInternal(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth)
        {
            paintContext.PaintPosX += 3;

            var actualText      = ToolboxXml.TextFromNodeCleaned(XmlNode);
            var selection       = this.CalculateStartAndEndOfSelection(actualText, cursor);
            var actualPaintData = LastPaintingDataText.CalculateActualPaintData(paintContext, cursorBlinkOn, this.XmlNode, actualText, this.Config.FontTextNode.Height, cursor, selection.Start, selection.Length);

            var alreadyUnpainted = false;

            switch (paintMode)
            {
            case PaintModes.ForcePaintNoUnPaintNeeded:
                alreadyUnpainted   = true;
                this.lastPaintData = null;
                break;

            case PaintModes.ForcePaintAndUnpaintBefore:
                alreadyUnpainted   = true;
                this.lastPaintData = null;
                this.UnPaint(gfx);
                break;

            case PaintModes.OnlyPaintWhenChanged:
                if (!actualPaintData.Equals(lastPaintData))
                {
                    this.lastPaintData = null;
                }
                break;
            }

            if (this.lastPaintData != null && this.lastPaintContextResult != null)
            {
                return(lastPaintContextResult.Clone());
            }

            this.lastPaintData  = actualPaintData;
            this.cursorPaintPos = null;

            if (lastFontHeight != this.Config.FontTextNode.Height)
            {
                lastFontHeight          = this.Config.FontTextNode.Height;
                lastCalculatedFontWidth = await this.xmlEditor.NativePlatform.Gfx.MeasureDisplayStringWidthAsync("W", this.Config.FontTextNode);
            }

            paintContext.HeightActualRow = Math.Max(paintContext.HeightActualRow, this.Config.MinLineHeight);

            int marginY = (paintContext.HeightActualRow - this.Config.FontTextNode.Height) / 2;

            const int charMarginRight = 2;

            var textPartsRaw = TextSplitHelper.SplitText(
                text: actualText,
                invertStart: selection.Start,
                invertLength: selection.Length,
                maxLength: (int)((paintContext.LimitRight - paintContext.LimitLeft) / lastCalculatedFontWidth) - charMarginRight,
                maxLengthFirstLine: (int)((paintContext.LimitRight - paintContext.PaintPosX) / lastCalculatedFontWidth) - charMarginRight)
                               .ToArray();

            var newTextParts = this.GetTextLinesFromTextParts(textPartsRaw, paintContext, cursorBlinkOn, cursor, lastCalculatedFontWidth).ToArray();

            // Now draw the content, if necessary wrap to several text parts and lines
            for (int i = 0; i < newTextParts.Length; i++)
            {
                var newPart = newTextParts[i];
                var oldPart = (this.textParts != null && i < this.textParts.Length) ? this.textParts[i] : null;
                if (alreadyUnpainted == false && newPart.Equals(oldPart))
                {
                    // no need to paint the text part again
                }
                else
                {
                    // draw the inverted background
                    if (!alreadyUnpainted && oldPart != null)
                    {
                        gfx.UnPaintRectangle(oldPart.Rectangle);
                    }

                    if (newPart.Inverted || this.colorBackground != this.Config.ColorBackground)
                    {
                        gfx.AddJob(new JobDrawRectangle
                        {
                            Batchable = true,
                            Layer     = GfxJob.Layers.TagBackground,
                            Rectangle = newPart.Rectangle,
                            FillColor = newPart.Inverted ? this.colorBackground.InvertedColor : this.colorBackground,
                        });
                    }

                    // draw the text
                    gfx.AddJob(new JobDrawString
                    {
                        Batchable = false,
                        Layer     = GfxJob.Layers.Text,
                        Text      = newPart.Text,
                        Color     = newPart.Inverted ? this.colorText.InvertedColor : this.colorText,
                        X         = newPart.Rectangle.X,
                        Y         = newPart.Rectangle.Y + marginY,
                        Font      = Config.FontTextNode
                    });;
                }
                paintContext.PaintPosY = newPart.Rectangle.Y;
                paintContext.PaintPosX = newPart.Rectangle.X + newPart.Rectangle.Width;
                paintContext.FoundMaxX = Math.Max(paintContext.FoundMaxX, paintContext.PaintPosX);
            }

            if (this.textParts != null) // unpaint old text parts out of new parts range
            {
                for (int i = newTextParts.Length; i < this.textParts.Length; i++)
                {
                    gfx.UnPaintRectangle(this.textParts[i].Rectangle);
                }
            }

            this.textParts = newTextParts;

            paintContext.PaintPosX += 2;

            this.lastPaintContextResult = paintContext.Clone();
            return(paintContext.Clone());
        }
示例#8
0
        protected override async Task <PaintContext> PaintInternal(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth)
        {
            this.nodeDimensions.Update();
            var isSelected = cursor?.StartPos != null && cursor?.EndPos != null && XmlCursorSelectionHelper.IsThisNodeInsideSelection(cursor, this.XmlNode);

            this.CreateChildElementsIfNeeded(gfx);

            Point newCursorPaintPos = null;

            bool alreadyUnpainted = false;

            switch (paintMode)
            {
            case PaintModes.ForcePaintNoUnPaintNeeded:
                alreadyUnpainted = true;
                break;

            case PaintModes.ForcePaintAndUnpaintBefore:
                this.UnPaint(gfx);
                alreadyUnpainted = true;
                break;

            case PaintModes.OnlyPaintWhenChanged:
                break;
            }

            // If the cursor is inside the empty node, then draw the cursor there
            if (cursor.StartPos.ActualNode == this.XmlNode)
            {
                if (cursor.StartPos.PosOnNode == XmlCursorPositions.CursorInFrontOfNode)
                {
                    // remember position for cursor line
                    newCursorPaintPos = new Point(paintContext.PaintPosX, paintContext.PaintPosY);
                }
            }

            var cursorIsOnThisNode = cursor.StartPos.ActualNode == this.XmlNode || cursor.EndPos.ActualNode == this.XmlNode;

            paintContext = await this.startTag.Paint(paintContext, cursorIsOnThisNode, cursorBlinkOn, alreadyUnpainted, isSelected, gfx);

            // If the cursor is inside the empty node, then draw the cursor there
            if (cursor.StartPos.ActualNode == this.XmlNode)
            {
                if (cursor.StartPos.PosOnNode == XmlCursorPositions.CursorInsideTheEmptyNode)
                {
                    // set position for cursor line
                    newCursorPaintPos = new Point(paintContext.PaintPosX - 1, paintContext.PaintPosY);
                }
            }

            paintContext = await this.PaintSubNodes(paintContext, cursorBlinkOn, cursor, gfx, paintMode, depth);

            if (this.endTag != null)
            {
                paintContext = await this.endTag.Paint(paintContext, cursorIsOnThisNode, cursorBlinkOn, alreadyUnpainted, isSelected, gfx);
            }

            // If the cursor is behind the node, then also draw the cursor there
            if (cursor.StartPos.ActualNode == this.XmlNode)
            {
                if (cursor.StartPos.PosOnNode == XmlCursorPositions.CursorBehindTheNode)
                {
                    newCursorPaintPos = new Point(paintContext.PaintPosX - 1, paintContext.PaintPosY);
                }
            }

            this.cursorPaintPos = newCursorPaintPos;
            return(paintContext.Clone());
        }
示例#9
0
        protected async Task <PaintContext> PaintSubNodes(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth)
        {
            if (this.XmlNode == null)
            {
                throw new ApplicationException("PaintSubNodes:xmlNode is null");
            }

            var childPaintContext = paintContext.Clone();

            childPaintContext.LimitLeft = paintContext.LimitLeft + this.Config.ChildIndentX;

            for (int childLauf = 0; childLauf < this.XmlNode.ChildNodes.Count; childLauf++)
            {
                // At this point, the ChildControl object should contain the corresponding instance of the XMLElement control for the current XMLChildNode
                var childElement = (XmlElement)childElements[childLauf];
                var displayType  = this.XmlRules.DisplayType(childElement.XmlNode);
                switch (displayType)
                {
                case DisplayTypes.OwnRow:

                    // This child element starts a new row and is then drawn in this row

                    // start new row
                    childPaintContext.LimitLeft       = paintContext.LimitLeft + this.Config.ChildIndentX;
                    childPaintContext.PaintPosX       = childPaintContext.LimitLeft;
                    childPaintContext.PaintPosY      += this.Config.SpaceYBetweenLines + paintContext.HeightActualRow; // line break
                    childPaintContext.HeightActualRow = 0;                                                             // no element in this line yet, therefore Height 0
                                                                                                                       // Set X-cursor to the start of the new line
                                                                                                                       // line down and then right into the ChildElement
                                                                                                                       // Line down
                    bool paintLines = false;
                    if (paintLines)
                    {
                        gfx.AddJob(new JobDrawLine
                        {
                            Layer     = GfxJob.Layers.TagBorder,
                            Batchable = true,
                            Color     = Color.LightGray,
                            X1        = paintContext.LimitLeft,
                            Y1        = paintContext.PaintPosY + this.Config.MinLineHeight / 2,
                            X2        = paintContext.LimitLeft,
                            Y2        = childPaintContext.PaintPosY + this.Config.MinLineHeight / 2
                        });

                        // Line to the right with arrow on ChildElement
                        gfx.AddJob(new JobDrawLine
                        {
                            Layer     = GfxJob.Layers.TagBorder,
                            Batchable = true,
                            Color     = Color.LightGray,
                            X1        = paintContext.LimitLeft,
                            Y1        = childPaintContext.PaintPosY + this.Config.MinLineHeight / 2,
                            X2        = childPaintContext.LimitLeft,
                            Y2        = childPaintContext.PaintPosY + this.Config.MinLineHeight / 2
                        });
                    }

                    childPaintContext = await childElement.Paint(childPaintContext, cursorBlinkOn, cursor, gfx, paintMode, depth + 1);

                    break;

                case DisplayTypes.FloatingElement:
                    // This child is a floating element; it inserts itself into the same line as the previous element and does not start a new line unless the current line is already too long
                    if (childPaintContext.PaintPosX > paintContext.LimitRight)     //  If the row is already too long
                    {
                        // to next row
                        paintContext.PaintPosY      += paintContext.HeightActualRow + this.Config.SpaceYBetweenLines;
                        paintContext.HeightActualRow = 0;
                        paintContext.PaintPosX       = paintContext.RowStartX;
                    }
                    else     // fits into this line
                    {
                        // set the child to the right of it
                    }
                    childPaintContext = await childElement.Paint(childPaintContext, cursorBlinkOn, cursor, gfx, paintMode, depth + 1);

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(displayType) + ":" + displayType.ToString());
                }
                paintContext.FoundMaxX = childPaintContext.FoundMaxX;
                paintContext.PaintPosX = childPaintContext.PaintPosX;
                paintContext.PaintPosY = childPaintContext.PaintPosY;
            }

            // If we have more ChildControls than XMLChildNodes, then delete them at the end of the ChildControl list
            while (this.XmlNode.ChildNodes.Count < childElements.Count)
            {
                var deleteChildElement = childElements[childElements.Count - 1];
                deleteChildElement.UnPaint(gfx);
                childElements.Remove(childElements[childElements.Count - 1]);
                deleteChildElement.Dispose();
            }
            return(paintContext);
        }