def update(self):
     ImgButton.update(self)
     if self.hover and self.anim_timer.update():
         self.cur_img += 1
         if self.cur_img >= len(self.images):
             self.cur_img = 0
         self.blit(self.images[self.cur_img], (0, 0))
Example #2
0
    def __init__(self, txt, fntsize=15, callback=None, **kwargs):
        img = TextLine(" " + txt + " ", fontsize=fntsize)

        w, h = img.get_size()
        pygame.draw.lines(img, (0, 0, 255), True,
                          ((0, 0), (w - 1, 0), (w - 1, h - 1), (0, h - 1)), 1)
        ImgButton.__init__(self, img, callback, **kwargs)
 def __init__(self, img, max, cur, psize=(108, 11), ppos=(14,4)):
     ImgButton.__init__(self, img, callback=self.clicked2)
     color = (20,200,20)
     bgcolor = (0,0,0)
     self.btn_left = pygame.Rect([(0,0), (11,19)])
     self.btn_right = pygame.Rect([(125,0), (11,19)])
     self.changed = 1
     self.increased = 0
     self.clicked2 = 0
     self.linked = []
     self.progress = ProgressBar(psize, color, bgcolor)
     self.progress.set_pos(ppos)
     self.poffset = 14
     self.max = max
     self.cur = cur
     self.active = 1
     self.full = False
     self.set_max(max)
     if max > 0:
         self.show_progress()
     else:
         self.progress.change(0.0)
         self.progress.draw(self)
         self.update_links()
         self.active = 0
 def __init__(self, img1, img2, callback, **kwargs):
     img = pygame.Surface(img1.get_size())
     ImgButton.__init__(self, img, callback, **kwargs)
     self.anim_timer = utils.Timer(20)
     self.images = [img1, img2]
     self.blit(img1, (0, 0))
     self.cur_img = 0
     self.anim_timer.counter = self.anim_timer.interval + 1
 def __init__(self, img, callback, **kwargs):
     ImgButton.__init__(self, img, callback, **kwargs)
     self.bg_image = img.copy()
     self.text = ""
     self.hi_col = (81, 255, 168)
     self.lo_col = (0, 0, 0)
     self.bg_col = self.lo_col
     self.fontcolor = (255, 255, 255)
 def __init__(self, size, text, bgcolor, callback, arg=None, font="small"):
     img = pygame.Surface(size)
     img.fill(bgcolor)
     self.bgcolor = bgcolor
     self.font = FONT[font]
     txt = self.font.print_line(text)
     pos = utils.center(txt.get_size(), size)
     img.blit(txt, pos)
     self.changed = 1
     ImgButton.__init__(self, img, callback, arg)
    def __init__(self, img, img2, callback, args=None, img3=None, \
        img4=None, snd=None):
        ImgButton.__init__(self, img, callback, args)
        self.active = True
        self.image = img
        self.image2 = img2
        self.cur_image = img
        self.changed = 0
        self.clicksnd = snd

        if img3:
            self.image3 = img3
        else:
            self.image3 = img

        if img4:
            self.image4 = img4
        else:
            self.image4 = img
Example #8
0
 def __init__(self, img, img2, callback, **kwargs):
     ImgButton.__init__(self, img.copy(), callback, **kwargs)
     self.img1 = img
     self.img2 = img2
Example #9
0
 def on_release(self):
     self.on_unhover()
     ImgButton.on_release(self)
Example #10
0
 def on_unhover(self):
     ImgButton.on_unhover(self)
     self.blit(self.normal, (0, 0))
Example #11
0
 def __init__(self, img, images, callback, **kwargs):
     ImgButton.__init__(self, img.copy(), callback, **kwargs)
     self.normal = img
     self.anim = FlipImg(images, interval=4)
    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)
Example #13
0
 def __init__(self, img, himg, simg, callback, **kwargs):
     ImgButton.__init__(self, img, callback, **kwargs)
     self.base_img = img  #normal img
     self.high_img = himg  #on hover
     self.sel_img = simg  #when selected
     self.sel = False
 def update(self):
     if self.active:
         ImgButton.update(self)
     return
 def on_release(self):
     if self.clicksnd:
         self.clicksnd.play()
     self.highlight()
     ImgButton.on_release(self)
