self._lights = LightManager(self._space, gamestate)
# Toolbar
self._tools = [
- ImageButton('32', 'seed.png', pos=(50, SCREEN_SIZE[1] - 40)),
+ ImageButton('32', 'seed.png', name='seed',
+ pos=(50, SCREEN_SIZE[1] - 40)),
]
@debug_timer("day.render")
# Check tools
for tool in self._tools:
if tool.pressed(ev):
- print 'tool'
+ print 'tool', tool.name
return
# Not tool, so check lights
self._lights.toggle_nearest(ev.pos, surfpos=True)
font_title = loader.load_font(FONTS['bold'], size=32)
self._title = font_title.render('A Game with a title', True,
(255, 255, 255))
- self._menu = {
- 'load level': TextButton("Load Level", (255, 255, 255)),
- 'saved game': TextButton("Load Saved Game", (255, 255, 255)),
- 'start game': TextButton("Start Game (Day)", (255, 255, 255)),
- }
+ self._menu = [
+ TextButton("Load Level", (255, 255, 255), name='load level'),
+ TextButton("Start Game (Day)", (255, 255, 255), name='start game'),
+ TextButton("Load Saved Game", (255, 255, 255), name='load game'),
+ ]
def render(self, surface, gamestate):
surface.fill((0, 128, 0))
surface.blit(self._title, pos, None)
height = 150
- for label in sorted(self._menu):
- item = self._menu[label]
+ for item in self._menu:
if not item.position:
item.position = ((surface.get_width() - item.get_width()) / 2,
height)
height += item.get_height() + 30
def _get_pressed(self, ev):
- for label, button in self._menu.items():
+ for button in self._menu:
if button.pressed(ev):
- return label
+ return button.name
return None
def _do_day(self):
class Button(object):
- def __init__(self, size, pos=None, padding=10):
+ def __init__(self, size, name=None, pos=None, padding=10):
self._size = size
self._padding = padding
self.position = pos
+ self.name = name
@property
def position(self):
class TextButton(Button):
- def __init__(self, text, colour, pos=None, padding=10):
+ def __init__(self, text, colour, name=None, pos=None, padding=10):
font = loader.load_font(FONTS['sans'], size=24)
self._text = font.render(text, True, colour)
- super(TextButton, self).__init__(self._text.get_size(), pos, padding)
+ super(TextButton, self).__init__(self._text.get_size(), name,
+ pos, padding)
def render(self, surface):
surface.blit(self._text, self._pos, None)
def __init__(self, *imgparts, **kwargs):
self._img = loader.load_image(*imgparts)
+ name = kwargs.get('name')
pos = kwargs.get('pos')
padding = kwargs.get('padding', 0)
- super(ImageButton, self).__init__(self._img.get_size(), pos, padding)
+ super(ImageButton, self).__init__(self._img.get_size(), name,
+ pos, padding)
def render(self, surface):
surface.blit(self._img, self._pos, None)