예제 #1
0
        public MapRenderable2D(LogicalMap2D logicalMap, ITexture tileset)
        {
            if (tileset == null)
            {
                throw new ArgumentNullException(nameof(tileset));
            }
            _logicalMap = logicalMap ?? throw new ArgumentNullException(nameof(logicalMap));
            var subImage = tileset.GetSubImageDetails(0);

            TileSize = subImage.Size;

            _underlay = AttachChild(new TileLayer(
                                        logicalMap,
                                        tileset,
                                        logicalMap.GetUnderlay,
                                        DrawLayer.Underlay,
                                        IconChangeType.Underlay));

            _overlay = AttachChild(new TileLayer(logicalMap,
                                                 tileset,
                                                 logicalMap.GetOverlay,
                                                 DrawLayer.Overlay,
                                                 IconChangeType.Overlay));

            _info = AttachChild(new InfoOverlay(logicalMap));

            var tileSize = tileset.GetSubImageDetails(0).Size;

            _annotations = AttachChild(new MapAnnotationLayer(logicalMap, tileSize));

            On <ToggleUnderlayEvent>(e => _underlay.IsActive = !_underlay.IsActive);
            On <ToggleOverlayEvent>(e => _overlay.IsActive   = !_overlay.IsActive);
        }
예제 #2
0
        public MapRenderable2D(LogicalMap2D logicalMap, ITexture tileset)
        {
            On <ToggleUnderlayEvent>(e => _underlay.IsActive = !_underlay.IsActive);
            On <ToggleOverlayEvent>(e => _overlay.IsActive   = !_overlay.IsActive);

            _logicalMap = logicalMap;
            var subImage = tileset.GetSubImageDetails(0);

            TileSize = subImage.Size;

            _underlay = AttachChild(new TileLayer(
                                        logicalMap,
                                        tileset,
                                        logicalMap.GetUnderlay,
                                        DrawLayer.Underlay,
                                        IconChangeType.Underlay));

            _overlay = AttachChild(new TileLayer(logicalMap,
                                                 tileset,
                                                 logicalMap.GetOverlay,
                                                 DrawLayer.Overlay,
                                                 IconChangeType.Overlay));

            var tileSize = tileset.GetSubImageDetails(0).Size;

            _annotations = AttachChild(new MapAnnotationLayer(logicalMap, tileSize));
        }
예제 #3
0
        public MapRenderable2D(MapData2D mapData, ITexture tileset, TilesetData tileData) : base(Handlers)
        {
            _mapData  = mapData;
            _tileset  = tileset;
            _tileData = tileData;
            _tileset.GetSubImageDetails(0, out var tileSize, out _, out _, out _);
            TileSize = tileSize;

            var underlay = new SpriteInstanceData[_mapData.Width * _mapData.Height];
            var overlay  = new SpriteInstanceData[_mapData.Width * _mapData.Height];

            _underlay = new MultiSprite(new SpriteKey(
                                            _tileset,
                                            (int)DrawLayer.Underlay,
                                            underlay[0].Flags))
            {
                Instances = underlay.ToArray()
            };

            _overlay = new MultiSprite(new SpriteKey(
                                           _tileset,
                                           (int)DrawLayer.Overlay3,
                                           overlay[0].Flags))
            {
                Instances = overlay.ToArray()
            };
        }
예제 #4
0
        public Tuple <SpriteKey, SpriteInstanceData> Resolve(Sprite sprite)
        {
            var      assetType = AssetTypeLookup[sprite.IdType];
            var      id        = sprite.NumericId;
            ITexture texture   = Resolve <IAssetManager>().LoadTexture(assetType, id);

            if (texture == null)
            {
                return(Tuple.Create(new SpriteKey(_defaultTexture, (int)DrawLayer.Diagnostic, sprite.Flags),
                                    SpriteInstanceData.Centred(sprite.Position,
                                                               new Vector2(_defaultTexture.Width, _defaultTexture.Height),
                                                               Vector2.Zero, Vector2.One, 0, 0)));
            }

            texture.GetSubImageDetails(sprite.SubObject, out var size, out var texOffset, out var texSize, out var layer);

            var key      = new SpriteKey(texture, sprite.RenderOrder, sprite.Flags);
            var instance = SpriteInstanceData.CopyFlags(
                sprite.Position,
                sprite.Size ?? size, texOffset, texSize, layer,
                sprite.Flags | (texture.Format == PixelFormat.R8_UNorm ? SpriteFlags.UsePalette : 0)
                );

            return(Tuple.Create(key, instance));
        }
예제 #5
0
 public MapRenderable2D(MapData2D mapData, ITexture tileset, TilesetData tileData) : base(Handlers)
 {
     _mapData  = mapData;
     _tileset  = tileset;
     _tileData = tileData;
     _tileset.GetSubImageDetails(0, out var tileSize, out _, out _, out _);
     TileSize = tileSize;
 }
