Пример #1
0
        public static IDirectionalTextureProvider DirFrame0(this SpriteSpecifier specifier)
        {
            var resc = IoCManager.Resolve <IResourceCache>();

            switch (specifier)
            {
            case SpriteSpecifier.Texture tex:
                return(resc.GetResource <TextureResource>(SpriteComponent.TextureRoot / tex.TexturePath).Texture);

            case SpriteSpecifier.Rsi rsi:
                if (resc.TryGetResource <RSIResource>(SpriteComponent.TextureRoot / rsi.RsiPath, out var theRsi))
                {
                    if (theRsi.RSI.TryGetState(rsi.RsiState, out var state))
                    {
                        return(state);
                    }
                }
                return(resc.GetFallback <TextureResource>().Texture);

            case SpriteSpecifier.EntityPrototype prototypeIcon:
                var protMgr = IoCManager.Resolve <IPrototypeManager>();
                if (!protMgr.TryIndex <EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
                {
                    Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
                    return(resc.GetFallback <TextureResource>().Texture);
                }
                return(SpriteComponent.GetPrototypeIcon(prototype, resc) ?? resc.GetFallback <TextureResource>().Texture);

            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        public static IRsiStateLike RsiStateLike(this SpriteSpecifier specifier)
        {
            var resC = IoCManager.Resolve <IResourceCache>();

            switch (specifier)
            {
            case SpriteSpecifier.Texture tex:
                return(tex.GetTexture(resC));

            case SpriteSpecifier.Rsi rsi:
                return(rsi.GetState(resC));

            case SpriteSpecifier.EntityPrototype prototypeIcon:
                var protMgr = IoCManager.Resolve <IPrototypeManager>();
                if (!protMgr.TryIndex <EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
                {
                    Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
                    return(SpriteComponent.GetFallbackState(resC));
                }

                return(SpriteComponent.GetPrototypeIcon(prototype, resC));

            default:
                throw new NotSupportedException();
            }
        }
 public void UpdateList(Label number, double numberVal, ItemList list, PowerMonitoringConsoleEntry[] listVal)
 {
     number.Text = Loc.GetString("power-monitoring-window-value", ("value", numberVal));
     // This magic is important to prevent scrolling issues.
     while (list.Count > listVal.Length)
     {
         list.RemoveAt(list.Count - 1);
     }
     while (list.Count < listVal.Length)
     {
         list.AddItem("YOU SHOULD NEVER SEE THIS (REALLY!)", null, false);
     }
     // Now overwrite the items properly...
     for (var i = 0; i < listVal.Length; i++)
     {
         var ent = listVal[i];
         _prototypeManager.TryIndex(ent.IconEntityPrototypeId, out EntityPrototype? entityPrototype);
         IRsiStateLike?iconState = null;
         if (entityPrototype != null)
         {
             iconState = SpriteComponent.GetPrototypeIcon(entityPrototype, StaticIoC.ResC);
         }
         var icon = iconState?.GetFrame(RSI.State.Direction.South, 0);
         var item = list[i];
         item.Text = $"{ent.NameLocalized} {Loc.GetString("power-monitoring-window-value", ("value", ent.Size))}";
         item.Icon = icon;
     }
 }
Пример #4
0
        public void Populate(List <VendingMachineInventoryEntry> inventory)
        {
            _items.Clear();
            _cachedInventory = inventory;
            foreach (VendingMachineInventoryEntry entry in inventory)
            {
                var itemName = _prototypeManager.Index <EntityPrototype>(entry.ID).Name;

                Texture icon = null;
                if (_prototypeManager.TryIndex(entry.ID, out EntityPrototype prototype))
                {
                    icon = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache)?.Default;
                }
                _items.AddItem($"{itemName} ({entry.Amount} left)", icon);
            }
        }
Пример #5
0
    public IRsiStateLike RsiStateLike(SpriteSpecifier specifier)
    {
        switch (specifier)
        {
        case SpriteSpecifier.Texture tex:
            return(tex.GetTexture(_resourceCache));

        case SpriteSpecifier.Rsi rsi:
            return(GetState(rsi));

        case SpriteSpecifier.EntityPrototype prototypeIcon:
            if (!_proto.TryIndex <EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
            {
                Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
                return(SpriteComponent.GetFallbackState(_resourceCache));
            }

            return(SpriteComponent.GetPrototypeIcon(prototype, _resourceCache));

        default:
            throw new NotSupportedException();
        }
    }