コード例 #1
0
ファイル: DrawableAvatar.cs プロジェクト: jun112561/osu
        private void load(LargeTextureStore textures)
        {
            if (textures == null)
            {
                throw new ArgumentNullException(nameof(textures));
            }

            Texture texture = null;

            if (user != null && user.Id > 1)
            {
                if (!File.Exists($"User Avatar\\{user.Id}.png"))
                {
                    try
                    {
                        if (!Directory.Exists("User Avatar"))
                        {
                            Directory.CreateDirectory("User Avatar");
                        }

                        var fileWebRequest = new Framework.IO.Network.WebRequest($@"https://a.ppy.sh/{user.Id}")
                        {
                            Method = System.Net.Http.HttpMethod.Get
                        };
                        fileWebRequest.Perform();

                        File.WriteAllBytes($"User Avatar\\{user.Id}.png", fileWebRequest.GetResponseData());
                    }
                    catch (Exception) { }
                }
                if (File.Exists($"User Avatar\\{user.Id}.png"))
                {
                    texture = Texture.FromStream(File.OpenRead($"User Avatar\\{user.Id}.png"));
                }
            }
            if (texture == null)
            {
                texture = textures.Get(@"Online/avatar-guest");
            }

            ClickableArea clickableArea;

            Add(clickableArea = new ClickableArea
            {
                RelativeSizeAxes = Axes.Both,
                Child            = new Sprite
                {
                    RelativeSizeAxes = Axes.Both,
                    Texture          = texture,
                    FillMode         = FillMode.Fit,
                    Anchor           = Anchor.Centre,
                    Origin           = Anchor.Centre
                },
                Action = openProfile
            });

            clickableArea.Enabled.BindTo(OpenOnClick);
        }
コード例 #2
0
        private void load(TextureStore textures)
        {
            if (Team == null)
            {
                return;
            }

            (acronym = Team.Acronym.GetBoundCopy()).BindValueChanged(acronym =>
            {
                AcronymText.Text    = Team.Acronym.Value;
                Team.FullName.Value = AcronymText.Text;
            }, true);
            (flag = Team.FlagName.GetBoundCopy()).BindValueChanged(acronym =>
            {
                if (long.TryParse(Team.FlagName.Value, out long userid) && userid > 0)
                {
                    if (!File.Exists($"User Avatar\\{userid}.png"))
                    {
                        try
                        {
                            if (!Directory.Exists("User Avatar"))
                            {
                                Directory.CreateDirectory("User Avatar");
                            }

                            var fileWebRequest = new Framework.IO.Network.WebRequest($@"https://a.ppy.sh/{userid}")
                            {
                                Method = System.Net.Http.HttpMethod.Get
                            };
                            fileWebRequest.Perform();

                            File.WriteAllBytes($"User Avatar\\{userid}.png", fileWebRequest.GetResponseData());
                        }
                        catch (Exception) { }
                    }
                    else
                    {
                        Flag.Texture = Texture.FromStream(File.OpenRead($"User Avatar\\{userid}.png"));
                    }
                }
            }, true);
        }