Esempio n. 1
0
        public static Brush GetEmblemTextureBrush(string clanTag)
        {
            if (string.IsNullOrEmpty(clanTag))
            {
                return(Brushes.Magenta);
            }

            if (CacheTextureBrushes.TryGetValue(clanTag, out var weakReferenceTextureBrush) &&
                weakReferenceTextureBrush.TryGetTarget(out var textureBrush))
            {
                return(textureBrush);
            }

            if (ClientFactionEmblemDataCache.TryGetValue(clanTag, out var emblem))
            {
                var texture = ClientFactionEmblemTextureProvider.GetEmblemTexture(emblem, useCache: true);
                textureBrush = Api.Client.UI.GetTextureBrush(texture);
                CacheTextureBrushes[clanTag] = new WeakReference <TextureBrush>(textureBrush);
                return(textureBrush);
            }

            // create placeholder texture brush, load the emblem async, and insert loaded emblem in the texture
            textureBrush = Api.Client.UI.CreateTextureBrush();
            CacheTextureBrushes[clanTag] = new WeakReference <TextureBrush>(textureBrush);
            LoadEmblemTextureAsync(clanTag, textureBrush);
            return(textureBrush);
        }
Esempio n. 2
0
        private static async void LoadEmblemTextureAsync(string clanTag, TextureBrush textureBrush)
        {
            var emblem = await ClientFactionEmblemDataCache.GetFactionEmblemAsync(clanTag);

            var texture = ClientFactionEmblemTextureProvider.GetEmblemTexture(emblem, useCache: true);

            Api.Client.UI.SetTextureBrushResource(textureBrush, texture);
        }