Пример #1
0
    public void OnMouseMotion(Vector mousePos, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        if (UpdateMouseTilePos(mousePos))
        {
            if (selection.Width == 0 || selection.Height == 0)
            {
                return;
            }

            if (drawing &&
                ((Modifiers & ModifierType.ShiftMask) != 0 ||
                 ((LastDrawPos.X - MouseTilePos.X) % selection.Width == 0 &&
                  (LastDrawPos.Y - MouseTilePos.Y) % selection.Height == 0
                 )
                )
                )
            {
                LastDrawPos = MouseTilePos;

                EditorAction(Modifiers);                        //Call editor-specific part of code
            }
            if (selecting)
            {
                UpdateSelection();
            }
            Redraw();
        }
    }
Пример #2
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if (application.CurrentTilemap.InBounds(TilePos))
     {
         brush.ApplyToTilemap(TilePos, application.CurrentTilemap);
     }
 }
Пример #3
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if ((selection.Width == 1) && (selection.Height == 1) && application.CurrentTilemap.InBounds(TilePos))
     {
         Replace(application.CurrentTilemap[TilePos], selection[0, 0]);
     }
 }
Пример #4
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if ((selection.Width == 1) && (selection.Height == 1))
     {
         FloodFill(TilePos, selection[0, 0]);
     }
 }
Пример #5
0
 private void FloodFill(FieldPos pos, int new_tile)
 {
     if (application.CurrentTilemap[pos] != new_tile)
     {
         FloodFillAt(pos, application.CurrentTilemap[pos], new_tile);
     }
 }
Пример #6
0
    public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap, bool skipNull)
    {
        if (pos.X >= Tilemap.Width)
        {
            return;
        }
        if (pos.Y >= Tilemap.Height)
        {
            return;
        }

        uint StartX = (uint)Math.Max(0, -pos.X);
        uint StartY = (uint)Math.Max(0, -pos.Y);
        uint W      = Math.Min((uint)(Tilemap.Width - pos.X), Width);
        uint H      = Math.Min((uint)(Tilemap.Height - pos.Y), Height);

        for (uint y = StartY; y < H; ++y)
        {
            for (uint x = StartX; x < W; ++x)
            {
                if ((skipNull) && (this[x, y] == 0) && (Width > 1 || Height > 1))
                {
                    continue;
                }
                Tilemap[(uint)(pos.X + x), (uint)(pos.Y + y)] = this[x, y];
            }
        }
    }
Пример #7
0
    public void OnMouseMotion(Vector mousePos, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        if (UpdateMouseTilePos(mousePos))
        {
            if (selection.Width == 0 || selection.Height == 0)
            {
                return;
            }

            if ((state == State.DRAWING) &&
                ((Modifiers & ModifierType.ShiftMask) != 0 ||
                 ((LastDrawPos.X - MouseTilePos.X) % selection.Width == 0 &&
                  (LastDrawPos.Y - MouseTilePos.Y) % selection.Height == 0
                 )
                )
                )
            {
                PerformActionBetweenPoints(LastDrawPos, MouseTilePos, Modifiers);
            }
            if (state == State.FILLING || state == State.SELECTING)
            {
                UpdateSelection();
            }
            Redraw();
        }

        LastDrawPos = MouseTilePos;
    }
Пример #8
0
 public virtual void Initialize()
 {
     skills   = new List <SkillUse>();
     buffs    = new List <Buff>();
     col      = this.GetComponent <BoxCollider2D>();
     fieldPos = new FieldPos(0, 0);
     SetGridPos();
 }
Пример #9
0
 /// <summary>
 /// Updates the LastPreview if the current mouse position has changed.
 /// </summary>
 private void UpdatePreview()
 {
     if (LastPreviewPos != MouseTilePos)
     {
         LastPreviewIsChange = brush.FindBestPattern(MouseTilePos, application.CurrentTilemap, ref LastPreview);
         LastPreviewPos      = MouseTilePos;
     }
 }
Пример #10
0
    /// <summary>
    /// Find the best pattern to use when changing tiles around the given position to one of the stored patterns.
    /// </summary>
    /// <param name="pos">The (center) position at the <paramref name="tilemap"/> to look at.</param>
    /// <param name="tilemap">The tilemap to look at.</param>
    /// <param name="bestPattern">A tileblock that will replace the area.</param>
    /// <returns>
    /// True if <paramref name="bestPattern"/> is different from the calculated
    /// pattern in <paramref name="tilemap"/>, otherwise false.
    /// </returns>
    public bool FindBestPattern(FieldPos pos, Tilemap tilemap, ref TileBlock bestPattern)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (int)(width / 2);
        int py = pos.Y - (int)(height / 2);

        return(FindBestPattern(px, py, tilemap, ref bestPattern));
    }
