Add tool for removing lights.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 21:48:53 +0000 (23:48 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 21:48:53 +0000 (23:48 +0200)
tabakrolletjie/lights.py
tabakrolletjie/scenes/day.py

index 747ce92e86449ea92102dbbb5b0d73465339dd66..3b6520c3d96cdb15b5614a66db0e3bc65e9e9dc5 100644 (file)
@@ -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:
index d19b0c6e526e68118be0fca16b005bd13b836f9b..16e2249e5c6fbb32b8007749dbd7cb08227a3934 100644 (file)
@@ -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,