//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
//#define RunSurveys
namespace DarkWynter.Engine
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Net;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
using System.Windows.Forms;
using Audio;
using Menus;
using Globals;
using Utilities;
using Controllers;
using ObjectLib;
using GameObjects;
using Physics;
using DarkWynter.Stream;
using DarkWynter.Engine.UserInterface;
#endregion
using Nuclex;
// Once we mix XNA with the System.Windows.Forms namespace, some ambiguities will
// arise. The following lines create some shortcuts so the can conveniently address
// the classes we actually want to use.
using XnaColor = Microsoft.Xna.Framework.Graphics.Color;
using XnaRectangle = Microsoft.Xna.Framework.Rectangle;
using DarkWynter.Engine.EventControl;
using System.ComponentModel;
using DarkWynter.Stream.UIInterfacing;
///
/// Base class for creating a game using the DarkWynter Engine.
/// DarkWynterEngine extends object modification to the user through XML.
/// DakrWynterEngine extends functionality to the user through overridable objects.
///
public class DarkWynterEngine : Nuclex.GameControl
{
#region Properties
///
/// Public static accessor to this class.
///
public static DarkWynterEngine engine;
///
/// Main User's Heads Up Display
///
public static HeadsUpDisplay _HUD;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public HeadsUpDisplay HUD { get { return _HUD; } set { _HUD = value; } }
///
/// Manage scoring, respawn, and gameover
///
private GameLogicController gameRules;
///
/// Game Controller
///
[Category("_Engine")]
public List gameControllers { get { return _gameControllers; } set { _gameControllers = value; } }
public List _gameControllers;
///
/// Menu Controller
///
[Category("_Engine")]
public List menuControllers { get { return _menuControllers; } set { _menuControllers = value; } }
public List _menuControllers;
///
/// A scenegraph/collections class, contains all GameObject instants
///
public ObjectLibrary _objectLibrary;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public ObjectLibrary objectLibrary { get { return _objectLibrary; } set { _objectLibrary = value; } }
///
/// Handles collision detection.
///
protected Collision _collision;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Collision collision { get { return _collision; } set { _collision = value; } }
///
/// Renders the scene once for each viewport.
///
protected Renderer _renderer;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Renderer renderer { get { return _renderer; } set { _renderer = value; } }
///
/// Menu System Componenets
///
protected MenuSystem _menuSystem;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public MenuSystem menuSystem { get { return _menuSystem; } set { _menuSystem = value; } }
///
/// Interface to GPU Uniform variables
///
private ShaderParameters _shaderParameters;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public ShaderParameters shaderParameters { get { return _shaderParameters; } set { _shaderParameters = value; } }
///
/// Interface to GPU Uniform variables
///
private Statics_Engine _staticsEngine;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Statics_Engine staticsEngine { get { return _staticsEngine; } set { _staticsEngine = value; } }
///
/// Interface to GPU Uniform variables
///
private Audio.Audio _audio;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Audio.Audio audio { get { return _audio; } set { _audio = value; } }
///
/// FPS - Frames Per Second
///
public FPSCounter _fps;
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public FPSCounter fps { get { return _fps; } set { _fps = value; } }
///
/// Terrain Mod Singleton
///
[Category("_Engine"), EditorAttribute(typeof(ObjectPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public MajikWand majikWand { get { return _majikWand; } set { _majikWand = value; } }
public static MajikWand _majikWand = new MajikWand();
///
/// User Preferences filepath or location on disk.
/// Default location at "_xml//UserSettings//UserSettings.xml"
///
public string userSettingsFile
{
get { return _userSettingsFile; }
set {
_userSettingsFile = value;
DarkWynterEngine.LoadUserPreferences(value);
}
}
public static string _userSettingsFile;
///
/// Supplied from upper layer components that require notification whenever a new Level is loaded.
///
/// Controller boolean event arguments
public delegate void OnGameChange();
public static event OnGameChange onGameChange;
///
/// Supplied from upper layer components that require notification whenever a new Level is loaded.
///
/// Controller boolean event arguments
public delegate void OnLevelChange(EventArgs args);
public static event OnLevelChange onLevelChange;
///
/// Supplied from upper layer components that require notification whenever a new Level is loaded.
///
/// Controller boolean event arguments
public delegate void OnSurveyPretest(object sender, EventArgs args);
public static event OnSurveyPretest onSurveyPretest;
public static bool launchPreTest = false;
///
/// Supplied from upper layer components that require notification whenever a new Level is loaded.
///
/// Controller boolean event arguments
public delegate void OnSurveyPosttest(object sender, EventArgs args);
public static event OnSurveyPosttest onSurveyPosttest;
public static bool launchPostTest = false;
///
/// Supplied from upper layer components that require notification each time update cycle completes.
///
/// Controller boolean event arguments
public delegate void OnUpdateComplete(object sender, EventArgs args);
public static event OnUpdateComplete onUpdateComplete;
#endregion
#region Methods
///
/// Main Engine Class.
/// Check for Hardware Capabilities.
/// Create GraphicsDeviceManager and ContentManager.
///
public DarkWynterEngine():base()
{
staticsEngine = new Statics_Engine();
// Publish a static pointer to this class to allow access to properties.
DarkWynterEngine.engine = this;
// Draw is called as many times as the hardware can handle.
// If(IsFixedTimeStep), then Update is called 30x per second.
// If(!IsFixedTimeStep), then Update is called as many times as the hardware can handle.
// The differrence affects both controller inputs and physics responses in the Virtual Environment.
this.IsFixedTimeStep = true;
// Set up Global Graphics Device and Content Loader
Statics_Stream.RenderSettings.graphics = this.graphics;
Statics_Engine.SystemSettings.content = new ContentManager(Services);
Statics_Stream.RenderSettings.graphics.SynchronizeWithVerticalRetrace = false;
// Check all available adapters on the system
for (int i = 0; i < GraphicsAdapter.Adapters.Count; i++)
{
// Get the capabilities of the hardware device
GraphicsDeviceCapabilities caps = GraphicsAdapter.Adapters[i].GetCapabilities(DeviceType.Hardware);
if (caps.MaxPixelShaderProfile < ShaderProfile.PS_3_0)
{
System.Diagnostics.Debug.WriteLine("This adapter does not support Shader Model 3.0.");
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.NOT_SUPPORTED;
}
else
{
//Yay! They can play
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.CREDIT_SCREEN;
}
}
// Initialize Control Docking
this.Dock = DockStyle.Fill;
this.Focus();
// Set up Mouse to Activate and Deactivate, using Left and Right mouse clicks respectively.
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
// Drag/Drop Level Creation
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(terrain_DragEnter);
this.DragDrop += new DragEventHandler(terrain_DragDrop);
}
///
/// Set Up Display Window.
/// Create Logging, XML, GameFlow, Renderer, SpriteBatch,
/// FontWriter, MenuSystem, Audio, ShaderParameters, ChatClient,
/// Frames Per Second Counter, and Screensaver
///
protected override void Initialize()
{
// Load machine settings
//DarkWynterEngine.LoadUserPreferences(userSettingsFile);
// Rendering Device
renderer = new Renderer(Statics_Engine.SystemSettings.content);
shaderParameters = new ShaderParameters(Statics_Engine.SystemSettings.content);
fps = new FPSCounter(true);
menuSystem = new MenuSystem();
collision = new Collision();
// Create Library and attach draw delegates to Renderer
objectLibrary = new ObjectLibrary();
renderer.drawObjectLibrary = new Renderer.DrawObjectLibrary(objectLibrary.Draw);
renderer.drawSprites = new Renderer.DrawSprites(objectLibrary.Draw_Billboards);
renderer.drawHUD = new Renderer.DrawHUD(objectLibrary.PostDraw_HUD);
// Controllers
gameRules = new GameLogicController();
gameControllers = new List();
menuControllers = new List();
ControllerManager.CheckForControllers();
audio = new DarkWynter.Engine.Audio.Audio();
//Audio.Audio.PlayLevelSong("Theme4");
// Start Logging
Logging.setStart(System.DateTime.Now);
Logging.G2LLogList.Add(System.DateTime.Now.ToString());
// Load Fonts and HUD
Statics_Stream.Fonts.Arial = Statics_Engine.SystemSettings.content.Load("Content/_fonts/Arial");
Statics_Stream.Fonts.ComicSans = Statics_Engine.SystemSettings.content.Load("Content/_fonts/ComicSansMS");
Statics_Stream.Fonts.ComicSansSmall = Statics_Engine.SystemSettings.content.Load("Content/_fonts/ComicSansSmall");
//LoadGame("_GameIndex.xml");
base.Initialize();
}
///
/// Loads xml System settings from SystemSettings.xml.
///
public static void LoadUserPreferences(string userSettingsFilePath)
{
try
{
// Load physics, music, and fog
XmlDocument reader = new XmlDocument();
reader.Load(userSettingsFilePath);
XmlNodeList allNodes = reader.ChildNodes;
foreach (XmlNode settingsNode in allNodes)
{
if (settingsNode.Name == "SystemSettings")
{
XmlNodeList settingsNodes = settingsNode.ChildNodes;
foreach (XmlNode node in settingsNodes)
{
if (node.Name == "EnableShadowMap1")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.enableShadowMap1 = true;
}
else
{
Statics_Engine.SystemSettings.enableShadowMap1 = false;
}
}
else if (node.Name == "EnableShadowMap2")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.enableShadowMap2 = true;
}
else
{
Statics_Engine.SystemSettings.enableShadowMap2 = false;
}
}
else if (node.Name == "EnableTerrainBumpMapping")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.enableTerrainBumpMapping = true;
}
else
{
Statics_Engine.SystemSettings.enableTerrainBumpMapping = false;
}
}
else if (node.Name == "EnableTerrainMultiTexturing")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.enableTerrainMultiTexturing = true;
}
else
{
Statics_Engine.SystemSettings.enableTerrainMultiTexturing = false;
}
}
else if (node.Name == "NumberOfTerrainTextures")
{
int value = int.Parse(node.Attributes["value"].Value);
if (value == 4)
{
Statics_Engine.SystemSettings.numberOfTerrainTextures = 4;
}
else if (value == 3)
{
Statics_Engine.SystemSettings.numberOfTerrainTextures = 3;
}
else
{
Statics_Engine.SystemSettings.numberOfTerrainTextures = 2;
}
}
else if (node.Name == "SingleLightSource")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.singleLightSource = true;
}
else
{
Statics_Engine.SystemSettings.singleLightSource = false;
}
}
else if (node.Name == "MusicEnabled")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.music = true;
}
else
{
Statics_Engine.SystemSettings.music = false;
}
}
else if (node.Name == "SoundEffects")
{
string value = node.Attributes["value"].Value;
if (value == "Yes")
{
Statics_Engine.SystemSettings.soundFX = true;
}
else
{
Statics_Engine.SystemSettings.soundFX = false;
}
}
}
}
}
}
// Catch all loading exceptions and print message to user.
catch (Exception e)
{
MessageBox.Show(e.Message);
DarkWynterEngine.ContentInstall_WarningMessage();
}
}
///
/// Saves xml System settings in SystemSettings.xml.
///
public static void SaveUserPreferences()
{
XmlTextWriter settingsFile = new XmlTextWriter(
DarkWynterEngine._userSettingsFile, null);
settingsFile.Formatting = Formatting.Indented;
settingsFile.WriteStartDocument();
settingsFile.WriteStartElement("SystemSettings");
settingsFile.WriteStartElement("EnableShadowMap1");
if (Statics_Engine.SystemSettings.enableShadowMap1)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("EnableShadowMap2");
if (Statics_Engine.SystemSettings.enableShadowMap2)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("EnableTerrainBumpMapping");
if (Statics_Engine.SystemSettings.enableTerrainBumpMapping)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("EnableTerrainMultiTexturing");
if (Statics_Engine.SystemSettings.enableTerrainMultiTexturing)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("NumberOfTerrainTextures");
if (Statics_Engine.SystemSettings.numberOfTerrainTextures == 4)
{
settingsFile.WriteAttributeString("value", "4");
}
else if (Statics_Engine.SystemSettings.numberOfTerrainTextures == 3)
{
settingsFile.WriteAttributeString("value", "3");
}
else
{
settingsFile.WriteAttributeString("value", "2");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("SingleLightSource");
if (Statics_Engine.SystemSettings.singleLightSource)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("MusicEnabled");
if (Statics_Engine.SystemSettings.music)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteStartElement("SoundEffects");
if (Statics_Engine.SystemSettings.soundFX)
{
settingsFile.WriteAttributeString("value", "Yes");
}
else
{
settingsFile.WriteAttributeString("value", "No");
}
settingsFile.WriteEndElement();
settingsFile.WriteEndElement();
settingsFile.WriteEndDocument();
settingsFile.Flush();
settingsFile.Close();
}
///
/// Load the GameIndex xml-file that describes this project.
/// GameIndex xml associates Levels, Controls, and Content.
///
///
///
public static void Load_GameIndex(string GameXMLFile, string projectRootPath)
{
try
{
// Reset the current directory path to new project
System.IO.Directory.SetCurrentDirectory(projectRootPath);
// Recreate contentManager with new root directory. Rootpath is Read-only after construction.
Statics_Engine.SystemSettings.content = new ContentManager(DarkWynterEngine.engine.Services, projectRootPath);
DarkWynterEngine.engine.renderer = new Renderer(Statics_Engine.SystemSettings.content);
DarkWynterEngine.engine.renderer.drawObjectLibrary = new Renderer.DrawObjectLibrary(DarkWynterEngine.engine.objectLibrary.Draw);
DarkWynterEngine.engine.renderer.drawSprites = new Renderer.DrawSprites(DarkWynterEngine.engine.objectLibrary.Draw_Billboards);
DarkWynterEngine.engine.renderer.drawHUD = new Renderer.DrawHUD(DarkWynterEngine.engine.objectLibrary.PostDraw_HUD);
_HUD = new HeadsUpDisplay();
// Open GameIndex Xml File.
XmlDocument reader = new XmlDocument();
reader.Load(GameXMLFile);
foreach (XmlNode gameNodes in reader.ChildNodes)
{
if (gameNodes.Name == "games")
{
foreach (XmlNode gameNode in gameNodes.ChildNodes)
{
if (gameNode.Name == "game")
{
// Load System Game Package
ObjectLibrary.LoadAssemblyTypes(gameNode.Attributes["assembly"].Value);
// Load the menu system
DarkWynterEngine.engine.menuSystem.Load(gameNode);
// Load Level Index
Statics_Engine.levelInfo = new List();
foreach (XmlNode levelNode in gameNode.ChildNodes)
{
if (levelNode.Name == "level")
{
Statics_Engine.LevelInfo level = new Statics_Engine.LevelInfo();
level.name = levelNode.Attributes["name"].Value;
level.filepath = levelNode.Attributes["xmlFile"].Value;
level.description = levelNode.Attributes["description"].Value;
Statics_Engine.levelInfo.Add(level);
}
}
}
}
}
}
}
// Catch all loading exceptions and print message to user.
catch (Exception e)
{
MessageBox.Show(e.Message);
DarkWynterEngine.ContentInstall_WarningMessage();
}
// Call OnGameChange Delegates
if (onGameChange != null) { onGameChange(); }
}
///
/// Displays a message to user that they must install content from the web.
///
public static void ContentInstall_WarningMessage()
{
DarkWynterEngine.engine.SuspendLayout();
Label installContentLabel = new Label();
installContentLabel.AutoSize = true;
installContentLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.00F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
installContentLabel.Location = new System.Drawing.Point(10, 10);
installContentLabel.Text = "Content Project could not be found... ";
installContentLabel.ForeColor = System.Drawing.Color.Silver;
Label installContentLabel2 = new Label();
installContentLabel2.AutoSize = true;
installContentLabel2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.00F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
installContentLabel2.Location = new System.Drawing.Point(10, 50);
installContentLabel2.Text = "Please select \"Download Package\" below, to install content from web.";
installContentLabel2.ForeColor = System.Drawing.Color.Silver;
Panel panel = new Panel();
panel.SuspendLayout();
panel.Dock = DockStyle.Fill;
panel.Controls.Add(installContentLabel);
panel.Controls.Add(installContentLabel2);
panel.ResumeLayout(false);
panel.PerformLayout();
DarkWynterEngine.engine.Controls.Clear();
DarkWynterEngine.engine.Controls.Add(panel);
DarkWynterEngine.engine.ResumeLayout(false);
DarkWynterEngine.engine.PerformLayout();
}
///
/// Update MenuSystemGame, Audio, FPS.
/// Check For Level Loading Request.
/// Check For Exit.
///
/// XNA GameTime
protected override void Update(GameTime gameTime)
{
// Only update dt if in real-time run mode
if (Statics_Engine.SystemSettings.dt_realTime)
{
// Set current change in time
Statics_Engine.SystemSettings.dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
}
// If requested via flag
if (Statics_Engine.GameSettings.LoadLevel)
{
// Load new Level
objectLibrary.LoadLevel(Statics_Engine.levelInfo[Statics_Engine.levelIndex].filepath);
// Call Level-Loaded Callback delegate to notify upper layers of change.
if (onLevelChange != null) { onLevelChange(new EventArgs()); }
}
// Update renderer settings if changed
//UpdateRendererSettings();
renderer.Update(Statics_Engine.SystemSettings.TOTAL_PLAYERS);
// If Window is active...
if (Statics_Engine.SystemSettings.WINDOW_IN_FOCUS)
{
// Update Game Mode Controllers
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE)
{
// Update Controllers
foreach (GameController gameController in gameControllers)
{
// Check that the human is alive and hence active in the game
if (objectLibrary.humans[gameController.playerNumber].IsAlive())
{
gameController.Update(objectLibrary, menuSystem);
}
}
// Update GameRules
gameRules.Update(objectLibrary);
//Update Event Handler
GameEventHandler.UpdateEvents();
}
// Update Menu Mode Controllers
else
{
// Update all menu controllers
foreach (MenuController menuController in menuControllers)
{
menuController.Update(objectLibrary, menuSystem);
}
}
ControllerManager.CheckForControllers();
}
// If compiler disabled
if (Statics_Engine.SystemSettings.enableCompilerConsole == false)
{
// If in 3D GameMode
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE)
{
// Update ObjectLibrary
objectLibrary.Update(objectLibrary, collision);
// Update TerrainMod Caps
majikWand.Update(objectLibrary);
}
else
{
if (Statics_Engine.SystemSettings.WINDOW_IN_FOCUS)
{
// Update menu system
menuSystem.Update(objectLibrary);
}
}
}
// Update Frame Rate Counter
if (Statics_Engine.SystemSettings.enableFPSDisplay)
{ fps.Update(); }
// Crank the audio engine
Audio.Audio.Update();
// Crank the video engine
//video.Update();
// Post to all subscribers that update is complete
if (DarkWynterEngine.onUpdateComplete != null)
{
DarkWynterEngine.onUpdateComplete(this, new EventArgs());
}
#region Surveys
#if RunSurveys
if (launchPreTest)
{
if (DarkWynterEngine.onSurveyPretest != null)
{
DarkWynterEngine.onSurveyPretest(this, new EventArgs());
launchPreTest = false;
}
}
if (launchPostTest)
{
Logging.writeG2LLog(
DarkWynter.Engine.Globals.Statics_Engine.PlayerSettings.studentIDNumber + "-G2Llog.txt",
DarkWynter.Engine.Utilities.Logging.G2LLogList
);
Logging.writeG2LLog(
DarkWynter.Engine.Globals.Statics_Engine.PlayerSettings.studentIDNumber + "-G2LPositionalLog.txt",
DarkWynter.Engine.Utilities.Logging.G2LPositionalLog
);
if (DarkWynterEngine.onSurveyPosttest != null)
{
DarkWynterEngine.onSurveyPosttest(this, new EventArgs());
launchPostTest = false;
}
}
#endif
#endregion
// Call XNA Update
base.Update(gameTime);
}
///
/// Draw Game or MenuSystem Screen
///
/// XNA GameTime
protected override void Draw(GameTime gameTime)
{
// Clear the device
Statics_Engine.SystemSettings.elementalGameTime = gameTime;
// If in Game Mode (or paused) call game draw function
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE || Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_PAUSE)
{
renderer.Draw(Statics_Engine.SystemSettings.TOTAL_PLAYERS);
}
if (Statics_Engine.SystemSettings.gameState != Enums_Engine.EngineState.GAME_MODE)
{
menuSystem.Draw(renderer.spriteBatch);
}
fps.Draw(renderer._spriteBatch);
renderer.DisableSpriteBatches();
// Call XNA Draw
base.Draw(gameTime);
}
///
/// Unload resources loaded using the content manager
///
protected override void UnloadContent()
{
base.UnloadContent();
Statics_Engine.SystemSettings.content.Unload();
Statics_Engine.SystemSettings.content.Dispose();
}
#endregion
#region Events
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE)
{
Vector2 currentDimensions = new Vector2(this.Size.Width, this.Size.Height);
if (currentDimensions != Statics_Engine.LevelSettings.ViewportSize)
{
// Determine multiplier
Vector2 HUDScaleMultiplier = currentDimensions / Statics_Engine.LevelSettings.ViewportSize;
//// Resize based on percentage of FULL screen viewport size
_HUD.Resize(HUDScaleMultiplier);
Statics_Engine.LevelSettings.ViewportSize = currentDimensions;
}
}
}
///
/// Copy the new image
///
///
///
void terrain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
///
/// Create the new bitmap onto the terrain and add the csobject to the list
///
///
///
void terrain_DragDrop(object sender, DragEventArgs e)
{
//objectLibrary.humans[0].holdingObject = ObjectLibrary.soloObjects[3];
objectLibrary.humans[0].holdingObject.mass.scale = new Vector3(100);
//// Create the object and attach to Player
//if (tempObj != null)
//{
// //if (tempObj is Waypoint)
// //{
// //}
// //if (tempObj is Actor)
// //{
// //}
// //if (tempObj is Prop)
// //{
// //}
//}
}
///
/// Override XNA function
/// Activate Mouse when window gains focus.
///
///
///
protected override void OnActivated(object sender, EventArgs args)
{
//base.OnActivated(sender, args);
Statics_Engine.SystemSettings.WINDOW_IN_FOCUS = true;
}
///
/// Override XNA function.
/// Deactivate Mouse when window looses focus.
///
///
///
protected override void OnDeactivated(object sender, EventArgs args)
{
//base.OnDeactivated(sender, args);
Statics_Engine.SystemSettings.WINDOW_IN_FOCUS = false;
}
///
/// Toggle game controllers on/off
///
public static void Activate()
{
Statics_Engine.SystemSettings.WINDOW_IN_FOCUS = true;
}
///
/// Deactivate Mouse, Controls, and most of the Update Loop.
///
public static void Deactivate()
{
Statics_Engine.SystemSettings.WINDOW_IN_FOCUS = false;
}
///
/// Activates Mouse, Controller, and unpauses Game when Left-Clicked.
/// Deactivates Mouse, Controller and pauses Game when Right-Clicked.
///
///
///
protected void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
DarkWynterEngine.Activate();
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
DarkWynterEngine.Deactivate();
}
}
///
/// Initiate exit procedure
///
public static void DoExit(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Would you like to close the application?", "Allow Close?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.No)
{
e.Cancel = true;
}
else if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE)
{
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.FINALIZE_G2LSTUFF;
}
else if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.FINALIZE_G2LSTUFF)
{
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.GAME_OVER;
}
else if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_OVER)
{
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.EXIT;
}
}
#endregion
}
}