Start hooking up editor functions
authorNeil <neil@dip.sun.ac.za>
Wed, 17 Apr 2013 20:34:40 +0000 (22:34 +0200)
committerNeil <neil@dip.sun.ac.za>
Wed, 17 Apr 2013 20:34:40 +0000 (22:34 +0200)
erdslangetjie/editor/editor.py

index afc480e70ea6b11144fe4202aa19706bd0fd044b..2e2c0bc92f0f6c475398fb254f9563be174b76a1 100644 (file)
@@ -7,6 +7,7 @@ from kivy.app import App
 from kivy.uix.widget import Widget
 from kivy.uix.floatlayout import FloatLayout
 from kivy.graphics import Color, Rectangle
+from kivy.uix.label import Label
 from kivy.utils import platform
 from kivy.config import Config
 
@@ -40,22 +41,69 @@ class EditorWindow(FloatLayout):
         level_data.close()
         self.level_obj.load_tiles()
 
+        self.tool = None
+        self.tool_widgets = []
+
     def build(self):
         self.clear_widgets()
         tiles = self.level_obj.get_tiles()
         bx, by = 0, 0
+        self.nodes = {}
         for tile_line in tiles:
             bx = 0
             for tile in tile_line:
                 node = Widget(size=(TILE_SIZE, TILE_SIZE), pos=(bx, by))
+                node.bind(on_touch_down=self.change_node)
+                node.bind(on_touch_move=self.change_node)
                 with node.canvas:
                     Color(1, 1, 1)
                     Rectangle(pos=node.pos, size=node.size,
                             texture=tile.texture)
                 self.add_widget(node)
+                self.nodes[(bx, by)] = node
                 bx += TILE_SIZE
             by += TILE_SIZE
 
+        name = Label(text="Level: [color=00ffcc]%s[/color]" % self.level,
+                markup=True, font_size=24, pos=(500, 360))
+        self.add_widget(name)
+
+        self.draw_toolbar()
+
+    def draw_toolbar(self):
+        for widget in self.tool_widgets:
+            widget.unbind(on_ref_press=self.change_tool)
+            self.remove_widget(widget)
+        self.tool_widgets = []
+        y = 300
+        for tool in ['wall', 'floor', 'entrance', 'exit']:
+            if self.tool == tool:
+                color = '00cccc'
+            else:
+                color = 'cccccc'
+            tool_label = Label(text='[color=%s][ref=%s]%s[/color]' %
+                    (color, tool, tool), markup=True, font_size=24,
+                    pos=(500, y))
+            y -= 50
+            tool_label.bind(on_ref_press=self.change_tool)
+            self.add_widget(tool_label)
+            self.tool_widgets.append(tool_label)
+
+    def change_tool(self, label, ref):
+        self.tool = ref
+        self.draw_toolbar()
+
+    def contained(self, node, pos):
+        if pos[0] < node.pos[0] or pos[0] > node.pos[0] + TILE_SIZE:
+            return False
+        if pos[1] < node.pos[1] or pos[1] > node.pos[1] + TILE_SIZE:
+            return False
+        return True
+
+    def change_node(self, node, touch):
+        if self.contained(node, touch.pos):
+            print touch, node, node.size, node.pos
+
 
 class EditorApp(App):