TILE_MENU_CURSOR = "\\16"
TILE_MENU_SPACING = 16
ZFILL_TILE_PATH = 2
+ TILE_LOAD_PREVIEW_SCALE = 16
+ TILE_LOAD_MENU_SHRINK = -100, -300
+ TILE_LOAD_MENU_PADDING = 8
+ TILE_LOAD_MENU_MARGIN = 2
def __init__(self, parent):
GameChild.__init__(self, parent)
self.at_box = False
self.at_test = False
self.at_tile_menu = False
+ self.at_tile_load = False
self.level_index = 0
self.tile_index = 0
self.palette_index = 0
+ self.tile_load_index = 0
self.loaded = False
self.menu_hidden = False
self.paint_pressed = False
new_tile.set_at((x, y), (0, 0, 0))
self.build_default_palette()
self.box = FlashingCursor(self, *([self.get_level_tile_size()] * 2))
+ self.tile_load_background = Sprite(self)
+ surface = Surface(dsr.inflate(self.TILE_LOAD_MENU_SHRINK).size)
+ surface.fill((0, 0, 0))
+ self.tile_load_background.add_frame(surface)
+ self.tile_load_background.location.center = dsr.center
+ self.tile_load_cursor = self.get_cursor(*([self.get_level_tile_size()] * 2))
+ # self.tile_load_preview_background = Sprite(self)
+ # rect = Rect((0, 0), [self.TILE_SIZE * self.TILE_LOAD_PREVIEW_SCALE] * 2)
+ # rect.inflate_ip(16, 16)
+ # surface = Surface(rect.size)
+ # surface.fill((0, 0, 0))
+ # self.tile_load_preview_background.add_frame(surface)
+ # self.tile_load_preview_background.location.topright = self.tile_load_background.location.topright
self.loaded = True
self.current_level_is_default = False
+ def draw_tile_database(self):
+ padding = self.TILE_LOAD_MENU_PADDING
+ x, y = self.get_tile_load_topleft()
+ ds = self.get_display_surface()
+ self.tile_database = []
+ for level in self.levels + self.get_game().levels.levels:
+ self.tile_database.extend(level.original_tiles)
+ self.tile_database.extend(self.get_game().glyphs.original_tiles)
+ count = 0
+ for tile in self.tile_database:
+ scaled = scale(tile, [self.get_level_tile_size()] * 2)
+ ds.blit(scaled, (x, y))
+ x += scaled.get_width() + self.TILE_LOAD_MENU_MARGIN
+ # if y < self.tile_load_preview_background.location.bottom:
+ # limit = self.tile_load_preview_background.location.left
+ # else:
+ # limit = self.tile_load_background.location.right - padding
+ # if x + tile.get_width() > limit:
+ count += 1
+ if count == self.get_tile_load_row_count():
+ count = 0
+ x = self.tile_load_background.location.left + padding
+ y += scaled.get_height() + self.TILE_LOAD_MENU_MARGIN
+ # preview = Sprite(self)
+ # surface = scale(self.tile_database[self.tile_load_index],
+ # [self.TILE_LOAD_PREVIEW_SCALE * self.TILE_SIZE] * 2)
+ # preview.add_frame(surface)
+ # preview.location.center = self.tile_load_preview_background.location.center
+ # preview.update()
+
+ def get_tile_load_row_count(self):
+ return (self.tile_load_background.location.w - self.TILE_LOAD_MENU_PADDING * 2) / \
+ (self.get_level_tile_size() + self.TILE_LOAD_MENU_MARGIN)
+
+ def get_tile_load_cursor_step(self):
+ return self.get_level_tile_size() + self.TILE_LOAD_MENU_MARGIN
+
+ def get_tile_load_row_width(self):
+ return self.get_tile_load_row_count() * self.get_tile_load_cursor_step()
+
+ def get_tile_load_topleft(self):
+ x = self.tile_load_background.location.left + self.TILE_LOAD_MENU_PADDING
+ y = self.tile_load_background.location.top + self.TILE_LOAD_MENU_PADDING
+ return x, y
+
def get_level_tile_size(self):
return self.TILE_SIZE * PictureProcessing.SCALE
config = self.get_configuration("editor")
return join(config["root-directory"], config["tiles-directory"])
- def get_new_levels_path(self):
+ def get_levels_path(self):
config = self.get_configuration("editor")
- return join(config["root-directory"], config["levels-directory"],
- config["new-directory"])
+ return join(config["root-directory"], config["levels-directory"])
+
+ def get_new_levels_path(self):
+ return join(self.get_levels_path(), self.get_configuration("editor", "new-directory"))
+
+ def get_original_levels_path(self):
+ return join(self.get_levels_path(), self.get_configuration("editor", "original-directory"))
def deactivate(self):
self.active = False
self.add_default_level()
self.at_tile_edit = True
self.at_tile_menu = False
+ elif self.tile_menu_index == 1:
+ self.tile_load_index = 0
+ self.tile_load_cursor.location.topleft = self.get_tile_load_topleft()
+ self.at_tile_load = True
+ self.at_tile_menu = False
elif self.tile_menu_index == 2:
self.delete_tile(self.tile_index)
self.at_tile_menu = False
self.at_tile_bar = True
+ elif self.at_tile_load:
+ level = self.get_current_level()
+ tile = self.tile_database[self.tile_load_index].copy()
+ tile.set_colorkey(None)
+ if self.add_tile_selected():
+ level.add_tile(tile)
+ else:
+ level.original_tiles[self.tile_index] = tile
+ level.tiles[self.tile_index] = scale(tile, [tile.get_width() * PictureProcessing.SCALE] * 2)
+ if self.current_level_is_default:
+ self.current_level_is_default = False
+ self.add_default_level()
+ self.save_level()
+ level.set_preview()
+ self.at_tile_load = False
+ self.at_tile_bar = True
elif self.at_palette:
self.at_palette = False
self.at_tile_edit = True
elif self.at_tile_menu:
self.at_tile_menu = False
self.at_tile_bar = True
+ elif self.at_tile_load:
+ self.at_tile_load = False
+ self.at_tile_bar = True
elif self.at_tile_edit:
self.at_tile_edit = False
self.at_tile_bar = True
self.at_palette = True
if self.palette_index_is_at_left():
self.wrap_palette_index()
+ if self.at_tile_load:
+ row_count = self.get_tile_load_row_count()
+ if (self.tile_load_index + 1) % row_count == 0:
+ # self.tile_load_index -= row_count - 1
+ # self.tile_load_cursor.move(dx=-self.get_tile_load_row_width())
+ # self.tile_load_cursor.move(dx=self.get_tile_load_cursor_step())
+ pass
+ elif self.tile_load_index == len(self.tile_database) - 1:
+ # self.tile_load_index = 0
+ # self.tile_load_cursor.location.topleft = self.get_tile_load_topleft()
+ pass
+ else:
+ self.tile_load_index += 1
+ self.tile_load_cursor.move(dx=self.get_tile_load_cursor_step())
elif self.at_palette:
if self.palette_index_is_at_left():
self.at_palette = False
elif compare(event, "down"):
if self.at_tile_edit or self.at_box:
dy = 1
+ if self.at_tile_load:
+ row_count = self.get_tile_load_row_count()
+ if self.tile_load_index + row_count > len(self.tile_database) - 1:
+ pass
+ else:
+ self.tile_load_index += row_count
+ self.tile_load_cursor.move(dy=self.get_tile_load_cursor_step())
if self.at_palette:
self.palette_index += 1
if self.at_view:
self.at_palette = True
if not self.palette_index_is_at_left():
self.wrap_palette_index()
+ if self.at_tile_load:
+ row_count = self.get_tile_load_row_count()
+ if self.tile_load_index == 0:
+ pass
+ elif self.tile_load_index % row_count == 0:
+ pass
+ else:
+ self.tile_load_index -= 1
+ self.tile_load_cursor.move(dx=-self.get_tile_load_cursor_step())
elif self.at_palette:
if not self.palette_index_is_at_left():
self.at_palette = False
self.at_tile_bar = True
if self.at_tile_edit or self.at_box:
dy = -1
+ if self.at_tile_load:
+ row_count = self.get_tile_load_row_count()
+ if self.tile_load_index - row_count < 0:
+ pass
+ else:
+ self.tile_load_index -= row_count
+ self.tile_load_cursor.move(dy=-self.get_tile_load_cursor_step())
if self.at_palette:
self.palette_index -= 1
elif compare(event, "paint"):
self.arrow_play.update()
self.arrow_paint.update()
# self.arrow_music.update()
- if self.at_tile_bar or self.at_tile_edit or self.at_palette or self.at_tile_menu:
+ if self.at_tile_bar or self.at_tile_edit or self.at_palette or self.at_tile_menu or self.at_tile_load:
self.tile_bar.update()
tiles = self.get_current_level().original_tiles
if len(tiles) < Interface.MAX_TILE_COUNT:
top = color_left_height * (self.palette_index - (length / 2 + length % 2))
self.palette_cursor.location.topleft = left - 1, palette_rect.top + top - 1
self.palette_cursor.update()
+ if self.at_tile_load:
+ self.tile_load_background.update()
+ # self.tile_load_preview_background.update()
+ self.draw_tile_database()
+ self.label_select.update()
+ self.tile_load_cursor.move(-1, -1)
+ self.tile_load_cursor.update()
+ self.tile_load_cursor.move(1, 1)
if self.at_box:
if self.box.location.centery > ds.get_rect().centery:
self.label_drag.location.top = self.VIEW_MARGIN
GameChild.__init__(self, parent)
sheet = load(self.get_resource("font.png")).convert()
sheet.set_colorkey(sheet.get_at((0, 0)))
+ original = self.original_tiles = []
tiles = self.tiles = []
for y in xrange(0, sheet.get_height(), self.TILE_SIZE):
surface = Surface([self.TILE_SIZE] * 2)
surface.set_colorkey(self.TRANSPARENT_COLOR)
surface.fill(self.TRANSPARENT_COLOR)
surface.blit(sheet, (0, -y))
+ original.append(surface)
surface = scale(surface, [surface.get_width() * \
PictureProcessing.SCALE] * 2)
tiles.append(surface)