public new Map Show( IWin32Window window ) { base.ShowDialog(window); if (!Success) return null; var bitmaplayer = new BitmapLayer() { Canvas = new Bitmap(GridSnapSize*MapSize.Width,GridSnapSize*MapSize.Height,PixelFormat.Format32bppArgb), Visible=true }; using ( var fx = Graphics.FromImage(bitmaplayer.Canvas) ) { fx.Clear(Color.Black); for ( int y=0 ; y<MapSize.Height ; ++y ) for ( int x=0 ; x<MapSize.Width ; ++x ) { if ( (x+y)%2==0 ) fx.FillRectangle( Brushes.DarkGray, x*GridSnapSize, y*GridSnapSize, GridSnapSize, GridSnapSize ); } } var bitlayer = new BitLayer() { Data = new bool[MapSize.Width,MapSize.Height], Visible=true }; for ( int y=0 ; y<MapSize.Height ; ++y ) for ( int x=0 ; x<MapSize.Width ; ++x ) { bitlayer.Data[x,y] = ((x<10)&&(y<10)); } var map = new Map() { Layers = { bitmaplayer, bitlayer } , SnapX = GridSnapSize , SnapY = GridSnapSize , Width = MapSize.Width , Height = MapSize.Height }; return map; }
protected override void OnKeyDown( KeyEventArgs args ) { args.SuppressKeyPress = args.Handled = true; base.OnKeyDown(args); switch ( args.KeyData ) { case Keys.Control | Keys.N: var dialog = new CreateMapDialog(); var newmap = dialog.Show(this); if ( newmap!=null ) { Map = newmap; LayersSidebar.SelectedLayer = Map.Layers.FirstOrDefault(); } break; case Keys.Control | Keys.Shift | Keys.S: DoSave(null); break; case Keys.Control | Keys.S: DoSave(DocumentFileName); break; case Keys.Control | Keys.O: var opendialog = new OpenFileDialog() { DefaultExt="mp1" , Filter = "Map Files|*.mp1" , InitialDirectory = Program.State.LastUsedDirectory ?? @"I:\home\projects\" , Title = "Open map file..." }; if ( opendialog.ShowDialog(this) == DialogResult.OK ) try { var bf = new BinaryFormatter(); var ms = new MemoryStream( File.ReadAllBytes(opendialog.FileName) ); Map = (Map)bf.Deserialize(ms); DocumentFileName = opendialog.FileName; LayersSidebar.SelectedLayer = Map.Layers.FirstOrDefault(); MapOffset = new Point ( -(Map.Width *Map.SnapX*MapZoom)/2 , -(Map.Height*Map.SnapY*MapZoom)/2 ); } catch ( Exception e ) { MessageBox.Show ( this , e.Message , "Error deserializing map" , MessageBoxButtons.OK ); } break; case Keys.Control | Keys.A: var fd = new OpenFileDialog() { InitialDirectory = @"I:\home\art" }; if ( fd.ShowDialog(this) == DialogResult.OK ) try { AttemptAddAsset( (Bitmap)Bitmap.FromFile(fd.FileName) ); } catch ( Exception ) { SystemSounds.Beep.Play(); } break; case Keys.Control | Keys.V: try { var image = (Bitmap)Clipboard.GetImage(); AttemptAddAsset(image); } catch ( Exception ) { SystemSounds.Beep.Play(); } break; case Keys.Delete: if ( Map==null ) break; if ( AssetsSidebar.SelectedAsset == null ) break; var result = MessageBox.Show ( this , "Are you sure you want to remove this asset from the list?" , "Confirmation" , MessageBoxButtons.YesNo , MessageBoxIcon.Question , MessageBoxDefaultButton.Button1 ); if ( result == DialogResult.Yes ) { Map.Assets.Remove( SelectedAsset ); } break; default: args.SuppressKeyPress = args.Handled = false; break; } }