Exemplo n.º 1
0
        private void addPanels()
        {
            //                              ---Download achievements.xml---
            //get xml from dropbox
            string xml;
            XmlNodeList nl = doc.SelectNodes("versions");
            XmlNode root = nl[0];
            using (WebClient client = new WebClient())
            {
                xml = client.DownloadString("https://www.dropbox.com/s/q23km2xt7bevaus/achievements.xml?dl=1");
            }

            doc.LoadXml(xml);
            //select nodes to get to achievements
            nl = doc.SelectNodes("achievements");
            root = nl[0];
            achievementsNo = root.ChildNodes.Count;

            //loop through panels and achievements

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                AchievementPanel pnl = new AchievementPanel();
                //get achievement in xml
                XmlNode xnode = root.ChildNodes[i];

                //create achievement panel and controls
                achievementsPnl.Controls.Add(pnl);

                pnl.achieved = Properties.Settings.Default.completedAchieves[i];

                //loop through controls in panel
                foreach (Control ctrl in pnl.Controls)
                {
                    //MessageBox.Show(ctrl.Name);
                    //check which control it is eg. title, description, image
                    //title
                    if (ctrl is Label && ctrl.Font.Size == 11)
                    {
                        ctrl.Text = xnode.ChildNodes.Item(0).InnerText;
                    }
                    //description
                    else if (ctrl is Label && ctrl.Font.Size == 8)
                    {
                        if (pnl.achieved)
                        {
                            //set text
                            ctrl.Text = xnode.ChildNodes.Item(1).InnerText;
                        }
                        else
                        {
                            ctrl.Text = "?";
                        }
                    }
                    else if (ctrl is PictureBox)
                    {
                        if (pnl.achieved)
                        {
                            try
                            {
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img" + i + ".jpg");
                            }
                            catch (Exception)
                            {
                                using (WebClient client = new WebClient())
                                {
                                    client.DownloadFile(@"http://www.batchfink.webege.com/img/" + i + ".jpg", path + @"\Content\Launcher\img\" + i + ".jpg");
                                }
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\" + i + ".jpg");
                            }
                        }
                        else
                        {
                            try
                            {
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\idk.jpg");
                            }
                            catch (Exception)
                            {
                                using (WebClient client = new WebClient())
                                {
                                    client.DownloadFile(@"http://www.batchfink.webege.com/img/idk.jpg", path + @"\Content\Launcher\img\idk.jpg");
                                }
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\idk.jpg");
                            }
                        }
                    }
                }

                //Add panel to panel list
                achPnls.Add(pnl);
            }
        }
Exemplo n.º 2
0
        private void addPanels()
        {
            //                              ---Download achievements.xml---
            //get xml from dropbox
            string      xml;
            XmlNodeList nl   = doc.SelectNodes("versions");
            XmlNode     root = nl[0];

            using (WebClient client = new WebClient())
            {
                xml = client.DownloadString("https://www.dropbox.com/s/q23km2xt7bevaus/achievements.xml?dl=1");
            }

            doc.LoadXml(xml);
            //select nodes to get to achievements
            nl             = doc.SelectNodes("achievements");
            root           = nl[0];
            achievementsNo = root.ChildNodes.Count;

            //loop through panels and achievements

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                AchievementPanel pnl = new AchievementPanel();
                //get achievement in xml
                XmlNode xnode = root.ChildNodes[i];

                //create achievement panel and controls
                achievementsPnl.Controls.Add(pnl);

                pnl.achieved = Properties.Settings.Default.completedAchieves[i];

                //loop through controls in panel
                foreach (Control ctrl in pnl.Controls)
                {
                    //MessageBox.Show(ctrl.Name);
                    //check which control it is eg. title, description, image
                    //title
                    if (ctrl is Label && ctrl.Font.Size == 11)
                    {
                        ctrl.Text = xnode.ChildNodes.Item(0).InnerText;
                    }
                    //description
                    else if (ctrl is Label && ctrl.Font.Size == 8)
                    {
                        if (pnl.achieved)
                        {
                            //set text
                            ctrl.Text = xnode.ChildNodes.Item(1).InnerText;
                        }
                        else
                        {
                            ctrl.Text = "?";
                        }
                    }
                    else if (ctrl is PictureBox)
                    {
                        if (pnl.achieved)
                        {
                            try
                            {
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img" + i + ".jpg");
                            }
                            catch (Exception)
                            {
                                using (WebClient client = new WebClient())
                                {
                                    client.DownloadFile(@"http://www.batchfink.webege.com/img/" + i + ".jpg", path + @"\Content\Launcher\img\" + i + ".jpg");
                                }
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\" + i + ".jpg");
                            }
                        }
                        else
                        {
                            try
                            {
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\idk.jpg");
                            }
                            catch (Exception)
                            {
                                using (WebClient client = new WebClient())
                                {
                                    client.DownloadFile(@"http://www.batchfink.webege.com/img/idk.jpg", path + @"\Content\Launcher\img\idk.jpg");
                                }
                                (ctrl as PictureBox).Load(path + @"\Content\Launcher\img\idk.jpg");
                            }
                        }
                    }
                }

                //Add panel to panel list
                achPnls.Add(pnl);
            }
        }