예제 #6
0
        SpriteInstanceData BuildInstanceData(int i, int j, TilesetData.TileData tile, int tickCount)
        {
            if (tile == null || tile.Flags.HasFlag(TilesetData.TileFlags.Debug))
            {
                return(_blankInstance);
            }

            int index    = j * _mapData.Width + i;
            int subImage = tile.GetSubImageForTile(tickCount);

            _tileset.GetSubImageDetails(
                subImage,
                out var tileSize,
                out var texPosition,
                out var texSize,
                out var layer);

            DrawLayer drawLayer = tile.Layer.ToDrawLayer();
            var       position  = new Vector3(
                new Vector2(i, j) * tileSize,
                drawLayer.ToZCoordinate(j));

            var instance = _tileData.UseSmallGraphics
                ?  SpriteInstanceData.TopMid(
                position,
                tileSize,
                texPosition,
                texSize,
                layer,
                0)
                : SpriteInstanceData.TopLeft(
                position,
                tileSize,
                texPosition,
                texSize,
                layer,
                0);

            // int zoneNum = _mapData.ZoneLookup[index];
            // int eventNum = zoneNum == -1 ? -1 : _mapData.Zones[zoneNum].EventNumber;

            instance.Flags = 0
                             // |(_tileset is EightBitTexture ? SpriteFlags.UsePalette : 0)
                             // | (HighlightIndex == index ? SpriteFlags.Highlight : 0)
                             // | (eventNum != -1 && _highLightEvent != eventNum ? SpriteFlags.Highlight : 0)
                             // | (_highLightEvent == eventNum ? SpriteFlags.GreenTint : 0)
                             // | (tile.Collision != TilesetData.Passability.Passable ? SpriteFlags.RedTint : 0)
                             // | ((tile.Flags & TilesetData.TileFlags.TextId) != 0 ? SpriteFlags.RedTint : 0)
                             // | (((int) tile.Type) == 8 ? SpriteFlags.GreenTint : 0)
                             // | (((int) tile.Type) == 12 ? SpriteFlags.BlueTint : 0)
                             // | (((int) tile.Type) == 14 ? SpriteFlags.GreenTint | SpriteFlags.RedTint : 0) //&& tickCount % 2 == 0 ? SpriteFlags.Transparent : 0)
            ;

            return(instance);
        }
예제 #7
0
        public Vector2 GetSize(Type idType, int id, int subObject)
        {
            var      assetType = AssetTypeLookup[idType];
            ITexture texture   = Resolve <IAssetManager>().LoadTexture(assetType, id);

            if (texture == null)
            {
                return(Vector2.One);
            }
            texture.GetSubImageDetails(subObject, out var size, out _, out _, out _);
            return(size);
        }
예제 #8
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 != CoreSpriteId.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(CoreSpriteId.UiGold); break;

            case Rations _: texture = assets.LoadTexture(CoreSpriteId.UiFood); break;

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

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

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

                var key = new SpriteKey(texture, DrawLayer.Cursor,
                                        SpriteKeyFlags.NoDepthTest | SpriteKeyFlags.NoTransform);

                _itemSprite = sm.Borrow(key, 1, this);
            }

            var subImage = texture.GetSubImageDetails(subItem);

            // TODO: Quantity text
            var instances = _itemSprite.Access();

            instances[0] = SpriteInstanceData.TopMid(
                normPosition + new Vector3(window.UiToNormRelative(6, 6), 0),
                window.UiToNormRelative(subImage.Size),
                subImage, 0);

            if (_itemAmountSprite != null)
            {
                _itemAmountSprite.Position = normPosition + new Vector3(window.UiToNormRelative(6, 18), 0);
            }
        }
예제 #9
0
        void Render()
        {
            if (!_dirty)
            {
                return;
            }
            _dirty = false;

            var assets = Resolve <IAssetManager>();
            var sm     = Resolve <ISpriteManager>();
            var window = Resolve <IWindowManager>();

            if (window.Size.X < 1 || window.Size.Y < 1)
            {
                return;
            }

            var cursorTexture = assets.LoadTexture(_cursorId);

            if (cursorTexture == null)
            {
                return;
            }

            if (cursorTexture != _cursorSprite?.Key.Texture)
            {
                _cursorSprite?.Dispose();

                var key = new SpriteKey(cursorTexture, DrawLayer.MaxLayer,
                                        SpriteKeyFlags.NoDepthTest | SpriteKeyFlags.NoTransform);

                _cursorSprite = sm.Borrow(key, 1, this);
            }

            var instances = _cursorSprite.Access();
            var position  = new Vector3(window.PixelToNorm(_position), 0.0f);
            var size      = window.UiToNormRelative(_size) / 2;

            instances[0] = SpriteInstanceData.TopMid(position, size, _cursorSprite, 0, 0);

            if (_cursorId == CoreSpriteId.CursorSmall) // Inventory screen, check what's being held.
            {
                var held = Resolve <IInventoryScreenState>().ItemInHand;

                int      subItem = 0;
                ITexture texture = null;

                if (held is GoldInHand)
                {
                    texture = assets.LoadTexture(CoreSpriteId.UiGold);
                }
                else if (held is RationsInHand)
                {
                    texture = assets.LoadTexture(CoreSpriteId.UiFood);
                }
                else if (held is ItemSlot itemInHand)
                {
                    var          item     = assets.LoadItem(itemInHand.Id);
                    ItemSpriteId spriteId = item.Icon + _frame % item.IconAnim;
                    texture = assets.LoadTexture(spriteId);
                    subItem = (int)spriteId;
                }

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

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

                    var key = new SpriteKey(texture, DrawLayer.MaxLayer,
                                            SpriteKeyFlags.NoDepthTest | SpriteKeyFlags.NoTransform);

                    _itemSprite = sm.Borrow(key, 1, this);
                }

                texture.GetSubImageDetails(subItem, out size, out var to, out var ts, out var tl);

                // TODO: Quantity text
                instances    = _itemSprite.Access();
                instances[0] = SpriteInstanceData.TopMid(
                    position + new Vector3(window.UiToNormRelative(new Vector2(6, 6)), 0),
                    window.UiToNormRelative(size),
                    to, ts, tl, 0);
            }
            else
            {
                _itemSprite?.Dispose();
                _itemSprite = null;
            }
        }