Exemple #1
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);
     }
 }
        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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
    }