Beispiel #1
0
        public void ShowBadges(byte badges, GameType game)
        {
            this._badgeFlags = badges;
            this._game = game;

            if (game == GameType.CRYSTAL) // Include GOLD & SILVER
                _maxBadges = 16;
            else
                _maxBadges = 8;

            _badgeNames.Clear();
            switch (game)
            {
                case GameType.EMERALD:
                    _badgeNames.AddRange(new List<string>() { "Stone Badge", "Knuckle Badge", "Dynamo Badge", "Heat Badge", "Balance Badge", "Feather Badge", "Mind Badge", "Rain Badge" });
                    break;
                case GameType.LEAFGREEN:
                    _badgeNames.AddRange(new List<string>() { "Boulder Badge", "Cascade Badge", "Thunder Badge", "Rainbow Badge", "Soul Badge", "Marsh Badge", "Volcano Badge", "Earth Badge" });
                    break;
                // TODO Other games
            }

            LayoutBadges(this._orientation); // refresh data

            try
            {
                for (int i = 0; i < this._badges.Count(); i++) {
                    PictureBox badge = this._badges[i];
                    if (badge.Tag == null) continue;

                    Console.WriteLine("Found " + badge.Tag + "! At location: " + badge.Location.ToString() + ", size: " + badge.Size.ToString());

                    string webname = badge.Tag.ToString().Split(' ').First().ToLower();

                    string local_resource = @"poke_sprites/" + webname + ".png";
                    if (!Directory.Exists(@"poke_sprites"))
                    {
                        Console.WriteLine("PokemonParty sprites directory does not exist. Creating one...");
                        Directory.CreateDirectory(@"poke_sprites");
                    }
                    if (!File.Exists(local_resource))
                    {
                        string remote_url = @"";
                        if (game == GameType.EMERALD) remote_url = @"http://stegriff.co.uk/content/badges/files/RSE/";
                        else if (game == GameType.LEAFGREEN) remote_url = @"http://stegriff.co.uk/content/badges/files/RBY/";
                        using (MinimalWebClient Client = new MinimalWebClient())
                        {
                            string remote_resource_name = webname + ".png";
                            Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name);
                        }
                    }

                    if (File.Exists(local_resource))
                    {
                        Image image = null;
                        try
                        {
                            image = AnimatedSprite.CleanImageFromFile(local_resource);
                        }
                        catch
                        {
                            Console.WriteLine("Error loading sprite image.");
                        }

                        if (image == null) Console.WriteLine("Loaded null badge image.");

                        try
                        {
                            //image = AnimatedSprite.FixedSize(image, badge.Width, badge.Height, this.BackColor);

                            Action setBadgeImage = () =>
                            {
                                badge.Image = image;
                            };

                            if (this.InvokeRequired) this.Invoke(setBadgeImage);
                            else if (Program.IsMainThread) setBadgeImage();
                        }
                        catch
                        {
                            Console.WriteLine("Unable to crop badge.");
                        };
                    }
                    else
                        Console.WriteLine("Unable to download badge sprites, even though the url exists?");
                }
            }
            catch
            {
                Console.WriteLine("Unable to download badges sprites");
            }
        }
