From 7226f363830b124ffc4f6b9a8a1a254a07b54be2 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 17 Apr 2013 22:34:40 +0200 Subject: [PATCH] Start hooking up editor functions --- erdslangetjie/editor/editor.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/erdslangetjie/editor/editor.py b/erdslangetjie/editor/editor.py index afc480e..2e2c0bc 100644 --- a/erdslangetjie/editor/editor.py +++ b/erdslangetjie/editor/editor.py @@ -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): -- 2.34.1