예제 #1
0
        protected virtual StringShape CreatePackageDetailsMessage(IBabyPackageProvider babyPackage)
        {
            if (String.IsNullOrEmpty(babyPackage.Author) &&
                String.IsNullOrEmpty(babyPackage.Title) &&
                babyPackage.Website == null)
            {
                return(null);
            }

            var website = String.Empty;

            if (babyPackage.Website != null)
            {
                website = babyPackage.Website.ToString().TrimEnd('/').Replace(babyPackage.Website.Scheme + "://", String.Empty);
            }
            var helpText = new StringShape(this.Game);

            helpText.String       = String.Format("{0}\n{1}\n{2}", babyPackage.Title, String.IsNullOrEmpty(babyPackage.Author) ? String.Empty : "By " + babyPackage.Author, website);
            helpText.Colour       = Color.Black;
            helpText.ShadowColour = Color.White;
            helpText.ShadowOffset = 1f;
            helpText.Location     = new Vector2(10);
            helpText.SpinTime     = TimeSpan.Zero;
            helpText.FadeInTime   = TimeSpan.FromSeconds(0.4);
            helpText.OnScreenTime = TimeSpan.FromSeconds(10);
            helpText.FadeOutTime  = TimeSpan.FromSeconds(1.5);
            // TODO: load font sizes based on screen resolution and from a pool of fonts so I'm not newing one up here.
            helpText.Font = this.Game.Content.Load <SpriteFont>(@"DejaVu Sans 14");
            return(helpText);
        }
예제 #2
0
        private void BabyShapes_HelpTextComponentRemoved(object sender, GameComponentCollectionEventArgs e)
        {
            // Clean up the helptext shape once it's lifespan is over.
            if (Object.ReferenceEquals(this._HelpText, e.GameComponent))
            {
                this._HelpText = null;
                this._BabyShapes.Components.ComponentRemoved -= new EventHandler <GameComponentCollectionEventArgs>(BabyShapes_HelpTextComponentRemoved);
            }

            // And add a message about the babypackage.
            var packageMessage = this.CreatePackageDetailsMessage(this.Game.Services.GetService <IBabyPackageProvider>());

            if (packageMessage != null)
            {
                this._BabyShapes.Components.Add(packageMessage);
            }
        }
예제 #3
0
        internal StringShape GetHelpText()
        {
            var helpText = new StringShape(this);

            helpText.String       = "Baby Bash XNA - A BabySmash clone using the XNA Framework\n© Murray Grant 2011\nPress  Ctrl + Alt + Shift + F4    to Exit\nPress  Ctrl + Alt + Shift + F12  for Options";
            helpText.Colour       = Color.Black;
            helpText.ShadowColour = Color.White;
            helpText.ShadowOffset = 1f;
            helpText.Location     = new Vector2(10);
            helpText.SpinTime     = TimeSpan.Zero;
            helpText.FadeInTime   = TimeSpan.FromSeconds(0.4);
            helpText.OnScreenTime = TimeSpan.FromSeconds(10);
            helpText.FadeOutTime  = TimeSpan.FromSeconds(1.5);
            // TODO: load font sizes based on screen resolution.
            helpText.Font = this._TextFont;
            return(helpText);
        }
예제 #4
0
        public BashingGameState(GameMain game, StringShape helpText)
            : base()
        {
            this.Game         = game;
            this._SpriteBatch = new SpriteBatch(this.Game.GraphicsDevice);
            this._HelpText    = helpText;
            this._BabyShapes  = new AggrigateComponent(this.Game);
            this._BabyShapes.Components.Add(helpText);
            this.Game.Components.Add(this._BabyShapes);

            // Set the initial mouse and keyboard states so shapes don't appear for no reason.
            this._LastMouseState = Mouse.GetState();
            this.UpdateLastKeysPressed(Keyboard.GetState());

            // Set the last pressed controller buttons to zero.
            for (var player = PlayerIndex.One; player <= PlayerIndex.Four; player++)
            {
                this._LastPressedButtons.Add(player, ControllerButton.None);
            }
        }