Beispiel #2
0
        public bool ShowTeam(List<Pokemon> pokes)
        {
            foreach (PictureBox slot in slots)
            {
                // Stop existing animations
                AnimatedSprite sprite = (slot.Tag is AnimatedSprite) ? (AnimatedSprite)slot.Tag : null;
                if (sprite == null) continue;
                else
                {
                    sprite.StopAnimation();
                    slot.Invalidate();
                }
            }

            try
            {
                foreach (Pokemon p in pokes)
                {
                    if (p.Species == 0) continue;
                    Console.WriteLine("Found Pkmn #" + p.Species + "!");

                    //string sprite_name = p.DexNumber.ToString().PadLeft(3, '0') + ".png";
                    string local_resource = @"poke_sprites/" + p.Name.ToLower() + ".gif";
                    if (!Directory.Exists(@"poke_sprites"))
                    {
                        Console.WriteLine("PokemonParty sprites directory does not exist. Creating one...");
                        Directory.CreateDirectory(@"poke_sprites");
                    }
                    if (!File.Exists(local_resource))
                    {
                        /*using (WebClient Client = new WebClient())
                        {
                            Client.DownloadFile(@"http://www.serebii.net/pokedex-xy/icon/" + sprite_name, sprite_file);
                        }*/
                        //string remote_url = @"http://www.pkparaiso.com/imagenes/xy/sprites/animados/";
                        string remote_url = @"http://play.pokemonshowdown.com/sprites/xyani/";
                        using (MinimalWebClient Client = new MinimalWebClient())
                        {
                            string remote_resource_name = p.Name.ToLower() + ".gif";
                            Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name);
                        }
                        /*using (HeadClient Client = new HeadClient())
                        {
                            for (int i = 2; i <= 5; i++)
                            {
                                string remote_resource_name = p.Name.ToLower() + "-" + i.ToString() + ".gif";
                                Client.HeadOnly = true;
                                try
                                {
                                    Client.DownloadData(remote_url + remote_resource_name);
                                    Client.HeadOnly = false;
                                    Client.DownloadFile(remote_url + remote_resource_name, @"poke_sprites/" + remote_resource_name);
                                }
                                catch
                                {
                                    Console.WriteLine("Couldn't find remote resource: " + remote_resource_name);
                                    break;
                                }
                            }
                        }*/
                        Console.WriteLine("Done downloading available sprites.");
                    }
                }
            }
            catch
            {
                Console.WriteLine("Unable to download pkmn team sprites");
            }

            try
            {
                for (int i = 0; i < pokes.Count; i++)
                {

                    //string sprite_name = pokes[i].DexNumber.ToString().PadLeft(3, '0') + ".png";
                    string sprite_name = pokes[i].Name.ToLower() + ".gif";
                    string sprite_file = @"poke_sprites/" + sprite_name;
                    //slots[i].ImageLocation = sprite_file;

                    if (!File.Exists(sprite_file))
                    {
                        Console.WriteLine("Sprite file does not exist: " + sprite_file);
                    }
                    else
                    {
                        Image image = null;
                        try
                        {
                            image = AnimatedSprite.CleanImageFromFile(sprite_file);
                        }
                        catch
                        {
                            Console.WriteLine("Error loading sprite image.");
                        }

                        _images[i].Clear();
                        if (image != null)
                        {
                            _images[i].Add(image);
                            /*for (int alt = 2; alt <= 5; alt++)
                            {
                                string local_resource_name = @"poke_sprites/" + pokes[i].Name.ToLower() + "-" + alt.ToString() + ".gif";
                                if (File.Exists(local_resource_name))
                                {
                                    _images[i].Add(Image.FromFile(local_resource_name));
                                }
                                else break;
                            }*/

                            // Let Paint draw it.
                            slots[i].Image = null;
                            try
                            {
                                slots[i].Tag = new AnimatedSprite(slots[i], _images[i]);
                            }
                            catch
                            {
                                slots[i].Tag = null;
                                Console.WriteLine("Unable to create AnimatedSprite.");
                            };
                        }
                    }

                    int max_chars = slotLevels[i].Width / 8;
                    string hp_percent = ((int)((double)pokes[i].CurrentHP / (double)pokes[i].TotalHP * (double)100)).ToString() + "%";
                    string status_condition = (pokes[i].CurrentHP == 0) ? "FNT" : Pokemon.GetStatusShorthand(pokes[i].ProminentStatusCondition);

                    // Pokemon Levels
                    Action updateInterface = () =>
                    {
                        if (pokes[i].Level != 0)
                        {
                            slotLevels[i].Text = (pokes[i].Nickname != null) ? pokes[i].Nickname : "";
                            slotLevels[i].Text += Environment.NewLine + (":L" + pokes[i].Level.ToString()).PadRight(max_chars - status_condition.Length) + status_condition;
                            slotLevels[i].Text += Environment.NewLine + ":HP".PadRight(max_chars - hp_percent.Length) + hp_percent;

                            if (pokes[i].CurrentHP == 0) slotLevels[i].ForeColor = this.TextSubColor;
                            else if (pokes[i].StatusCondition != Pokemon.StatusType.NONE) slotLevels[i].ForeColor = Pokemon.GetStatusColor(pokes[i].ProminentStatusCondition);
                            else slotLevels[i].ForeColor = this.TextForeColor;
                        }
                        else slotLevels[i].Text = ":Egg";
                        slotLevels[i].Visible = true;
                    };

                    if (this.InvokeRequired) this.Invoke(updateInterface);
                    else if (Program.IsMainThread) updateInterface();
                }

                for (int i = pokes.Count; i < 6; i++)
                {
                    Action hideLabel = () =>
                    {
                        slotLevels[i].Visible = false;
                    };

                    if (this.InvokeRequired) this.Invoke(hideLabel);
                    else if (Program.IsMainThread) hideLabel();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to set pkmn team sprites: " + e.Message);
            }
            return true;
        }