Inheritance: IResource
Example #1
0
        public ImportTilePool(Project project)
        {
            InitializeComponent();

            _project = project;

            _localTexturePool = new TexturePool();
            _localManager = new TilePoolManager(_localTexturePool);

            _buttonOK.Enabled = false;

            _layerControl = new LayerGraphicsControl();
            _layerControl.Dock = DockStyle.Fill;
            _layerControl.WidthSynced = true;
            _layerControl.CanvasAlignment = CanvasAlignment.UpperLeft;
            _layerControl.TextureCache.SourcePool = _localManager.TexturePool;

            _rootLayer = new GroupLayerPresenter();
            _layerControl.RootLayer = new GroupLayer(_rootLayer);

            _previewPanel.Controls.Add(_layerControl);

            _message.Text = "";

            _buttonTransColor.Click += ButtonTransColorClickHandler;
            _checkboxTransColor.Click += CheckboxTransColorClickHandler;
            _layerControl.MouseDown += PreviewControlClickHandler;
        }
Example #2
0
        public NewLevel(Project project)
        {
            InitializeForm();

            _project = project;
            _name.Text = FindDefaultLevelName();

            _validateController.Validate();
        }
        public TileSelection GetAsTileSelection(Project project, int tileWidth, int tileHeight)
        {
            Dictionary<TileCoord, TileStack> xlat = new Dictionary<TileCoord, TileStack>();
            foreach (KeyValuePair<TileCoord, Guid[]> item in _tiles) {
                TileStack stack = new TileStack();

                foreach (Guid tileId in item.Value) {
                    TilePool pool = project.TilePoolManager.PoolFromItemKey(tileId);
                    Tile tile = pool.GetTile(tileId);
                    stack.Add(tile);
                }

                xlat.Add(item.Key, stack);
            }

            TileSelection selection = new TileSelection(tileWidth, tileHeight);
            selection.AddTiles(xlat);

            return selection;
        }
Example #4
0
        public Level (Stream stream, Project project)
            : this(Guid.NewGuid(), "Level")
        {
            Extra = new List<XmlElement>();

            XmlReaderSettings settings = new XmlReaderSettings() {
                CloseInput = true,
                IgnoreComments = true,
                IgnoreWhitespace = true,
            };

            using (XmlReader reader = XmlTextReader.Create(stream, settings)) {
                XmlSerializer serializer = new XmlSerializer(typeof(LevelX));
                LevelX proxy = serializer.Deserialize(reader) as LevelX;

                if (proxy.PropertyGroup != null)
                    _uid = proxy.PropertyGroup.LevelGuid;
                _name = new ResourceName(this, proxy.Name);

                Initialize(proxy, project);
            }
        }
Example #5
0
        private Project EmptyProject()
        {
            //Form form = new Form();
            //GraphicsDeviceService gds = GraphicsDeviceService.AddRef(form.Handle, 128, 128);

            Project project = new Project() {
                Name = "New Project"
            };
            //project.Initialize(gds.GraphicsDevice);

            return project;
        }
Example #6
0
        private void CommandOpenProject()
        {
            if (CommandCanOpenProject()) {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Open Project File";
                ofd.Filter = "Treefrog Project Files|*.tlp;*.tlpx";
                ofd.Multiselect = false;
                ofd.RestoreDirectory = false;

                if (ofd.ShowDialog() == DialogResult.OK) {
                    if (!File.Exists(ofd.FileName)) {
                        MessageBox.Show("Could not find file: " + ofd.FileName, "Open Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    try {
                        using (FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)) {
                            Project project = new Project(fs, new FileProjectResolver(ofd.FileName));
                            Open(project);

                            _projectPath = ofd.FileName;
                        }
                    }
                    catch (IOException e) {
                        MessageBox.Show("Could not open file '" + ofd.FileName + "' for reading.\n\n" + e.Message, "Open Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Example #7
0
        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();
            }
        }
Example #8
0
        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();
        }
Example #9
0
        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();
            }
        }
Example #10
0
 public LevelContent(Project project)
 {
     Project = project;
 }
        private void BindProject(Project project)
        {
            if (_project == project)
                return;

            _content.Clear();
            _openContent.Clear();

            if (_project != null) {
                _project.Levels.ResourceAdded -= LevelAddedHandler;
                _project.Levels.ResourceRemoved -= LevelRemovedHandler;
                _project.Levels.ResourceModified -= LevelModifiedHandler;
            }

            _project = project;

            if (_project != null) {
                _project.Levels.ResourceAdded += LevelAddedHandler;
                _project.Levels.ResourceRemoved += LevelRemovedHandler;
                _project.Levels.ResourceModified += LevelModifiedHandler;

                foreach (Level level in _project.Levels)
                    _content[level.Uid] = new LevelPresenter(_pm, _editor, level);
            }
        }
