/[RomCheater]/trunk/RomCheater.RVAScratchPad/Form1.cs
ViewVC logotype

Diff of /trunk/RomCheater.RVAScratchPad/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.RVAScratchPad/Form1.cs	2013/06/18 07:04:57	707
+++ trunk/RomCheater.RVAScratchPad/Form1.cs	2013/06/18 10:25:55	713
@@ -5,14 +5,227 @@
 using System.Drawing;
 using System.Text;
 using System.Windows.Forms;
+using RomCheater.Logging;
+using RomCheater.Docking;
+using WeifenLuo.WinFormsUI.Docking;
+using System.IO;
+using RomCheater.PluginFramework.Core;
+using RomCheater.Core;
 
 namespace RomCheater.RVAScratchPad
 {
     public partial class Form1 : Form
     {
-        public Form1()
+        private bool m_bSaveLayout = true;
+        PluginLoader loader = null;
+        IConfigPlugin ConfigPlugin = null;
+
+        IUserControlPlugin RVACalcPlugin = null;
+        IUserControlPlugin ScratchPadPlugin = null;
+
+        private DeserializeDockContent m_deserializeDockContent;
+        private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
+        private FloatingWebBrowser m_wb = new FloatingWebBrowser();
+
+        #region LogWriterSupport
+        static LogWriter _LoggerInstance;
+        static LogWriter LoggerInstance
+        {
+            get { return _LoggerInstance; }
+            set { _LoggerInstance = value; }
+        }
+        #endregion
+
+        public Form1() : this(false) { }
+        public Form1(bool no_console_redirect)
         {
             InitializeComponent();
+            load_loggerflags();
+            //SetupDocks();
+            LoggerInstance = m_LogWindow.Logwriter;
+            LoggerInstance.CreateNewLog(false);
+            logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
+            load_plugins();
+            if (no_console_redirect)
+                LoggerInstance.RedirectConsoleOutput = false;           
+        }
+        private void load_loggerflags()
+        {
+            logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
+#if FORCE_ALL_LOGGING_FLAGS
+            logger.SetLoggingFlags(loggerflags.ALL);
+#endif
+        }
+        private void load_plugins() { load_plugins(false); }
+        private void load_plugins_silent() { load_plugins(true); }
+        private void load_plugins(bool silent)
+        {
+            loader = new PluginLoader();
+            loader.LoadPlugins(silent);
+
+
+            ConfigPlugin = loader.GetGenericConfigPlugin();
+            if (ConfigPlugin != null && !silent)
+                logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
+
+            //var UserControlPlugins = new List<IUserControlPlugin>(loader.LoadedUserControlPlugins);
+            //foreach (var userplugin in UserControlPlugins) { }
+
+
+            //var config_guids = loader.GetKnownPluginGuids<IConfigPlugin>();
+            //var input_guids = loader.GetKnownPluginGuids<IInputPlugin>();
+            //var window_guids = loader.GetKnownPluginGuids<IWindowPlugin>();
+            //var userplugin_guids = loader.GetKnownPluginGuids<IUserControlPlugin>();
+            //var plugin1 = loader.GetPluginByName<IUserControlPlugin>("ScratchPad Plugin");
+            //var plugin2 = loader.GetPluginByName<IUserControlPlugin>("RVA Calculator Plugin");
+
+
+            //var plugin1 = PluginCollection.UserControlPlugins.CheatCodePlugin.Plugin;
+            //var plugin2 = PluginCollection.UserControlPlugins.EmuMMAPPlugin.Plugin;
+            //var plugin3 = PluginCollection.UserControlPlugins.RVACalculatorPlugin.Plugin;
+            //var plugin4 = PluginCollection.UserControlPlugins.ScratchPadPlugin.Plugin;
+
+            //var plugin1 = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
+            //var plugin2 = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);            
+
+            var plugins = PluginCollection.GetPluginsByType(PluginType.Window);
+
+        }
+
+
+
+        #region Dock Support
+        //void AddDockToWindowList(object sender, EventArgs e)
+        //{
+        //    DockContent dc;
+        //    TypeBinder.Bind(sender, out dc);
+        //    ToolStripMenuItem tsmi = new ToolStripMenuItem(dc.Text);
+        //    tsmi.Name = dc.Name;
+        //    tsmi.Tag = dc;
+        //    tsmi.Click += new EventHandler(tsmi_Click);
+        //    mnuWindows.DropDownItems.Add(tsmi);
+        //}
+        //void tsmi_Click(object sender, EventArgs e)
+        //{
+        //    ToolStripMenuItem tsmi;
+        //    TypeBinder.Bind(sender, out tsmi);
+        //    DockContent dc;
+        //    TypeBinder.Bind(tsmi.Tag, out dc);
+        //    dc.Activate();
+        //}
+        //void RemoveDockFromWindowList(object sender, FormClosedEventArgs e)
+        //{
+        //    DockContent dc;
+        //    TypeBinder.Bind(sender, out dc);
+        //    mnuWindows.DropDownItems.RemoveByKey(dc.Name);
+        //}
+        private IDockContent GetContentFromPersistString(string persistString)
+        {
+            if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
+            if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
+            else { return null; }
+        }
+        public void SetupDocks()
+        {
+            m_LogWindow = new FloatingLogWindow();
+            m_wb = new FloatingWebBrowser();
+        }
+        #region SetupDockWindowHandler support
+        public void SetupDockWindowHandler()
+        {
+            SetupLogWindowHandler();
+            SetupWebBrowserWindowHandler();
+        }
+        private void SetupLogWindowHandler()
+        {
+            if (m_LogWindow == null) return;
+            //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
+            //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
+            m_LogWindow.Activate();
+        }
+        private void SetupWebBrowserWindowHandler()
+        {
+            if (m_wb == null) return;
+            //m_wb.Shown += new EventHandler(AddDockToWindowList);
+            //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
+            //m_wb.Activate();
+        }
+        #endregion
+        public void ShowDocks()
+        {
+            ShowLogWindow();
+            SetupLogWindowHandler();
+            ShowWebBrowser();
+            SetupWebBrowserWindowHandler();
+        }
+        public void ShowLogWindow()
+        {
+            if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
+            LoggerInstance = m_LogWindow.Logwriter;
+            LoggerInstance.CreateNewLog(false);
+            m_LogWindow.CloseButton = false;
+            m_LogWindow.CloseButtonVisible = false;
+            m_LogWindow.Show(dockPanel, DockState.DockBottom);
+        }
+
+
+        public void ShowWebBrowser()
+        {
+            //load_plugins_silent();
+            m_wb = new FloatingWebBrowser();
+            m_wb.CloseButton = false;
+            m_wb.CloseButtonVisible = false;
+            m_wb.Show(dockPanel);
+        }
+        #endregion
+
+        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
+            if (m_bSaveLayout)
+                dockPanel.SaveAsXml(configFile);
+            else if (File.Exists(configFile))
+                File.Delete(configFile);
+            // notify any docked windows of formclosing
+            foreach (var t in this.dockPanel.Contents)
+            {
+                t.OnDeactivate<FormClosingEventArgs>(e);
+            }
+        }
+
+        private void Form1_Shown(object sender, EventArgs e)
+        {
+            //dockPanel.SuspendLayout(true);
+            //ShowDocks();
+            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
+            if (File.Exists(configFile))
+            {
+                try
+                {
+                    dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
+                    SetupDockWindowHandler();
+                }
+                catch (Exception)
+                {
+                    this.Controls.Remove(dockPanel);
+                    dockPanel = new DockPanel();
+                    dockPanel.Dock = DockStyle.Fill;
+                    dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
+                    this.Controls.Add(dockPanel);
+                    ShowDocks();
+                }
+            }
+            else
+            {
+                ShowDocks();
+            }
+
+            //dockPanel.ResumeLayout(true, true);
+        }
+
+        private void mnuItemExit_Click(object sender, EventArgs e)
+        {
+            this.Close();
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22