/* * TutorialScreen.cs * Authors: Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System.Collections.Generic; using tAC_Engine.Graphics.Entities; using Util; namespace StellarProspector { /// /// Defines what a single section of the tutorial is /// public class TutorialSection { #region Fields /// /// Code preformed at the beginning and/or end of each section of the tutorial /// /// reference to the current game screen public delegate void Code(GameScreen game); /// /// Condition(s) that must be met in order for the tutorial to advance /// to the next section /// /// Reference to the current game screen /// Whether the check has been met or not public delegate bool Check(GameScreen game); /// /// Code preformed at the beginning of the tutorial section /// public Code Init; /// /// Code preformed at the end of the tutorial section /// public Code Deinit; /// /// Dialog that will be displayed during this tutorial section /// public DialogScreen Dialog; /// /// Condition that must be met in order to finish the tutorial section /// public Check When; #endregion #region Creation /// /// Constructor for a single section of the tutorial /// /// Code preformed at the beginning of the tutorial section /// Code preformed at the end of the tutorial section /// Dialog that will be displayed during this tutorial section /// Condition that must be met in order to finish the tutorial section public TutorialSection(Code initialize, Code deinitialize, DialogScreen dialog, Check when) { Init = initialize; Deinit = deinitialize; Dialog = dialog; When = when; } #endregion } /// /// Used to process tutorial script for Stellar Propsector /// public class TutorialScreen : GameScreen { #region Fields private Microsoft.Xna.Framework.Graphics.SpriteBatch sb; private InputHandler mInputHandler; private TutorialSection[] Sections; private int CurrentSection; private bool DialogDone; private bool Uninitialized = true; #endregion #region Creation /// /// Constructor for the tutorial game screen /// /// Reference to the current game screen /// List of tutorial sections to be performed public TutorialScreen(GameScreen game, List sections) { Sections = sections.ToArray(); } /// /// Returns a nely created entity with the texture of the given /// /// Name of the texture for the given entity /// The entity sprite public EntitySprite newEntity(string filename) { EntitySprite en = new EntitySprite(Content, filename); AddComponent(en); return en; } #endregion #region Initialization /// /// Initializes basic needed tutorial components /// public override void Initialize() { mInputHandler = GetInputHandler(); mInputHandler.Initialize(); base.Initialize(); } /// /// Reinitializes the tutorial game screen /// public override void Reinitialize() { DialogDone = true; base.Reinitialize(); } #endregion #region Management /// /// Loads necessary content components /// protected override void LoadContent() { sb = new Microsoft.Xna.Framework.Graphics.SpriteBatch(GraphicsDevice); base.LoadContent(); } /// /// Unloads and disposes content components /// protected override void UnloadContent() { sb.Dispose(); base.UnloadContent(); } #endregion #region Update /// /// Updates the tutorial /// /// The time that has passed so far in game public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { if (CurrentSection == Sections.Length) { Done(); return; } if (Uninitialized) { Sections[CurrentSection].Init.Invoke(this); Raise(Sections[CurrentSection].Dialog); Uninitialized = false; } if (Sections[CurrentSection].When == null) { if (DialogDone) { nextSection(); } } else { if (Sections[CurrentSection].When.Invoke(this)) { if (Sections[CurrentSection].Dialog != null) { Sections[CurrentSection].Dialog.Clear(); } nextSection(); } } base.Update(gameTime); } /// /// Advances the tutorial to the next section /// private void nextSection() { if (Sections[CurrentSection].Deinit != null) { Sections[CurrentSection].Deinit.Invoke(this); } CurrentSection++; DialogDone = false; if (CurrentSection < Sections.Length) { if (Sections[CurrentSection].Init != null) { Sections[CurrentSection].Init.Invoke(this); } if (Sections[CurrentSection].Dialog != null) { Raise(Sections[CurrentSection].Dialog); } } else { Done(); } } #endregion } }