ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/RomCheaterConfigDialog.cs
(Generate patch)

Comparing trunk/RomCheater/RomCheaterConfigDialog.cs (file contents):
Revision 63 by william, Wed May 9 16:14:39 2012 UTC vs.
Revision 92 by william, Wed May 9 21:42:21 2012 UTC

--- trunk/RomCheater/RomCheaterConfigDialog.cs	2012/05/09 16:14:39	63
+++ trunk/RomCheater/RomCheaterConfigDialog.cs	2012/05/09 21:42:21	92
@@ -7,19 +7,79 @@ using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using RomCheater.Logging;
+using RomCheater.PluginFramework.Core;
+using RomCheater.PluginFramework.Interfaces;
 
 namespace RomCheater
 {
     public partial class RomCheaterConfigDialog : Form
     {
+        private PluginLoader loader = null;
         public RomCheaterConfigDialog()
         {
             InitializeComponent();
         }
-
+        public RomCheaterConfigDialog(PluginLoader loader) : this()
+        {
+            this.loader = loader;
+        }
         private void RomCheaterConfigDialog_Load(object sender, EventArgs e)
         {
-            foreach(loggerflags flags in Enum.GetValues(typeof(loggerflags)))
+            logger.Info.WriteLine("Loading user settings...");
+            load_loggerflags();
+            setup_plugin_entries();
+            logger.Info.WriteLine("Loaded user settings.");
+        }
+
+        private void setup_plugin_entries()
+        {
+            foreach (IConfigPlugin c in loader.LoadedConfigPlugins) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]",c.Name, c.Id.ToString())); }
+            foreach (IInputPlugin c in loader.LoadedInputPlugins) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.Id.ToString())); }
+            foreach (IWindowPlugin c in loader.LoadedWindowPlugins) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.Id.ToString())); }
+            if (loader.LoadedConfigPlugins.Count == 0) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+            if (loader.LoadedInputPlugins.Count == 0) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+            if (loader.LoadedWindowPlugins.Count == 0) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+
+            comboConfigPlugins.SelectedIndex = 0;
+            comboInputPlugins.SelectedIndex = 0;
+            comboWindowPlugins.SelectedIndex = 0;
+
+            // select each plugin base on the last plugin
+            foreach (string item in comboConfigPlugins.Items)
+            {
+                if (item == RomCheater.Properties.Settings.Default.LastConfigPlugin)
+                {
+                    logger.Debug.WriteLine("    loading LastConfigPlugin: {0}", RomCheater.Properties.Settings.Default.LastConfigPlugin);
+                    comboConfigPlugins.SelectedIndex = comboConfigPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+            foreach (string item in comboInputPlugins.Items)
+            {
+                if (item == RomCheater.Properties.Settings.Default.LastInputPlugin)
+                {
+                    logger.Debug.WriteLine("    loading LastInputPlugin: {0}", RomCheater.Properties.Settings.Default.LastInputPlugin);
+                    comboInputPlugins.SelectedIndex = comboInputPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+            foreach (string item in comboWindowPlugins.Items)
+            {
+                if (item == RomCheater.Properties.Settings.Default.LastWindowPlugin)
+                {
+                    logger.Debug.WriteLine("    loading LastWindowPlugin: {0}", RomCheater.Properties.Settings.Default.LastWindowPlugin);
+                    comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+
+        }
+
+        private void load_loggerflags()
+        {
+            logger.Debug.WriteLine("Loading logger flags...");
+            loggerflags logflags = (loggerflags)Logging.Properties.Settings.Default.LoggingFlags;
+            foreach (loggerflags flags in Enum.GetValues(typeof(loggerflags)))
             {
                 if (flags == loggerflags.ALL ||
                     flags == loggerflags.NONE ||
@@ -34,19 +94,21 @@ namespace RomCheater
                 chkloggerflags.Text = name;
                 chkloggerflags.Tag = value;
                 grpLoggingFlags_flow.Controls.Add(chkloggerflags);
-                loggerflags logflags = (loggerflags)Logging.Properties.Settings.Default.LoggingFlags;
+                logger.Debug.WriteLine("\tAdding logger flag: {0} value: 0x{1:x4}", name, value);
 
                 if (logflags.HasFlag((loggerflags)value))
                 {
                     chkloggerflags.Checked = true;
+                    logger.Debug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, value);
                 }
             }
             grpLoggingFlags.AutoSize = true;
             grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+            logger.Debug.WriteLine("Loaded logger flags.");
         }
-
         private void btnSave_Click(object sender, EventArgs e)
         {
+            logger.Info.WriteLine("Saving user settings...");
             SaveSettings();
             this.Close();
         }
@@ -54,23 +116,38 @@ namespace RomCheater
         {
             this.Close();
         }
-
         private void SaveSettings()
         {
             SaveLoggingFlags();
+            SaveSelectedPlugins();
             RomCheater.Properties.Settings.Default.Save();
             Logging.Properties.Settings.Default.Save();
+            logger.Info.WriteLine("Saved user settings.");
+        }
+        private void SaveSelectedPlugins()
+        {
+            logger.Debug.WriteLine("    Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
+            RomCheater.Properties.Settings.Default.LastConfigPlugin = comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString();
+
+            logger.Debug.WriteLine("    Setting LastInputPlugin to {0}", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString());
+            RomCheater.Properties.Settings.Default.LastInputPlugin = comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString();
+
+            logger.Debug.WriteLine("    Setting LastWindowPlugin to {0}", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString());
+            RomCheater.Properties.Settings.Default.LastWindowPlugin = comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString();
         }
         private void SaveLoggingFlags()
         {
+            logger.Debug.WriteLine("Saving Logger flags...");
             loggerflags logflags = loggerflags.NONE;
             foreach (CheckBox cb in grpLoggingFlags_flow.Controls)
             {
                 if (!cb.Checked) continue;
-                int value = Convert.ToInt32(cb.Tag);
+                int value = Convert.ToInt32(cb.Tag);                
                 logflags = logflags | (loggerflags)value;
+                logger.Debug.WriteLine("\tAdding flag: {0} value: 0x{1:x4} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags);                
             }
             Logging.Properties.Settings.Default.LoggingFlags = (int)logflags;
+            logger.Debug.WriteLine("Saved Logger flags.");
         }
     }
 }