Пример #1
0
        public void Undo()
        {
            if (_current > 0)
            {
                _current--;
                MapClipboard r = new MapClipboard(_parent);
                r.Width  = Actions[_current].Clipboard.Width;
                r.Height = Actions[_current].Clipboard.Height;
                r.Copy(Actions[_current].X, Actions[_current].Y);
                RedoActions.Push(new HistoryElement(r, Actions[_current].X, Actions[_current].Y));


                Actions[_current].Clipboard.Paste(Actions[_current].X, Actions[_current].Y);
            }
        }
Пример #2
0
        public void Add(int x, int y, int w, int h)
        {
            MapClipboard t = new MapClipboard(_parent);

            t.Width  = w;
            t.Height = h;
            t.Copy(x, y);
            if (_current == Actions.Count)
            {
                Actions.Add(new HistoryElement(t, x, y));
            }
            else
            {
                Actions.RemoveRange(_current, Actions.Count - _current);
                Actions.Add(new HistoryElement(t, x, y));
            }
            _current = Actions.Count;
            RedoActions.Clear();
        }
Пример #3
0
        public void Update()
        {
            NeedToRender = false;
            int dx = 0, dy = 0;

            if (Input.Up.Clicked && _selectedY - 1 >= 0)
            {
                dy--;
            }
            else if (Input.Down.Clicked && _selectedY + 1 < _parent.LevelHeight)
            {
                dy++;
            }
            else if (Input.Left.Clicked && _selectedX - 1 >= 0)
            {
                dx--;
            }
            else if (Input.Right.Clicked && _selectedX + 1 < _parent.LevelWidth)
            {
                dx++;
            }

            if (Input.Shift.Clicked)
            {
                if (_selectedW + dx <= _parent.LevelWidth)
                {
                    _selectedW += dx;
                }
                if (_selectedH + dy <= _parent.LevelHeight)
                {
                    _selectedH += dy;
                }

                if (_selectedW == 0)
                {
                    _selectedW = -1;
                }
                if (_selectedH == 0)
                {
                    _selectedH = -1;
                }

                if (_selectedX + _selectedW - _parent._tileOffsetX > _parent.DisplayedElementsX)
                {
                    _selectedW--;
                }
                if (_selectedY + _selectedH - _parent._tileOffsetY > _parent.DisplayedElementsY)
                {
                    _selectedH--;
                }

                if (_selectedX + _selectedW < _parent._tileOffsetX)
                {
                    _selectedW++;
                }
                if (_selectedY + _selectedH < _parent._tileOffsetY)
                {
                    _selectedH++;
                }

                if (_selectedW == -1)
                {
                    _selectedX++;
                    _selectedW = -2;
                }
                if (_selectedH == -1)
                {
                    _selectedY++;
                    _selectedH = -2;
                }
                NeedToRender = true;
            }
            else if (dx != 0 || dy != 0)
            {
                _clear(_parent.Screen);
                _selectedW   = 1;
                _selectedH   = 1;
                _selectedX  += dx;
                _selectedY  += dy;
                NeedToRender = true;
            }

            if (Input.Ctrl.Down && Input.C.Down && Width > 1 && Height > 1)
            {
                _clipboard.Clear();
                _clipboard.Width  = Width;
                _clipboard.Height = Height;
                _clipboard.Copy(X, Y);
            }
            else if (Input.Ctrl.Down && Input.V.Down)
            {
                if (!_clipboard.IsEmpty)
                {
                    _parent._history.Add(X, Y, _clipboard.Width, _clipboard.Height);
                    _clipboard.Paste(X, Y);
                    NeedToRender = true;
                }
            }
            else if (Input.Ctrl.Down && Input.X.Clicked)
            {
                _clipboard.Clear();
                _clipboard.Width  = Width;
                _clipboard.Height = Height;
                _clipboard.Copy(X, Y);
                Delete();
                NeedToRender = true;
            }

            if (X < _parent._tileOffsetX)
            {
                _parent._tileOffsetX--;
                _parent._background.SetOffset(_parent._tileOffsetX * GTile.WIDTH, _parent._tileOffsetY * GTile.HEIGHT);
                _parent.Render(_parent.Screen);
                return;
            }
            else if (X > _parent._tileOffsetX + _parent.DisplayWidth / GTile.WIDTH)
            {
                _parent._tileOffsetX++;
                _parent._background.SetOffset(_parent._tileOffsetX * GTile.WIDTH, _parent._tileOffsetY * GTile.HEIGHT);
                _parent.Render(_parent.Screen);
                return;
            }

            if (Y < _parent._tileOffsetY)
            {
                _parent._tileOffsetY--;
                _parent._background.SetOffset(_parent._tileOffsetX * GTile.WIDTH, _parent._tileOffsetY * GTile.HEIGHT);
                _parent.Render(_parent.Screen);
                return;
            }
            else if (Y >= _parent._tileOffsetY + _parent.DisplayHeight / GTile.HEIGHT)
            {
                _parent._tileOffsetY++;
                _parent._background.SetOffset(_parent._tileOffsetX * GTile.WIDTH, _parent._tileOffsetY * GTile.HEIGHT);
                _parent.Render(_parent.Screen);
                return;
            }

            if (Input.Delete.Clicked)
            {
                Delete();
                NeedToRender = true;
            }

            if (_parent._isOutsideBorder(X, Y))
            {
                _rectColor = Color.Silver;
            }
            else if (_parent._isBorder(X, Y))
            {
                _rectColor = Color.Red;
            }
            else
            {
                _rectColor = Color.White;
            }
        }