Inheritance: IDisposable, ILayerContext, IPointerResponderProvider, ICommandSubscriber, ILayerListPresenter
        private void BindLevel(LevelPresenter levelPresenter)
        {
            if (_levelPresenter == levelPresenter)
            {
                return;
            }

            if (_levelPresenter != null)
            {
                _levelPresenter.LevelGeometryInvalidated -= LevelGeometryInvalidated;
                ClearLayers();
            }

            _levelPresenter = levelPresenter;

            if (_levelPresenter != null)
            {
                _levelPresenter.LevelGeometryInvalidated += LevelGeometryInvalidated;
            }

            InitializeLayerHierarchy(levelPresenter);
            InitializeLayers();
            UpdateAreaBox();

            OnCurrentLevelChanged(EventArgs.Empty);
        }
Exemple #2
0
        public void BindController(LevelPresenter controller)
        {
            if (_controller != null) {
                _controller.LevelGeometry = null;
                _controller.PointerEventResponderChanged -= PointerEventResponderChanged;
                _controller.ContextMenuActivated -= ContextMenuActivatedHandler;
            }

            _controller = controller;
            if (_controller != null) {
                _controller.LevelGeometry = _layerControl.LevelGeometry;
                _controller.PointerEventResponderChanged += PointerEventResponderChanged;
                _controller.ContextMenuActivated += ContextMenuActivatedHandler;

                _pointerController.Responder = _controller.PointerEventResponder;

                _root = new GroupLayer(controller.RootLayer);

                _layerControl.RootLayer = _root;
                _layerControl.TextureCache.SourcePool = _controller.TexturePool;

                _layerControl.ReferenceOriginX = _controller.Level.OriginX;
                _layerControl.ReferenceOriginY = _controller.Level.OriginY;
                _layerControl.ReferenceWidth = _controller.Level.Width;
                _layerControl.ReferenceHeight = _controller.Level.Height;
            }
            else {
                _root = null;
                _layerControl.RootLayer = null;
                _layerControl.TextureCache.SourcePool = null;

                _pointerController.Responder = null;
            }
        }
        private void SelectLevel(Guid levelUid)
        {
            Level          prev      = _project.Levels.Contains(levelUid) ? _project.Levels[levelUid] : null;
            LevelPresenter prevLevel = _currentLevelRef;

            if (_currentLevel == levelUid)
            {
                return;
            }

            // Unbind previously selected layer if necessary
            if (_currentLevelRef != null)
            {
                _currentLevelRef.Deactivate();
                _commandManager.RemoveCommandSubscriber(_currentLevelRef);
            }

            _currentLevel    = Guid.Empty;
            _currentLevelRef = null;

            // Bind new layer
            if (levelUid != null && _levelContentController.ContentIsValid(levelUid))
            {
                _currentLevel    = levelUid;
                _currentLevelRef = CurrentLevel;

                _commandManager.AddCommandSubscriber(_currentLevelRef);

                if (!_project.Levels.Contains(levelUid))
                {
                    throw new InvalidOperationException("Selected a LevelPresenter with no corresponding model Level!  Selected name: " + levelUid);
                }

                ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
                info.BindInfoPresenter(CurrentLevel.InfoPresenter);

                CurrentLevel.InfoPresenter.RefreshContentInfo();

                CurrentLevel.Activate();
            }
            else
            {
                ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
                info.BindInfoPresenter(null);
            }

            InvalidateLevelCommands();
            CommandManager.Invalidate(CommandKey.ViewGrid);

            OnSyncCurrentLevel(new SyncLevelEventArgs(prev, prevLevel));
            OnSyncContentView(EventArgs.Empty);
        }
        private void InitializeLayerHierarchy(LevelPresenter presenter)
        {
            _rootContentLayer = new GroupLayerPresenter();
            _rootLayer        = new GroupLayerPresenter();

            if (presenter != null)
            {
                _rootLayer.Layers.Add(_rootContentLayer);
                _rootLayer.Layers.Add(new AnnotationLayerPresenter()
                {
                    Annotations = _annotations,
                });
            }
        }
 public SyncLevelEventArgs(Level level, LevelPresenter controller)
 {
     PreviousLevel = level;
     PreviousLevelPresenter = controller;
 }
 public SyncLevelEventArgs(Level level, LevelPresenter controller)
 {
     PreviousLevel          = level;
     PreviousLevelPresenter = controller;
 }
        private void CommandAddLevel()
        {
            if (CommandCanAddLevel()) {
                NewLevel form = new NewLevel(_project);
                if (form.ShowDialog() == DialogResult.OK) {
                    LevelPresenter pres = new LevelPresenter(this, form.Level);
                    _levels[form.Level.Uid] = pres;

                    _openContent.Add(form.Level.Uid);
                    SelectLevel(form.Level.Uid);
                    Presentation.PropertyList.Provider = form.Level;

                    Modified = true;
                    RefreshEditor();
                }
            }
        }
        private void SelectLevel(Guid levelUid)
        {
            Level prev = _project.Levels.Contains(levelUid) ? _project.Levels[levelUid] : null;
            LevelPresenter prevLevel = _currentLevelRef;

            if (_currentLevel == levelUid) {
                return;
            }

            // Unbind previously selected layer if necessary
            if (_currentLevelRef != null) {
                _currentLevelRef.Deactivate();
                _commandManager.RemoveCommandSubscriber(_currentLevelRef);
            }

            _currentLevel = Guid.Empty;
            _currentLevelRef = null;

            // Bind new layer
            if (levelUid != null && _levels.ContainsKey(levelUid)) {
                _currentLevel = levelUid;
                _currentLevelRef = CurrentLevel;

                _commandManager.AddCommandSubscriber(_currentLevelRef);

                if (!_project.Levels.Contains(levelUid)) {
                    throw new InvalidOperationException("Selected a LevelPresenter with no corresponding model Level!  Selected name: " + levelUid);
                }

                ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
                info.BindInfoPresenter(CurrentLevel.InfoPresenter);

                CurrentLevel.InfoPresenter.RefreshContentInfo();

                CurrentLevel.Activate();
            }
            else {
                ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
                info.BindInfoPresenter(null);
            }

            InvalidateLevelCommands();
            CommandManager.Invalidate(CommandKey.ViewGrid);

            OnSyncCurrentLevel(new SyncLevelEventArgs(prev, prevLevel));
            OnSyncContentView(EventArgs.Empty);
        }
        public void NewDefault()
        {
            Project prevProject = _project;

            if (_project != null) {
                _project.Modified -= ProjectModifiedHandler;
            }

            _project = EmptyProject();
            _project.Modified += ProjectModifiedHandler;
            //_project.Levels.ResourceRemapped += LevelNameChangedHandler;

            _project.ObjectPoolManager.Pools.Add(new ObjectPool("Default"));

            _openContent = new List<Guid>();
            _levels = new Dictionary<Guid, LevelPresenter>();

            Level level = new Level("Level 1", 0, 0, 800, 480);
            level.Project = _project;
            level.Layers.Add(new MultiTileGridLayer("Tile Layer 1", 16, 16, 50, 30));

            Level level2 = new Level("Level 2", 0, 0, 800, 480);
            level2.Project = _project;
            level2.Layers.Add(new MultiTileGridLayer("Tile Layer 1", 32, 32, 25, 15));

            LevelPresenter pres = new LevelPresenter(this, level);
            _levels[level.Uid] = pres;

            LevelPresenter pres2 = new LevelPresenter(this, level2);
            _levels[level2.Uid] = pres2;

            _openContent.Add(level.Uid);
            _openContent.Add(level2.Uid);

            _project.Levels.Add(level);
            _project.Levels.Add(level2);

            SelectLevel(level.Uid);

            PropertyListPresenter propList = _presentation.PropertyList as PropertyListPresenter;
            propList.Provider = level;

            ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
            info.BindInfoPresenter(CurrentLevel.InfoPresenter);

            Modified = false;
            Project.ResetModified();

            OnSyncCurrentProject(new SyncProjectEventArgs(prevProject));

            RefreshEditor();
        }
        public void Open(Project project)
        {
            Project prevProject = _project;

            if (_project != null) {
                _project.Modified -= ProjectModifiedHandler;
            }

            _project = project;
            _project.Modified += ProjectModifiedHandler;
            //_project.Levels.ResourceRemapped += LevelNameChangedHandler;

            _currentLevel = Guid.Empty;

            _openContent = new List<Guid>();
            _levels = new Dictionary<Guid, LevelPresenter>();

            PropertyListPresenter propList = _presentation.PropertyList as PropertyListPresenter;

            foreach (Level level in _project.Levels) {
                LevelPresenter pres = new LevelPresenter(this, level);
                _levels[level.Uid] = pres;

                _openContent.Add(level.Uid);

                if (_currentLevel == Guid.Empty) {
                    SelectLevel(level.Uid);
                    propList.Provider = level; // Initial Property Provider
                }
            }

            if (CurrentLevel != null) {
                ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
                info.BindInfoPresenter(CurrentLevel.InfoPresenter);
            }

            Modified = false;
            Project.ResetModified();

            OnSyncCurrentProject(new SyncProjectEventArgs(prevProject));

            RefreshEditor();

            if (CurrentLevel != null) {
                //CurrentLevel.RefreshLayerList();
            }
        }
        public void New()
        {
            SelectLevel(Guid.Empty);

            Project project = EmptyProject();

            NewLevel form = new NewLevel(project);
            if (form.ShowDialog() != DialogResult.OK) {
                return;
            }

            Project prevProject = _project;

            if (_project != null) {
                _project.Modified -= ProjectModifiedHandler;
            }

            _project = project;
            _project.Modified += ProjectModifiedHandler;
            //_project.Levels.ResourceRemapped += LevelNameChangedHandler;

            _project.ObjectPoolManager.Pools.Add(new ObjectPool("Default"));

            _openContent = new List<Guid>();
            _levels = new Dictionary<Guid, LevelPresenter>();

            PropertyListPresenter propList = _presentation.PropertyList as PropertyListPresenter;

            foreach (Level level in _project.Levels) {
                LevelPresenter pres = new LevelPresenter(this, level);
                _levels[level.Uid] = pres;

                _openContent.Add(level.Uid);

                if (_currentLevel == Guid.Empty) {
                    SelectLevel(level.Uid);
                    propList.Provider = level; // Initial Property Provider
                }
            }

            //_project.ObjectPoolManager.CreatePool("Default");

            ContentInfoArbitrationPresenter info = _presentation.ContentInfo as ContentInfoArbitrationPresenter;
            info.BindInfoPresenter(CurrentLevel.InfoPresenter);

            Modified = false;
            Project.ResetModified();

            OnSyncCurrentProject(new SyncProjectEventArgs(prevProject));

            RefreshEditor();

            if (CurrentLevel != null) {
                //CurrentLevel.RefreshLayerList();
            }
        }
 public LevelInfoPresenter(LevelPresenter level)
 {
     _level = level;
     _level.Zoom.ZoomLevelChanged += ZoomStateChanged;
 }
Exemple #13
0
        private void InitializeLayerHierarchy(LevelPresenter presenter)
        {
            _rootContentLayer = new GroupLayerPresenter();
            _rootLayer = new GroupLayerPresenter();

            if (presenter != null) {
                _rootLayer.Layers.Add(_rootContentLayer);
                _rootLayer.Layers.Add(new AnnotationLayerPresenter() {
                    Annotations = _annotations,
                });
            }
        }
Exemple #14
0
        private void BindLevel(LevelPresenter levelPresenter)
        {
            if (_levelPresenter == levelPresenter)
                return;

            if (_levelPresenter != null) {
                _levelPresenter.LevelGeometryInvalidated -= LevelGeometryInvalidated;
                ClearLayers();
            }

            _levelPresenter = levelPresenter;

            if (_levelPresenter != null) {
                _levelPresenter.LevelGeometryInvalidated += LevelGeometryInvalidated;
            }

            InitializeLayerHierarchy(levelPresenter);
            InitializeLayers();
            UpdateAreaBox();

            OnCurrentLevelChanged(EventArgs.Empty);
        }
 public LevelInfoPresenter(LevelPresenter level)
 {
     _level = level;
     _level.Zoom.ZoomLevelChanged += ZoomStateChanged;
 }