Welcome.cs :  » Game » SokoSolve-Sokoban » SokoSolve » UI » Controls » Primary » 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 » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » UI » Controls » Primary » Welcome.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using SokoSolve.Common.Math;
using SokoSolve.Core;
using SokoSolve.Core.Model;
using SokoSolve.Core.Model.DataModel;
using SokoSolve.Core.UI;
using SokoSolve.UI.Controls.Secondary;
using SokoSolve.UI.Controls.Web;
using SokoSolve.UI.Section;
using SokoSolve.UI.Section.Library;

namespace SokoSolve.UI.Controls.Primary{
    public partial class Welcome : UserControl
    {
        public Welcome()
        {
            InitializeComponent();

            InitHTML();
        }

        
        /// <summary>
        /// Helper. Retrieve FormMain.
        /// </summary>
        FormMain Form
        {
            get
            {
                FormMain main = FindForm() as FormMain;
                if (main == null) throw new NullReferenceException("FormMain not found. This can only be used after the control is added to the form.");
                return main;
            }
        }

        /// <summary>
        /// Set the HTML
        /// </summary>
        private void InitHTML()
        {
            
                StringBuilder html = new StringBuilder(File.ReadAllText(FileManager.GetContent("$html/Welcome.html")));

                XmlProvider prov = new XmlProvider();

                if (!File.Exists(ProfileController.Current.LibraryLastFile))
                {
                    ProfileController.Current.LibraryLastFile = FileManager.GetContent("$Libraries\\Sasquatch.ssx");
                }

                Core.Model.Library lib = prov.Load(ProfileController.Current.LibraryLastFile);

                HtmlBuilder leftpane = new HtmlBuilder();
                HtmlBuilder rightpane = new HtmlBuilder();
                Current = lib.GetPuzzleByID(ProfileController.Current.LibraryLastPuzzle);
                if (Current == null)
                {
                    ProfileController.Current.LibraryLastPuzzle = lib.Puzzles[0].PuzzleID;
                    Current = lib.Puzzles[0];
                }

                if (Current != null)
                {
                    leftpane.AddSection(null);
                    HtmlReporter.Report(leftpane, Current.Library.Details);

                    rightpane.AddLine("{0}/{1} '<b>{2}</b>'", Current.Order, Current.Library.Puzzles.Count, Current.Details.Name);
                    rightpane.Add("<a href=\"app://Puzzle/{0}\">", Current.PuzzleID);
                    rightpane.Add(Current.MasterMap, DrawingHelper.DrawPuzzle(Current.MasterMap), null);
                    rightpane.Add("</a>");
                    rightpane.AddLine("<br/><i>Click to play...</i>");
                }
                else
                {
                    // Library has no puzzles    
                }

                html = html.Replace("[Details]", leftpane.GetHTMLBody());
                html = html.Replace("[Image]", rightpane.GetHTMLBody());
                html = html.Replace("[BASEHREF]", FileManager.GetContent("$html"));
                html = html.Replace("[USERNAME]", ProfileController.Current.UserName);
                htmlView.SetHTML(html.ToString());
           


            // Perform a version check
            if (ProfileController.Current.LastVersionCheck + new TimeSpan(7, 0, 0, 0) < DateTime.Now)
            {
                HelpCheckVersion.PerformVersionCheck(false);
            }
        }

        private void htmlView_OnCommand(object sender, SokoSolve.UI.Controls.Web.UIBrowserEvent e)
        {
            if (e.Command == new Uri("app://Library"))
            {
                Form.InitLibrary(this.Current.Library);
                Form.Mode = FormMain.Modes.Library;
                return;      
            }

            if (e.Command == new Uri("app://Controller/Home"))
            {
                InitHTML();
                return;
            }

            if (e.Command == new Uri("app://Controller/Back"))
            {
                InitHTML();
                return;
            }

            if (e.Command == new Uri("app://HTML/About.html"))
            {
                htmlView.Navigate(FileManager.GetContent("$html\\About.html"));
                return;
            }

            if (e.Command == new Uri("app://HTML/ReleaseNotes.html"))
            {
                htmlView.Navigate(FileManager.GetContent("$html\\ReleaseNotes.html"));
                return;
            }

            if (e.Command == new Uri("app://HTML/HowToPlay.html"))
            {
                htmlView.Navigate(FileManager.GetContent("$html\\HowToPlay.html"));
                return;
            }

            if (e.Command.ToString().StartsWith("app://puzzle/"))
            {
                Form.StartGame(Current, Current.MasterMap, FormMain.Modes.Welcome);
                return;
            }

            if (e.Command == new Uri("app://Profile"))
            {
                FormProfileSettings settings = new FormProfileSettings();
                settings.ShowDialog();
                InitHTML();
                return;
            }
        }

        private Puzzle Current;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.