def __init__(self, bgsurf): MsgState.__init__(self, bgsurf) wx, wy = self.winpos txt = TextLine("Load") x = utils.center(txt.get_size(), self.window.get_size())[0] y = 10 self.window.blit(txt, (x, y)) #get map files self.filenames = get_mapnames(MAP_folder) self.cur_page = 0 self.max_lines = 10 #file buttons x = 45 y = 40 img = pygame.Surface((300, 14)) img.fill((0, 0, 150)) self.file_buttons = [] for i in xrange(self.max_lines): btn = ImgButton(img, callback=self.load_map, btn_nr=i) btn.set_pos((x + self.winpos[0], y + self.winpos[1])) self.file_buttons.append(btn) self.widgets.append(btn) y += 20 #scroll buttons s = 25 img = pygame.Surface((s, s)) #draw rectangle img.fill((10, 10, 10)) pygame.draw.polygon(img, (255, 255, 255), [(0, 0), (s, s / 2), (0, s)], 1) y = y + self.winpos[1] + 20 x = self.winpos[0] + 220 btn = ImgButton(img, callback=self.scroll, dir=1) btn.set_pos((x, y)) self.widgets.append(btn) x = x - s - 20 img = pygame.transform.rotate(img, 180) btn = ImgButton(img, callback=self.scroll, dir=-1) btn.set_pos((x, y)) self.widgets.append(btn) self.draw_filenames()
def __init__(self): State.__init__(self) self.buttons = {} #tileset area self.tileset_area = StaticWidget((1020, 280)) self.tileset_area.set_pos((2, 485)) self.tileset_area.pos = (2, 485) ca = ClickArea(pygame.Rect([2, 485, 1024, 280]), self.choose_tiletype) self.widgets.append(ca) self.tileset_id = "ts_tileset" self.marked_type = None self.load_tileset() #set clan buttons = [ "wood", "day", "fire", "life", "earth", "night", "metal", "water", "death" ] x, y = 900, 50 for clan in buttons: btn = ImgButton(GLOBALS["signets"][clan][1], \ self.set_clan, clan=clan) btn.set_pos((x, y)) self.widgets.append(btn) self.buttons[clan] = btn btn.draw(self.background) y = y + btn.get_size()[1] + 5 self.clan = "fire" #Camera self.camera = Camera(None) #load empty map self.filename = "" self.load_map(new=True) #map area self.map_area = StaticWidget((640, 480)) self.map_area.set_pos((0, 0)) self.map_area_rect = pygame.Rect([0, 0, 640, 480]) self.widgets.append(ca) #grid overlay for map area w, h = self.map_area.get_size() self.grid = StaticWidget((w, h)) self.grid.fill((255, 0, 255)) self.grid.set_colorkey((255, 0, 255)) self.grid.set_alpha(100) for row in xrange(h / tsize): for col in xrange(w / tsize): pygame.draw.line(self.grid, (255, 255, 255), (col * 32, 0), (col * 32, h)) pygame.draw.line(self.grid, (255, 255, 255), (0, row * 32), (w, row * 32)) self.grid.set_pos(self.map_area.get_pos()) #buttons buttons = [(" NEW ", self.new_map), (" LOAD ", self.open_file), (" SAVE AS ", self.save_file), (" SAVE ", self.save_map)] x, y = 650, 1 for b in buttons: name, callback = b btn = ImgButton(TextLine(name), callback) btn.set_pos((x, y)) btn.draw_border((255, 255, 255)) self.widgets.append(btn) btn.draw(self.background) x = x + btn.get_size()[0] + 4 #add objects buttons = [ (" delete obj", "delete"), (" add start ", "start"), (" add exit ", "exit"), (" add enemy ", "enemy"), (" add dialog-trigger ", "dtrigger"), ] x, y = 650, 50 for b in buttons: name, cmd = b btn = ImgButton(TextLine(name, fontsize=15), \ self.select_add_object, cmd=cmd) btn.set_pos((x, y)) self.widgets.append(btn) btn.draw(self.background) y = y + btn.get_size()[1] + 5 self.buttons[cmd] = btn #TEST button :) btn = ImgButton(TextLine(" TEST ", fontsize=25), self.test) btn.set_pos((900, 420)) btn.draw_border((255, 255, 255)) self.widgets.append(btn) btn.draw(self.background) #keyboard events pygame.key.set_repeat(10, 20) #scroll map self.add_kbevent(KEYDOWN, K_UP, self.scroll_map, vy=-1) self.add_kbevent(KEYDOWN, K_DOWN, self.scroll_map, vy=1) self.add_kbevent(KEYDOWN, K_LEFT, self.scroll_map, vx=-1) self.add_kbevent(KEYDOWN, K_RIGHT, self.scroll_map, vx=1)
def __init__(self, mapdata=None): BaseState.__init__(self) self.selected = None self.map_pos = (0, 32) self.scr_update = 1 self.next_was = None #tile buttons buttons = [ "delete.png", "start.png", "finish.png", "ground.png", "btn.png", "del_pipe.png", "pipe.png", "pipe_exit.png", "pipe_turn.png", "pipe_tjunc.png", "block.png", ] x, y = 0, 0 self.tile_buttons = {} for b in buttons: self.background.blit(GFX_tiles[b], (x, y)) tile_button = ImgButton(img=GFX_tiles[b], callback=self.select_type, name=b) tile_button.set_pos((x, y)) self.widgets.append(tile_button) self.tile_buttons[b] = tile_button x += 34 self.select_type("delete.png") #color buttons y = 0 x = 800 - ((len(COLORS) + 1) * 34) img = GFX_tiles["del_col.png"] #nocolor button self.background.blit(img, (x, y)) col_button = ImgButton(img, callback=self.select_type, name="del_col.png") col_button.set_pos((x, y)) self.widgets.append(col_button) self.tile_buttons["del_col.png"] = col_button x += 34 img = pygame.Surface((32, 32)) for c in COLORS: #draw button for each color img.fill(c) name = COLORS.index(c) self.background.blit(img, (x, y)) col_button = ImgButton(img=img, callback=self.select_type, name=name) col_button.set_pos((x, y)) self.widgets.append(col_button) self.tile_buttons[name] = col_button x += 34 #save, load and test button x, y = 704, 584 buttons = ["save.png", "load.png", "test.png"] for b in buttons: img = GFX_tiles[b] self.background.blit(img, (x, y)) btn = ImgButton(img, callback=self.submit, action=b) btn.set_pos((x, y)) self.widgets.append(btn) x += 34 #quit button x = 0 img = GFX_tiles["quit.png"] self.background.blit(img, (x, y)) btn = ImgButton(img, callback=self.quit) btn.set_pos((x, y)) self.widgets.append(btn) #new button x += 34 img = GFX_tiles["new.png"] self.background.blit(img, (x, y)) btn = ImgButton(img, callback=self.new_map) btn.set_pos((x, y)) self.widgets.append(btn) #map if mapdata: self.mapdata = mapdata else: self.mapdata = MapData() self.mapcopy = self.mapdata.copy() self.map_layer = pygame.Surface((800, 544)) self.map_layer.set_colorkey((255, 0, 255)) self.map_layer.fill((20, 20, 20)) self.pipe_layer = pygame.Surface((800, 544)) self.pipe_layer.set_colorkey((255, 0, 255)) self.pipe_layer.fill((255, 0, 255)) draw_map(self.mapdata, self.map_layer) draw_pipes(self.mapdata, self.pipe_layer) #tile buttons for k in self.mapdata.tiles.keys(): tile = self.mapdata.tiles[k] rect = [[ tile.pos[0] * 32 + self.map_pos[0], tile.pos[1] * 32 + self.map_pos[1] ], [32, 32]] btn = DragArea(rect, callback=self.put_tile, coord=k) self.widgets.append(btn) #grid self.grid_layer = pygame.Surface((800, 544)) self.grid_layer.fill((255, 0, 255)) self.grid_layer.set_colorkey((255, 0, 255)) for i in xrange(1, 25): pygame.draw.line(self.grid_layer, (255, 255, 255), (i * 32, 0), (i * 32, 544)) for i in xrange(1, 17): pygame.draw.line(self.grid_layer, (255, 255, 255), (0, i * 32), (800, i * 32)) #keyboard shortcuts self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit) #self.add_kbevent(KEYDOWN, K_F3, self.new_map) self.add_kbevent(KEYDOWN, K_F5, self.submit, action="test.png") self.add_kbevent(KEYDOWN, K_F7, self.submit, action="save.png") self.add_kbevent(KEYDOWN, K_F8, self.submit, action="load.png")
def __init__(self, new=True): State.__init__(self) self.success = False self.new = new #start tutorial before showing level selection! self.signet_pos = { "wood": (83, 181), "day": (158, 75), "fire": (284, 34), "life": (410, 75), "earth": (485, 181), "night": (456, 307), "metal": (348, 368), "water": (220, 368), "death": (112, 307) } self.light_pos = { "wood": (239, 225), "day": (261, 173), "fire": (315, 155), "life": (369, 173), "earth": (391, 225), "night": (383, 271), "metal": (345, 307), "water": (285, 307), "death": (247, 271) } self.cur_blinking = None self.cur_blending = None self.cur_clan = None self.blink_timer = Timer(50) self.blink_count = 0 self.blink_max = 10 self.light = GLOBALS["ui_stuff"]["green_light"] r = pygame.Rect([281, 203, 78, 77]) r.inflate(-10, -10) bigredbutton = ClickArea(r, self.bigred_pressed) self.widgets.append(bigredbutton) self.donotpress = pygame.Rect([267, 188, 106, 95]) self.signets = GLOBALS["signets"] self.bg_image = GLOBALS["backgrounds"]["gameboard.png"].copy() self.ui_layer = pygame.Surface(GLOBALS["screen_size"]) self.ui_layer.fill((255, 0, 255)) self.ui_layer.set_colorkey((255, 0, 255)) self.tooltip_layer = pygame.Surface(GLOBALS["screen_size"]) self.tooltip_layer.fill((255, 0, 255)) self.tooltip_layer.set_colorkey((255, 0, 255)) self.tooltip = StaticWidget((80, 20)) self.dnp_tooltip = GLOBALS["ui_stuff"]["donotpress"] #level selection buttons self.signet_buttons = [] levels = GLOBALS["clan_levels"] for k in self.signet_pos.keys(): if self.signets.has_key(k) and levels.has_key(k): btn = ImgButton(self.signets[k][0], self.start_level, \ clan=k, level=levels[k]) btn.set_pos(self.signet_pos[k]) btn.rect = pygame.Rect([self.signet_pos[k], btn.get_size()]) btn.rect.inflate(-20, -20) btn.clan = k self.widgets.append(btn) self.signet_buttons.append(btn) #show savegame progress self.show_signet(player_data["unlocked"]) #keyboard events self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit) self.background.blit(self.bg_image, (0, 0)) self.background.blit(self.tooltip_layer, (0, 0)) self.background.blit(self.ui_layer, (0, 0)) self.tooltip_layer.fill((255, 0, 255))