Less buggy Kivy 1.7 hackery
[erdslangetjie.git] / erdslangetjie / localwidgets.py
index 885ac51907ecfeb59f90f53c7f2c4a711946202e..a4fca0fd2cd70e5b3a599a993b4c70accad16ae1 100644 (file)
@@ -63,18 +63,15 @@ class GameWindow(RelativeLayout):
         self._background = Widget(size=self.size, pos=(0, 0))
         tiles = self.level_obj.get_tiles()
         bx, by = 0, 0
-        for tile_line in tiles:
-            bx = 0
-            for tile in tile_line:
-                self.draw_tile((bx, by), tile)
-                bx += TILE_SIZE
-            by += TILE_SIZE
-        self.add_widget(self._background)
-
-    def draw_tile(self, pos, tile):
         with self._background.canvas:
-            Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE),
-                    texture=tile.texture)
+            for tile_line in tiles:
+                bx = 0
+                for tile in tile_line:
+                    Rectangle(pos=(bx, by), size=(TILE_SIZE, TILE_SIZE),
+                            texture=tile.texture)
+                    bx += TILE_SIZE
+                by += TILE_SIZE
+        self.add_widget(self._background)
 
     def fix_scroll_margins(self):
         # We need to call this after app.root is set
@@ -282,7 +279,9 @@ class GameWindow(RelativeLayout):
             self.level_obj.trigger_button(self.nemesis.pos)
         for map_pos, new_tile in self.level_obj.get_changed_tiles():
             pos = (map_pos[0] * TILE_SIZE, map_pos[1] * TILE_SIZE)
-            self.draw_tile(pos, new_tile)
+            with self._background.canvas:
+                Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE),
+                        texture=new_tile.texture)
         return False
 
     def _calc_mouse_pos(self, pos):
@@ -298,6 +297,7 @@ class GameWindow(RelativeLayout):
         if self._near_player(pos):
             self.mouse_move = True
             self.mouse_start = pos
+            return True
 
     def on_touch_up(self, touch):
         self.mouse_move = False
@@ -311,6 +311,7 @@ class GameWindow(RelativeLayout):
                         pos[1] - self.mouse_start[1])
                 self.do_move(direction)
                 self.mouse_start = pos
+                return True
 
 
 class Screen(Widget):
@@ -361,6 +362,27 @@ class LostScreen(Screen):
     START = 'Retry?'
 
 
+class MyScrollView(ScrollView):
+
+    def on_touch_down(self, touch):
+        for child in self.children:
+            if child.on_touch_down(touch):
+                return True
+        return super(MyScrollView, self).on_touch_down(touch)
+
+    def on_touch_move(self, touch):
+        for child in self.children:
+            if child.on_touch_move(touch):
+                return True
+        return super(MyScrollView, self).on_touch_move(touch)
+
+    def on_touch_up(self, touch):
+        for child in self.children:
+            if child.on_touch_up(touch):
+                return True
+        return super(MyScrollView, self).on_touch_up(touch)
+
+
 class GameApp(App):
 
     title = "Bane's Befuddlement"
@@ -400,7 +422,7 @@ class GameApp(App):
                 self.config, data=config_json)
 
     def build(self):
-        root = ScrollView(size_hint=(None, None))
+        root = MyScrollView(size_hint=(None, None))
         level_name = self.config.getdefault('bane', 'start_level', None)
         if level_name:
             self.levels.set_level_to(level_name)