public static void DrawSprite(Grid grid, Graphics g, Rectangle destination, Item item, Palette palette, int frameNumber = 0, int stackCount = 0, bool hasSpecialLevel = false) { Color color = palette.Colors[item.Active && item.ActiveColor != -1 && !(item is Level) && !item.IsObject ? item.ActiveColor : item.Color]; if (item is Special specialItem) { if (specialItem.Type == (byte)SpecialType.Art || specialItem.Type == (byte)SpecialType.Unknown) { g.DrawImage(SpecialIcon, destination); } return; } else if (item.ID == 0 || string.IsNullOrEmpty(item.Sprite)) { using (SolidBrush brush = new SolidBrush(item.ID == 0 ? palette.Edge : color)) { g.FillRectangle(brush, destination); } return; } Sprite sprite = null; if (item.ID != short.MaxValue && !Reader.Sprites.TryGetValue(item.Sprite, out sprite)) { throw new Exception($"Failed to find Sprite {item.Sprite}"); } Bitmap image = null; int frame = ((frameNumber + item.Position) % 3) + 1; image = sprite[0, frame]?.Image; switch ((Tiling)item.Tiling) { case Tiling.Directional: case Tiling.Animated: switch ((Direction)item.Direction) { case Direction.Up: image = sprite[8, frame]?.Image; break; case Direction.Left: image = sprite[16, frame]?.Image; break; case Direction.Down: image = sprite[24, frame]?.Image; break; } break; case Tiling.Tiled: if (grid != null) { bool isLevelPath = item is Level || item is LevelPath; int position = item.Position + grid.Width; int value = 0; Cell cell; if (position < grid.Cells.Count) { cell = grid.Cells[position]; value = cell.ContainsObject(item) || IsEdge(grid, position) || (isLevelPath && cell.HasLevelPath()) ? 8 : 0; } position = item.Position - 1; if (position >= 0) { cell = grid.Cells[position]; value |= cell.ContainsObject(item) || IsEdge(grid, position) || (isLevelPath && cell.HasLevelPath()) ? 4 : 0; } position = item.Position - grid.Width; if (position >= 0) { cell = grid.Cells[position]; value |= cell.ContainsObject(item) || IsEdge(grid, position) || (isLevelPath && cell.HasLevelPath()) ? 2 : 0; } position = item.Position + 1; if (position < grid.Cells.Count) { cell = grid.Cells[position]; value |= cell.ContainsObject(item) || IsEdge(grid, position) || (isLevelPath && cell.HasLevelPath()) ? 1 : 0; } image = sprite[value, frame]?.Image; } break; case Tiling.Character: switch ((Direction)item.Direction) { case Direction.Up: image = sprite[8, frame]?.Image; break; case Direction.Left: image = sprite[16, frame]?.Image; break; case Direction.Down: image = sprite[24, frame]?.Image; break; } if (item.Sleeping) { image = sprite[31, frame]?.Image; } break; } if (image == null) { image = sprite[0, frame]?.Image; if (image == null) { image = Error; } } if (item is Level level) { if (level.Style == (byte)LevelStyle.Icon) { Bitmap img = sprite[level.SpriteNum, level.SpriteNumExtra]?.Image; if (img != null) { image = img; } } DrawLevel(g, destination, level, image, palette.Colors[level.ActiveColor], palette.Colors[level.Color], frameNumber); } else { DrawImage(g, image, destination, color, hasSpecialLevel); } if (stackCount > 0) { int fontWidth = destination.Width / 3; if (fontWidth <= 0) { fontWidth = 1; } using (Font font = new Font(CustomFont.Families[0], fontWidth, FontStyle.Bold, GraphicsUnit.Pixel)) { string text = stackCount.ToString(); SizeF textSize = g.MeasureString(text, font, 9999999, StringFormat.GenericTypographic); g.DrawString(text, font, Brushes.Red, new Point(destination.X + 1, destination.Y - 2), StringFormat.GenericTypographic); } } }
private static void DrawSpecials(Graphics g, Grid grid, Rectangle bounds, int rowEnd, Palette palette, bool drawLevels, int frameNumber) { int xOrig = bounds.X; int size = grid.Cells.Count; for (int i = 0; i < size; i++) { Cell cell = grid.Cells[i]; int items = cell.Objects.Count; for (int j = 0; j < items; j++) { Item item = cell.Objects[j]; if (item is Special specialItem) { if (!drawLevels && specialItem.Type == (byte)SpecialType.Flower) { Flower flower = specialItem.GetFlower(); DrawFlower(g, bounds, flower.Radius, palette.Colors[flower.Color], palette.Colors[flower.InnerColor], frameNumber); } else if (!drawLevels && specialItem.Type == (byte)SpecialType.Controls) { GameControl gameControl = specialItem.GetGameControl(); switch (gameControl.Type) { case ControlType.Down: g.DrawImage(DownIcon, bounds); break; case ControlType.Idle: g.DrawImage(IdleIcon, bounds); break; case ControlType.Left: g.DrawImage(LeftIcon, bounds); break; case ControlType.Pause: g.DrawImage(PauseIcon, bounds); break; case ControlType.Right: g.DrawImage(RightIcon, bounds); break; case ControlType.Undo: g.DrawImage(UndoIcon, bounds); break; case ControlType.Up: g.DrawImage(UpIcon, bounds); break; case ControlType.Unknown: g.DrawImage(SpecialIcon, bounds); break; } } else if (drawLevels && specialItem.Type == (byte)SpecialType.Level) { Level level = specialItem.GetLevel(); if (level.Style == (byte)LevelStyle.Icon) { level.Style = (byte)LevelStyle.Dot; } DrawLevel(g, bounds, level, null, palette.Colors[level.ActiveColor], palette.Colors[level.Color], frameNumber); } break; } } bounds.X += bounds.Width; if (bounds.X >= rowEnd) { bounds.Y += bounds.Height; bounds.X = xOrig; } } }