/// <summary> /// Triggered when a token is removed from the board. /// </summary> public void OnTokenRemoved( object sender, TokenArgs args) { // Check to see if the token above is burning Token token = args.Token; if (args.IsBurnt) { // Show the burning state with a new sprite (which we // remove when it is done). BurntSprite bt = new BurntSprite(GetTokenSprite(token)); sprites.Add(bt); } // Get the token sprite ContainerSprite ms = GetContainerSprite(token); // Remove the sprites from the list sprites.Remove(ms); // Redraw the entire screen QueueDraw(); log.Debug("TokenRemoved: {0} count {1}", args.Token, sprites.Count); }
/// <summary> /// Triggered when a token is added to the board. /// </summary> public void OnTokenAdded( object sender, TokenArgs args) { // Create a new token TokenSprite ts = new TokenSprite(this, args.Token); ContainerSprite ms = new ContainerSprite(ts); sprites.Add(ms); // Move the sprite over ms.RateX = 100; ms.RateY = 100; ms.X = ms.DesiredX = TileSize * args.Token.Column; ms.Y = ms.DesiredY = TileSize * args.Token.Row; ms.Y -= TileSize; // Check the state if (Game.State == GameState.InProgress && args.Token.Type == TokenType.Flooded && args.Token.Value == ' ') { // Flooded tokens show up in place, but with a special // animation ms.Y = ms.DesiredY; ms.X = ms.DesiredX; ts.DrawableState.Frame = TokenSprite.FloodedStart; } // We need to sort the list again sortNext = true; QueueDraw(); log.Debug( "TokenAdded: {0} sprits {1} state {2}", ts, sprites.Count, Game.State); }
/// <summary> /// Gets the first token sprite in the point. /// </summary. private TokenSprite GetTokenSprite( double dx, double dy) { // Adjust for our offset int x = (int)dx; //(int) dx - pixmapX; int y = (int)dy; //(int) dy - pixmapY; // Go through it foreach (ISprite sprite in sprites) { // Don't bother if we aren't a moving one ContainerSprite ms = sprite as ContainerSprite; if (ms == null) { continue; } TokenSprite ts = ms.TokenSprite; // Check it if (ts.Rectangle.Contains(x, y)) { return(ts); } } // Can't find it //log.Debug("GetTokenSprite: {0}x{1}", x, y); return(null); }
/// <summary> /// Gets a token sprite for a given token, or returns null if /// there is one. /// </summary> public TokenSprite GetTokenSprite(Token token) { // Return it ContainerSprite ms = GetContainerSprite(token); if (ms == null) { return(null); } else { return(ms.ProxiedSprite as TokenSprite); } }
/// <summary> /// Gets a token sprite for a given token, or returns null if /// there is one. /// </summary> public ContainerSprite GetContainerSprite(Token token) { // Go through the sprites, unwrap the moving sprites, and // check for the token. foreach (ISprite sprite in sprites) { if (sprite is ContainerSprite) { ContainerSprite ms = (ContainerSprite)sprite; TokenSprite ts = ms.TokenSprite; if (ts != null && ts.Token == token) { return(ms); } } } // Can't find it return(null); }
/// <summary> /// Triggered when the drawing area is configured. /// </summary> private void OnConfigure( object obj, ConfigureEventArgs args) { // Pull out some fields and figure out the sizes EventConfigure ev = args.Event; Window window = ev.Window; int width = Allocation.Width; int height = Allocation.Height; int min = Math.Min(width, height); // Figure out the tile height tileSize = min / Game.Board.Size; log.Info("New tile size: {0}px", tileSize); // Adjust the viewport height viewport.Height = height; viewport.Width = width; // Create the backing pixmap pixmap = new Pixmap(window, width, height, -1); // We moved, so rapid move the tiles foreach (ISprite sprite in sprites) { ContainerSprite cs = sprite as ContainerSprite; if (cs != null) { cs.FireInvalidate(); cs.X = cs.TokenSprite.X = tileSize * cs.TokenSprite.Token.Column; cs.FireInvalidate(); } } // Mark ourselves as done QueueDraw(); args.RetVal = true; }