changeset 270:3c95ba7408f1

Add protected level name list. Add load & new buttons
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 13:25:00 +0200
parents adaaea7a8fef
children 49c125e8bc2a
files mamba/constants.py mamba/habitats/editor.py
diffstat 2 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/constants.py	Thu Sep 15 13:23:59 2011 +0200
+++ b/mamba/constants.py	Thu Sep 15 13:25:00 2011 +0200
@@ -27,6 +27,9 @@
 FOCUS_COLOR = 'yellow'
 COLOR = 'black'
 
+# Special level directory files
+RESERVED_NAMES = ['index', 'blank']
+
 # Directions
 UP, DOWN, LEFT, RIGHT = [(0, -1), (0, 1), (-1, 0), (1, 0)]
 
--- a/mamba/habitats/editor.py	Thu Sep 15 13:23:59 2011 +0200
+++ b/mamba/habitats/editor.py	Thu Sep 15 13:25:00 2011 +0200
@@ -12,9 +12,10 @@
 from mamba.widgets.toollist import ToolListWidget
 from mamba.level import Level, TILE_MAP, THING_MAP
 from mamba.data import check_level_exists
-from mamba.constants import SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS
+from mamba.constants import (SCREEN, EDIT_SCREEN, NAME, ESCAPE_KEYS,
+        RESERVED_NAMES)
 
-MAX_TOOLS = 8
+MAX_TOOLS = 6
 
 
 class EditorHabitat(Habitat):
@@ -130,9 +131,16 @@
         button_height += mode_button.surface.get_height() + button_padding
         button_height += 2
 
-        save_button = TextButton((button_left, button_height), "Save Level")
-        save_button.add_callback('clicked', self.save)
-        self.container.add(save_button)
+        new = TextButton((button_left, button_height), "New")
+        new.add_callback('clicked', self.new)
+        self.container.add(new)
+        load = TextButton((button_left + 60, button_height), "Load")
+        load.add_callback('clicked', self.load)
+        self.container.add(load)
+
+        save = TextButton((button_left + 120, button_height), "Save")
+        save.add_callback('clicked', self.save)
+        self.container.add(save)
 
     def change_tool(self, ev, widget, new_tool, text):
         self.edit_widget.set_tool(new_tool)
@@ -140,8 +148,17 @@
         self.current_tool.prepare()
 
     def save(self, ev, widget):
+        if self.level.level_name in RESERVED_NAMES:
+            print "Can't save over reserved name"
+            return
         self.level.save_level()
 
+    def new(self, ev, widget):
+        pass
+
+    def load(self, ev, widget):
+        pass
+
     def change_toolbar(self, ev, widget):
         if self.mode == 'Tile':
             self.mode = 'Thing'