/// <summary>
        /// Dragdrop - process file drops
        /// Add them if appropriate
        /// </summary>
        void modEntriesPanel_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList())
            {
                StringCollection filePaths = ((DataObject)e.Data).GetFileDropList();

                //Get all files that were dropped in, by searching subdirectories too
                List<String> resultFiles = new List<string>();
                foreach (string path in filePaths)
                    if ((new FileInfo(path).Attributes & FileAttributes.Directory) != 0)
                    {
                        resultFiles.AddRange(Util.GetAllChildFiles(path));
                    }
                    else
                        resultFiles.Add(path);

                List<TreeNode> resultantNodes = new List<TreeNode>();
                string iconPath = null;

                //If there is a script it overrides default action
                RMPropInterpreter script = null;
                foreach (string path in resultFiles)
                {
                    string rafPath = GuessRafPathFromPath(path);
                    if (rafPath != "undefined")
                    {
                        TreeNode node = new TreeNode(path.Replace("\\", "/").Split("/").Last());
                        node.Nodes.Add("Local Path: " + path);
                        node.Nodes.Add("RAF Path: " + rafPath);
                        node.Tag = new ModEntryNodeTag()
                        {
                            localPath = path,
                            rafPath = rafPath
                        };
                        resultantNodes.Add(node);
                    }
                    else
                    {   //We usually skip it if it is undefined.  We have some special cases
                        if (path.EndsWith("rafmanagericon.jpg"))
                        {
                            iconPath = path;
                        }
                        else if (path.EndsWith("rafmanagerscript"))
                        {
                            try
                            {
                                script = new RMPropInterpreter(
                                    path,
                                    this
                                );
                            }catch(Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }else
                            Log("Unable to resolve local path to RAF path: " + path);
                    }
                }

                ModEntry modEntry = null;
                if (script == null)
                {
                    //resultFiles has all our files.
                    StringQueryDialog sqd = new StringQueryDialog("What is the name of the mod that you are dropping into RAF Manager?");
                    sqd.ShowDialog();
                    if (sqd.Value == "") return;
                    modEntry = CreateAndAppendModEntry(sqd.Value, "-", "-", resultantNodes.ToArray());
                }
                else
                {
                    modEntry = CreateAndAppendModEntry(script.Name, script.Creator, script.WebsiteURL, resultantNodes.ToArray());
                    modEntry.Script = script;
                }

                try
                {
                    if (iconPath != null)
                    {
                        modEntry.IconImage = Bitmap.FromFile(iconPath);
                        modEntry.IconImage.Tag = iconPath;
                    }
                }
                catch { }
            }
        }
Exemple #2
0
        public ModOptionsWindow(RMPropInterpreter script)
        {
            InitializeComponent();

            this.Load += new EventHandler(ModOptionsWindow_Load);

            this.ControlBox = false;

            List <Setting> settings = script.Settings;
            Graphics       g        = this.CreateGraphics();

            int padding           = 2;
            int comboBoxWidth     = 150;
            int longestLabelWidth = 0;

            for (int i = 0; i < settings.Count; i++)
            {
                longestLabelWidth = Math.Max(longestLabelWidth, (int)g.MeasureString(settings[i].Label, font).Width);
            }

            this.ClientSize = new System.Drawing.Size(
                padding + longestLabelWidth + padding + comboBoxWidth + padding,
                this.ClientSize.Height
                );
            int offsetY = 2;

            for (int i = 0; i < settings.Count; i++)
            {
                Setting  setting  = settings[i];
                Label    label    = new Label();
                ComboBox comboBox = new ComboBox();

                label.Text      = setting.Label;
                label.ForeColor = Color.FromArgb(230, 230, 230);
                comboBox.Items.AddRange(setting.GetOptions());
                comboBox.SelectedItem          = setting.SelectedValue;
                comboBox.SelectedIndexChanged += delegate(object sender, EventArgs e)
                {
                    setting.SelectedValue = (string)comboBox.SelectedItem;
                };
                comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

                label.Top       = offsetY;
                comboBox.Top    = offsetY;
                comboBox.Width  = comboBoxWidth;
                comboBox.Left   = this.ClientSize.Width - comboBox.Width - padding;
                label.Width     = (int)g.MeasureString(label.Text, font).Width;
                label.Left      = comboBox.Left - label.Width - padding;
                label.Height    = comboBox.Height;
                label.TextAlign = ContentAlignment.MiddleRight;

                offsetY += padding + Math.Max(label.Height, comboBox.Height);

                this.Controls.Add(label);
                this.Controls.Add(comboBox);
            }

            Button done = new Button();

            done.Text      = "Done";
            done.Top       = offsetY;
            done.Left      = this.ClientSize.Width - done.Width - padding;
            done.Click    += new EventHandler(done_Click);
            done.BackColor = SystemColors.Control;
            offsetY       += done.Height + padding;
            this.Controls.Add(done);
            this.ClientSize = new Size(
                this.ClientSize.Width,
                offsetY
                );
        }
