using System;
using System.Drawing;
using System.Windows.Forms;
using RealmForge;
using RealmForge.Scripting;
namespace MightAndMagic.UI{
/// <summary>
/// Summary description for Launcher.
/// </summary>
public class Launcher : RealmForge.UI.Forms.Launcher
{
#region Fields and Properties
protected const string launcherBackgroundImage = "MMTLauncher.png";
protected Screen m_LauncherScreen = null;
#endregion
#region Constructors
public Launcher()
{
}
#endregion
#region Methods
protected override void PreConfigure() {
m_LauncherScreen = MMT.ScreenConfig.Screens["startup"] as Screen;
//this.buttons = new string[] { "New", "Load", "Readme", "Options", "Credits", "Quit" };
hoverOverbuttonTextColor = Color.Silver;
buttonTextColor = Color.DarkGoldenrod;
buttonTextFont = new Font("Monotype Corsiva", 26.25f, FontStyle.Italic | FontStyle.Bold, GraphicsUnit.Point);
spaceBetweenButtons = 30;
}
protected override void Configure() {
this.SuspendLayout();
this.BackgroundImage = Image.FromFile(launcherBackgroundImage);
this.Icon = new Icon(StandardResources.RealmForgeIcon);
this.TabStop = false;
this.FormBorderStyle = FormBorderStyle.None;//non resizable and no window border
this.Text = RF.Config.RenderWindowTitle; //title/caption is the same name as the game
this.Name = "Launcher";
this.StartPosition = FormStartPosition.CenterScreen;
this.ClientSize = BackgroundImage.Size; //same as background image size
// CreateClickRegion(new Point(10, this.ClientSize.Height - 104), new Size(96, 96), new EventHandler(this.RealmForgeLogoClicked));
// CreateClickRegion(new Point(480, 16), new Size(103, 216), new EventHandler(this.TitleClicked));//RealmForge Corner Logo
// CreateClickRegion(new Point(16, 8), new Size(215, 155), new EventHandler(this.TitleClicked));//RealmForge Corner Logo
//96x96 at 10,height-104
//103x216 at 480,16
CreateButtons();
this.ResumeLayout(false);
}
protected void TitleClicked(object sender, EventArgs e) {
}
protected void RealmForgeLogoClicked(object sender, EventArgs e) {
Utility.OpenBrowser(StandardUrls.RealmForgeHomepage);
}
protected override void CreateButtons() {
//creates a class that has a method with the EventHandler signature and calls the specified script
//this script requires that the Control be passed as the owner (which it is for EventHandler) and its Control.Tag value hold the string representing the command to do or the window ID to open
// EventHandler clickHandler = new EventHandler(HandleClick);
// CreateButtons(250, 160, 24, new Size(176, 32), clickHandler, buttons );
// TODO: Make this use the configured script handler
foreach(ButtonGroup oGroup in m_LauncherScreen.ButtonGroups)
{
Point startPos = oGroup.Position;
foreach(ScreenButton oButton in oGroup.Buttons)
{
EventHandler evtHandler = new EventHandler(this.HandleClick);
if (oButton is TextScreenButton)
{
TextScreenButton txtBtn = oButton as TextScreenButton;
CreateButton(txtBtn.Text, startPos, new Size(176, 32), txtBtn.ID, evtHandler);
}
else if (oButton is RegionScreenButton)
{
RegionScreenButton rgnBtn = oButton as RegionScreenButton;
CreateClickRegion(rgnBtn.Position, rgnBtn.Size, evtHandler);
}
if (oGroup.Direction == ButtonDirection.Horizontal)
startPos.X += (int)oGroup.ButtonSpacing;
else if (oGroup.Direction == ButtonDirection.Vertical)
startPos.Y += (int)oGroup.ButtonSpacing;
}
}
}
protected bool alreadyStarted = false;
public void ShowRenderWindow() {
RF.Windows.Hide("Launcher");
}
public void HandleClick(object sender, EventArgs e) {
try{
Control button = (Control)sender;
string windowID = (string)button.Tag;
switch(windowID.ToLower()) {
case "play":
if(alreadyStarted)
return; //prevent from erroring when new is pressed 2x in a row
alreadyStarted = true;
RSL.UI.ShowLoadingScreen loadingScreenController = new RSL.UI.ShowLoadingScreen();
loadingScreenController.Show();
//General SwitchTo would be used to change to the RenderWindow from the Launcher, but Axiom automatically
//shows its own window on startup... this also means that we have to wait to customize it until Axiom startup has finished
//which leaves an ugly Axiom windows temporarily and also requires the AxiomIcon.ico to be present
RF.Engine.Initialized.AddHandlers(new SimpleMethod(loadingScreenController.HideLoadingScreen),new SimpleMethod(ShowRenderWindow));
RF.App.StartRendering();
break;
case "Load":
//RF.Windows.Hide("Launcher");
RF.Windows.Show("LoadScreen");
break;
case "Multiplayer":
//RF.Windows.Hide("Launcher");
RF.Windows.Show("PlayerLobby");
break;
case "Options":
//RF.Windows.Hide("Launcher");
RF.Windows.ShowDialog("OptionsDialog");
break;
case "Credits":
//RF.Windows.Hide("Launcher");
RF.Windows.ShowDialog("CreditsDialog");
break;
case "Readme":
RealmForge.Utility.RunFile(StandardResources.ReadmeFile);
break;
case "exit":
RF.App.Shutdown();
break;
}
} catch(Exception ex) {
Log.Write(ex);
Errors.RealmForge("Launcher Button Click failed to handle");
}
}
#endregion
}
}
|