示例#1
0
        //---------------------------------------------------------------------------

        public void ExecuteAction(int sourceX, int sourceY, bool isLeftMousePressed)
        {
            SelectionRect selection = TilesetManager.Get().GetSelection();

            switch (EditManager.Get().Mode)
            {
            case EEditMode.Tiles:
                if (isLeftMousePressed)
                {
                    SetTile(LayerManager.Get().Mode, sourceX, sourceY, selection.X, selection.Y, selection.Width, selection.Height);
                }
                break;

            case EEditMode.Eraser:
                if (isLeftMousePressed)
                {
                    ClearTile(LayerManager.Get().Mode, sourceX, sourceY);
                }
                break;

            case EEditMode.Fill:
                if (isLeftMousePressed)
                {
                    FillTile(LayerManager.Get().Mode, sourceX, sourceY, selection.X, selection.Y);
                }
                break;

            case EEditMode.Blocker:
                if (isLeftMousePressed)
                {
                    SetBlocker(sourceX, sourceY, !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)));
                }
                break;
            }
        }
示例#2
0
        //---------------------------------------------------------------------------

        public MapBlockerControl()
        {
            InitializeComponent();
            DataContext = this;

            EditManager.Get().ModeChanged += OnModeChanged;
        }
示例#3
0
        //---------------------------------------------------------------------------

        public void Init(int width, int height)
        {
            MapWidth = width;
            OnPropertyChanged("MapWidth");
            OnPropertyChanged("PxWidth");

            MapHeight = height;
            OnPropertyChanged("MapHeight");
            OnPropertyChanged("PxHeight");

            ResetImage();
            OnModeChanged(EditManager.Get().Mode);
        }
示例#4
0
        //---------------------------------------------------------------------------

        private void UpdateHighlight(int x, int y)
        {
            SelectionRect tilesetSelection = TilesetManager.Get().GetSelection();
            SelectionRect rect             = new SelectionRect(x, y, tilesetSelection.Width, tilesetSelection.Height).Within(new SelectionRect(0, 0, MapWidth, MapHeight));

            switch (EditManager.Get().Mode)
            {
            case EEditMode.Tiles:
                UpdateHighlight(rect.X, rect.Y, rect.Width, rect.Height);
                break;

            case EEditMode.Eraser:
                UpdateHighlight(rect.X, rect.Y, 1, 1);
                break;

            case EEditMode.Fill:
                UpdateHighlight(rect.X, rect.Y, 1, 1);
                break;
            }
        }
示例#5
0
        //---------------------------------------------------------------------------

        private void SetHighlight(Point point, bool isHovering)
        {
            if (isHovering)
            {
                int beginX = (int)(point.X / m_TileWidth);
                int beginY = (int)(point.Y / m_TileHeight);

                switch (EditManager.Get().Mode)
                {
                case EEditMode.Tiles:
                    SelectionRect selection = TilesetManager.Get().GetSelection();
                    SetHighlight(beginX, beginY, selection != null ? selection.Width : 1, selection != null ? selection.Height : 1, true);
                    break;

                case EEditMode.Blocker:
                    SetHighlight(beginX, beginY, 1, 1, true);
                    break;
                }
            }
            else
            {
                SetHighlight(0, 0, 0, 0, false);
            }
        }
示例#6
0
        //---------------------------------------------------------------------------

        public LevelCanvas()
        {
            InitializeComponent();
            DataContext = this;

            LevelManager.Get().RegisterCanvas(this);

            EditManager.Get().Register(EEditMode.Tiles, TilesEditMode);
            EditManager.Get().Register(EEditMode.Eraser, EraserEditMode);
            EditManager.Get().Register(EEditMode.Selection, SelectionEditMode);
            EditManager.Get().Register(EEditMode.Fill, FillEditMode);
            EditManager.Get().Register(EEditMode.Blocker, BlockerEditMode);

            EditManager.Get().ChangeMode(EEditMode.Tiles);

            LayerManager.Get().Register(ELayerMode.First, FirstLayer);
            LayerManager.Get().Register(ELayerMode.Second, SecondLayer);
            LayerManager.Get().Register(ELayerMode.Third, ThirdLayer);

            LayerManager.Get().ChangeMode(ELayerMode.First);

            #region Keybindings
            InputManager.Get().RegisterShortcut(Key.Z, ModifierKeys.Control, () =>
            {
                UndoManager.Get().Undo();
            });

            InputManager.Get().RegisterShortcut(Key.Y, ModifierKeys.Control, () =>
            {
                UndoManager.Get().Redo();
            });

            InputManager.Get().RegisterShortcut(Key.T, ModifierKeys.Control, () =>
            {
                EditManager.Get().ChangeMode(EEditMode.Tiles);
            });

            InputManager.Get().RegisterShortcut(Key.E, ModifierKeys.Control, () =>
            {
                EditManager.Get().ChangeMode(EEditMode.Eraser);
            });

            InputManager.Get().RegisterShortcut(Key.S, ModifierKeys.Control, () =>
            {
                EditManager.Get().ChangeMode(EEditMode.Selection);
            });

            InputManager.Get().RegisterShortcut(Key.F, ModifierKeys.Control, () =>
            {
                EditManager.Get().ChangeMode(EEditMode.Fill);
            });

            InputManager.Get().RegisterShortcut(Key.B, ModifierKeys.Control, () =>
            {
                EditManager.Get().ChangeMode(EEditMode.Blocker);
            });

            InputManager.Get().RegisterShortcut(Key.F1, ModifierKeys.None, () =>
            {
                LayerManager.Get().ChangeMode(ELayerMode.First);
            });

            InputManager.Get().RegisterShortcut(Key.F2, ModifierKeys.None, () =>
            {
                LayerManager.Get().ChangeMode(ELayerMode.Second);
            });

            InputManager.Get().RegisterShortcut(Key.F3, ModifierKeys.None, () =>
            {
                LayerManager.Get().ChangeMode(ELayerMode.Third);
            });
            #endregion
        }
示例#7
0
        //---------------------------------------------------------------------------

        public void Dispose()
        {
            EditManager.Get().ModeChanged -= OnModeChanged;
        }