Launcher.cs :  » Game » RealmForge » MightAndMagic » UI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » MightAndMagic » UI » Launcher.cs
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
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.