Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GameListUI(object):
- @staticmethod
- def from_database(**kwargs):
- all_games = []
- for library_id, library_name in database.queryLibrary():
- games = database.queryOrganicGames(library_id, 'libraryname.name', True)
- all_games.extend(games)
- return GameListUI(game_list=all_games, **kwargs)
- def __init__(self, **kwargs):
- self.game_list = kwargs['game_list']
- self.bound_rect = kwargs['bound_rect']
- self.start_x, self.start_y, self.end_x, self.end_y = self.bound_rect
- self.width = self.end_x - self.start_x
- self.height = self.end_y - self.start_y
- self.max_visible_games = 4
- self.horizontal_gap = 10
- self.vertical_gap = 10
- self.selected_index = 0
- self.line_height = (self.height - ((self.max_visible_games-1) * self.vertical_gap)) / self.max_visible_games
- def scroll(self, offset):
- self.selected_index += offset
- if self.selected_index < 0:
- self.selected_index = 0
- elif self.selected_index >= len(self.game_list):
- self.selected_index = len(self.game_list) - 1
- print(self.selected_index)
- def render(self):
- for curr_index, game in enumerate(self.game_list[self.selected_index:self.selected_index+self.max_visible_games]):
- curr_pos_y = self.start_y + (self.line_height + self.vertical_gap) * curr_index
- picture = pygame.image.load('mame/snap/{}'.format(game['picture']))
- big_pic = pygame.transform.scale(picture, (self.line_height, self.line_height))
- rect_pic = big_pic.get_rect(topleft=(self.start_x, curr_pos_y))
- screen.blit(big_pic, rect_pic)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement