X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fscenes%2Froach_management.py;h=dd05e755404334f6b37394a044a02b30f1ec6f78;hb=ed7b7dbe49f3962132f0db806552a5873d6fc113;hp=77100ab7435290d03f7c77d10e45aac171339427;hpb=208b0bfa93ce450a3d1e686d0bd0b2c93104f7b8;p=koperkapel.git diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index 77100ab..dd05e75 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -1,5 +1,6 @@ """ Roach management scene. """ +from pygame.constants import BLEND_RGBA_MULT, BLEND_RGBA_SUB from pgzero.constants import keys, mouse from pgzero.actor import Actor from pgzero.screen import Screen @@ -9,7 +10,8 @@ from ..constants import WIDTH, HEIGHT from ..roaches import big_roaches, roach_by_name from ..serums import big_serums, roach_is_serumless, SERUMS from ..vehicles.base import Vehicle -from .base import Scene, ChangeSceneEvent +from .base import Scene, ChangeSceneEvent, defer_to_update +from ..util import safepath TOOLBAR_LEFT_X = WIDTH * 3 // 4 @@ -51,7 +53,6 @@ class RoachesScene(Scene): def enter(self, world): self._vehicle = Vehicle.current(world) - self._update_calls = [] self._init_bg() self._init_seats() self._init_roaches(world) @@ -67,6 +68,15 @@ class RoachesScene(Scene): else: base.fill((10, 10, 10)) base.blit(overlay, (0, 0)) + frame = self._vehicle.roach_management_frame() + if frame is not None: + frame = frame.copy() + frame.fill((255, 255, 255, 8), None, BLEND_RGBA_MULT) + frame_rect = frame.get_rect() + base.blit(frame, ( + VEHICLE_MID_X - frame_rect.w // 2, + VEHICLE_MID_Y - frame_rect.h // 2), + None, BLEND_RGBA_SUB) self.actors.default.add(SurfActor(base)) def _init_seats(self): @@ -126,10 +136,10 @@ class RoachesScene(Scene): def _init_pads(self): self._roach_pad = self._pad_layer.add( - Actor("roach_management/roach_pad", anchor=("left", "bottom"))) + Actor(safepath("roach_management/roach_pad"), anchor=("left", "bottom"))) self._roach_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y) self._inventory_pad = self._pad_layer.add( - Actor("roach_management/inventory_pad", anchor=("left", "top"))) + Actor(safepath("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): @@ -141,23 +151,23 @@ class RoachesScene(Scene): def _init_buttons(self): self._button_layer.clear() self._add_button( - "roach_management/left_button", ("left", "bottom"), (1, -1), + safepath("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), + safepath("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), + safepath("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), + safepath("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), + safepath("roach_management/eject_button"), ("right", "top"), (-1, 1), (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach) def _roach_left(self): @@ -177,24 +187,18 @@ class RoachesScene(Scene): self._seat_pos = seat_pos self._seat_layer[self._seat_pos].selected = True - def _eject_roach(self, world=None): - if world is None: - self._update_calls.append(self._eject_roach) - return + @defer_to_update + def _eject_roach(self, world): self._vehicle.seat_roach(world, None, self._seat_pos) - def _click_roach_pad(self, world=None): - if world is None: - self._update_calls.append(self._click_roach_pad) - return + @defer_to_update + def _click_roach_pad(self, world): if self._outside_roaches: roach = self._outside_roaches[self._outside_roach_pos] self._vehicle.seat_roach(world, roach, self._seat_pos) - def _click_inventory_pad(self, world=None): - if world is None: - self._update_calls.append(self._click_inventory_pad) - return + @defer_to_update + def _click_inventory_pad(self, world): roach_name = self._vehicle.roach_at(world, self._seat_pos) if roach_name is None: return @@ -208,19 +212,15 @@ class RoachesScene(Scene): if roach_is_serumless(roach): roach[serum] = True world.serums = serums - self._update_calls.append((self._update_roach_actor, roach_name)) + self._update_roach_actor(roach_name) + @defer_to_update def _update_roach_actor(self, world, roach_name): roach = roach_by_name(world, roach_name) self._roach_actors[roach_name] = big_roaches.assemble(roach) def update(self, world, engine, dt): - update_calls, self._update_calls = self._update_calls, [] - while update_calls: - f, args = update_calls.pop(), () - if type(f) is tuple: - f, args = f[0], f[1:] - f(world, *args) + super().update(world, engine, dt) events = world.pop_events() self._update_inventory(world) self._update_roaches(world)