コード例 #1
0
        private void LoadAndShowTree()
        {
            if (!GetTreeFileName(false))
            {
                return;
            }

            LoadedTree = null;

            GUIObject root = LoadTree(TreeFileName);

            while (Hierarchy.Nodes.Count > 0)
            {
                ((GUIObject)Hierarchy.Nodes[0].Tag).Delete();
            }

            root.RefreshRepresentation(true);

            GUIObject obj = root.FindSelected();

            if (obj != null)
            {
                obj.Selected = true;
            }
            else
            {
                root.Selected = true;
            }

            LoadedTree = root;
        }
コード例 #2
0
        public MainForm()
        {
            Instance = this;
            InitializeComponent();

            // Optimize panel drawing
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, Design, new object[] { true });

            // Setup paths
            Func <string, string> fixPath = delegate(string path)
            {
                path = path.Replace('/', '\\');
                if (!path.EndsWith("\\"))
                {
                    path += "\\";
                }
                return(Path.GetFullPath(path));
            };
            IniFile config = new IniFile(".\\FOnline.cfg");

            Utilites.GuiPath          = fixPath(config.IniReadValue("Options", "GuiPath", @""));
            Utilites.GuiOutputPath    = fixPath(config.IniReadValue("Options", "GuiOutputPath", @""));
            Utilites.GuiResourcesPath = fixPath(config.IniReadValue("Options", "GuiResourcesPath", @""));

            // Load default scheme
            LoadScheme(Utilites.GuiPath + "Default.foguischeme");

            // Hierarchy drag and drop
            Hierarchy.ItemDrag += delegate(object sender, ItemDragEventArgs e)
            {
                DoDragDrop(e.Item, DragDropEffects.Move);
            };
            Hierarchy.DragEnter += delegate(object sender, DragEventArgs e)
            {
                e.Effect = DragDropEffects.Move;
            };
            Hierarchy.DragDrop += delegate(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
                {
                    TreeView tree     = (TreeView)sender;
                    Point    pt       = tree.PointToClient(new Point(e.X, e.Y));
                    TreeNode destNode = tree.GetNodeAt(pt);
                    TreeNode srcNode  = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                    if (srcNode.Parent != null && destNode != null && srcNode != destNode && ((GUIObject)srcNode.Tag).Find(((GUIObject)destNode.Tag).Name) == null)
                    {
                        ((GUIObject)srcNode.Tag).AssignParent((GUIObject)destNode.Tag);
                    }
                }
            };

            // Hierarchy node selection
            Hierarchy.NodeMouseClick += delegate(object sender, TreeNodeMouseClickEventArgs e)
            {
                Hierarchy.SelectedNode = e.Node;
                Design.Invalidate();
            };
            Hierarchy.AfterSelect += delegate(object sender, TreeViewEventArgs e)
            {
                Properties.SelectedObject = e.Node.Tag;
                Design.Invalidate();
            };

            // Hierarchy menu strip
            ToolStripMenuItem addMenuStrip = new ToolStripMenuItem("Add");

            addMenuStrip.DropDownItems.Add("Panel").Tag       = (Action <GUIObject>) delegate(GUIObject obj) { new GUIPanel(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Button").Tag      = (Action <GUIObject>) delegate(GUIObject obj) { new GUIButton(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("CheckBox").Tag    = (Action <GUIObject>) delegate(GUIObject obj) { new GUICheckBox(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("RadioButton").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIRadioButton(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Text").Tag        = (Action <GUIObject>) delegate(GUIObject obj) { new GUIText(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Text Input").Tag  = (Action <GUIObject>) delegate(GUIObject obj) { new GUITextInput(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Message Box").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIMessageBox(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Console").Tag     = (Action <GUIObject>) delegate(GUIObject obj) { new GUIConsole(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Grid").Tag        = (Action <GUIObject>) delegate(GUIObject obj) { new GUIGrid(obj).RefreshRepresentation(false); };
            addMenuStrip.DropDownItems.Add("Item View").Tag   = (Action <GUIObject>) delegate(GUIObject obj) { new GUIItemView(obj).RefreshRepresentation(false); };

            ToolStripMenuItem convertMenuStrip = new ToolStripMenuItem("Convert");

            convertMenuStrip.DropDownItems.Add("Panel").Tag       = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIPanel(obj)); };
            convertMenuStrip.DropDownItems.Add("Button").Tag      = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIButton(obj)); };
            convertMenuStrip.DropDownItems.Add("CheckBox").Tag    = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUICheckBox(obj)); };
            convertMenuStrip.DropDownItems.Add("RadioButton").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIRadioButton(obj)); };
            convertMenuStrip.DropDownItems.Add("Text").Tag        = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIText(obj)); };
            convertMenuStrip.DropDownItems.Add("Text Input").Tag  = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUITextInput(obj)); };
            convertMenuStrip.DropDownItems.Add("Message Box").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIMessageBox(obj)); };
            convertMenuStrip.DropDownItems.Add("Console").Tag     = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIConsole(obj)); };
            convertMenuStrip.DropDownItems.Add("Grid").Tag        = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIGrid(obj)); };
            convertMenuStrip.DropDownItems.Add("Item View").Tag   = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIItemView(obj)); };

            ToolStripMenuItem moveUpMenuStrip = new ToolStripMenuItem("Move node up");

            moveUpMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null)
                                                                                 {
                                                                                     obj.MoveUp();
                                                                                 }
            };

            ToolStripMenuItem moveDownMenuStrip = new ToolStripMenuItem("Move node down");

            moveDownMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null)
                                                                                   {
                                                                                       obj.MoveDown();
                                                                                   }
            };

            ToolStripMenuItem deleteMenuStrip = new ToolStripMenuItem("Delete node");

            deleteMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null)
                                                                                 {
                                                                                     obj.Delete();
                                                                                 }
            };

            ToolStripMenuItem newTreeMenuStrip = new ToolStripMenuItem("New GUI");

            newTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { NewTree(); };

            ToolStripMenuItem loadTreeMenuStrip = new ToolStripMenuItem("Load GUI");

            loadTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { LoadAndShowTree(); };

            ToolStripMenuItem saveTreeMenuStrip = new ToolStripMenuItem("Save GUI");

            saveTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SaveTree(obj, false); GenerateScheme(); };

            ToolStripMenuItem saveAsTreeMenuStrip = new ToolStripMenuItem("Save GUI As");

            saveAsTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SaveTree(obj, true); GenerateScheme(); };

            ToolStripMenuItem setCoordsTreeMenuStrip = new ToolStripMenuItem("Set Coords");

            setCoordsTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SetCoords(); };

            ContextMenuStrip hierarchyMenuStrip = new ContextMenuStrip();

            hierarchyMenuStrip.Items.Add(addMenuStrip);
            hierarchyMenuStrip.Items.Add(convertMenuStrip);
            hierarchyMenuStrip.Items.Add(moveUpMenuStrip);
            hierarchyMenuStrip.Items.Add(moveDownMenuStrip);
            hierarchyMenuStrip.Items.Add(deleteMenuStrip);
            hierarchyMenuStrip.Items.Add(newTreeMenuStrip);
            hierarchyMenuStrip.Items.Add(loadTreeMenuStrip);
            hierarchyMenuStrip.Items.Add(saveTreeMenuStrip);
            hierarchyMenuStrip.Items.Add(saveAsTreeMenuStrip);
            hierarchyMenuStrip.Items.Add(setCoordsTreeMenuStrip);

            ToolStripItemClickedEventHandler clickHandler = delegate(object sender, ToolStripItemClickedEventArgs e)
            {
                if (e.ClickedItem.Tag != null)
                {
                    hierarchyMenuStrip.Close();
                    GUIObject curObj = (Hierarchy.SelectedNode != null ? (GUIObject)Hierarchy.SelectedNode.Tag : null);
                    if (convertMenuStrip.DropDownItems.Contains(e.ClickedItem))
                    {
                        if (curObj != null)
                        {
                            curObj.Delete();

                            GUIObject newObj = ((Func <GUIObject, GUIObject>)e.ClickedItem.Tag)(curObj.GetParent());
                            newObj.RefreshRepresentation(false);

                            while (curObj.Children.Count > 0)
                            {
                                curObj.Children[0].AssignParent(newObj);
                            }

                            if (curObj.GetParent() == null)
                            {
                                LoadedTree = newObj;
                            }

                            List <FieldInfo> sourceFields = GetAllFields(curObj.GetType());
                            List <FieldInfo> destFields   = GetAllFields(newObj.GetType());
                            foreach (FieldInfo fi in destFields)
                            {
                                if (destFields.FindIndex(fi2 => fi2.Name == fi.Name) != -1 && fi.Name != "_HierarchyNode" && fi.Name != "_Children")
                                {
                                    fi.SetValue(newObj, fi.GetValue(curObj));
                                }
                            }
                            newObj.RefreshRepresentation(false);
                        }
                        else
                        {
                            MessageBox.Show("Create or load GUI first.");
                        }
                    }
                    else
                    {
                        if (curObj == null && addMenuStrip.DropDownItems.Contains(e.ClickedItem))
                        {
                            MessageBox.Show("Create or load GUI first.");
                        }
                        else
                        {
                            ((Action <GUIObject>)e.ClickedItem.Tag)(curObj);
                        }
                    }
                }
            };

            addMenuStrip.DropDownItemClicked     += clickHandler;
            convertMenuStrip.DropDownItemClicked += clickHandler;
            hierarchyMenuStrip.ItemClicked       += clickHandler;
            Hierarchy.ContextMenuStrip            = hierarchyMenuStrip;

            // Design drag handler
            bool  designDragging        = false;
            Point designDragMouseStart  = Point.Empty;
            Point designDragObjectStart = Point.Empty;

            Design.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                if (Hierarchy.SelectedNode != null)
                {
                    GUIObject obj = (GUIObject)Hierarchy.SelectedNode.Tag;
                    if (obj.IsHit(e.X, e.Y))
                    {
                        designDragging        = true;
                        designDragMouseStart  = new Point(e.X, e.Y);
                        designDragObjectStart = obj.Position;
                        Design.Capture        = true;
                    }
                }
            };
            Design.MouseUp += delegate(object sender, MouseEventArgs e)
            {
                designDragging = false;
                Design.Capture = false;
            };
            Design.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (designDragging && Hierarchy.SelectedNode != null)
                {
                    GUIObject obj      = (GUIObject)Hierarchy.SelectedNode.Tag;
                    Point     position = obj.Position;
                    position.X   = designDragObjectStart.X + e.X - designDragMouseStart.X;
                    position.Y   = designDragObjectStart.Y + e.Y - designDragMouseStart.Y;
                    obj.Position = position;
                    Properties.Refresh();
                    Design.Refresh();
                }
            };
        }