def handle_events(self, events): global mark_counter, marked_tiles # Feed events into the loop events = BaseDebugWindow.handle_events(self, events) sprite_height = 16 if self.mb.lcd.LCDC.sprite_height else 8 for event in events: if event == WindowEvent._INTERNAL_MOUSE and event.window_id == self.window_id: if event.mouse_button == 0: tile_x, tile_y = event.mouse_x // self.scale // 8, event.mouse_y // self.scale // sprite_height sprite_identifier = tile_y * (self.width // 8) + tile_x if sprite_identifier > constants.SPRITES: # Out of bounds continue sprite = Sprite(self.mb, sprite_identifier) marked_tiles.add( MarkedTile( tile_identifier=sprite.tile_identifier, mark_id="SPRITE", mark_color=MARK[mark_counter], sprite_height=sprite_height, sprite=True, )) mark_counter += 1 mark_counter %= len(MARK) elif event.mouse_button == 1: marked_tiles.clear() elif event == WindowEvent._INTERNAL_MARK_TILE: marked_tiles.add(event.tile_identifier) return events
def _sprites_on_screen(self): if self._sprite_cache_invalid: self._cached_sprites_on_screen = [] for s in range(40): sprite = Sprite(self.mb, s) if sprite.on_screen: self._cached_sprites_on_screen.append(sprite) self._sprite_cache_invalid = False return self._cached_sprites_on_screen
def draw_overlay(self): sprite_height = 16 if self.mb.lcd._LCDC.sprite_height else 8 # Mark selected tiles for m, matched_sprites in zip( marked_tiles, self.pyboy.botsupport_manager().sprite_by_tile_identifier([m.tile_identifier for m in marked_tiles]) ): for sprite_index in matched_sprites: sprite = Sprite(self.mb, sprite_index) self.mark_tile(sprite.x, sprite.y, m.mark_color, sprite_height, 8, False)