public override void Subscribed() { var sm = Resolve <ISpriteManager>(); var underlayKey = new SpriteKey(_tileset, DrawLayer.Underlay, 0); var overlayKey = new SpriteKey(_tileset, DrawLayer.Overlay3, 0); _underlay = sm.Borrow(underlayKey, _mapData.Width * _mapData.Height, this); _overlay = sm.Borrow(overlayKey, _mapData.Width * _mapData.Height, this); Raise(new LoadPaletteEvent(Palette)); Update(true); }
protected override void Subscribed() { if (_sprite == null) { var assets = Resolve <IAssetManager>(); var texture = assets.LoadTexture(_id); var key = new SpriteKey(texture, DrawLayer.Interface, SpriteKeyFlags.NoTransform | SpriteKeyFlags.NoDepthTest); _sprite = Resolve <ISpriteManager>().Borrow(key, 1, this); } Rebuild(); }
void UpdateSprite(Vector3 position, Vector2 size, DrawLayer layer) { if (layer != _sprite?.Key.RenderOrder) { _sprite?.Dispose(); var sm = Resolve <ISpriteManager>(); var key = new SpriteKey(CommonColors.BorderTexture, layer, SpriteKeyFlags.NoTransform | SpriteKeyFlags.NoDepthTest); _sprite = sm.Borrow(key, 1, this); } else if (_lastPosition == position && _lastSize == size) { return; } var instances = _sprite.Access(); instances[0] = SpriteInstanceData.TopLeft(position, size, _sprite, (int)CommonColors.Palette[_color], 0); _lastPosition = position; _lastSize = size; }
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, DrawLayer.MaxLayer, SpriteKeyFlags.NoTransform | SpriteKeyFlags.NoDepthTest); _hotspotSprite = sm.Borrow(key, 1, this); } var instances = _hotspotSprite.Access(); var position = new Vector3(window.PixelToNorm(Position), 0.0f); var size = window.UiToNormRelative(Vector2.One); instances[0] = SpriteInstanceData.TopLeft(position, size, _hotspotSprite, (int)commonColors.Palette[CommonColor.Yellow3], 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); } }
public PositionedSpriteBatch(SpriteLease lease, Vector2 size) { _sprite = lease ?? throw new ArgumentNullException(nameof(lease)); Size = size; }
protected override void Unsubscribed() { _sprite?.Dispose(); _sprite = null; }
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); } }
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; } }
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); } }