Esempio n. 1
0
        void RenderHotspot(ISpriteManager sm, IWindowManager window, bool showHotspot)
        {
            if (!showHotspot)
            {
                _hotspotSprite?.Dispose();
                _hotspotSprite = null;
                return;
            }

            var commonColors = Resolve <ICommonColors>();

            if (_hotspotSprite == null)
            {
                var key = new SpriteKey(commonColors.BorderTexture, SpriteSampler.Point, DrawLayer.MaxLayer, SpriteKeyFlags.NoTransform | SpriteKeyFlags.NoDepthTest);
                _hotspotSprite = sm.Borrow(key, 1, this);
            }

            var position = new Vector3(window.PixelToNorm(Position), 0.0f);
            var size     = window.UiToNormRelative(Vector2.One);

            bool lockWasTaken = false;
            var  instances    = _hotspotSprite.Lock(ref lockWasTaken);

            try
            {
                var region = _hotspotSprite.Key.Texture.Regions[(int)commonColors.Palette[CommonColor.Yellow3]];
                instances[0] = new SpriteInstanceData(position, size, region, SpriteFlags.TopMid);
            }
            finally { _hotspotSprite.Unlock(lockWasTaken); }
        }
Esempio n. 2
0
        void RenderCursor(IAssetManager assets, ISpriteManager sm, IWindowManager window, Vector3 position)
        {
            if (!_showCursor)
            {
                _cursorSprite?.Dispose();
                _itemSprite?.Dispose();
                _cursorSprite = null;
                _itemSprite   = null;
                return;
            }

            var cursorTexture = assets.LoadTexture(_cursorId);

            if (cursorTexture == null)
            {
                return;
            }

            if (cursorTexture != _cursorSprite?.Key.Texture)
            {
                _cursorSprite?.Dispose();
                var key = new SpriteKey(cursorTexture, SpriteSampler.Point, DrawLayer.Cursor, SpriteKeyFlags.NoDepthTest | SpriteKeyFlags.NoTransform);
                _cursorSprite = sm.Borrow(key, 1, this);
            }

            var size = window.UiToNormRelative(new Vector2(cursorTexture.Width, cursorTexture.Height));

            bool lockWasTaken = false;
            var  instances    = _cursorSprite.Lock(ref lockWasTaken);

            try
            {
                instances[0] = new SpriteInstanceData(position, size, _cursorSprite.Key.Texture.Regions[0], SpriteFlags.TopMid);
            }
            finally { _cursorSprite.Unlock(lockWasTaken); }
        }
Esempio n. 3
0
        void RenderItemInHandCursor(IAssetManager assets, ISpriteManager sm, IWindowManager window, Vector3 normPosition)
        {
            var held           = Resolve <IInventoryManager>().ItemInHand;
            var itemAmountText = GetAmountText();

            if (_lastItemAmountText != itemAmountText)
            {
                var tm = Resolve <ITextManager>();
                _lastItemAmountText = itemAmountText;
                _itemAmountSprite?.Dispose();
                _itemAmountSprite = itemAmountText == null
                    ? null
                    : tm.BuildRenderable(new TextBlock(itemAmountText), DrawLayer.MaxLayer, null, this);
            }

            if (_cursorId != Base.CoreSprite.CursorSmall) // Inventory screen, check what's being held.
            {
                _itemSprite?.Dispose(); _itemSprite             = null;
                _itemAmountSprite?.Dispose(); _itemAmountSprite = null;
                return;
            }

            int      subItem = 0;
            ITexture texture = null;

            switch (held.Item)
            {
            case Gold: texture = assets.LoadTexture(Base.CoreSprite.UiGold); break;

            case Rations: texture = assets.LoadTexture(Base.CoreSprite.UiFood); break;

            case ItemData item:
            {
                texture = assets.LoadTexture(item.Icon);
                subItem = item.IconSubId + _frame % item.IconAnim;
                break;
            }
            }

            if (texture == null)
            {
                _itemSprite?.Dispose();
                _itemSprite = null;
                return;
            }

            if (texture != _itemSprite?.Key.Texture)
            {
                _itemSprite?.Dispose();

                var key = new SpriteKey(texture, SpriteSampler.Point, DrawLayer.Cursor, SpriteKeyFlags.NoDepthTest | SpriteKeyFlags.NoTransform);
                _itemSprite = sm.Borrow(key, 1, this);
            }

            var subImage = texture.Regions[subItem];

            bool lockWasTaken = false;
            var  instances    = _itemSprite.Lock(ref lockWasTaken);

            try
            {
                // TODO: Quantity text
                instances[0] = new SpriteInstanceData(
                    normPosition + new Vector3(window.UiToNormRelative(6, 6), 0),
                    window.UiToNormRelative(subImage.Size),
                    subImage, SpriteFlags.TopMid);
            }
            finally { _itemSprite.Unlock(lockWasTaken); }

            if (_itemAmountSprite != null)
            {
                _itemAmountSprite.Position = normPosition + new Vector3(window.UiToNormRelative(6, 18), 0);
            }
        }