예제 #5
0
        public LoadingGameState(GameMain game, CancellationToken cancelMarker)
            : base()
        {
            this.Game = game;
            var taskMgr = this.Game.Services.GetService <TaskManager>();

            this._SpriteBatch = new SpriteBatch(this.Game.GraphicsDevice);

            // Display help text at the start.
            this._HelpText             = this.Game.GetHelpText();
            this._HelpText.SpriteBatch = this._SpriteBatch;

            // Show an animation while loading.
            this._LoaderAnimation             = this.GetLoadingAnimation();
            this._LoaderAnimation.SpriteBatch = this._SpriteBatch;

            var loadTimers = new LoadTimers();

            // Create loader thread.
            // This is executed in the first call to Update().
            this._Loader = new Task(() =>
            {
                var loadStopwatch = System.Diagnostics.Stopwatch.StartNew();

                if (cancelMarker.IsCancellationRequested)
                {
                    cancelMarker.ThrowIfCancellationRequested();
                }

                // Create services.
                this.Game.Services.AddService(typeof(IConfigurationService), new ConfigurationManager(this.Game));
                this.Game.Services.AddService(typeof(IBabyPackageProvider), new XmlFolderBabyPackage(this.Game));
                this.Game.Services.AddService(typeof(ISoundService), new SoundServiceContainer(new SoundService(this.Game)));
                this.Game.Services.AddService(typeof(IApplicationUpdater), new ApplicationUpdater(this.Game));

                if (cancelMarker.IsCancellationRequested)
                {
                    cancelMarker.ThrowIfCancellationRequested();
                }

                // Load content based on those services.
                var startConfigLoad = loadStopwatch.Elapsed;
                var configMgr       = this.Game.Services.GetService <IConfigurationService>();
                bool configExists   = configMgr.Exists;
                configMgr.Load();
                if (!configExists)       // Ensure the configuration file is saved.
                {
                    configMgr.Save(configMgr.Current);
                }
                loadTimers.ConfigLoadTime = loadStopwatch.Elapsed.Subtract(startConfigLoad);

                if (cancelMarker.IsCancellationRequested)
                {
                    cancelMarker.ThrowIfCancellationRequested();
                }

                // Load up the baby package.
                var startBabyPackageLoad = loadStopwatch.Elapsed;
                var babyPackpageProvider = this.Game.Services.GetService(typeof(IBabyPackageProvider)) as IBabyPackageProvider;
                babyPackpageProvider.Load(configMgr.Current.PathToBabyPackage, cancelMarker);
                loadTimers.BabyPackageLoadTime = loadStopwatch.Elapsed;

                if (cancelMarker.IsCancellationRequested)
                {
                    cancelMarker.ThrowIfCancellationRequested();
                }

                // Loading can generate lots of garbage, so do a collection while the loading animation is still on screen.
                GC.Collect();

                loadStopwatch.Stop();
                loadTimers.TotalLoadTime = loadStopwatch.Elapsed;
            });

            var loaderComplete = this._Loader.ContinueWith((t) =>
            {
                // When loading is finished, null it and remove the loading animation.
                this._Loader = null;

                // Notify that we've finished loading.
                if (this.LoadComplete != null)
                {
                    this._HelpText.SpriteBatch = null;
                    this.LoadComplete(this, new LoadCompleteEventArgs(this._HelpText, loadTimers));
                }

                // Load up a few assemblies from disk to keep the options screen responsive.
                var optionsLoader = new Task(() =>
                {
                    var optionsScreen = new OptionsMenuDialog(this.Game);
                    var guiManager    = new Nuclex.UserInterface.GuiManager(this.Game.Services);
                    this.Game.Services.RemoveService(typeof(Nuclex.UserInterface.IGuiService));
                    var fileBrowseDialog = new System.Windows.Forms.OpenFileDialog();
                });
                taskMgr.RegisterTask(optionsLoader);
                optionsLoader.Start();
            }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());

            var updaterTask = loaderComplete.ContinueWith(t =>
            {
                // Spin up the updater (which delays a bit before running).
                var updater = this.Game.Services.GetService <IApplicationUpdater>();
                if (updater.SupportsUpdates)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(30));
                    updater.DoCheckAndUpdate();
                }
            }, TaskContinuationOptions.NotOnFaulted);

            // Register all the tasks with the game to handle exceptions.
            taskMgr.RegisterTask(this._Loader);
            taskMgr.RegisterTask(loaderComplete);
            taskMgr.RegisterTask(updaterTask);
        }
예제 #6
0
 internal LoadCompleteEventArgs(StringShape helpText, LoadTimers loadTimers)
 {
     this.LoadTimers = loadTimers;
     this.HelpText   = helpText;
 }