Exemplo n.º 1
0
        public void AddOrRemoveXml(int id, string name = null)
        {
            SplitPanels.Panel1.Controls.Clear();
            SplitPanels.Panel2.Controls.Clear();

            var xmlobjects = new List <XmlObject>();
            var i          = 0;
            var target     = string.Empty;

            foreach (var xmlobject in Array.ConvertAll(XmlPanel.Controls.Find("xmlobject", true), xmlobject => (XmlObject)xmlobject))
            {
                if (xmlobject.Id != id)
                {
                    var newxmlobject = new XmlObject()
                    {
                        Location   = new Point(3, 3 + i * 42),
                        Name       = "xmlobject",
                        Size       = new Size(188, 36),
                        TabIndex   = 2,
                        Id         = xmlobject.Id,
                        XmlContent = xmlobject.XmlContent,
                        FileName   = xmlobject.FileName,
                        FileSize   = xmlobject.FileSize,
                        Palletes   = xmlobject.Palletes
                    };
                    newxmlobject.Action = () =>
                    {
                        SplitPanels.Panel1.Controls.Clear();

                        foreach (var pallete in newxmlobject.Palletes)
                        {
                            pallete.ParentId = newxmlobject.Id;

                            SplitPanels.Panel1.Controls.Add(pallete);
                        }

                        WorkingTitleLabel.Text   = "Working on...";
                        WorkingContentLabel.Text = newxmlobject.FileName;
                    };
                    xmlobjects.Add(newxmlobject);

                    i++;
                }
                else
                {
                    target = xmlobject.FileName;
                }
            }

            if (name != null)
            {
                var xmlobject = new XmlObject()
                {
                    Location   = new Point(3, 3 + i * 42),
                    Name       = "xmlobject",
                    Size       = new Size(188, 36),
                    TabIndex   = 2,
                    Id         = i,
                    XmlContent = null,
                    FileName   = name,
                    FileSize   = "<new>",
                    Palletes   = new List <SpritePallete>()
                };
                xmlobject.Action = () =>
                {
                    SplitPanels.Panel1.Controls.Clear();

                    WorkingTitleLabel.Text   = string.Empty;
                    WorkingContentLabel.Text = "This XML document is empty!";
                };

                XmlObjects.Add(name, new List <ObjectsContent>());
                XmlItems.Add(name, new List <ItemsContent>());
                XmlTiles.Add(name, new List <TilesContent>());

                xmlobjects.Add(xmlobject);
            }

            MainTab.Controls.Remove(XmlPanel);

            XmlPanel = new Panel()
            {
                AutoScroll  = true,
                BackColor   = SystemColors.Info,
                BorderStyle = BorderStyle.Fixed3D,
                Location    = new Point(550, 202),
                Name        = "XmlPanel",
                Size        = new Size(220, 335),
                TabIndex    = 1
            };

            MainTab.Controls.Add(XmlPanel);

            i = 0;

            foreach (var xmlobject in xmlobjects.OrderBy(xml => xml.FileName))
            {
                xmlobject.Location = new Point(3, 3 + i * 42);

                XmlPanel.Controls.Add(xmlobject);

                i++;
            }

            WorkingTitleLabel.Text   = string.Empty;
            WorkingContentLabel.Text = string.Empty;
            XmlCountLabel.Text       = XmlPanel.Controls.Count.ToString();

            if (target != string.Empty)
            {
                XmlLibrary.RemovedXmls.Add(target);
                XmlLibrary.Xmls.Remove(target);
            }
        }