Example #16
0
    def __init__(self, edit=True, folder="custom"):
        img = GFX["levelsel"]
        BgState.__init__(self, img)
        pygame.mouse.set_visible(1)
        self.preview = pygame.Surface((416, 320))
        self.preview_pos = (312, 105)
        self.edit = edit
        self.folder = folder
        self.stats = {
            "cats": 0,
            "dogs": 0,
            "catnip": 0,
            "cataway": 0,
            "highscore": []
        }
        self.scores = []

        #list of map filenames
        self.msg = TextLine("")
        self.maps = get_maps(self.folder)

        #buttons
        btn = ClickFlipButton(GFX["btn_up1"],
                              GFX["btn_up2"],
                              callback=self.set_page,
                              add=-1)
        btn.set_pos((56, 233))
        self.add_button("up", btn)

        btn = ClickFlipButton(GFX["btn_down1"],
                              GFX["btn_down2"],
                              callback=self.set_page,
                              add=1)
        btn.set_pos((56, 265))
        self.add_button("down", btn)

        btn = FixedTextButton((64, 32), "Cancel", callback=self.quit)
        btn.set_pos((120, 457))
        btn.draw_border()
        self.add_button("cancel", btn)

        btn = FixedTextButton((64, 32), "Load", callback=self.load)
        btn.set_pos((216, 457))
        btn.draw_border()
        self.add_button("load", btn)

        if not edit:  #hide campaign maps in editor
            btn = ImgButton(GFX["sel_camp1"].copy(),
                            callback=self.set_folder,
                            val="lvl")
            btn.set_pos((117, 41))
            self.add_button("lvl", btn)

        btn = ImgButton(GFX["sel_cus1"].copy(),
                        callback=self.set_folder,
                        val="custom")
        btn.set_pos((212, 41))
        self.add_button("custom", btn)

        #pacmode unlocked when campaign done
        if SAVE["unlock"] >= 14:
            btn = ImgButton(GFX["mode_cat"], callback=self.set_pacmode)
            btn.set_pos((674, 55))
            self.add_button("pacmode", btn)
        self.pacmode = False

        #stats/score area
        stats = StaticWidget((160, 96))
        stats.blit(GFX["ghost"], (3, 0))
        stats.blit(GFX["pacdog-img"], (3, 32))
        stats.blit(GFX["catnip"], (3, 64))
        stats.blit(GFX["cataway"], (96, 0))
        self.stat_bg = stats

        score_bg = StaticWidget((160, 96))
        self.score_bg = score_bg

        self.stat_flip = FlipImg([stats.copy(), score_bg.copy()])
        self.stat_flip.set_pos((472, 457))

        #filename buttons
        size = (160, 30)
        file_pos = (120, 106)
        x = file_pos[0]
        y = file_pos[1]
        for i in xrange(10):
            name = ""
            if i < len(self.maps):
                name = self.maps[i]
            btn = FixedTextButton(size, name, callback=self.select, nr=i)
            btn.set_pos((x, y))
            self.add_button(i, btn)
            y = y + size[1] + 2

        self.page = 0
        self.selected = 0
        self.max_page = 0
        self.set_folder(self.folder)
        self.select(0)

        self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
 def on_release(self):
     if self.enabled:
         ImgButton.on_release(self)
 def __init__(self, img, type, callback, arg):
     ImgButton.__init__(self, img, callback, arg)
     self.struct_type = type
     self.enabled = True
Example #19
0
 def on_click(self):
     ImgButton.on_click(self)
     self.blit(self.img2, (0, 0))
Example #20
0
 def on_release(self):
     ImgButton.on_release(self)
     self.blit(self.img1, (0, 0))
Example #21
0
    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")
Example #22
0
 def on_hover(self):
     self.fill((0, 0, 0))
     self.blit(self.high_img, (0, 0))
     ImgButton.on_hover(self)
 def __init__(self, img, callback):
     ImgButton.__init__(self, img, callback=self.clicked2)
     self.set_colorkey((255,0,255))
     #self.hitmask = pygame.mask.from_surface(self)
     self.pos = (0,0)
Example #24
0
 def __init__(self, size, txt, callback, **kwargs):
     img = pygame.Surface(size)
     ImgButton.__init__(self, img, callback, **kwargs)
     self.bg = img.copy()
     self.text = txt
     self.draw_text(txt)
 def __init__(self, img1, img2, callback, **kwargs):
     ImgButton.__init__(self, img1, callback, **kwargs)
     self.set_colorkey((255, 0, 255))
     self.fill((255, 0, 255))
     self.img1 = img1
     self.img2 = img2
Example #26
0
    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, 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))