private void CommandImportObject() { if (CommandCanImportObject()) { using (ImportObject form = new ImportObject()) { foreach (ObjectClass objClass in SelectedObjectPool.Objects) { form.ReservedNames.Add(objClass.Name); } if (form.ShowDialog() == DialogResult.OK) { TextureResource resource = TextureResourceBitmapExt.CreateTextureResource(form.SourceFile); ObjectClass objClass = new ObjectClass(form.ObjectName) { MaskBounds = new Rectangle(form.MaskLeft ?? 0, form.MaskTop ?? 0, (form.MaskRight ?? 0) - (form.MaskLeft ?? 0), (form.MaskBottom ?? 0) - (form.MaskTop ?? 0)), Origin = new Point(form.OriginX ?? 0, form.OriginY ?? 0), }; SelectedObjectPool.AddObject(objClass); objClass.Image = resource; RefreshObjectPoolCollection(); OnSyncObjectPoolManager(EventArgs.Empty); } } } }
public override void RenderContent(RenderLayer renderContext, SpriteBatch spriteBatch) { Dictionary <string, Texture2D> brushClassOverlays = _form._brushClassOverlays; DynamicTileBrush brush = _form._brush; if (!brushClassOverlays.ContainsKey(brush.BrushClass.ClassName)) { System.Drawing.Bitmap overlayBitmap = null; if (brush.BrushClass.ClassName == "Basic") { overlayBitmap = Properties.Resources.DynBrushBasic; } else if (brush.BrushClass.ClassName == "Extended") { overlayBitmap = Properties.Resources.DynBrushExtended; } else { return; } TextureResource overlayResource = TextureResourceBitmapExt.CreateTextureResource(overlayBitmap); brushClassOverlays.Add(brush.BrushClass.ClassName, overlayResource.CreateTexture(spriteBatch.GraphicsDevice)); } Texture2D overlay = brushClassOverlays[brush.BrushClass.ClassName]; int width = (int)(overlay.Width * renderContext.LevelGeometry.ZoomFactor * (brush.TileWidth / 16.0)); int height = (int)(overlay.Height * renderContext.LevelGeometry.ZoomFactor * (brush.TileHeight / 16.0)); Microsoft.Xna.Framework.Rectangle dstRect = new Microsoft.Xna.Framework.Rectangle(0, 0, width, height); spriteBatch.Draw(overlay, dstRect, new Microsoft.Xna.Framework.Color(1f, 1f, 1f, .5f)); }
private TilePool LoadFile() { if (_fileStream == null) { return(null); } if (_fileStream.Position != 0) { _fileStream.Position = 0; } _localManager.Reset(); TextureResource resource = TextureResourceBitmapExt.CreateTextureResource(_fileStream); TilePool.TileImportOptions options = new TilePool.TileImportOptions() { TileHeight = (int)_numTileHeight.Value, TileWidth = (int)_numTileWidth.Value, SpaceX = (int)_numXSpacing.Value, SpaceY = (int)_numYSpacing.Value, MarginX = (int)_numXMargin.Value, MarginY = (int)_numYMargin.Value, ImportPolicty = TileImportPolicy.SetUnique, }; _previewPool = _localManager.ImportPool(_textName.Text, resource, options); _originalResource = _previewPool.TileSource.Crop(_previewPool.TileSource.Bounds); if (_useTransColor) { SetTransparentColor(); } // Update preview window if (_previewLayer != null) { _previewLayer.Dispose(); } Model.TileSetLayer layer = new Model.TileSetLayer(_previewPool.Name, _previewPool); _previewLayer = new TileSetLayerPresenter(layer) { LevelGeometry = _layerControl.LevelGeometry, }; _rootLayer.Layers.Clear(); _rootLayer.Layers.Add(_previewLayer); // Update stats _countTilesHigh.Text = ((_height + (int)_numYSpacing.Value) / ((int)_numTileHeight.Value + (int)_numYSpacing.Value + (int)_numYMargin.Value)).ToString(); _countTilesWide.Text = ((_width + (int)_numXSpacing.Value) / ((int)_numTileWidth.Value + (int)_numXSpacing.Value + (int)_numXMargin.Value)).ToString(); _countUniqueTiles.Text = _previewPool.Count.ToString(); return(_previewPool); }
private void FileInfo() { TextureResource resource = TextureResourceBitmapExt.CreateTextureResource(_fileStream); _width = resource.Width; _height = resource.Height; _fileStream.Position = 0; }
public override TileRegistryContent Process(TileRegistryContent input, ContentProcessorContext context) { if (!Directory.Exists("build")) { Directory.CreateDirectory("build"); } input.TilePool = input.Project.TilePoolManager.Pools[TilesetId]; input.Id = TilesetId; string path = "build\\" + ProjectKey + "_tileset_tex_" + TilesetId + ".png"; Bitmap image = TextureResourceBitmapExt.CreateBitmap(input.TilePool.TileSource); image.Save(path, ImageFormat.Png); // the asset name is the entire path, minus extension, after the content directory string asset = string.Empty; if (path.StartsWith(Directory.GetCurrentDirectory())) { asset = path.Remove(path.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1); } else { asset = Path.GetFileNameWithoutExtension(path); } // build the asset as an external reference OpaqueDataDictionary data = new OpaqueDataDictionary(); data.Add("GenerateMipmaps", false); data.Add("ResizeToPowerOfTwo", false); data.Add("TextureFormat", TextureProcessorOutputFormat.Color); context.BuildAsset <TextureContent, TextureContent>( new ExternalReference <TextureContent>(path), "TextureProcessor", data, "TextureImporter", asset); input.TextureAsset = asset; return(input); }
private void LoadObjectPreview(String path) { try { _sourceImage = TextureResourceBitmapExt.CreateTextureResource(path); _originX = 0; _originY = 0; _maskLeft = 0; _maskTop = 0; _maskRight = _sourceImage.Width; _maskBottom = _sourceImage.Height; _sourceFileValid = true; UpdateMaskPropertyFields(); } catch (Exception) { _sourceFileValid = false; } }
public void CommandImportOver(object param) { if (!TilePoolExists(param)) { return; } Guid uid = (Guid)param; TilePool tilePool = Editor.Project.TilePoolManager.Pools[uid]; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Title = "Import Raw Tileset"; ofd.Filter = "Images Files|*.bmp;*.gif;*.png|All Files|*"; ofd.Multiselect = false; ofd.RestoreDirectory = false; if (ofd.ShowDialog() == DialogResult.OK) { try { TextureResource import = TextureResourceBitmapExt.CreateTextureResource(ofd.FileName); TextureResource original = tilePool.TileSource; if (original.Width != import.Width || original.Height != import.Height) { MessageBox.Show("Imported tileset dimensions are incompatible with the selected Tile Pool.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } tilePool.Tiles.ReplaceTexture(import); } catch { MessageBox.Show("Could not read selected image file.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } }