from kivy.config import Config
from erdslangetjie.data import filepath, load
-from erdslangetjie.level import Level
+from erdslangetjie.level import (Level, WALL, GATE, BUTTON,
+ FLOOR, ENTRY, EXIT)
if platform() != 'android':
Config.set('graphics', 'height', '760')
+tool_map = {
+ 'button': BUTTON,
+ 'gate': GATE,
+ 'wall': WALL,
+ 'floor': FLOOR,
+ 'add entry': ENTRY,
+ 'add exit': EXIT
+ }
+
+
class EditorWindow(FloatLayout):
def __init__(self, level):
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
+ self._draw_tile((bx, by), tile)
bx += TILE_SIZE
by += TILE_SIZE
self.add_widget(name)
self.draw_toolbar()
+ self.draw_save_button()
+
+ def _draw_tile(self, tile_pos, tile):
+ node = Widget(size=(TILE_SIZE, TILE_SIZE), pos=tile_pos)
+ 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[tile_pos] = node
def draw_toolbar(self):
for widget in self.tool_widgets:
self.remove_widget(widget)
self.tool_widgets = []
y = 300
- for tool in ['wall', 'floor', 'add entrance', 'add exit']:
+ for tool in sorted(tool_map):
if self.tool == tool:
color = '00cccc'
else:
color = 'cccccc'
- tool_label = Label(text='[color=%s][ref=%s]%s[/color]' %
+ tool_label = Label(text='[color=%s][ref=%s]%s[/ref][/color]' %
(color, tool, tool), markup=True, font_size=24,
pos=(500, y))
y -= 50
self.add_widget(tool_label)
self.tool_widgets.append(tool_label)
+ def draw_save_button(self):
+ save_label = Label(text='[color=ffffff][ref=save]Save[/ref][/color]',
+ markup=True, font_size=24, pos=(500, -100))
+ save_label.bind(on_ref_press=self.do_save)
+ self.add_widget(save_label)
+
+ def do_save(self, label, ref):
+ pass
+
def change_tool(self, label, ref):
self.tool = ref
self.draw_toolbar()
return True
def change_node(self, node, touch):
- if self.contained(node, touch.pos):
- print touch, node, node.size, node.pos
+ if self.tool and self.contained(node, touch.pos):
+ tile_pos = (node.pos[0] / TILE_SIZE, node.pos[1] / TILE_SIZE)
+ action = tool_map[self.tool]
+ if self.level_obj.get_tile_type(tile_pos) != action:
+ self.level_obj.set_tile_type(tile_pos, action)
+ for map_pos, new_tile in self.level_obj.get_changed_tiles():
+ node_pos = (map_pos[0] * TILE_SIZE, map_pos[1] * TILE_SIZE)
+ old_node = self.nodes[node_pos]
+ self.remove_widget(old_node)
+ self._draw_tile(node_pos, new_tile)
class EditorApp(App):
return self._data[pos[1]][pos[0]]
def set_tile_type(self, pos, new_type):
+ print '\n'.join([''.join(x) for x in self._data])
self._data[pos[1]][pos[0]] = new_type
- new_tile = self._get_tile_image(new_type, pos)
+ print
+ print '\n'.join([''.join(x) for x in self._data])
+ print pos, self._in_limits(pos)
+ new_tile = self._get_tile_image(pos, new_type)
self._tiles[pos[1]][pos[0]] = new_tile
self._changed.append((pos, new_tile))
# Also update neighbourhood for wall types, etc.
for new_pos in [(pos[0] - 1, pos[1]), (pos[0] + 1, pos[1]),
- (pos[0], pos[1] - 1), (pos[0], pos[1] + 1)]:
+ (pos[0] - 1, pos[1] - 1), (pos[0] + 1, pos[1] + 1),
+ (pos[0], pos[1] - 1), (pos[0], pos[1] + 1),
+ (pos[0] - 1, pos[1] + 1), (pos[0] + 1, pos[1] - 1)]:
if not self._in_limits(new_pos):
continue
tile = self._data[new_pos[1]][new_pos[0]]
- new_tile = self._get_tile_image(tile, pos)
+ print new_pos, tile
+ new_tile = self._get_tile_image(new_pos, tile)
self._tiles[new_pos[1]][new_pos[0]] = new_tile
self._changed.append((new_pos, new_tile))
self._data[pos[1]][pos[0]]
except IndexError:
return False
+ print pos, self._data[pos[1]][pos[0]]
return True
def blocked(self, pos):