예제 #1
0
    def __init__(self, pos=zero, is_opponent=False):
        super(StatusView,self).__init__(pos)
        self._toggled = False
        self._spacing = 10
        self._reveal_library = False
        self.color = (0.5, 0.5, 0.5)
        self.is_opponent = is_opponent
        #self._pos.set_transition(dt=0.1, method="linear")
        #symbols = ["life", "library", "hand", "graveyard", "exile"]
        symbols = ["life", "hand", "library", "graveyard", "exile"]
        self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(symbols, [Image, Image, Image, Image, Image])])
        for symbol in self.symbols.values():
            symbol.alpha = 0.8
        self.player_name = Label("", 11, halign="left", fontname = "Arial Bold", valign="center", shadow=False)
        #sizes = [20, 16, 14, 14, 14]
        sizes = [20, 14, 14, 14, 14]
        self.values = dict([(symbol, Label('', size, fontname = "Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)])
        #for val in self.values.values():
        self.avatar = Image(pyglet.image.Texture.create(80,80))
        self.avatar.shaking = 0
        self.avatar.alpha = anim.animate(1., 1., dt=0.25)
        self.alpha = anim.animate(1., 1., dt=0.25)

        self.manapool = ManaPool(is_opponent)
        self.zone_view = ZoneView()
        self._library = LibraryImage(is_opponent)
        self.width, self.height = 145,135
예제 #2
0
    def __init__(self, pos=zero, is_opponent=False):
        super(StatusView, self).__init__(pos)
        self._toggled = False
        self._spacing = 10
        self._reveal_library = False
        self.color = (0.5, 0.5, 0.5)
        self.is_opponent = is_opponent
        #self._pos.set_transition(dt=0.1, method="linear")
        #symbols = ["life", "library", "hand", "graveyard", "exile"]
        symbols = ["life", "hand", "library", "graveyard", "exile"]
        self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(
            symbols, [Image, Image, Image, Image, Image])])
        for symbol in self.symbols.values():
            symbol.alpha = 0.8
        self.player_name = Label("",
                                 11,
                                 halign="left",
                                 fontname="Arial Bold",
                                 valign="center",
                                 shadow=False)
        #sizes = [20, 16, 14, 14, 14]
        sizes = [20, 14, 14, 14, 14]
        self.values = dict([(symbol,
                             Label('',
                                   size,
                                   fontname="Arial Bold",
                                   halign="center",
                                   valign="center",
                                   shadow=False))
                            for symbol, size in zip(symbols, sizes)])
        #for val in self.values.values():
        self.avatar = Image(pyglet.image.Texture.create(80, 80))
        self.avatar.shaking = 0
        self.avatar.alpha = anim.animate(1., 1., dt=0.25)
        self.alpha = anim.animate(1., 1., dt=0.25)

        self.manapool = ManaPool(is_opponent)
        self.zone_view = ZoneView()
        self._library = LibraryImage(is_opponent)
        self.width, self.height = 145, 135
예제 #3
0
class StatusView(Widget):
    alpha = anim.Animatable()
    def __init__(self, pos=zero, is_opponent=False):
        super(StatusView,self).__init__(pos)
        self._toggled = False
        self._spacing = 10
        self._reveal_library = False
        self.color = (0.5, 0.5, 0.5)
        self.is_opponent = is_opponent
        #self._pos.set_transition(dt=0.1, method="linear")
        #symbols = ["life", "library", "hand", "graveyard", "exile"]
        symbols = ["life", "hand", "library", "graveyard", "exile"]
        self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(symbols, [Image, Image, Image, Image, Image])])
        for symbol in self.symbols.values():
            symbol.alpha = 0.8
        self.player_name = Label("", 11, halign="left", fontname = "Arial Bold", valign="center", shadow=False)
        #sizes = [20, 16, 14, 14, 14]
        sizes = [20, 14, 14, 14, 14]
        self.values = dict([(symbol, Label('', size, fontname = "Arial Bold", halign="center", valign="center", shadow=False)) for symbol, size in zip(symbols, sizes)])
        #for val in self.values.values():
        self.avatar = Image(pyglet.image.Texture.create(80,80))
        self.avatar.shaking = 0
        self.avatar.alpha = anim.animate(1., 1., dt=0.25)
        self.alpha = anim.animate(1., 1., dt=0.25)

        self.manapool = ManaPool(is_opponent)
        self.zone_view = ZoneView()
        self._library = LibraryImage(is_opponent)
        self.width, self.height = 145,135
    #    self.layout()
    def resize(self, width, height):
        self.layout()
    #    offset = 5
    #    if self.is_opponent:
    #        pos = euclid.Vector3(offset, height-self.height-offset, 0)
    #    else:
    #        pos = euclid.Vector3(offset, offset, 0)
    #    self._pos.set(pos)
        self._orig_pos = self.pos
    def clear(self):
        self.symbols['life'].rotatey = anim.constant(0)
        status = self.values
        counters = ["life", "hand", "library", "graveyard", "exile"]
        for c in counters: status[c].set_text(0)
    def toggle(self):
        if not self._toggled: 
            x = self.width - self.values['life'].width-self._spacing*1.5
            self.pos += euclid.Vector3(-x, 0, 0)
        else: self.pos = self._orig_pos
        self._toggled = not self._toggled
    def toggle_library(self):
        self._reveal_library = not self._reveal_library
    def animate(self, status):
        symbol = self.symbols[status]
        symbol.scale = anim.animate(symbol.scale, 1.15*symbol.scale, dt=1.0, method=lambda t: anim.oscillate_n(t, 3))
    def handle_click(self, x, y):
        x -= self.pos.x
        y -= self.pos.y
        for status, item in self.symbols.items():
            sx, sy, sw, sh = item.pos.x, item.pos.y, item.width/2., item.height/2.
            if x > sx-sw and x < sx+sw and y >= sy-sh and y <= sy+sh:
                return status
        else:
            return (0 < x <= self.width and 0 < y <= self.height)
    def setup_player(self, player, color, avatar):
        self.player = player
        self.color = color
        self.avatar.img = avatar.get_texture()
        self.player_name.set_text(player.name)
        self.update_life()
        for zone in ["library", "hand", "graveyard", "exile"]:
            self.update_zone(getattr(player, zone))
    def new_turn(self, player):
        return
        life = self.symbols["life"]
        if self.player == player: life.rotatey = anim.animate(0,360,dt=5,method='linear',extend='repeat')
        else: life.rotatey = anim.constant(0)
    def pass_priority(self, player):
        alpha = 1.0 if self.player == player else 0.6
        self.alpha = self.avatar.alpha = alpha
    def animate_life(self, amount):
        symbol = self.symbols["life"]
        curr_scale = symbol._final_scale
        if amount > 0: final_scale = curr_scale*1.5
        else: final_scale = curr_scale*0.5
        symbol._scale = anim.animate(curr_scale, final_scale,dt=0.75, method="oscillate")
        symbol.alpha = anim.animate(symbol.alpha, 0.7,dt=0.75, method="oscillate")
        self.update_life()
    def update_life(self):
        status = self.values
        player = self.player
        counters = ["life"] #, "poison"]
        for c in counters: status[c].set_text(getattr(player, c))
    def update_zone(self, zone):
        val = len(zone)
        status = self.values[str(zone)]
        if val > 0:
        #    self.symbols[str(zone)].alpha = 0.8
            status.set_text(val)
        else:
        #    self.symbols[str(zone)].alpha = 0.4
            status.set_text('0')
        if str(zone) == "library": self._library.update(zone)
    def layout(self):
        life_img, life = self.symbols["life"], self.values["life"]
        life_img.alpha = anim.constant(0.3)
        life_img._final_scale = 0.25
        life_img._scale = anim.constant(life_img._final_scale)
        #life_img.visible = anim.constant(0)
        avatar = self.avatar
        spacing = self._spacing
        if self.is_opponent:
            x, y = spacing, life.height / 2.
        
            self.player_name.pos = euclid.Vector3(x, y, 0)
            self.manapool.pos = euclid.Vector3(self.width, 0, 0)
            x = self.width - life.width/2 - spacing
            life.pos = life_img.pos = euclid.Vector3(x, y, 0)
            
            for i, status in enumerate(["graveyard", "library", "hand"]):
                symbol, value = self.symbols[status], self.values[status]
                #symbol.scale = 0.3
                #symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing+symbol.height/2+0.7*i*(symbol.height), 0)
                symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing/2+symbol.height/2+i*(symbol.height), 0)
                
            library, lib = self._library, self.symbols["library"]
            library.scale = 0.5
            library.pos = euclid.Vector3(self.width, life.height+spacing/2+1.5*lib.height, 0)
            #status = "library"
            #library, value = self.symbols["library"], self.values["library"]
            #library.scale = 0.3
            #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, life.height+library.height/2+spacing,0)
            avatar.pos = euclid.Vector3(spacing + avatar.width/2, life.height+avatar.height/2+spacing,0)
        else:
            x, y = spacing, self.height - life.height / 2.
        
            self.player_name.pos = euclid.Vector3(x, y, 0)
            self.manapool.pos = euclid.Vector3(self.width, self.height, 0)
            x = self.width - life.width/2 - spacing
            life.pos = life_img.pos = euclid.Vector3(x, y, 0)
            
            for i, status in enumerate(["graveyard", "library", "hand"][::-1]):
                symbol, value = self.symbols[status], self.values[status]
                #symbol.scale = 0.3
                #symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-0.7*i*(symbol.height), 0)
                symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-i*(symbol.height)-spacing/2, 0)
                
            library, lib = self._library, self.symbols["library"]
            library.scale = 0.5
            library.pos = euclid.Vector3(self.width, 1.5*lib.height, 0)
            #status = "library"
            #library, value = self.symbols["library"], self.values["library"]
            #library.scale = 0.3
            #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, self.height-life.height-library.height/2-spacing,0)
            avatar.pos = euclid.Vector3(spacing + avatar.width/2, self.height-life.height-avatar.height/2-spacing,0)
            
    def render_after_transform(self):
        ac = self.color
        glColor4f(ac[0], ac[1], ac[2], self.alpha)
        life_height = self.values['life'].height
        h1, h2 = self.height - life_height, life_height
        if self.is_opponent: h1, h2 = h2, h1
        render_9_part("box4",
                      self.width, h1,
                      x=0, y=0)
        render_9_part("box4",
                      self.width, h2,
                      x=0, y=h1)
        
        self.avatar.render()
        self.player_name.render()
        for status in ["life", "library", "hand", "graveyard"]: #, "exile"]:
            symbol, value = self.symbols[status], self.values[status]
            symbol.render()
            value.render()
        self.manapool.render()
        self.zone_view.render()
        if self._reveal_library: self._library.render()