Exemplo n.º 2
0
        public void RefreshXmls()
        {
            SplitPanels.Panel1.Controls.Clear();
            SplitPanels.Panel2.Controls.Clear();

            var i = 0;

            MainTab.Controls.Remove(XmlPanel);

            XmlPanel = new Panel()
            {
                AutoScroll  = true,
                BackColor   = SystemColors.Info,
                BorderStyle = BorderStyle.Fixed3D,
                Location    = new Point(550, 202),
                Name        = "XmlPanel",
                Size        = new Size(220, 335),
                TabIndex    = 1
            };

            MainTab.Controls.Add(XmlPanel);

            foreach (var xml in XmlLibrary.Xmls.OrderBy(name => name.Key))
            {
                var objects    = new List <ObjectsContent>();
                var items      = new List <ItemsContent>();
                var tiles      = new List <TilesContent>();
                var name       = xml.Key;
                var xmlcontent = xml.Value.Value;

                if (xmlcontent != null)
                {
                    foreach (var elem in xmlcontent.XPathSelectElements("//Object"))
                    {
                        switch ((ContentType)int.Parse(elem.Attribute("type").Value))
                        {
                        case ContentType.Objects: objects.Add(new ObjectsContent(elem)); break;

                        case ContentType.Items: items.Add(new ItemsContent(elem)); break;

                        case ContentType.Tiles: tiles.Add(new TilesContent(elem)); break;
                        }
                    }
                }

                if (!XmlObjects.ContainsKey(name))
                {
                    XmlObjects.Add(name, objects);
                }
                if (!XmlItems.ContainsKey(name))
                {
                    XmlItems.Add(name, items);
                }
                if (!XmlTiles.ContainsKey(name))
                {
                    XmlTiles.Add(name, tiles);
                }

                var xobjects = XmlObjects[name];
                var xitems   = XmlItems[name];
                var xtiles   = XmlTiles[name];
                var palletes = new List <KeyValuePair <int, SpritePallete> >();
                var columns  = new List <int>()
                {
                    4, 43, 82, 121, 160, 199
                };
                var row    = 0;
                var column = 0;

                foreach (var xobject in xobjects)
                {
                    var xobjectpallete = new SpritePallete()
                    {
                        Origin   = name,
                        Type     = ContentType.Objects,
                        Id       = xobject.Id,
                        Name     = "spritepallete",
                        Size     = new Size(33, 33),
                        TabIndex = 2,
                        Image    = Spritesheets[xobject.TextureData.File].Image[xobject.TextureData.X, xobject.TextureData.Y]
                    };

                    palletes.Add(new KeyValuePair <int, SpritePallete>(xobject.Id, xobjectpallete));
                }

                foreach (var xitem in xitems)
                {
                    var xitempallete = new SpritePallete()
                    {
                        Origin   = name,
                        Type     = ContentType.Items,
                        Id       = xitem.Id,
                        Name     = "spritepallete",
                        Size     = new Size(33, 33),
                        TabIndex = 2,
                        Image    = Spritesheets[xitem.TextureData.File].Image[xitem.TextureData.X, xitem.TextureData.Y]
                    };

                    palletes.Add(new KeyValuePair <int, SpritePallete>(xitem.Id, xitempallete));
                }

                foreach (var xtile in xtiles)
                {
                    var xtilepallete = new SpritePallete()
                    {
                        Origin   = name,
                        Type     = ContentType.Tiles,
                        Id       = xtile.Id,
                        Name     = "spritepallete",
                        Size     = new Size(33, 33),
                        TabIndex = 2,
                        Image    = Spritesheets[xtile.TextureData.File].Image[xtile.TextureData.X, xtile.TextureData.Y]
                    };

                    palletes.Add(new KeyValuePair <int, SpritePallete>(xtile.Id, xtilepallete));
                }

                foreach (var pallete in palletes.OrderBy(id => id.Key))
                {
                    var sampleobject = xobjects.FirstOrDefault(sample => sample.Id == pallete.Key);
                    var sampleitem   = xitems.FirstOrDefault(sample => sample.Id == pallete.Key);
                    var sampletile   = xtiles.FirstOrDefault(sample => sample.Id == pallete.Key);

                    ItemControl itemcontrol = null;

                    if (sampleobject != null)
                    {
                        itemcontrol = new ItemControl(pallete.Value, name, sampleobject);
                    }

                    if (sampleitem != null)
                    {
                        itemcontrol = new ItemControl(pallete.Value, name, sampleitem);
                    }

                    if (sampletile != null)
                    {
                        itemcontrol = new ItemControl(pallete.Value, name, sampletile);
                    }

                    itemcontrol.Location = new Point(0, 0);
                    itemcontrol.Name     = "itemcontrol";
                    itemcontrol.Size     = new Size(295, 534);
                    itemcontrol.TabIndex = 2;

                    pallete.Value.Location    = new Point(columns[column], 3 + row * 39);
                    pallete.Value.ItemControl = itemcontrol;
                    pallete.Value.Action      = () =>
                    {
                        SplitPanels.Panel2.Controls.Clear();

                        if (pallete.Value.ItemControl != null)
                        {
                            SplitPanels.Panel2.Controls.Add(pallete.Value.ItemControl);
                        }
                    };

                    column++;

                    if (column == columns.Count)
                    {
                        column = 0;
                        row++;
                    }
                }

                var xmlobject = new XmlObject()
                {
                    Location   = new Point(3, 3 + i * 42),
                    Name       = "xmlobject",
                    Size       = new Size(188, 36),
                    TabIndex   = 2,
                    Id         = i,
                    XmlContent = xml.Value.Value,
                    FileName   = xml.Key,
                    FileSize   = xml.Value.Key,
                    Palletes   = palletes.OrderBy(id => id.Key).Select(pallete => pallete.Value).ToList()
                };
                xmlobject.Action = () =>
                {
                    SplitPanels.Panel1.Controls.Clear();
                    SplitPanels.Panel2.Controls.Clear();

                    foreach (var pallete in xmlobject.Palletes)
                    {
                        pallete.ParentId = xmlobject.Id;

                        SplitPanels.Panel1.Controls.Add(pallete);
                    }

                    WorkingTitleLabel.Text   = "Working on...";
                    WorkingContentLabel.Text = xml.Key;
                };

                XmlPanel.Controls.Add(xmlobject);

                i++;
            }
        }