Пример #11
0
    public virtual void PerformActionBetweenPoints(FieldPos p1, FieldPos p2, ModifierType Modifiers)
    {
        // from discussion of Bresenham's line algorithm on Wikipedia, "General Line Drawing Algorithm"
        int x1 = p1.X, y1 = p1.Y,
            x2 = p2.X, y2 = p2.Y,
            dX = Math.Abs(x2 - x1), dY = Math.Abs(y2 - y1),
            x = x1, y = y1,
            offsetX, offsetY;

        if (x1 > x2)
        {
            offsetX = -1;
        }
        else
        {
            offsetX = 1;
        }
        if (y1 > y2)
        {
            offsetY = -1;
        }
        else
        {
            offsetY = 1;
        }
        PerformActionOnTile(new FieldPos(x, y), Modifiers);
        if (dX > dY)
        {
            int error = dX / 2;
            while (x != x2)
            {
                error -= dY;
                if (error < 0)
                {
                    y     += offsetY;
                    error += dX;
                }
                x += offsetX;
                PerformActionOnTile(new FieldPos(x, y), Modifiers);
            }
        }
        else
        {
            int error = dY / 2;
            while (y != y2)
            {
                error -= dX;
                if (error < 0)
                {
                    x     += offsetX;
                    error += dY;
                }
                y += offsetY;
                PerformActionOnTile(new FieldPos(x, y), Modifiers);
            }
        }
    }
Пример #12
0
        public override bool Equals(object obj)
        {
            if (!(obj is FieldPos))
            {
                return(false);
            }
            FieldPos pos = (FieldPos)obj;

            return(this == pos);
        }
Пример #13
0
 public int this[FieldPos pos]
 {
     get {
         return((InBounds(pos)) ? field[pos] : 0);
     }
     set {
         if (InBounds(pos))
         {
             field[pos] = value;
         }
     }
 }
Пример #14
0
    public void OnMouseButtonPress(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        UpdateMouseTilePos(mousePos);

        if (button == 1)
        {
            if (selecting)                      //both buttons => cancel selection
            {
                selecting = false;
                selection.Resize(0, 0, 0);
                selection.FireChangedEvent();
            }
            else
            {
                // save backup of Tilemap
                tilemapBackup = application.CurrentTilemap.SaveState();

                EditorAction(Modifiers);                        //Call editor-specific part of code

                LastDrawPos = MouseTilePos;
                drawing     = true;
                Redraw();
            }
        }
        if (button == 3)
        {
            if (drawing)                //both buttons => cancel drawing
            {
                drawing = false;
                application.CurrentTilemap.RestoreState(tilemapBackup);
            }
            else
            {
                if (MouseTilePos.X < 0 || MouseTilePos.Y < 0 ||
                    MouseTilePos.X >= application.CurrentTilemap.Width ||
                    MouseTilePos.Y >= application.CurrentTilemap.Height)
                {
                    return;
                }

                SelectStartPos = MouseTilePos;
                selecting      = true;
                UpdateSelection();
                Redraw();
            }
        }
    }
Пример #15
0
    /// <summary>
    /// Smooths Tilemap by changing tiles around the given position to one of the stored patterns
    /// </summary>
    public void ApplyToTilemap(FieldPos pos, Tilemap tilemap)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (int)(width / 2);
        int py = pos.Y - (int)(height / 2);

        TileBlock bestPattern = null;

        // if we find any usable pattern, we apply it
        if (FindBestPattern(px, py, tilemap, ref bestPattern))
        {
            bestPattern.ApplyToTilemap(new FieldPos(px, py), tilemap);
        }
    }
Пример #16
0
    /// <summary>
    /// Smooths Tilemap by changing tiles around the given position to one of the stored patterns
    /// </summary>
    public void ApplyToTilemap(FieldPos pos, Tilemap tilemap)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (width / 2);
        int py = pos.Y - (height / 2);

        TileBlock bestPattern = null;

        // if we find any usable pattern, we apply it
        if (FindBestPattern(px, py, tilemap, ref bestPattern))
        {
            // Only apply to the center
            tilemap[pos] = bestPattern[width / 2, height / 2];
        }
    }
Пример #17
0
 private void FloodFillAt(FieldPos pos, int oldId, int newId)
 {
     if (!application.CurrentTilemap.InBounds(pos))
     {
         return;
     }
     if (application.CurrentTilemap[pos] != oldId)
     {
         return;
     }
     application.CurrentTilemap[pos] = newId;
     FloodFillAt(new FieldPos(pos.X, pos.Y - 1), oldId, newId);
     FloodFillAt(new FieldPos(pos.X, pos.Y + 1), oldId, newId);
     FloodFillAt(new FieldPos(pos.X - 1, pos.Y), oldId, newId);
     FloodFillAt(new FieldPos(pos.X + 1, pos.Y), oldId, newId);
 }
