// Comparison method used to customize sorting public static object Compare(string propertyName, object a, object b) { WorldListEntry entry1 = (WorldListEntry)a; WorldListEntry entry2 = (WorldListEntry)b; switch (propertyName) { case "Description": if (entry1.MapHeader == null && entry2.MapHeader == null) { return(0); } if (entry1.MapHeader == null) { return(-1); } if (entry2.MapHeader == null) { return(1); } int volumeDifference = entry1.MapHeader.Volume - entry2.MapHeader.Volume; return(Math.Min(1, Math.Max(-1, volumeDifference))); case "Name": return(StringComparer.OrdinalIgnoreCase.Compare(entry1.name, entry2.name)); default: throw new NotImplementedException(); } }
public AddWorldPopup(WorldListEntry world) { InitializeComponent(); fileBrowser.Filter = MapLoadFilter; cBackup.Items.AddRange(WorldListEntry.BackupEnumNames); bwLoader.DoWork += AsyncLoad; bwLoader.RunWorkerCompleted += AsyncLoadCompleted; bwGenerator.WorkerReportsProgress = true; bwGenerator.DoWork += AsyncGen; bwGenerator.ProgressChanged += AsyncGenProgress; bwGenerator.RunWorkerCompleted += AsyncGenCompleted; bwRenderer.WorkerReportsProgress = true; bwRenderer.DoWork += AsyncDraw; bwRenderer.ProgressChanged += AsyncDrawProgress; bwRenderer.RunWorkerCompleted += AsyncDrawCompleted; renderer = new IsoCat(); // event routed through BackgroundWorker to avoid cross-thread invocation issues renderer.ProgressChanged += (progressSender, progressArgs) => bwRenderer.ReportProgress(progressArgs.ProgressPercentage, progressArgs.UserState); nMapWidth.Validating += MapDimensionValidating; nMapHeight.Validating += MapDimensionValidating; nMapLength.Validating += MapDimensionValidating; cAccess.Items.Add("(everyone)"); cBuild.Items.Add("(everyone)"); foreach (Rank rank in RankManager.Ranks) { cAccess.Items.Add(MainForm.ToComboBoxOption(rank)); cBuild.Items.Add(MainForm.ToComboBoxOption(rank)); } progressBar.Visible = false; tStatus1.Text = ""; tStatus2.Text = ""; World = world; cPreviewMode.SelectedIndex = 0; savePreviewDialog.Filter = "PNG Image|*.png|TIFF Image|*.tif;*.tiff|Bitmap Image|*.bmp|JPEG Image|*.jpg;*.jpeg"; savePreviewDialog.Title = "Saving preview image..."; cGenerator.Items.AddRange(MapGenUtil.GeneratorList.Select(gen => gen.Name).ToArray()); cGenerator.SelectedIndex = 0; tsbLoadPreset.DropDownItemClicked += tsbLoadPreset_DropDownItemClicked; tsbCopyGenSettings.DropDownItemClicked += tsbImportSettings_DropDownItemClicked; Shown += LoadMap; }
public AddWorldPopup( WorldListEntry world ) { InitializeComponent(); fileBrowser.Filter = MapLoadFilter; cBackup.Items.AddRange( WorldListEntry.BackupEnumNames ); bwLoader.DoWork += AsyncLoad; bwLoader.RunWorkerCompleted += AsyncLoadCompleted; bwGenerator.WorkerReportsProgress = true; bwGenerator.DoWork += AsyncGen; bwGenerator.ProgressChanged += AsyncGenProgress; bwGenerator.RunWorkerCompleted += AsyncGenCompleted; bwRenderer.WorkerReportsProgress = true; bwRenderer.DoWork += AsyncDraw; bwRenderer.ProgressChanged += AsyncDrawProgress; bwRenderer.RunWorkerCompleted += AsyncDrawCompleted; renderer = new IsoCat(); // event routed through BackgroundWorker to avoid cross-thread invocation issues renderer.ProgressChanged += ( progressSender, progressArgs ) => bwRenderer.ReportProgress( progressArgs.ProgressPercentage, progressArgs.UserState ); nMapWidth.Validating += MapDimensionValidating; nMapHeight.Validating += MapDimensionValidating; nMapLength.Validating += MapDimensionValidating; cAccess.Items.Add( "(everyone)" ); cBuild.Items.Add( "(everyone)" ); foreach( Rank rank in RankManager.Ranks ) { cAccess.Items.Add( MainForm.ToComboBoxOption( rank ) ); cBuild.Items.Add( MainForm.ToComboBoxOption( rank ) ); } progressBar.Visible = false; tStatus1.Text = ""; tStatus2.Text = ""; World = world; cPreviewMode.SelectedIndex = 0; savePreviewDialog.Filter = "PNG Image|*.png|TIFF Image|*.tif;*.tiff|Bitmap Image|*.bmp|JPEG Image|*.jpg;*.jpeg"; savePreviewDialog.Title = "Saving preview image..."; cGenerator.Items.AddRange( MapGenUtil.GeneratorList.Select( gen => gen.Name ).ToArray() ); cGenerator.SelectedIndex = 0; tsbLoadPreset.DropDownItemClicked += tsbLoadPreset_DropDownItemClicked; tsbCopyGenSettings.DropDownItemClicked += tsbImportSettings_DropDownItemClicked; Shown += LoadMap; }
public AddWorldPopup(WorldListEntry world) { InitializeComponent(); renderer = new IsoCat(); fileBrowser.Filter = MapLoadFilter; cBackup.Items.AddRange(WorldListEntry.BackupEnumNames); cTemplates.Items.AddRange(Enum.GetNames(typeof(MapGenTemplate))); cTheme.Items.AddRange(Enum.GetNames(typeof(MapGenTheme))); bwLoader.DoWork += AsyncLoad; bwLoader.RunWorkerCompleted += AsyncLoadCompleted; bwGenerator.DoWork += AsyncGen; bwGenerator.WorkerReportsProgress = true; bwGenerator.ProgressChanged += AsyncGenProgress; bwGenerator.RunWorkerCompleted += AsyncGenCompleted; bwRenderer.WorkerReportsProgress = true; bwRenderer.WorkerSupportsCancellation = true; bwRenderer.DoWork += AsyncDraw; bwRenderer.ProgressChanged += AsyncDrawProgress; bwRenderer.RunWorkerCompleted += AsyncDrawCompleted; nMapWidth.Validating += MapDimensionValidating; nMapLength.Validating += MapDimensionValidating; nMapHeight.Validating += MapDimensionValidating; cAccess.Items.Add("(everyone)"); cBuild.Items.Add("(everyone)"); foreach (Rank rank in RankManager.Ranks) { cAccess.Items.Add(MainForm.ToComboBoxOption(rank)); cBuild.Items.Add(MainForm.ToComboBoxOption(rank)); } tStatus1.Text = ""; tStatus2.Text = ""; World = world; savePreviewDialog.Filter = "PNG Image|*.png|TIFF Image|*.tif;*.tiff|Bitmap Image|*.bmp|JPEG Image|*.jpg;*.jpeg"; savePreviewDialog.Title = "Saving preview image..."; browseTemplateDialog.Filter = "MapGenerator Template|*.ftpl"; browseTemplateDialog.Title = "Opening a MapGenerator template..."; saveTemplateDialog.Filter = browseTemplateDialog.Filter; saveTemplateDialog.Title = "Saving a MapGenerator template..."; Shown += LoadMap; }
public AddWorldPopup( WorldListEntry world ) { InitializeComponent(); renderer = new IsoCat(); fileBrowser.Filter = MapLoadFilter; cBackup.Items.AddRange( WorldListEntry.BackupEnumNames ); cTemplates.Items.AddRange( Enum.GetNames( typeof( MapGenTemplate ) ) ); cTheme.Items.AddRange( Enum.GetNames( typeof( MapGenTheme ) ) ); bwLoader.DoWork += AsyncLoad; bwLoader.RunWorkerCompleted += AsyncLoadCompleted; bwGenerator.DoWork += AsyncGen; bwGenerator.WorkerReportsProgress = true; bwGenerator.ProgressChanged += AsyncGenProgress; bwGenerator.RunWorkerCompleted += AsyncGenCompleted; bwRenderer.WorkerReportsProgress = true; bwRenderer.WorkerSupportsCancellation = true; bwRenderer.DoWork += AsyncDraw; bwRenderer.ProgressChanged += AsyncDrawProgress; bwRenderer.RunWorkerCompleted += AsyncDrawCompleted; nMapWidth.Validating += MapDimensionValidating; nMapLength.Validating += MapDimensionValidating; nMapHeight.Validating += MapDimensionValidating; cAccess.Items.Add( "(everyone)" ); cBuild.Items.Add( "(everyone)" ); foreach( Rank rank in RankManager.Ranks ) { cAccess.Items.Add( MainForm.ToComboBoxOption( rank ) ); cBuild.Items.Add( MainForm.ToComboBoxOption( rank ) ); } tStatus1.Text = ""; tStatus2.Text = ""; World = world; savePreviewDialog.Filter = "PNG Image|*.png|TIFF Image|*.tif;*.tiff|Bitmap Image|*.bmp|JPEG Image|*.jpg;*.jpeg"; savePreviewDialog.Title = "Saving preview image..."; browseTemplateDialog.Filter = "MapGenerator Template|*.ftpl"; browseTemplateDialog.Title = "Opening a MapGenerator template..."; saveTemplateDialog.Filter = browseTemplateDialog.Filter; saveTemplateDialog.Title = "Saving a MapGenerator template..."; Shown += LoadMap; }
void tsbImportSettings_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { WorldListEntry entry = e.ClickedItem.Tag as WorldListEntry; if (entry == null) { BeginInvoke((Action)ImportSettingsFromFile); // allow menu to close return; } Map ourMap; if (MapUtility.TryLoadHeader(entry.FullFileName, false, out ourMap)) { MapGenParamsFromMap(entry.FileName, ourMap); } else { MessageBox.Show("Could not load map file!"); } }
public WorldListEntry([NotNull] WorldListEntry original) { if (original == null) { throw new ArgumentNullException("original"); } name = original.Name; Hidden = original.Hidden; Backup = original.Backup; BlockDBEnabled = original.BlockDBEnabled; blockDBIsPreloaded = original.blockDBIsPreloaded; blockDBLimit = original.blockDBLimit; blockDBTimeLimit = original.blockDBTimeLimit; accessSecurity = new SecurityController(original.accessSecurity); buildSecurity = new SecurityController(original.buildSecurity); LoadedBy = original.LoadedBy; LoadedOn = original.LoadedOn; MapChangedBy = original.MapChangedBy; MapChangedOn = original.MapChangedOn; environmentEl = original.environmentEl; }
void LoadMap( object sender, EventArgs args ) { // get the list of existing worlds otherWorlds = MainForm.Worlds.Where( w => w != World ).ToArray(); // Fill in the "Copy existing world" combobox foreach( WorldListEntry otherWorld in otherWorlds ) { cWorld.Items.Add( otherWorld.Name + " (" + otherWorld.Description + ")" ); copyOptionsList.Add( otherWorld ); var item = new ToolStripMenuItem( otherWorld.Name ) {Tag = otherWorld}; tsbCopyGenSettings.DropDownItems.Insert( 0, item ); } if( World == null ) { // initialize defaults for a new world (Adding) Text = "Adding a New World"; // keep trying "NewWorld#" until we find an unused number int worldNameCounter = 1; while( MainForm.IsWorldNameTaken( "NewWorld" + worldNameCounter ) ) { worldNameCounter++; } World = new WorldListEntry( "NewWorld" + worldNameCounter ); tName.Text = World.Name; cAccess.SelectedIndex = 0; cBuild.SelectedIndex = 0; cBackup.SelectedIndex = 0; cBlockDB.SelectedIndex = 0; // Auto cVisibility.SelectedIndex = 0; Map = null; } else { // Fill in information from an existing world (Editing) World = new WorldListEntry( World ); Text = "Editing World \"" + World.Name + "\""; originalWorldName = World.Name; tName.Text = World.Name; cAccess.SelectedItem = World.AccessPermission; cBuild.SelectedItem = World.BuildPermission; cBackup.SelectedItem = World.Backup; cVisibility.SelectedIndex = (World.Hidden ? 1 : 0); switch( World.BlockDBEnabled ) { case YesNoAuto.Auto: cBlockDB.SelectedIndex = 0; break; case YesNoAuto.Yes: cBlockDB.SelectedIndex = 1; break; case YesNoAuto.No: cBlockDB.SelectedIndex = 2; break; } } // Disable "copy" tab if there are no other worlds if( cWorld.Items.Count > 0 ) { cWorld.SelectedIndex = 0; } else { tabs.TabPages.Remove( tabCopy ); } // Disable "existing map" tab if map file does not exist fileToLoad = World.FullFileName; if( File.Exists( fileToLoad ) ) { ShowMapDetails( tExistingMapInfo, fileToLoad ); StartLoadingMap(); } else { tabs.TabPages.Remove( tabExisting ); tabs.SelectTab( tabLoad ); } savePreviewDialog.FileName = World.Name; }
void LoadMap(object sender, EventArgs args) { // Fill in the "Copy existing world" combobox foreach (WorldListEntry otherWorld in MainForm.Worlds) { if (otherWorld != World) { cWorld.Items.Add(otherWorld.Name + " (" + otherWorld.Description + ")"); copyOptionsList.Add(otherWorld); } } if (World == null) { Text = "Adding a New World"; // keep trying "NewWorld#" until we find an unused number int worldNameCounter = 1; while (MainForm.IsWorldNameTaken("NewWorld" + worldNameCounter)) { worldNameCounter++; } World = new WorldListEntry("NewWorld" + worldNameCounter); tName.Text = World.Name; cAccess.SelectedIndex = 0; cBuild.SelectedIndex = 0; cBackup.SelectedIndex = 0; xBlockDB.CheckState = CheckState.Indeterminate; Map = null; } else { // Editing a world World = new WorldListEntry(World); Text = "Editing World \"" + World.Name + "\""; originalWorldName = World.Name; tName.Text = World.Name; cAccess.SelectedItem = World.AccessPermission; cBuild.SelectedItem = World.BuildPermission; cBackup.SelectedItem = World.Backup; xHidden.Checked = World.Hidden; switch (World.BlockDBEnabled) { case YesNoAuto.Auto: xBlockDB.CheckState = CheckState.Indeterminate; break; case YesNoAuto.Yes: xBlockDB.CheckState = CheckState.Checked; break; case YesNoAuto.No: xBlockDB.CheckState = CheckState.Unchecked; break; } } // Disable "copy" tab if there are no other worlds if (cWorld.Items.Count > 0) { cWorld.SelectedIndex = 0; } else { tabs.TabPages.Remove(tabCopy); } // Disable "existing map" tab if mapfile does not exist fileToLoad = World.FullFileName; if (File.Exists(fileToLoad)) { ShowMapDetails(tExistingMapInfo, fileToLoad); StartLoadingMap(); } else { tabs.TabPages.Remove(tabExisting); tabs.SelectTab(tabLoad); } // Set Generator comboboxes to defaults cTemplates.SelectedIndex = (int)MapGenTemplate.River; savePreviewDialog.FileName = World.Name; }
void LoadMap( object sender, EventArgs args ) { // Fill in the "Copy existing world" combobox foreach( WorldListEntry otherWorld in MainForm.Worlds ) { if( otherWorld != World ) { cWorld.Items.Add( otherWorld.Name + " (" + otherWorld.Description + ")" ); copyOptionsList.Add( otherWorld ); } } if( World == null ) { Text = "Adding a New World"; // keep trying "NewWorld#" until we find an unused number int worldNameCounter = 1; while( MainForm.IsWorldNameTaken( "NewWorld" + worldNameCounter ) ) { worldNameCounter++; } World = new WorldListEntry( "NewWorld" + worldNameCounter ); tName.Text = World.Name; cAccess.SelectedIndex = 0; cBuild.SelectedIndex = 0; cBackup.SelectedIndex = 5; xBlockDB.CheckState = CheckState.Indeterminate; Map = null; } else { // Editing a world World = new WorldListEntry( World ); Text = "Editing World \"" + World.Name + "\""; originalWorldName = World.Name; tName.Text = World.Name; cAccess.SelectedItem = World.AccessPermission; cBuild.SelectedItem = World.BuildPermission; cBackup.SelectedItem = World.Backup; xHidden.Checked = World.Hidden; switch( World.BlockDBEnabled ) { case YesNoAuto.Auto: xBlockDB.CheckState = CheckState.Indeterminate; break; case YesNoAuto.Yes: xBlockDB.CheckState = CheckState.Checked; break; case YesNoAuto.No: xBlockDB.CheckState = CheckState.Unchecked; break; } } // Disable "copy" tab if there are no other worlds if( cWorld.Items.Count > 0 ) { cWorld.SelectedIndex = 0; } else { tabs.TabPages.Remove( tabCopy ); } // Disable "existing map" tab if mapfile does not exist fileToLoad = World.FullFileName; if( File.Exists( fileToLoad ) ) { ShowMapDetails( tExistingMapInfo, fileToLoad ); StartLoadingMap(); } else { tabs.TabPages.Remove( tabExisting ); tabs.SelectTab( tabLoad ); } // Set Generator comboboxes to defaults cTemplates.SelectedIndex = (int)MapGenTemplate.River; savePreviewDialog.FileName = World.Name; }
void LoadMap(object sender, EventArgs args) { // get the list of existing worlds otherWorlds = MainForm.Worlds.Where(w => w != World).ToArray(); // Fill in the "Copy existing world" combobox foreach (WorldListEntry otherWorld in otherWorlds) { cWorld.Items.Add(otherWorld.Name + " (" + otherWorld.Description + ")"); copyOptionsList.Add(otherWorld); var item = new ToolStripMenuItem(otherWorld.Name) { Tag = otherWorld }; tsbCopyGenSettings.DropDownItems.Insert(0, item); } if (World == null) { // initialize defaults for a new world (Adding) Text = "Adding a New World"; // keep trying "NewWorld#" until we find an unused number int worldNameCounter = 1; while (MainForm.IsWorldNameTaken("NewWorld" + worldNameCounter)) { worldNameCounter++; } World = new WorldListEntry("NewWorld" + worldNameCounter); tName.Text = World.Name; cAccess.SelectedIndex = 0; cBuild.SelectedIndex = 0; cBackup.SelectedIndex = 0; cBlockDB.SelectedIndex = 0; // Auto cVisibility.SelectedIndex = 0; Map = null; } else { // Fill in information from an existing world (Editing) World = new WorldListEntry(World); Text = "Editing World \"" + World.Name + "\""; originalWorldName = World.Name; tName.Text = World.Name; cAccess.SelectedItem = World.AccessPermission; cBuild.SelectedItem = World.BuildPermission; cBackup.SelectedItem = World.Backup; cVisibility.SelectedIndex = (World.Hidden ? 1 : 0); switch (World.BlockDBEnabled) { case YesNoAuto.Auto: cBlockDB.SelectedIndex = 0; break; case YesNoAuto.Yes: cBlockDB.SelectedIndex = 1; break; case YesNoAuto.No: cBlockDB.SelectedIndex = 2; break; } } // Disable "copy" tab if there are no other worlds if (cWorld.Items.Count > 0) { cWorld.SelectedIndex = 0; } else { tabs.TabPages.Remove(tabCopy); } // Disable "existing map" tab if map file does not exist fileToLoad = World.FullFileName; if (File.Exists(fileToLoad)) { ShowMapDetails(tExistingMapInfo, fileToLoad); StartLoadingMap(); } else { tabs.TabPages.Remove(tabExisting); tabs.SelectTab(tabLoad); } savePreviewDialog.FileName = World.Name; }