Represents a single-use state object for a particular set of map generator parameters (IMapGeneratorParameters). Provides a synchronous method to carry out generation, asynchronous method to cancel generation, various properties to indicate progress, and an event to report progress changes.
Ejemplo n.º 1
0
 void AsyncGenCompleted( object sender, RunWorkerCompletedEventArgs e ) {
     stopwatch.Stop();
     if( genState.Canceled ) {
         tStatus1.Text = "Generation cancelled!";
         progressBar.Visible = false;
     } else if( Map == null ) {
         tStatus1.Text = "Generation failed!";
         Logger.LogAndReportCrash( "Exception while generating map", "ConfigGUI", e.Error, false );
         progressBar.Visible = false;
     } else {
         tStatus1.Text = "Generation successful (" + stopwatch.Elapsed.TotalSeconds.ToString( "0.000" ) + "s)";
         tStatus2.Text = ", drawing...";
         Redraw( true );
     }
     bGenerate.Enabled = true;
     bGenerate.Text = "Generate";
     genState = null;
 }
Ejemplo n.º 2
0
        void bGenerate_Click( object sender, EventArgs e ) {
            if( genState != null ) {
                genState.CancelAsync();
                tStatus1.Text = "Canceling...";
                bGenerate.Enabled = false;
                return;
            }
            Map = null;

            MapGeneratorParameters genParams = genGui.GetParameters();
            genState = genParams.CreateGenerator();

            tStatus1.Text = "Generating...";
            tStatus2.Text = "";
            if( genState.ReportsProgress ) {
                progressBar.Style = ProgressBarStyle.Continuous;
                genState.ProgressChanged +=
                    ( progressSender, progressArgs ) =>
                    bwGenerator.ReportProgress( progressArgs.ProgressPercentage, progressArgs.UserState );
            } else {
                progressBar.Style = ProgressBarStyle.Marquee;
            }
            if( genState.SupportsCancellation ) {
                bGenerate.Text = "Cancel";
            } else {
                bGenerate.Enabled = false;
            }
            progressBar.Value = 0;
            progressBar.Visible = true;
            Refresh();
            bwGenerator.RunWorkerAsync();
            World.MapChangedBy = WorldListEntry.WorldInfoSignature;
            World.MapChangedOn = DateTime.UtcNow;
        }