Пример #18
0
 private void FloodFillAt(FieldPos pos, int oldId, int newId)
 {
     if (!application.CurrentTilemap.InBounds(pos))
     {
         return;
     }
     if (application.CurrentTilemap[pos] != oldId)
     {
         return;
     }
     application.CurrentTilemap[pos] = newId;
     FloodFillAt(pos.Up, oldId, newId);
     FloodFillAt(pos.Down, oldId, newId);
     FloodFillAt(pos.Left, oldId, newId);
     FloodFillAt(pos.Right, oldId, newId);
 }
Пример #19
0
    public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap, bool skipNull)
    {
        int StartX = Math.Max(0, -pos.X);
        int StartY = Math.Max(0, -pos.Y);
        int W      = Math.Min(Tilemap.Width - pos.X, Width);
        int H      = Math.Min(Tilemap.Height - pos.Y, Height);

        for (int y = StartY; y < H; ++y)
        {
            for (int x = StartX; x < W; ++x)
            {
                if ((skipNull) && (this[x, y] == 0) && (Width > 1 || Height > 1))
                {
                    continue;
                }
                Tilemap[pos.X + x, pos.Y + y] = this[x, y];
            }
        }
    }
Пример #20
0
    protected bool UpdateMouseTilePos(Vector MousePos)
    {
        //count position relative to current tilemap
        int      XPos            = (int)(MousePos.X - application.CurrentTilemap.X);
        int      YPos            = (int)(MousePos.Y - application.CurrentTilemap.Y);
        FieldPos NewMouseTilePos = new FieldPos(XPos / Tileset.TILE_WIDTH,
                                                YPos / Tileset.TILE_HEIGHT);

        if (XPos < 0)
        {
            NewMouseTilePos.X--;                        //Fix for negative X values
        }
        if (YPos < 0)
        {
            NewMouseTilePos.Y--;                        //Fix for negative Y values
        }
        if (NewMouseTilePos != MouseTilePos)
        {
            MouseTilePos = NewMouseTilePos;
            return(true);
        }

        return(false);
    }
Пример #21
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap)
 {
     ApplyToTilemap(pos, Tilemap, true);
 }
Пример #22
0
    internal TileBlock.StateData tilemapBackup;     // saved OnMouseButtonPress

    public abstract void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers);
Пример #23
0
 public bool InBounds(FieldPos pos)
 {
     return(field.InBounds(pos));
 }
Пример #24
0
 public void SetFieldPos(FieldPos _fpos)
 {
     fieldPos = _fpos;
     SetGridPos();
 }
Пример #25
0
 public virtual void Initialize(int _fx, int _fy)
 {
     Initialize();
     fieldPos = new FieldPos(_fx, _fy);
     SetGridPos();
 }
Пример #26
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     selection.ApplyToTilemap(TilePos, application.CurrentTilemap, ((Modifiers & ModifierType.ControlMask) == 0));
 }
Пример #27
0
    public void OnMouseButtonPress(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        UpdateMouseTilePos(mousePos);
        LastDrawPos = MouseTilePos;

        if (button == 3)
        {
            if (state == State.DRAWING)                 //both buttons => cancel drawing
            {
                state = State.NONE;
                application.CurrentTilemap.RestoreState(tilemapBackup);
            }
            else
            {
                if (MouseTilePos.X < 0 || MouseTilePos.Y < 0 ||
                    MouseTilePos.X >= application.CurrentTilemap.Width ||
                    MouseTilePos.Y >= application.CurrentTilemap.Height)
                {
                    return;
                }

                SelectStartPos = MouseTilePos;
                state          = State.SELECTING;
                UpdateSelection();
            }
        }
        else if (button == 1)
        {
            if (state == State.DRAWING)                 //both buttons => cancel selection
            {
                state = State.NONE;
                selection.Resize(0, 0, 0);
                selection.FireChangedEvent();
            }
            else
            {
                // save backup of Tilemap
                tilemapBackup = application.CurrentTilemap.SaveState();

                if ((Modifiers & ModifierType.ShiftMask) != 0)
                {
                    if (MouseTilePos.X < 0 || MouseTilePos.Y < 0 ||
                        MouseTilePos.X >= application.CurrentTilemap.Width ||
                        MouseTilePos.Y >= application.CurrentTilemap.Height)
                    {
                        return;
                    }

                    SelectStartPos = MouseTilePos;
                    state          = State.FILLING;
                    UpdateSelection();
                }
                else
                {
                    PerformActionBetweenPoints(LastDrawPos, MouseTilePos, Modifiers);

                    state = State.DRAWING;
                }
            }
        }
        Redraw();
    }