protected static void RenderEntityDetails(int x, int y, ShopItemControl display, IEntity shopItem, ISystemContainer systemContainer, ISpriteManager spriteManager) { BLT.Font(""); SpriteAppearance appearance = shopItem.Has <SpriteAppearance>() ? shopItem.Get <SpriteAppearance>() : new SpriteAppearance { Bottom = "unknown" }; AnimationFrame frame = shopItem.Has <Animated>() ? systemContainer.AnimationSystem.GetFrame(shopItem) : AnimationFrame.Idle0; Price price = shopItem.Get <Price>(); var playerWealth = systemContainer.ItemSystem.CheckWealth(systemContainer.PlayerSystem.Player, price.Currency); var canAfford = playerWealth >= price.Amount; BLTLayers.Set(BLTLayers.UIElementPieces, display.ActivityIndex); string appearanceBottom = appearance.Bottom; RenderSpriteIfSpecified(x + 4 + BLTTilesIOSystem.TILE_SPACING * 2, y + 4, spriteManager, appearanceBottom, frame); BLTLayers.Set(BLTLayers.UIElementPieces + 1, display.ActivityIndex); string appearanceTop = appearance.Top; RenderSpriteIfSpecified(x + 4 + BLTTilesIOSystem.TILE_SPACING * 2, y + 4, spriteManager, appearanceTop, frame); BLTLayers.Set(BLTLayers.Text, display.ActivityIndex); BLT.Font("text"); BLT.Print(new Rectangle(x + 2, y + BLTTilesIOSystem.TILE_SPACING * 2 + 2, 6 * BLTTilesIOSystem.TILE_SPACING, 10), ContentAlignment.TopCenter, shopItem.GetBLTName()); BLT.Color(canAfford ? Color.Gold : Color.Gray); BLT.Print(new Rectangle(x + 2, y + BLTTilesIOSystem.TILE_SPACING * 2 + 12, 6 * BLTTilesIOSystem.TILE_SPACING, 10), ContentAlignment.TopCenter, $"{price.Amount} {price.Currency}"); BLT.Color(Color.White); }
private static string GetConnect(SpriteAppearance appearance, bool top) { if (appearance == null) { return(null); } return(!top ? appearance.BottomConnect : appearance.TopConnect); }
public static TileDirections GetDirections(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top) { SpriteAppearance appearance = tilesTracker[x, y, z]; string connect = GetConnect(appearance, top); SpriteConnectType connectType = GetConnectType(appearance, top); TileDirections directions = TileDirections.None; if (appearance == null || connect == null) { return(directions); } SpriteAppearance above = tilesTracker[x, y - 1, z]; SpriteAppearance below = tilesTracker[x, y + 1, z]; SpriteAppearance left = tilesTracker[x - 1, y, z]; SpriteAppearance right = tilesTracker[x + 1, y, z]; bool aboveConnect = GetConnect(above, top) == connect; bool belowConnect = GetConnect(below, top) == connect; bool leftConnect = GetConnect(left, top) == connect; bool rightConnect = GetConnect(right, top) == connect; if (aboveConnect) { directions |= TileDirections.Up; } if (belowConnect) { directions |= TileDirections.Down; } if (leftConnect) { directions |= TileDirections.Left; } if (rightConnect) { directions |= TileDirections.Right; } if (connectType == SpriteConnectType.Wall) { directions = ApplyWallTypeConnectionRules(tilesTracker, x, y, z, top, directions, connect); } return(directions); }
protected static void RenderEntitySprite(int x, int y, IDataRogueControl display, ISystemContainer systemContainer, ISpriteManager spriteManager, IEntity entity) { if (entity != null) { BLT.Font(""); SpriteAppearance appearance = entity.Has <SpriteAppearance>() ? entity.Get <SpriteAppearance>() : new SpriteAppearance { Bottom = "unknown" }; AnimationFrame frame = entity.Has <Animated>() ? systemContainer.AnimationSystem.GetFrame(entity) : AnimationFrame.Idle0; BLTLayers.Set(BLTLayers.UIElementPieces, display.ActivityIndex); string appearanceBottom = appearance.Bottom; RenderSpriteIfSpecified(x, y, spriteManager, appearanceBottom, frame); BLTLayers.Set(BLTLayers.UIElementPieces + 1, display.ActivityIndex); string appearanceTop = appearance.Top; RenderSpriteIfSpecified(x, y, spriteManager, appearanceTop, frame); } }
protected override void DisplayInternal(ISpriteManager spriteManager, IDataRogueControl control, ISystemContainer systemContainer, List <MapCoordinate> playerFov) { var x = control.Position.X; var y = control.Position.Y; var display = control as IDataRogueInfoControl; List <IEntity> interactables = systemContainer.InteractableSystem.GetInteractablesNear(systemContainer.PlayerSystem.Player); if (interactables.Any()) { var possibleInteractions = interactables .SelectMany(e => e.Components.OfType <Interaction>() .Select(i => new { Entity = e, Interactable = i })); (IEntity, Interaction)currentInteraction = systemContainer.InteractableSystem.GetCurrentInteractionFor(systemContainer.PlayerSystem.Player); var interactEntity = currentInteraction.Item1; var interactable = currentInteraction.Item2; BLT.Font(""); SpriteAppearance appearance = interactEntity.Has <SpriteAppearance>() ? interactEntity.Get <SpriteAppearance>() : new SpriteAppearance { Bottom = "unknown" }; AnimationFrame frame = interactEntity.Has <Animated>() ? systemContainer.AnimationSystem.GetFrame(interactEntity) : AnimationFrame.Idle0; BLTLayers.Set(BLTLayers.UIElementPieces, display.ActivityIndex); string appearanceBottom = appearance.Bottom; RenderSpriteIfSpecified(x + 4, y + 4, spriteManager, appearanceBottom, frame); BLTLayers.Set(BLTLayers.UIElementPieces + 1, display.ActivityIndex); string appearanceTop = appearance.Top; RenderSpriteIfSpecified(x + 4, y + 4, spriteManager, appearanceTop, frame); BLTLayers.Set(BLTLayers.Text, display.ActivityIndex); BLT.Font("text"); BLT.Color(Color.LightBlue); BLT.Print(x + BLTTilesIOSystem.TILE_SPACING + 6, y + BLTTilesIOSystem.TILE_SPACING / 2, interactable.Verb); BLT.Color(Color.White); BLT.Print(x + BLTTilesIOSystem.TILE_SPACING + 6, y + 4 + BLTTilesIOSystem.TILE_SPACING / 2, interactEntity.DescriptionName); RenderBackgroundBox(x, y, display.ActivityIndex, control.Position.Size, spriteManager); } }
private static bool OppositeCornersConnect(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top, TileDirections fromDirection, string connect) { Vector clockwiseVector = OppositeCornerClockwise[fromDirection]; SpriteAppearance clockwiseAppearance = tilesTracker[x + clockwiseVector.X, y + clockwiseVector.Y, z]; string clockwiseConnect = top ? clockwiseAppearance.TopConnect : clockwiseAppearance.BottomConnect; if (connect != clockwiseConnect) { return(false); } Vector anticlockwiseVector = OppositeCornerAnticlockwise[fromDirection]; SpriteAppearance anticlockwiseAppearance = tilesTracker[x + anticlockwiseVector.X, y + anticlockwiseVector.Y, z]; string anticlockwiseConnect = top ? anticlockwiseAppearance.TopConnect : anticlockwiseAppearance.BottomConnect; if (connect != anticlockwiseConnect) { return(false); } return(true); }
protected static void RenderEntityDetails(int x, int y, IDataRogueInfoControl display, IEntity hoveredEntity, ISystemContainer systemContainer, ISpriteManager spriteManager) { BLT.Font(""); SpriteAppearance appearance = hoveredEntity.Has <SpriteAppearance>() ? hoveredEntity.Get <SpriteAppearance>() : new SpriteAppearance { Bottom = "unknown" }; AnimationFrame frame = hoveredEntity.Has <Animated>() ? systemContainer.AnimationSystem.GetFrame(hoveredEntity) : AnimationFrame.Idle0; BLTLayers.Set(BLTLayers.UIElementPieces, display.ActivityIndex); string appearanceBottom = appearance.Bottom; RenderSpriteIfSpecified(x + 2, y + 3, spriteManager, appearanceBottom, frame); BLTLayers.Set(BLTLayers.UIElementPieces + 1, display.ActivityIndex); string appearanceTop = appearance.Top; RenderSpriteIfSpecified(x + 2, y + 3, spriteManager, appearanceTop, frame); BLTLayers.Set(BLTLayers.Text, display.ActivityIndex); BLT.Font("text"); BLT.Print(x + BLTTilesIOSystem.TILE_SPACING + 4, y - 1 + BLTTilesIOSystem.TILE_SPACING / 2, hoveredEntity.GetBLTName()); y += 12; foreach (var split in display.Parameters.Split(';')) { var counter = GetCounter(split, hoveredEntity, out string counterText); if (counter != null) { var text = $"{counterText}: {counter}"; RenderText(x + 4, y, display.ActivityIndex, out var textSize, text, display.Color); y += 3; } } BLT.Font("text"); BLT.Print(x + 4, y, hoveredEntity.Get <Description>().Detail); }
private static SpriteConnectType GetConnectType(SpriteAppearance appearance, bool top) { return(top ? appearance.TopConnectType : appearance.BottomConnectType); }
protected virtual void RenderMap(ISpriteManager spriteManager, IDataRogueControl mapConfiguration, ISystemContainer systemContainer, List <MapCoordinate> playerFov) { var cameraPosition = systemContainer.RendererSystem.CameraPosition; var currentMap = systemContainer.MapSystem.MapCollection[cameraPosition.Key]; var cameraX = cameraPosition.X; var cameraY = cameraPosition.Y; var playerMoving = systemContainer.PlayerSystem.Player?.TryGet <Moving>(); var playerMovingOffsetX = playerMoving == null ? 0 : -playerMoving.OffsetX; var playerMovingOffsetY = playerMoving == null ? 0 : -playerMoving.OffsetY; var renderWidth = mapConfiguration.Position.Width / BLTTilesIOSystem.TILE_SPACING; var renderHeight = mapConfiguration.Position.Height / BLTTilesIOSystem.TILE_SPACING; int offsetX = renderWidth / 2; int offsetY = renderHeight / 2; var tilesTracker = new SpriteAppearance[renderWidth + 2, renderHeight + 2, 2]; var frameTracker = new AnimationFrame[renderWidth + 2, renderHeight + 2, 2]; var offsetTracker = new BLTMapRendererOffset[renderWidth + 2, renderHeight + 2, 2]; var particlesTracker = new List <IEntity> [renderWidth + 2, renderHeight + 2]; var renderTracker = new bool[renderWidth + 2, renderHeight + 2]; var fovTracker = new bool[renderWidth + 2, renderHeight + 2]; for (int x = -1; x < renderWidth + 1; x++) { for (int y = -1; y < renderHeight + 1; y++) { var lookupX = cameraX - offsetX + x; var lookupY = cameraY - offsetY + y; MapCoordinate coordinate = new MapCoordinate(currentMap.MapKey, lookupX, lookupY); var isInFov = playerFov?.Contains(coordinate) ?? true; renderTracker[x + 1, y + 1] = isInFov || currentMap.SeenCoordinates.Contains(coordinate); fovTracker[x + 1, y + 1] = isInFov; var entities = GetEntitiesAt(systemContainer, currentMap, coordinate); var particles = entities.Where(e => e.Has <TextParticle>()).ToList(); foreach (var particle in particles) { entities.Remove(particle); } var mapCell = entities.Last(); var topEntity = entities .OrderByDescending(a => a.Get <Appearance>().ZOrder) .FirstOrDefault(e => isInFov || IsRemembered(currentMap, coordinate, e)); if (topEntity == mapCell) { topEntity = null; } tilesTracker[x + 1, y + 1, 0] = mapCell.Get <SpriteAppearance>(); var animatedCell = mapCell.TryGet <Animated>(); if (animatedCell != null) { frameTracker[x + 1, y + 1, 0] = systemContainer.AnimationSystem.GetFrame(mapCell); } else { frameTracker[x + 1, y + 1, 0] = 0; } var movingCell = mapCell.TryGet <Moving>(); if (movingCell != null) { offsetTracker[x + 1, y + 1, 0] = new BLTMapRendererOffset(movingCell.OffsetX + playerMovingOffsetX, movingCell.OffsetY + playerMovingOffsetY); } else { offsetTracker[x + 1, y + 1, 0] = new BLTMapRendererOffset(playerMovingOffsetX, playerMovingOffsetY); } if (topEntity != null) { var spriteAppearance = topEntity.TryGet <SpriteAppearance>(); if (spriteAppearance != null) { tilesTracker[x + 1, y + 1, 1] = spriteAppearance; } else { tilesTracker[x + 1, y + 1, 1] = new SpriteAppearance { Top = "unknown" }; } var animatedEntity = topEntity.TryGet <Animated>(); if (animatedEntity != null) { frameTracker[x + 1, y + 1, 1] = systemContainer.AnimationSystem.GetFrame(topEntity); } else { frameTracker[x + 1, y + 1, 1] = 0; } var moving = topEntity.TryGet <Moving>(); if (moving != null) { offsetTracker[x + 1, y + 1, 1] = new BLTMapRendererOffset(moving.OffsetX + playerMovingOffsetX, moving.OffsetY + playerMovingOffsetY); } else { offsetTracker[x + 1, y + 1, 1] = new BLTMapRendererOffset(playerMovingOffsetX, playerMovingOffsetY); } } particlesTracker[x + 1, y + 1] = particles.ToList(); } } RenderMapSprites(spriteManager, mapConfiguration, renderTracker, renderWidth, renderHeight, tilesTracker, frameTracker, offsetTracker, 0, false); RenderMapSprites(spriteManager, mapConfiguration, renderTracker, renderWidth, renderHeight, tilesTracker, frameTracker, offsetTracker, 1, false); RenderMapSprites(spriteManager, mapConfiguration, renderTracker, renderWidth, renderHeight, tilesTracker, frameTracker, offsetTracker, 0, true); RenderMapSprites(spriteManager, mapConfiguration, renderTracker, renderWidth, renderHeight, tilesTracker, frameTracker, offsetTracker, 1, true); RenderMapParticles(systemContainer, renderTracker, fovTracker, particlesTracker, renderWidth, renderHeight, mapConfiguration); RenderMapShade(spriteManager, renderTracker, fovTracker, renderWidth, renderHeight, offsetTracker, mapConfiguration); }