Exemplo n.º 3
0
        public async Task <ObservableCollection <Lib.Xml_helper> > Xml_Read(string filepath0)
        {
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //dlg.FileName = ""; // Default file name
            //dlg.DefaultExt = ".xml";  // Default file extension
            //dlg.Filter = "All files(*.*)|*.*|All files(*.*)|*.* "; // Filter files by extension
            //// Show open file dialog box
            //Nullable<bool> result = dlg.ShowDialog();
            //// Process open file dialog box results
            //if (result == true)
            //{// Growl.Success("成功");
            if (filepath0 != "")
            {
                XmlItems.Clear();
                XmlItems0.Clear();
                XmlItems1.Clear();
                string    filename  = filepath0;//dig.filename
                XDocument xDocument = new XDocument();
                XElement  xElement  = XElement.Load(filename);

                IEnumerable <XElement> xElement1 = from p1 in xElement.Elements("RecipeParameter")
                                                   select p1;
                await Task.Run(() => {
                    foreach (XElement p1 in xElement1)
                    {
                        Application.Current.Dispatcher.Invoke((System.Action)(() =>
                        {
                            XmlItems0.Add(

                                new Lib.Alm(
                                    Convert.ToInt32(p1.Element("ID").Value),
                                    p1.Element("Name").Value.ToString(),
                                    p1.Element("CreatTime").Value.ToString()
                                    ));
                        }));
                    }
                });

                ;
                IEnumerable <XElement> xElement2 = from p2 in xElement.Elements("ProcessParameter")
                                                   select p2;
                await Task.Run(() =>
                {
                    foreach (XElement p2 in xElement2)
                    {
                        Application.Current.Dispatcher.Invoke((System.Action)(() =>
                        {
                            XmlItems1.Add(

                                new Lib.Recipe_Process(

                                    p2.Element("Pressure0").Value.ToString(),
                                    p2.Element("Pressure1").Value.ToString(),
                                    p2.Element("Pressure2").Value.ToString(),
                                    p2.Element("Pressure3").Value.ToString(),
                                    p2.Element("Pressure4").Value.ToString(),
                                    p2.Element("Temperature0").Value.ToString(),
                                    p2.Element("Temperature1").Value.ToString(),
                                    p2.Element("Temperature2").Value.ToString(),
                                    p2.Element("Temperature3").Value.ToString(),
                                    p2.Element("Temperature4").Value.ToString(),
                                    p2.Element("SynchronousDistance0").Value.ToString(),
                                    p2.Element("SynchronousDistance1").Value.ToString(),
                                    p2.Element("SynchronousDistance2").Value.ToString(),
                                    p2.Element("SynchronousDistance3").Value.ToString(),
                                    p2.Element("SynchronousDistance4").Value.ToString(),
                                    p2.Element("SynchronousSpeed0").Value.ToString(),
                                    p2.Element("SynchronousSpeed1").Value.ToString(),
                                    p2.Element("SynchronousSpeed2").Value.ToString(),
                                    p2.Element("SynchronousSpeed3").Value.ToString(),
                                    p2.Element("SynchronousSpeed4").Value.ToString()
                                    ));
                        }));
                    }
                });

                ; IEnumerable <XElement> xElements = from p in xElement.Elements("Asix")
                                                     select p;
                await Task.Run(() =>
                {
                    foreach (XElement p in xElements)
                    {
                        Application.Current.Dispatcher.Invoke((System.Action)(() =>
                        {
                            XmlItems.Add(

                                new Lib.Xml_helper(

                                    Convert.ToInt32(p.Element("ID").Value),
                                    p.Element("POsition0").Value.ToString(),
                                    p.Element("POsition1").Value.ToString(),
                                    p.Element("POsition2").Value.ToString(),
                                    p.Element("POsition3").Value.ToString(),
                                    p.Element("POsition4").Value.ToString(),
                                    p.Element("POsition5").Value.ToString(),
                                    p.Element("POsition6").Value.ToString(),
                                    p.Element("POsition7").Value.ToString(),
                                    p.Element("POsition8").Value.ToString(),
                                    p.Element("POsition9").Value.ToString(),
                                    p.Element("Speed0").Value.ToString(),
                                    p.Element("Speed1").Value.ToString(),
                                    p.Element("Speed2").Value.ToString(),
                                    p.Element("Speed3").Value.ToString(),
                                    p.Element("Speed4").Value.ToString(),
                                    p.Element("Speed5").Value.ToString(),
                                    p.Element("Speed6").Value.ToString(),
                                    p.Element("Speed7").Value.ToString(),
                                    p.Element("Speed8").Value.ToString(),
                                    p.Element("Speed9").Value.ToString())
                                );
                        }));
                    }
                });

                // }
            }
            return(XmlItems);
        }