예제 #4
0
class StatusView(Widget):
    alpha = anim.Animatable()

    def __init__(self, pos=zero, is_opponent=False):
        super(StatusView, self).__init__(pos)
        self._toggled = False
        self._spacing = 10
        self._reveal_library = False
        self.color = (0.5, 0.5, 0.5)
        self.is_opponent = is_opponent
        #self._pos.set_transition(dt=0.1, method="linear")
        #symbols = ["life", "library", "hand", "graveyard", "exile"]
        symbols = ["life", "hand", "library", "graveyard", "exile"]
        self.symbols = dict([(symbol, cls(symbol)) for symbol, cls in zip(
            symbols, [Image, Image, Image, Image, Image])])
        for symbol in self.symbols.values():
            symbol.alpha = 0.8
        self.player_name = Label("",
                                 11,
                                 halign="left",
                                 fontname="Arial Bold",
                                 valign="center",
                                 shadow=False)
        #sizes = [20, 16, 14, 14, 14]
        sizes = [20, 14, 14, 14, 14]
        self.values = dict([(symbol,
                             Label('',
                                   size,
                                   fontname="Arial Bold",
                                   halign="center",
                                   valign="center",
                                   shadow=False))
                            for symbol, size in zip(symbols, sizes)])
        #for val in self.values.values():
        self.avatar = Image(pyglet.image.Texture.create(80, 80))
        self.avatar.shaking = 0
        self.avatar.alpha = anim.animate(1., 1., dt=0.25)
        self.alpha = anim.animate(1., 1., dt=0.25)

        self.manapool = ManaPool(is_opponent)
        self.zone_view = ZoneView()
        self._library = LibraryImage(is_opponent)
        self.width, self.height = 145, 135

    #    self.layout()
    def resize(self, width, height):
        self.layout()
        #    offset = 5
        #    if self.is_opponent:
        #        pos = euclid.Vector3(offset, height-self.height-offset, 0)
        #    else:
        #        pos = euclid.Vector3(offset, offset, 0)
        #    self._pos.set(pos)
        self._orig_pos = self.pos

    def clear(self):
        self.symbols['life'].rotatey = anim.constant(0)
        status = self.values
        counters = ["life", "hand", "library", "graveyard", "exile"]
        for c in counters:
            status[c].set_text(0)

    def toggle(self):
        if not self._toggled:
            x = self.width - self.values['life'].width - self._spacing * 1.5
            self.pos += euclid.Vector3(-x, 0, 0)
        else:
            self.pos = self._orig_pos
        self._toggled = not self._toggled

    def toggle_library(self):
        self._reveal_library = not self._reveal_library

    def animate(self, status):
        symbol = self.symbols[status]
        symbol.scale = anim.animate(symbol.scale,
                                    1.15 * symbol.scale,
                                    dt=1.0,
                                    method=lambda t: anim.oscillate_n(t, 3))

    def handle_click(self, x, y):
        x -= self.pos.x
        y -= self.pos.y
        for status, item in self.symbols.items():
            sx, sy, sw, sh = item.pos.x, item.pos.y, item.width / 2., item.height / 2.
            if x > sx - sw and x < sx + sw and y >= sy - sh and y <= sy + sh:
                return status
        else:
            return (0 < x <= self.width and 0 < y <= self.height)

    def setup_player(self, player, color, avatar):
        self.player = player
        self.color = color
        self.avatar.img = avatar.get_texture()
        self.player_name.set_text(player.name)
        self.update_life()
        for zone in ["library", "hand", "graveyard", "exile"]:
            self.update_zone(getattr(player, zone))

    def new_turn(self, player):
        return
        life = self.symbols["life"]
        if self.player == player:
            life.rotatey = anim.animate(0,
                                        360,
                                        dt=5,
                                        method='linear',
                                        extend='repeat')
        else:
            life.rotatey = anim.constant(0)

    def pass_priority(self, player):
        alpha = 1.0 if self.player == player else 0.6
        self.alpha = self.avatar.alpha = alpha

    def animate_life(self, amount):
        symbol = self.symbols["life"]
        curr_scale = symbol._final_scale
        if amount > 0: final_scale = curr_scale * 1.5
        else: final_scale = curr_scale * 0.5
        symbol._scale = anim.animate(curr_scale,
                                     final_scale,
                                     dt=0.75,
                                     method="oscillate")
        symbol.alpha = anim.animate(symbol.alpha,
                                    0.7,
                                    dt=0.75,
                                    method="oscillate")
        self.update_life()

    def update_life(self):
        status = self.values
        player = self.player
        counters = ["life"]  #, "poison"]
        for c in counters:
            status[c].set_text(getattr(player, c))

    def update_zone(self, zone):
        val = len(zone)
        status = self.values[str(zone)]
        if val > 0:
            #    self.symbols[str(zone)].alpha = 0.8
            status.set_text(val)
        else:
            #    self.symbols[str(zone)].alpha = 0.4
            status.set_text('0')
        if str(zone) == "library": self._library.update(zone)

    def layout(self):
        life_img, life = self.symbols["life"], self.values["life"]
        life_img.alpha = anim.constant(0.3)
        life_img._final_scale = 0.25
        life_img._scale = anim.constant(life_img._final_scale)
        #life_img.visible = anim.constant(0)
        avatar = self.avatar
        spacing = self._spacing
        if self.is_opponent:
            x, y = spacing, life.height / 2.

            self.player_name.pos = euclid.Vector3(x, y, 0)
            self.manapool.pos = euclid.Vector3(self.width, 0, 0)
            x = self.width - life.width / 2 - spacing
            life.pos = life_img.pos = euclid.Vector3(x, y, 0)

            for i, status in enumerate(["graveyard", "library", "hand"]):
                symbol, value = self.symbols[status], self.values[status]
                #symbol.scale = 0.3
                #symbol.pos = value.pos = euclid.Vector3(x, life.height+spacing+symbol.height/2+0.7*i*(symbol.height), 0)
                symbol.pos = value.pos = euclid.Vector3(
                    x, life.height + spacing / 2 + symbol.height / 2 + i *
                    (symbol.height), 0)

            library, lib = self._library, self.symbols["library"]
            library.scale = 0.5
            library.pos = euclid.Vector3(
                self.width, life.height + spacing / 2 + 1.5 * lib.height, 0)
            #status = "library"
            #library, value = self.symbols["library"], self.values["library"]
            #library.scale = 0.3
            #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, life.height+library.height/2+spacing,0)
            avatar.pos = euclid.Vector3(
                spacing + avatar.width / 2,
                life.height + avatar.height / 2 + spacing, 0)
        else:
            x, y = spacing, self.height - life.height / 2.

            self.player_name.pos = euclid.Vector3(x, y, 0)
            self.manapool.pos = euclid.Vector3(self.width, self.height, 0)
            x = self.width - life.width / 2 - spacing
            life.pos = life_img.pos = euclid.Vector3(x, y, 0)

            for i, status in enumerate(["graveyard", "library", "hand"][::-1]):
                symbol, value = self.symbols[status], self.values[status]
                #symbol.scale = 0.3
                #symbol.pos = value.pos = euclid.Vector3(x, self.height-life.height-symbol.height/2-0.7*i*(symbol.height), 0)
                symbol.pos = value.pos = euclid.Vector3(
                    x, self.height - life.height - symbol.height / 2 - i *
                    (symbol.height) - spacing / 2, 0)

            library, lib = self._library, self.symbols["library"]
            library.scale = 0.5
            library.pos = euclid.Vector3(self.width, 1.5 * lib.height, 0)
            #status = "library"
            #library, value = self.symbols["library"], self.values["library"]
            #library.scale = 0.3
            #library.pos = value.pos = euclid.Vector3(spacing + library.width/2, self.height-life.height-library.height/2-spacing,0)
            avatar.pos = euclid.Vector3(
                spacing + avatar.width / 2,
                self.height - life.height - avatar.height / 2 - spacing, 0)

    def render_after_transform(self):
        ac = self.color
        glColor4f(ac[0], ac[1], ac[2], self.alpha)
        life_height = self.values['life'].height
        h1, h2 = self.height - life_height, life_height
        if self.is_opponent: h1, h2 = h2, h1
        render_9_part("box4", self.width, h1, x=0, y=0)
        render_9_part("box4", self.width, h2, x=0, y=h1)

        self.avatar.render()
        self.player_name.render()
        for status in ["life", "library", "hand", "graveyard"]:  #, "exile"]:
            symbol, value = self.symbols[status], self.values[status]
            symbol.render()
            value.render()
        self.manapool.render()
        self.zone_view.render()
        if self._reveal_library: self._library.render()