adjusted item_selection and created a module 'beatplayer'
This commit is contained in:
@ -5,21 +5,23 @@ import math
|
||||
|
||||
class ItemSelection:
|
||||
|
||||
def __init__(self, surface, max_item_width, max_count):
|
||||
def __init__(self, max_item_width, max_display_count = 9):
|
||||
self.index = 0
|
||||
self.items = []
|
||||
self.surface = surface
|
||||
self.surface = pygame.Surface((0,0), pygame.SRCALPHA)
|
||||
self.max_item_width = max_item_width
|
||||
self.max_count = max_count
|
||||
self.max_display_count = max_display_count
|
||||
|
||||
def set_items(self, items):
|
||||
self.items = items
|
||||
self.surface = pygame.Surface(
|
||||
(self.max_item_width+50, self.get_display_count()*40),
|
||||
pygame.SRCALPHA)
|
||||
(self.max_item_width+50, self.get_display_count()*40), pygame.SRCALPHA)
|
||||
|
||||
def get_display_count(self):
|
||||
return min(self.max_count, len(self.items))
|
||||
return min(self.max_display_count, len(self.items))
|
||||
|
||||
def get_count(self):
|
||||
return len(self.items)
|
||||
|
||||
def update(self):
|
||||
self.surface.fill("black")
|
||||
@ -34,11 +36,12 @@ class ItemSelection:
|
||||
text_surface = font_helvetica16.render(text, False, color_primary_light)
|
||||
else:
|
||||
text_surface = font_helvetica16.render(text, False, color_primary)
|
||||
opacity = -20 + math.floor((i+1) * 2 * 255 / self.max_count
|
||||
if i < self.max_count/2
|
||||
else (self.max_count-i) * 2 * 255 / self.max_count)
|
||||
opacity = -15 + math.floor((i+1) * 2 * 255 / self.max_display_count
|
||||
if i < self.max_display_count/2
|
||||
else (self.max_display_count-i) * 2 * 255 / self.max_display_count)
|
||||
text_surface.set_alpha(opacity)
|
||||
#if text_surface.get_width() > self.max_item_width: self.max_item_width = text_surface.get_width()
|
||||
self.surface.blit(text_surface, ((10, self.surface.get_height()/self.get_display_count()*i)))
|
||||
pygame.draw.rect(self.surface, color_primary_light, (0, self.surface.get_height()/2-25, self.max_item_width+20, 40), 2)
|
||||
pygame.draw.rect(self.surface, color_primary_light,
|
||||
(0, self.surface.get_height()/2-25, self.max_item_width+20, 40), 2)
|
||||
|
||||
Reference in New Issue
Block a user