""" Roach management scene. """
-from pgzero.constants import keys
+from pgzero.constants import keys, mouse
from pgzero.actor import Actor
-from ..actors.buttons import TextButton
+from ..actors.buttons import TextButton, ImageButton
from ..constants import WIDTH, HEIGHT
from .base import Scene, ChangeSceneEvent
BUTTON_INSET = (20, 20)
-def inset_button(pos, dx, dy):
+def inset_button(pos, d):
return (
- pos[0] + dx * BUTTON_INSET[0],
- pos[1] + dy * BUTTON_INSET[1])
+ pos[0] + d[0] * BUTTON_INSET[0],
+ pos[1] + d[1] * BUTTON_INSET[1])
class RoachesScene(Scene):
Actor("roach_management/inventory_pad", anchor=("left", "top")))
self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
+ def _add_button(self, name, anchor, inset, pos, action):
+ button = self._buttons.add(
+ ImageButton(name, anchor=anchor, action=action))
+ button.pos = inset_button(pos, inset)
+ return button
+
def _init_buttons(self):
- self._roach_left = self._buttons.add(
- Actor("roach_management/left_button", anchor=("left", "bottom")))
- self._roach_left.pos = inset_button(
- self._roach_pad.bottomleft, 1, -1)
-
- self._roach_right = self._buttons.add(
- Actor("roach_management/right_button", anchor=("right", "bottom")))
- self._roach_right.pos = inset_button(
- self._roach_pad.bottomright, -1, -1)
-
- self._inventory_left = self._buttons.add(
- Actor("roach_management/left_button", anchor=("left", "bottom")))
- self._inventory_left.pos = inset_button(
- self._inventory_pad.bottomleft, 1, -1)
-
- self._inventory_right = self._buttons.add(
- Actor("roach_management/right_button", anchor=("right", "bottom")))
- self._inventory_right.pos = inset_button(
- self._inventory_pad.bottomright, -1, -1)
-
- self._road_eject = self._buttons.add(
- Actor("roach_management/eject_button", anchor=("right", "top")))
- self._road_eject.pos = inset_button(
- (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), -1, 1)
+ self._add_button(
+ "roach_management/left_button", ("left", "bottom"), (1, -1),
+ self._roach_pad.bottomleft, self._roach_left)
+
+ self._add_button(
+ "roach_management/right_button", ("right", "bottom"), (-1, -1),
+ self._roach_pad.bottomright, self._roach_right)
+
+ self._add_button(
+ "roach_management/left_button", ("left", "bottom"), (1, -1),
+ self._inventory_pad.bottomleft, self._inventory_left)
+
+ self._add_button(
+ "roach_management/right_button", ("right", "bottom"), (-1, -1),
+ self._inventory_pad.bottomright, self._inventory_right)
+
+ self._add_button(
+ "roach_management/eject_button", ("right", "top"), (-1, 1),
+ (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach)
+
+ def _roach_left(self):
+ print("Cycle outside roaches left.")
+
+ def _roach_right(self):
+ print("Cycle outside roaches right.")
+
+ def _inventory_left(self):
+ print("Cycle inventory left.")
+
+ def _inventory_right(self):
+ print("Cycle inventory right.")
+
+ def _eject_roach(self):
+ print("Eject roach.")
def update(self, world, dt):
for i, roach in enumerate(world.roaches):
if key == keys.ESCAPE:
from .menu import MenuScene
return [ChangeSceneEvent(MenuScene())]
+
+ def on_mouse_down(self, pos, button):
+ if button == mouse.LEFT:
+ for actor in self.actors.buttons:
+ if actor.collidepoint(pos):
+ actor.action()
+ break