private void Metatile_OnClick(Widget widget, InputEventMouse e) { Sprite sprite = State.Data.Sprites[State.SelectedSprite]; if (sprite != null) { MetaTile metatile = (MetaTile)widget; Sprite.FrameTypeEnum frametype; if (metatile.Index >= 0x200) { frametype = Sprite.FrameTypeEnum.Extra; } else if (metatile.Index >= 0x100) { frametype = Sprite.FrameTypeEnum.Extended; } else { frametype = Sprite.FrameTypeEnum.Standard; } SpriteMetaTileFrame tile = sprite.GetMetaTileFrame(frametype, metatile.Index & 0xFF)[metatile.ClickedTile]; if (e.Button == MouseButton.Left) { tile.Tile = (byte)State.SelectedTile; tile.TilePage = (byte)(State.SelectedPage); metatile.SetTile(metatile.ClickedTile, tile.Tile, State.GfxPage(tile.TilePage).Texture); } else if (e.Button == MouseButton.Right) { tile.Flip(); metatile.SetTileFlip(metatile.ClickedTile, tile.FlipH, tile.FlipV); } refreshSpriteDataDisplay(); } }
private void refreshMetatileDisplay() { Sprite sprite = State.Data.Sprites[State.SelectedSprite]; if (sprite == null) { foreach (Label l in lstMetaSpriteLabels) { l.Visible = false; } foreach (MetaTile m in lstMetaSprites) { m.Visible = false; } } else { if (lstMetaSprites.Count != sprite.FrameCount || m_InvalidateAllMetatiles) { m_InvalidateAllMetatiles = false; foreach (Label l in lstMetaSpriteLabels) { l.Parent.RemoveWidget(l); } foreach (MetaTile m in lstMetaSprites) { m.Parent.RemoveWidget(m); } lstMetaSpriteLabels.Clear(); lstMetaSprites.Clear(); int x = 192; int y = 8; int tiles_w = cmbSpriteSize.SelectedIndex + 1; int tiles_h = tiles_w; if (sprite.HasStandardSprites) { Label lbl = new Label(x, y, "Standard Sprites:"); panel_CurrentSprite.AddWidget(lbl); lstMetaSpriteLabels.Add(lbl); for (int i = 0; i < 8; i++) { MetaTile m = new MetaTile(i, x + i * 38, y + 18, 32, 32, Metatile_OnClick, tiles_w, tiles_h); panel_CurrentSprite.AddWidget(m); lstMetaSprites.Add(m); SpriteMetaTileFrame[] tiles = sprite.GetMetaTileFrame(Sprite.FrameTypeEnum.Standard, i); for (int j = 0; j < tiles.Length; j++) { m.SetTile(j, tiles[j].Tile, State.GfxPage(tiles[j].TilePage).Texture); m.SetTileFlip(j, tiles[j].FlipH, tiles[j].FlipV); } } y += 56; } if (sprite.HasExtendedSprites) { Label lbl = new Label(x, y, "Extended Sprites:"); panel_CurrentSprite.AddWidget(lbl); lstMetaSpriteLabels.Add(lbl); for (int i = 0; i < 4; i++) { MetaTile m = new MetaTile(0x100 + i, x + i * 38, y + 18, 32, 32, Metatile_OnClick, tiles_w, tiles_h); panel_CurrentSprite.AddWidget(m); lstMetaSprites.Add(m); SpriteMetaTileFrame[] tiles = sprite.GetMetaTileFrame(Sprite.FrameTypeEnum.Extended, i); for (int j = 0; j < tiles.Length; j++) { m.SetTile(j, tiles[j].Tile, State.GfxPage(tiles[j].TilePage).Texture); m.SetTileFlip(j, tiles[j].FlipH, tiles[j].FlipV); } } y += 56; } if (sprite.ExtraFramesInt != 0) { Label lbl = new Label(x, y, "Extra Frames:"); panel_CurrentSprite.AddWidget(lbl); lstMetaSpriteLabels.Add(lbl); for (int i = 0; i < sprite.ExtraFramesInt; i++) { MetaTile m = new MetaTile(0x200 + i, x + (i % 12) * 38, y + 18 + (i / 12) * 38, 32, 32, Metatile_OnClick, tiles_w, tiles_h); panel_CurrentSprite.AddWidget(m); lstMetaSprites.Add(m); SpriteMetaTileFrame[] tiles = sprite.GetMetaTileFrame(Sprite.FrameTypeEnum.Extra, i); for (int j = 0; j < tiles.Length; j++) { m.SetTile(j, tiles[j].Tile, State.GfxPage(tiles[j].TilePage).Texture); m.SetTileFlip(j, tiles[j].FlipH, tiles[j].FlipV); } } } } foreach (Label l in lstMetaSpriteLabels) { l.Visible = true; } foreach (MetaTile m in lstMetaSprites) { m.Visible = true; } } }