Ejemplo n.º 1
0
 def __init__(self, window_tileset):
     h_max = WindowThumbTile.H_MAX
     w = 2 * self.offset + 64 + self.font.size("h = 99 ")[0]
     h = 2 * self.offset + 32 + 8 * h_max + self.font.get_linesize()
     screen_w, screen_h = pygame.display.get_surface().get_size()
     x = screen_w - w
     y = 0
     Window.__init__(self, x, y, w, h)
     self.tile = IsoTile(0, 0)
     self.h = 0  # map.get_height(i, j)
     self.window_tileset = window_tileset
     self.last_param = None
     self.create_contents()
     self.windowskin = Cache.load_windowskin("editor.png")
     self.update()
Ejemplo n.º 2
0
class WindowThumbTile(Window):
    """draw the active IsoTile for the IsoEditor"""

    H_MAX = 4

    def __init__(self, window_tileset):
        h_max = WindowThumbTile.H_MAX
        w = 2 * self.offset + 64 + self.font.size("h = 99 ")[0]
        h = 2 * self.offset + 32 + 8 * h_max + self.font.get_linesize()
        screen_w, screen_h = pygame.display.get_surface().get_size()
        x = screen_w - w
        y = 0
        Window.__init__(self, x, y, w, h)
        self.tile = IsoTile(0, 0)
        self.h = 0  # map.get_height(i, j)
        self.window_tileset = window_tileset
        self.last_param = None
        self.create_contents()
        self.windowskin = Cache.load_windowskin("editor.png")
        self.update()

    @property
    def ref(self):
        return self.window_tileset.tileref

    @ref.setter
    def ref(self, value):
        self.window_tileset.tileref = value

    @property
    def tileset(self):
        return self.window_tileset.tileset

    @tileset.setter
    def tileset(self, value):
        self.window_tileset.tileset = value

    @property
    def tilesetname(self):
        return self.window_tileset.tilesetname

    @property
    def offset(self):
        return 8

    def update(self, tileset=None, ref=None, h=None):
        if tileset != None:
            self.tileset = tileset
        if ref != None:
            self.ref = ref
        if h != None and 0 <= h < 40:
            self.h = h
        if self.last_param != (self.tilesetname, self.ref, self.h):
            self.last_param = self.tilesetname, self.ref, self.h
            self.need_refresh = True

    def mouseover(self, event):
        if self.rect.collidepoint(event.pos):
            return True
        return False

    def refresh(self):
        self.need_refresh = False
        self.tile.draw_image(self.tilesetname, self.ref, self.h, 0, 64 + 8 * (self.h - 8))
        self.contents.fill((0, 0, 0, 0))
        self.draw_text(64, 0, "h = %s" % self.h)
        self.draw_text(0, self.contents_rect.height - self.font.get_linesize(), self.tilesetname)
        self.contents.blit(self.tile.image, (0, 0), (0, 0, 64, 96))

    @property
    def tile_infos(self):
        return self.tileset, self.ref, self.h

    @tile_infos.setter
    def tile_infos(self, tile_infos):
        self.update(*tile_infos)

    def update_onclick(self, event):
        if self.rect.collidepoint(event.pos):
            dh = (event.button == 5) - (event.button == 4)
            if dh:
                self.update(h=self.h + dh)
            return True  # get focus
        return False  # have not focus

    def draw(self, destsurf):
        if self.need_refresh:
            self.refresh()
            Window.draw(self, destsurf)