Example #12
0
        public static Project FromXProxy(ProjectX proxy, ProjectResolver resolver, Project project)
        {
            if (proxy == null)
                return null;

            if (proxy.PropertyGroup != null) {
                project.Uid = proxy.PropertyGroup.ProjectGuid;
                project.Name = proxy.PropertyGroup.ProjectName;
                project._defaultLibraryUid = proxy.PropertyGroup.DefaultLibrary;
                project.Extra = new List<XmlElement>(proxy.PropertyGroup.Extra ?? new XmlElement[0]);
            }

            project._texturePool = new MetaTexturePool();

            project._tilePools = new MetaTilePoolManager(project._texturePool);
            project._objectPools = new MetaObjectPoolManager(project._texturePool);
            project._tileBrushes = new MetaTileBrushManager();

            foreach (var itemGroup in proxy.ItemGroups) {
                if (itemGroup.Libraries != null) {
                    foreach (var libProxy in itemGroup.Libraries) {
                        using (Stream stream = resolver.InputStream(libProxy.Include)) {
                            project.AddLibrary(new Library(stream) {
                                FileName = libProxy.Include,
                            });
                        }
                    }
                }

                if (itemGroup.Levels != null) {
                    foreach (var level in itemGroup.Levels) {
                        using (Stream stream = resolver.InputStream(level.Include)) {
                            project.Levels.Add(new Level(stream, project) {
                                FileName = level.Include,
                            });
                        }
                    }
                }
            }

            //project._tilePools.Pools.PropertyChanged += project.TilePoolsModifiedHandler;
            //project._objectPools.Pools.PropertyChanged += project.HandleObjectPoolManagerPropertyChanged;

            return project;
        }
        private void BindProject(Project project)
        {
            if (_project == project)
                return;

            if (_project != null) {
                _project.Levels.ResourceAdded -= _levelEventBindings[EventBindings.LevelAdded];
                _project.Levels.ResourceRemoved -= _levelEventBindings[EventBindings.LevelRemoved];
                _project.Levels.ResourceModified -= _levelEventBindings[EventBindings.LevelModified];
            }

            _project = project;

            if (_project != null) {
                _project.Levels.ResourceAdded += _levelEventBindings[EventBindings.LevelAdded];
                _project.Levels.ResourceRemoved += _levelEventBindings[EventBindings.LevelRemoved];
                _project.Levels.ResourceModified += _levelEventBindings[EventBindings.LevelModified];

                BindLibraryManager(_project.LibraryManager);
                BindObjectManager(_project.ObjectPoolManager);
                BindTilePoolManager(_project.TilePoolManager);
            }
            else {
                BindLibraryManager(null);
                BindObjectManager(null);
                BindTilePoolManager(null);
            }

            OnProjectReset(EventArgs.Empty);
        }
Example #14
0
 public ObjectRegistryContent(Project project)
 {
     Project = project;
 }
        private void BindProject(Project project)
        {
            if (_project == project)
                return;

            if (_project != null) {
                _project.DefaultLibraryChanged -= DefaultLibraryChangedHandler;
            }

            _project = project;

            if (_project != null) {
                _project.DefaultLibraryChanged += DefaultLibraryChangedHandler;

                BindLibraryManager(_project.LibraryManager);
            }
            else {
                BindLibraryManager(null);
            }

            OnProjectReset(EventArgs.Empty);
        }
Example #16
0
        private void Initialize (LevelX proxy, Project project)
        {
            if (proxy.PropertyGroup != null) {
                Extra = proxy.PropertyGroup.Extra;
            }

            _project = project;
            _x = proxy.OriginX;
            _y = proxy.OriginY;
            _width = Math.Max(1, proxy.Width);
            _height = Math.Max(1, proxy.Height);
            _indexSequence = proxy.TileIndex.Sequence;

            Dictionary<int, Guid> tileIndex = new Dictionary<int, Guid>();
            foreach (var entry in proxy.TileIndex.Entries) {
                _localTileIndex.Add(entry.Id, entry.Uid);
                tileIndex.Add(entry.Id, entry.Uid);

                if (entry.Id >= _indexSequence)
                    _indexSequence = entry.Id + 1;
            }

            foreach (LevelX.LayerX layerProxy in proxy.Layers) {
                if (layerProxy is LevelX.MultiTileGridLayerX)
                    Layers.Add(new MultiTileGridLayer(layerProxy as LevelX.MultiTileGridLayerX, this, tileIndex));
                else if (layerProxy is LevelX.ObjectLayerX)
                    Layers.Add(new ObjectLayer(layerProxy as LevelX.ObjectLayerX, this));
            }

            foreach (var propertyProxy in proxy.Properties)
                CustomProperties.Add(Property.FromXmlProxy(propertyProxy));
        }
Example #17
0
 public SyncProjectEventArgs(Project project)
 {
     PreviousProject = project;
 }
        private void BindProject(Project project)
        {
            if (_project == project)
                return;

            if (_project != null) {

            }

            _project = project;

            _openContent.Clear();

            if (_project != null) {

            }

            OnProjectReset(EventArgs.Empty);
        }
Example #19
0
 public TileRegistryContent(Project project)
 {
     Project = project;
 }
Example #20
0
 public EditorPresenter(Project project)
     : this()
 {
     Open(project);
 }
Example #21
0
        public void PostDeserialize(Project project)
        {
            ObjectPool pool = project.ObjectPoolManager.PoolFromItemKey(_classId);
            if (pool == null)
                throw new Exception("Invalid ObjectClass Id");

            _class = pool.GetObject(_classId);
            if (_class == null)
                throw new Exception("Invalid ObjectClass Id");

            UpdateBounds();
        }
Example #22
0
        public static Level FromXProxy (LevelX proxy, Project project)
        {
            if (proxy == null)
                return null;

            Guid uid = proxy.PropertyGroup != null ? proxy.PropertyGroup.LevelGuid : Guid.NewGuid();

            Level level = new Level(uid, proxy.Name);
            level.Initialize(proxy, project);

            return level;
        }