From 30ae643c600f90d917256aecdac5bf0856e256e5 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 23:48:53 +0200 Subject: [PATCH] Add tool for removing lights. --- tabakrolletjie/lights.py | 8 ++++++++ tabakrolletjie/scenes/day.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 747ce92..3b6520c 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -59,6 +59,10 @@ class LightManager(object): self._lights.append(light) light.add(self._space) + def remove_light(self, light): + self._lights.remove(light) + light.remove(self._space) + def battery_dead(self): self._battery_dead = True for light in self._lights: @@ -207,6 +211,10 @@ class BaseLight(object): self.ray_manager.set_space(space) self.ray_manager.update_shapes() + def remove(self, space): + if self.body.space is not None: + space.remove(self.body, *self.body.shapes) + def _cached_surface(self, name, surface): surf = self._surface_cache.get(name) if surf is None: diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index d19b0c6..16e2249 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -115,6 +115,10 @@ class DayScene(BaseScene): tools.append(tool) x += step + tools.append(ImageButton( + '32', 'remove.png', name='remove light', pos=(x, y))) + x += step + tools.append(ImageButton( '32', 'default_cursor.png', name='reset tool', pos=(x, y))) @@ -231,6 +235,11 @@ class DayScene(BaseScene): gamestate.station["lights"].append(cfg) self._lights.add_light(cfg) + def _remove_light(self, ev): + light = self._lights.nearest(ev.pos, surfpos=True, max_distance=25.0) + if light: + self._lights.remove_light(light) + def event(self, ev, gamestate): if self._ending: return @@ -270,6 +279,10 @@ class DayScene(BaseScene): self._set_cursor( 'seed', transform=Alpha(alpha=172)) self._clear_light_toolbar() + elif self._tool.name == 'remove light': + self._set_cursor( + 'remove', transform=Alpha(alpha=172)) + self._clear_light_toolbar() elif self._tool.name == 'light': self._unset_cursor() self._draw_light_toolbar( @@ -289,6 +302,8 @@ class DayScene(BaseScene): if self._tool: if self._tool.name == "seed": self._place_seed(gamestate, ev) + elif self._tool.name == "remove light": + self._remove_light(ev) elif self._tool.name == "light" and self._light_colors: self._place_light( gamestate, self._tool.light_config, -- 2.34.1