Exemple #3
0
        /// <summary>
        /// Dragdrop - process file drops
        /// Add them if appropriate
        /// </summary>
        void modEntriesPanel_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList())
            {
                StringCollection filePaths = ((DataObject)e.Data).GetFileDropList();

                //Get all files that were dropped in, by searching subdirectories too
                List <String> resultFiles = new List <string>();
                foreach (string path in filePaths)
                {
                    if ((new FileInfo(path).Attributes & FileAttributes.Directory) != 0)
                    {
                        resultFiles.AddRange(Util.GetAllChildFiles(path));
                    }
                    else
                    {
                        resultFiles.Add(path);
                    }
                }

                List <TreeNode> resultantNodes = new List <TreeNode>();
                string          iconPath       = null;

                //If there is a script it overrides default action
                RMPropInterpreter script = null;
                foreach (string path in resultFiles)
                {
                    string rafPath = GuessRafPathFromPath(path);
                    if (rafPath != "undefined")
                    {
                        TreeNode node = new TreeNode(path.Replace("\\", "/").Split("/").Last());
                        node.Nodes.Add("Local Path: " + path);
                        node.Nodes.Add("RAF Path: " + rafPath);
                        node.Tag = new ModEntryNodeTag()
                        {
                            localPath = path,
                            rafPath   = rafPath
                        };
                        resultantNodes.Add(node);
                    }
                    else
                    {   //We usually skip it if it is undefined.  We have some special cases
                        if (path.EndsWith("rafmanagericon.jpg"))
                        {
                            iconPath = path;
                        }
                        else if (path.EndsWith("rafmanagerscript"))
                        {
                            try
                            {
                                script = new RMPropInterpreter(
                                    path,
                                    this
                                    );
                            }catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                        else
                        {
                            Log("Unable to resolve local path to RAF path: " + path);
                        }
                    }
                }

                ModEntry modEntry = null;
                if (script == null)
                {
                    //resultFiles has all our files.
                    StringQueryDialog sqd = new StringQueryDialog("What is the name of the mod that you are dropping into RAF Manager?");
                    sqd.ShowDialog();
                    if (sqd.Value == "")
                    {
                        return;
                    }
                    modEntry = CreateAndAppendModEntry(sqd.Value, "-", "-", resultantNodes.ToArray());
                }
                else
                {
                    modEntry        = CreateAndAppendModEntry(script.Name, script.Creator, script.WebsiteURL, resultantNodes.ToArray());
                    modEntry.Script = script;
                }

                try
                {
                    if (iconPath != null)
                    {
                        modEntry.IconImage     = Bitmap.FromFile(iconPath);
                        modEntry.IconImage.Tag = iconPath;
                    }
                }
                catch { }
            }
        }
        public ModOptionsWindow(RMPropInterpreter script)
        {
            InitializeComponent();

            this.Load += new EventHandler(ModOptionsWindow_Load);

            this.ControlBox = false;

            List<Setting> settings = script.Settings;
            Graphics g = this.CreateGraphics();
            
            int padding = 2;
            int comboBoxWidth = 150;
            int longestLabelWidth = 0;
            for (int i = 0; i < settings.Count; i++)
                longestLabelWidth = Math.Max(longestLabelWidth, (int)g.MeasureString(settings[i].Label, font).Width);

            this.ClientSize = new System.Drawing.Size(
                padding + longestLabelWidth + padding + comboBoxWidth + padding,
                this.ClientSize.Height
            );
            int offsetY = 2;
            for (int i = 0; i < settings.Count; i++)
            {
                Setting setting = settings[i];
                Label label = new Label();
                ComboBox comboBox = new ComboBox();

                label.Text = setting.Label;
                label.ForeColor = Color.FromArgb(230, 230, 230);
                comboBox.Items.AddRange(setting.GetOptions());
                comboBox.SelectedItem = setting.SelectedValue;
                comboBox.SelectedIndexChanged += delegate(object sender, EventArgs e)
                {
                    setting.SelectedValue = (string)comboBox.SelectedItem;
                };
                comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

                label.Top = offsetY;
                comboBox.Top = offsetY;
                comboBox.Width = comboBoxWidth;
                comboBox.Left = this.ClientSize.Width - comboBox.Width - padding;
                label.Width = (int)g.MeasureString(label.Text, font).Width;
                label.Left = comboBox.Left - label.Width - padding;
                label.Height = comboBox.Height;
                label.TextAlign = ContentAlignment.MiddleRight;

                offsetY += padding + Math.Max(label.Height, comboBox.Height);

                this.Controls.Add(label);
                this.Controls.Add(comboBox);
            }

            Button done = new Button();
            done.Text = "Done";
            done.Top = offsetY;
            done.Left = this.ClientSize.Width - done.Width - padding;
            done.Click += new EventHandler(done_Click);
            done.BackColor = SystemColors.Control;
            offsetY += done.Height + padding;
            this.Controls.Add(done);
            this.ClientSize = new Size(
                this.ClientSize.Width,
                offsetY
            );
        }