--- /dev/null
+
+import pygame.mouse
+import pygame.sprite
+
+from .loader import loader
+
+
+class Cursor(pygame.sprite.Sprite):
+
+ def __init__(self):
+ super(Cursor, self).__init__()
+ self._active = False
+
+ def activate(self, name, group):
+ self.image = loader.load_image('cursors', name + '.png')
+ self.rect = self.image.get_rect()
+ self._active = True
+ group.empty()
+ group.add(self)
+ pygame.mouse.set_visible(0)
+
+ def deactivate(self, group):
+ self._active = False
+ pygame.mouse.set_visible(1)
+ group.empty()
+
+ def update(self):
+ if self._active:
+ self.rect.center = pygame.mouse.get_pos()
""" Base scene class. """
+from pygame.sprite import RenderUpdates
+from ..cursor import Cursor
+
class BaseScene(object):
+ def __init__(self):
+ self._cursor = Cursor()
+ self._cursor_group = RenderUpdates()
+
+ def _set_cursor(self, name):
+ self._cursor.activate(name, self._cursor_group)
+
+ def _unset_cursor(self):
+ self._cursor.deactivate(self._cursor_group)
+
+ def _draw_cursor(self, surface):
+ """Draw the cursor. Should be called at the end of the render
+ method by scenes that need it."""
+ self._cursor_group.update()
+ self._cursor_group.draw(surface)
+
def enter(self, gamestate):
""" Enter the scene. """
pos=(50, SCREEN_SIZE[1] - 40)),
]
+ def exit(self, gamestate):
+ self._unset_cursor()
+
@debug_timer("day.render")
def render(self, surface, gamestate):
surface.fill((0, 0, 155))
self._lights.render_fittings(surface)
for tool in self._tools:
tool.render(surface)
+ self._draw_cursor(surface)
def event(self, ev, gamestate):
if ev.type == pgl.KEYDOWN:
for tool in self._tools:
if tool.pressed(ev):
print 'tool', tool.name
+ self._set_cursor(tool.name)
return
# Not tool, so check lights
self._lights.toggle_nearest(ev.pos, surfpos=True)