using System;
using System.Windows.Forms;
using System.Drawing;
using RealmForge;
using RealmForge.Scripting;
using RealmForge.UI;
using RealmForge.UI.Forms;
using RealmForge.Scene;
using RealmForge.SceneObjects;
using RealmForge.Modules;
using RealmForge.Serialization;
using RealmForge.Reflection;
using RealmForge.Primitives;
using RealmForge.Rendering;
using MightAndMagic.UI;
namespace MightAndMagic{
/// <summary>
/// Startup plugin for the engine that initializes the Might and Magic Tribute (MMT) game, registers its master modules, and provides the entrance point for the application
/// </summary>
/// <remarks>This plugin is instantiated right after the Modules config is loaded since it is located in a the application or entry-point assembly.
/// The constructor will be called before even the Startup Plugins are started and would as well if this was a plugin listed
/// in the PreInitializationModules section of Modules.config.</remarks>
public class MMT : IPlugin
{
#region Fields and Properties
internal static ScreenConfig ScreenConfig = null;
#endregion
#region Constructors
public MMT()
{
//register module to be loaded or replace existing registration with one that has IsActive set to true
RF.Modules.Config.Modules.Create("MMT", ModuleType.MasterModule);
RF.Modules.Config.Modules.Create("../MMTMedia", ModuleType.MediaPack);
}
#endregion
#region Static Methods
/// <summary>
/// Entrance point for the application
/// </summary>
/// <param name="args"></param>
[STAThread()]
public static void Main(string[] args) {
//Startup RealmForge and the AppManager and continue loading resources until rendering starts
//Subscribe or monitor to different events when an instance of this Game plugin class is automatically created and started
RF.Start();
}
#endregion
#region Methods
public void Start() {
RF.Classes.RegisterTypes(
typeof(UI.TextScreenButton),
typeof(UI.RegionScreenButton),
typeof(UI.ButtonDirection),
typeof(UI.ButtonGroup),
typeof(UI.Screen),
typeof(UI.Parameter));
ScreenConfig = (ScreenConfig)Serializer.Deserialize(typeof(ScreenConfig), Files.Inteface);
MainRenderForm renderWindow = new MainRenderForm();
renderWindow.Icon = new Icon("MMT.ico");
//renderWindow.TopMost = true; //difficult to debug with this
RF.Windows.Register(RF.Config.RenderWindowID,renderWindow);
//RF.Engine.RenderWindowCreated.AddHandler(renderWindowCreator);
//RF.Engine.RenderWindowCreated.AddHandler(new Script(ConfigureRenderWindow));
RF.Modules.Config.StartupRealm = "Serenity";
RF.Config.RenderWindowTitle = "Might and Magic Tribute";
RF.Windows.StartupWindowName = "Launcher";
RF.Windows.RegisterWindowCreator("Launcher", new Script(CreateLauncher));
RF.Engine.SceneCreated.AddHandler(new Script(CreateScene));
}
protected void CreateLauncher(object owner, object args) {
try{
string windowID = (string)args;
Form f = new MightAndMagic.UI.Launcher();
f.Load += new EventHandler(BringWindowToFront);
if(owner != null)
((IWindowManager)owner).Register(windowID,f); //incase the primary manager isnt used
else
RF.Windows.Register(windowID,f);
} catch(Exception e) {
Log.Write(e);
}
}
protected void BringWindowToFront(object sender, EventArgs e)
{
((Form)sender).BringToFront();
}
protected void CreateScene(object owner, object args) {
RF.Scene.Sky = SkyInfo.CreateDome("RF/Skies/Cloudy", 8f, 5f, 4000f);
RF.Scene.AmbientLight = Color.Gray;
RF.Scene.SkyEnabled = true;
RF.Camera.LookAt(RF.Scene.GetSceneNode("Dragon"));
RF.Resources.ShowGuiOverlay("MMT/Overlays/InGame/DebugOverlay");
RF.Resources.ShowGuiOverlay("MMT/Overlays/InGameHUD");
//ISceneObject obj = RF.Scene.GetSceneObject("Tavern");
//obj.OrientationAngles = new Vector3(-90, 90, 0);
//Axiom.Overlays.Overlay overlay = Axiom.Overlays.OverlayManager.Instance.GetByName("MMT/Overlays/InGameHUD");
//Axiom.Overlays.OverlayElementContainer elementC = overlay.GetChild("MMT/Overlays/InGameHUD/StatusText");
// Render the minimap...
// Axiom.Overlays.OverlayElementContainer elementContainer = Axiom.Overlays.OverlayElementManager.Instance.GetElement("MMT/Overlays/InGameHUD/MiniMap") as Axiom.Overlays.OverlayElementContainer;
// if (elementContainer != null)
// {
// //elementContainer
// }
RF.Timer.AddPeriodHandler(1f, new Script(UpdateRenderStats));
// SceneBuilder scene = RF.SceneObjects;
//
// //create a plane of water that can be deformed to simulate splashes
// PlaneInfo plane = new PlaneInfo(22800, 22800, 0);
// plane.SubdivisionsX = plane.SubdivisionsY = 64;
// AxiomWaterRegion water = new AxiomWaterRegion("Water", null, plane);
// water.FastNormalCalculations = true; //fake the normals, by default
// scene.AddNewObject(water);
}
protected void UpdateRenderStats(object owner, object args)
{
FPSInfo fps = RF.Engine.Stats;
//RF.Engine.SetGuiElementText("MMT/Overlays/InGame/DebugOverlay/CurrFps", "Current FPS: " + fps.Current);
RF.Resources.UpdateGuiElements(
"MMT/Overlays/InGame/DebugOverlay/CurrFps", String.Format("Current FPS: {0:##0}", fps.Current),
"MMT/Overlays/InGame/DebugOverlay/BestFps", String.Format("Best FPS: {0:##0}", fps.Best),
"MMT/Overlays/InGame/DebugOverlay/WorstFps", String.Format("Worst FPS: {0:##0}", fps.Worst),
"MMT/Overlays/InGame/DebugOverlay/AverageFps", String.Format("Average FPS: {0:##0}", fps.Average),
"MMT/Overlays/InGame/DebugOverlay/NumTris", String.Format("Triangle Count: {0:#,##0}", RF.Engine.PolygonsRenderedLastFrame));
//RF.Engine.SetGuiElementText("MMT/Overlays/InGameHUD/StatusText", String.Format("Character Position: {0}", RF.Scene.GetSceneObject("MainCamera").AbsolutePosition.ToString()));
}
public bool IsMapVisible = false;
public void Stop()
{
}
#endregion
internal class Files
{
private Files() {}
public static string Inteface = "MMT/Config/mmt_interface.xml";
}
internal class Icons
{
private Icons() {}
public static string MMTIcon = @"MMT.ico";
}
}
}
|