/* * 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 Microsoft.Xna.Framework.Graphics; using Util; using Microsoft.Xna.Framework.Input; namespace MaritimeDefender { /// /// Defines how a section of the tutorial works /// public class TutorialSection { #region Delegates /// /// Delegate that allows for processing of C# code for tutorial scripts /// /// Reference to the current game screen public delegate void Code(GameScreen game); /// /// Delegate that allows for processing of C# condition code for tutorial scripts /// /// Reference to the current game screen /// True if the read in boolean logic is true public delegate bool Check(GameScreen game); #endregion #region Fields /// /// Code that will be processed when the tutorial section starts /// public Code Init; /// /// Code that will be processed when the tutorial section ends /// public Code Deinit; /// /// Dialog that will be displayed during the section of the tutorial /// public DialogScreen Dialog; /// /// If not null, the condition that must be fulfilled for this tutorial section to end /// public Check When; #endregion #region Creation /// /// Constructor /// /// Code that will be processed when the tutorial section starts /// Code that will be processed when the tutorial section ends /// Dialog that will be displayed during the section of the tutorial /// If not null, the condition that must be fulfilled for this tutorial section to end public TutorialSection(Code initialize, Code deinitialize, DialogScreen dialog, Check when) { Init = initialize; Deinit = deinitialize; Dialog = dialog; When = when; } #endregion } /// /// Defines how the tutorial screen for Maritime Defender works /// public class TutorialScreen : GameScreen { // The array of sections within the tutorial private readonly TutorialSection[] Sections; // List of all the entities being used currently in the tutorial private readonly List mEntities = new List(); // List of private SpriteBatch sb; // private int CurrentSection; // private bool DialogDone; // private bool Uninitialized = true; // private bool loaded; /// /// /// public GameScreen mGame; /// /// /// public InputHandler mInputHandler; /// /// /// /// /// public TutorialScreen(GameScreen game, List sections) { mGame = game; Sections = sections.ToArray(); } public Entity newEntity(string filename) { Entity en = new Entity(filename); if (loaded) { en.LoadContent(Content); } mEntities.Add(en); return en; } public void clearEntities() { mEntities.Clear(); } /// /// Based on the tutorial section number given, does the appropriate logging /// *Note* This will need to be updated if ever the tutorial is changed /// /// The number of the tutorial section completed public void TutorialEventSelect(int sectionNum) { switch (sectionNum) { case 0: // Start of the tutorial. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_TutorialStart, "MD_TutorialStart Event=Dialogue"); break; case 1: // End of section 1: 1 dialog and mission briefing slide. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section1, "MD_Tutorial1 Event=Dialogue Event=Animation"); break; case 2: // End of section 2: 1 dialog and small animation. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section2, "MD_Tutorial2 Event=Dialogue"); break; case 3: // End of section 3: 1 dialog and dragoon schematic. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section3, "MD_Tutorial3 Event=Dialogue Event=Dialogue"); break; case 4: // End of section 4: 2 dialogs and freighter schematic. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section4, "MD_Tutorial4 Event=Dialogue Event=Movements"); break; case 5: // End of section 5: 1 dialog and steering practice (press both left and right movement keys). ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section5, "MD_Tutorial5 Event=Dialogue Event=Movement"); break; case 6: // End of section 6: 1 dialog and additional steering practice (head to top). ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section6, "MD_Tutorial6 Event=Dialogue Event=Movement"); break; case 7: // End of section 7: 2 dialogs and further steering practice (head to bottom). ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section7, "MD_Tutorial7 Event=Dialogue Event=Dialogue Event=Movement"); break; case 8: // End of section 8: 2 dialogs and press fire button ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section8, "MD_Tutorial8 Event=Dialogue Event=Dialogue Event=ShooterActivateFireWeapon"); break; case 9: // End of section 9: 1 dialog and connect to warp. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section9, "MD_Tutorial9 Event=Dialogue Event=Wormhole"); break; case 10: // End of section 10: 2 dialogs and spawning of friendly ship. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section10, "MD_Tutorial10 Event=Dialogue Event=Dialogue Event=ShooterPresentFriendly"); break; case 11: // End of section 11: 1 dialog and connecting to wormhole. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section11, "MD_Tutorial11 Event=Dialogue Event=Wormhole"); break; case 12: // End of section 12: 3 dialogs and fighting spawned enemy. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section12, "MD_Tutorial12 Event=Dialogue Event=Dialogue Event=Dialogue Event=ShooterPresentEnemy"); break; case 13: // End of section 13: 1 dialog and warp appearence. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section13, "MD_Tutorial13 Event=Dialogue Event=Wormhole"); break; case 14: // End of section 14: 2 dialogs and changed to dot coherence phase. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section14, "MD_Tutorial14 Event=Dialogue Event=Dialogue Event=DotPhaseBegin"); break; case 15: // End of section 15: 1 dialog and pressing of left movement key. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section15, "MD_Tutorial15 Event=UserRespondLeft"); break; case 16: // End of section 16: 3 dialogs. Ending tutorial. ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_Section16, "MD_Tutorial16 Event=Dialogue Event=Dialogue Event=Dialogue"); ((MaritimeDefender)mGame).logger.Write((int)EventCode.MD_TutorialEnd, "MD_TutorialEnd"); break; } } public override void Initialize() { mInputHandler = GetInputHandler(); mInputHandler.Initialize(); mInputHandler.BindButton(Keys.Escape, Trigger.Activated, (int)EventCode.MD_Pause); base.Initialize(); //mGame.Initialize(); } protected override void LoadContent() { sb = new SpriteBatch(GraphicsDevice); foreach (Entity en in mEntities) { en.LoadContent(Content); } loaded = true; base.LoadContent(); } protected override void UnloadContent() { sb.Dispose(); foreach (Entity en in mEntities) { en.UnloadContent(); } loaded = false; base.UnloadContent(); } protected override void Dispose(bool disposing) { if (disposing) { } base.Dispose(disposing); } public override void Reinitialize() { DialogDone = true; base.Reinitialize(); } public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { //Handle Input while (mInputHandler.HasEvent()) { InputEvent inputEvent = mInputHandler.GetNextEvent(); switch ((EventCode)inputEvent.EventCode) { case EventCode.MD_Pause: Done(); break; } } 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)) { Sections[CurrentSection].Dialog.Clear(); nextSection(); } } foreach (Entity e in mEntities) { e.Update(gameTime); } base.Update(gameTime); //mGame.Update(gameTime); } 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(); } } public override void Draw(Microsoft.Xna.Framework.GameTime gameTime) { sb.Begin(); foreach (Entity e in mEntities) { e.Draw(sb); } sb.End(); base.Draw(gameTime); //mGame.Draw(gameTime); } } }