Example #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);
            }
        }
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            if (searchStr != null)
            {
                searchStr = searchStr.ToLower();
            }

            foreach (var prototype in prototypeManager.EnumeratePrototypes <EntityPrototype>())
            {
                if (searchStr != null && !prototype.ID.ToLower().Contains(searchStr))
                {
                    continue;
                }

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

                var spriteNameParam = prototype.GetBaseSpriteParameters().FirstOrDefault();
                var spriteName      = "";
                if (spriteNameParam != null)
                {
                    spriteName = spriteNameParam.GetValue <string>();
                }

                var tex  = resourceCache.GetResource <TextureResource>("Textures/" + spriteName);
                var rect = container.GetChild("TextureWrap").GetChild <TextureRect>("TextureRect");
                if (tex != null)
                {
                    rect.Texture = tex.Texture;
                    // 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.Texture.Height;
                    rect.Scale = new Vector2(scale, scale);
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
Example #3
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);
            }
        }