예제 #1
0
            public static IconComponent Read(BinaryReader br)
            {
                IconComponent ret = new IconComponent();

                ret.Data = br.ReadStructures <UInt32>(8).ToArray();
                return(ret);
            }
예제 #2
0
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            searchStr      = searchStr?.ToLowerInvariant();

            var prototypes = new List <EntityPrototype>();

            foreach (var prototype in prototypeManager.EnumeratePrototypes <EntityPrototype>())
            {
                if (prototype.Abstract)
                {
                    continue;
                }

                if (searchStr != null && !_doesPrototypeMatchSearch(prototype, searchStr))
                {
                    continue;
                }

                prototypes.Add(prototype);
            }

            prototypes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            foreach (var prototype in prototypes)
            {
                var button = new EntitySpawnButton()
                {
                    Prototype = prototype,
                };
                var container = button.GetChild("HBoxContainer");
                button.ActualButton.OnToggled           += OnItemButtonToggled;
                container.GetChild <Label>("Label").Text = prototype.Name;

                var tex  = IconComponent.GetPrototypeIcon(prototype);
                var rect = container.GetChild("TextureWrap").GetChild <TextureRect>("TextureRect");
                if (tex != null)
                {
                    rect.Texture = tex.Default;
                    // Ok I can't find a way to make this TextureRect scale down sanely so let's do this.
                    var scale = (float)TARGET_ICON_HEIGHT / tex.Default.Height;
                    rect.Scale = new Vector2(scale, scale);
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
 public void Populate(List <VendingMachineInventoryEntry> inventory)
 {
     _items.Clear();
     _cachedInventory = inventory;
     foreach (VendingMachineInventoryEntry entry in inventory)
     {
         Texture icon = null;
         if (_prototypeManager.TryIndex(entry.ID, out EntityPrototype prototype))
         {
             icon = IconComponent.GetPrototypeIcon(prototype, _resourceCache).TextureFor(Direction.South);
         }
         _items.AddItem($"{entry.ID} ({entry.Amount} left)", icon);
     }
 }
예제 #4
0
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            searchStr      = searchStr?.ToLowerInvariant();

            var prototypes = new List <EntityPrototype>();

            foreach (var prototype in prototypeManager.EnumeratePrototypes <EntityPrototype>())
            {
                if (prototype.Abstract)
                {
                    continue;
                }

                if (searchStr != null && !_doesPrototypeMatchSearch(prototype, searchStr))
                {
                    continue;
                }

                prototypes.Add(prototype);
            }

            prototypes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            foreach (var prototype in prototypes)
            {
                var button = new EntitySpawnButton()
                {
                    Prototype = prototype,
                };
                button.ActualButton.OnToggled += OnItemButtonToggled;
                button.EntityLabel.Text        = prototype.Name;

                var tex  = IconComponent.GetPrototypeIcon(prototype, resourceCache);
                var rect = button.EntityTextureRect;
                if (tex != null)
                {
                    rect.Texture = tex.Default;
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
예제 #5
0
        public void ComponentSizeSerializeTest()
        {
            var    iconSize = new[] { ComponentSize.Xxs, ComponentSize.Xs, ComponentSize.Sm, ComponentSize.Md, ComponentSize.Lg, ComponentSize.Xl, ComponentSize.Xxl, ComponentSize._3xl, ComponentSize._4xl, ComponentSize._5xl };
            string testUrl  = "https://example.com/icon/png/caution.png";

            var expectedSizes = new[] { "xxs", "xs", "sm", "md", "lg", "xl", "xxl", "3xl", "4xl", "5xl" };
            var expectedJson  = "{{\"type\":\"icon\",\"url\":\"{0}\",\"size\":\"{1}\"}}";

            foreach (var size in iconSize.Zip(expectedSizes, (test, exp) => new { Test = test, Expected = exp }))
            {
                var test = new IconComponent(testUrl)
                {
                    Size = size.Test, Margin = null
                };
                var json = JsonConvert.SerializeObject(test);

                Assert.AreEqual(string.Format(expectedJson, testUrl, size.Expected), json);
            }
        }
예제 #6
0
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            if (searchStr != null)
            {
                searchStr = searchStr.ToLower();
            }

            var prototypes = prototypeManager.EnumeratePrototypes <EntityPrototype>()
                             .Where(prototype => !prototype.Abstract && (searchStr == null || prototype.ID.ToLower().Contains(searchStr)))
                             .OrderBy(prototype => prototype.Name);

            foreach (var prototype in prototypes)
            {
                var button = new EntitySpawnButton()
                {
                    Prototype = prototype,
                };
                var container = button.GetChild("HBoxContainer");
                button.ActualButton.OnToggled           += OnItemButtonToggled;
                container.GetChild <Label>("Label").Text = prototype.Name;

                var tex  = IconComponent.GetPrototypeIcon(prototype);
                var rect = container.GetChild("TextureWrap").GetChild <TextureRect>("TextureRect");
                if (tex != null)
                {
                    rect.Texture = tex.Default;
                    // Ok I can't find a way to make this TextureRect scale down sanely so let's do this.
                    var scale = (float)TARGET_ICON_HEIGHT / tex.Default.Height;
                    rect.Scale = new Vector2(scale, scale);
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
예제 #7
0
    public IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
    {
        var icon = IconComponent.GetPrototypeIcon(prototype, _resourceCache);

        if (icon != null)
        {
            return(icon);
        }

        if (!prototype.Components.ContainsKey("Sprite"))
        {
            return(SpriteComponent.GetFallbackState(resourceCache));
        }

        var dummy           = Spawn(prototype.ID, MapCoordinates.Nullspace);
        var spriteComponent = EnsureComp <SpriteComponent>(dummy);
        var result          = spriteComponent.Icon ?? SpriteComponent.GetFallbackState(resourceCache);

        Del(dummy);

        return(result);
    }
예제 #8
0
        static void Richtextify(ICoreClientAPI capi, VtmlToken token, ref List <RichTextComponentBase> elems, Stack <CairoFont> fontStack, Action <LinkTextComponent> didClickLink)
        {
            if (token is VtmlTagToken)
            {
                VtmlTagToken tagToken = token as VtmlTagToken;

                switch (tagToken.Name)
                {
                case "br":
                    elems.Add(new RichTextComponent(capi, "\r\n", fontStack.Peek()));
                    break;

                case "i":
                    CairoFont font = fontStack.Peek().Clone();
                    font.Slant = FontSlant.Italic;
                    fontStack.Push(font);
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "a":
                    LinkTextComponent cmp = new LinkTextComponent(capi, tagToken.ContentText, fontStack.Peek(), didClickLink);
                    tagToken.Attributes.TryGetValue("href", out cmp.Href);

                    elems.Add(cmp);
                    break;

                case "icon":
                    string iconName;
                    tagToken.Attributes.TryGetValue("name", out iconName);
                    IconComponent iconcmp = new IconComponent(capi, iconName, fontStack.Peek());
                    elems.Add(iconcmp);
                    break;

                case "itemstack":
                    string    code;
                    string    type;
                    float     size      = (float)fontStack.Peek().GetFontExtents().Height;
                    EnumFloat floatType = EnumFloat.Inline;
                    string    floattypestr;
                    if (tagToken.Attributes.TryGetValue("floattype", out floattypestr))
                    {
                        if (!Enum.TryParse(floattypestr, out floatType))
                        {
                            floatType = EnumFloat.Inline;
                        }
                    }

                    tagToken.Attributes.TryGetValue("code", out code);
                    if (!tagToken.Attributes.TryGetValue("type", out type))
                    {
                        type = "block";
                    }

                    ItemStack stack;
                    if (type == "item")
                    {
                        stack = new ItemStack(capi.World.GetItem(new AssetLocation(code)));
                    }
                    else
                    {
                        stack = new ItemStack(capi.World.GetBlock(new AssetLocation(code)));
                    }

                    float sizemul = 1f;
                    if (tagToken.Attributes.TryGetValue("rsize", out var sizemulstr))
                    {
                        sizemul = sizemulstr.ToFloat();
                    }

                    SlideshowItemstackTextComponent stckcmp = new SlideshowItemstackTextComponent(capi, new ItemStack[] { stack }, size / RuntimeEnv.GUIScale, floatType);
                    stckcmp.renderSize   *= sizemul;
                    stckcmp.VerticalAlign = EnumVerticalAlign.Middle;

                    if (tagToken.Attributes.TryGetValue("offx", out var offxstr))
                    {
                        stckcmp.offX = GuiElement.scaled(offxstr.ToFloat(0));
                    }
                    if (tagToken.Attributes.TryGetValue("offy", out var offystr))
                    {
                        stckcmp.offY = GuiElement.scaled(offystr.ToFloat(0));
                    }

                    elems.Add(stckcmp);
                    break;

                case "font":
                    fontStack.Push(getFont(tagToken, fontStack));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "clear":
                    elems.Add(new ClearFloatTextComponent(capi));
                    break;

                case "strong":
                    fontStack.Push(fontStack.Peek().Clone().WithWeight(Cairo.FontWeight.Bold));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;
                }


                if (tagToken.Name != null && TagConverters.ContainsKey(tagToken.Name))
                {
                    RichTextComponentBase elem = TagConverters[tagToken.Name](capi, tagToken, fontStack, didClickLink);
                    if (elem != null)
                    {
                        elems.Add(elem);
                    }
                }
            }
            else
            {
                VtmlTextToken textToken = token as VtmlTextToken;
                elems.Add(new RichTextComponent(capi, textToken.Text, fontStack.Peek()));
            }
        }