Beispiel #1
0
 def __init__(self,value,pos=euclid.Vector3(0,0,0)):
     super(Image,self).__init__(pos)
     if isinstance(value, str): self.img = ImageCache.get(value)
     else: self.img = value
     self.alpha = anim.animate(1.0,1.0,dt=1,method="sine")
     self.color = (1.0, 1.0, 1.0)
     self._scale = anim.animate(self._final_scale, self._final_scale, dt=0.25, method="sine")
Beispiel #2
0
    def __init__(self, symbol, width=None, height=None):
        self.symbol = symbol
        image = ImageCache.get('s'+symbol)
        self._colorless = False
        if not image: 
            image = ImageCache.get('sC')
            self._colorless = True
        self.image = image.get_texture()
        self.width = width is None and image.width or width
        self.height = height is None and image.height or height
        self.vertex_lists = {}
        self.labels = {}

        anchor_y = self.height // image.height * image.anchor_y
        ascent = max(0, self.height - anchor_y)
        descent = min(-2, -anchor_y)
        super(MtgElement, self).__init__(ascent, descent, self.width)
Beispiel #3
0
    def __init__(self, symbol, width=None, height=None):
        self.symbol = symbol
        image = ImageCache.get('s' + symbol)
        self._colorless = False
        if not image:
            image = ImageCache.get('sC')
            self._colorless = True
        self.image = image.get_texture()
        self.width = width is None and image.width or width
        self.height = height is None and image.height or height
        self.vertex_lists = {}
        self.labels = {}

        anchor_y = self.height // image.height * image.anchor_y
        ascent = max(0, self.height - anchor_y)
        descent = min(-2, -anchor_y)
        super(MtgElement, self).__init__(ascent, descent, self.width)
Beispiel #4
0
 def __init__(self, value, pos=euclid.Vector3(0, 0, 0)):
     super(Image, self).__init__(pos)
     if isinstance(value, str): self.img = ImageCache.get(value)
     else: self.img = value
     self.alpha = anim.animate(1.0, 1.0, dt=1, method="sine")
     self.color = (1.0, 1.0, 1.0)
     self._scale = anim.animate(self._final_scale,
                                self._final_scale,
                                dt=0.25,
                                method="sine")
Beispiel #5
0
    def _render(cls, img, front, gamecard, tiny=False):
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, cls.fbo)
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                  img.target, img.id, 0)
        width, height = img.width, img.height
        wf, hf = (width / 397.), (height / 553.)
        tiny_font = "pixelmix"
        tfont_size = 6

        #//-------------------------
        glPushAttrib(GL_VIEWPORT_BIT)
        glViewport(0, 0, width, height)
        glPushAttrib(GL_TRANSFORM_BIT)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0.0, width, 0.0, height, -1.0, 1.0)

        glClearColor(0., 0., 0., 0.)
        glClear(GL_COLOR_BUFFER_BIT)
        #glClearColor(1.,1.,1.,1.)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        cmap = dict(zip(["White", "Blue", "Black", "Red", "Green"], "WUBRG"))
        cmap1 = dict(zip("WUBRG", range(5)))
        colors = tuple(
            sorted([cmap[str(c)] for c in gamecard.color],
                   key=lambda c: cmap1[c]))
        num_colors = len(colors)

        blend_color = None
        overlay_color = None
        overlay_blend = None
        final_overlay = None
        if gamecard.types == Land:
            frame = ImageCache.get_texture("frames/Land.png")
            abilities = map(str, gamecard.abilities)
            mana = list(
                itertools.chain(*[
                    re.findall("{([WUBRG])}", a) for a in abilities
                    if "Add " in a
                ]))
            num_colors = len(mana)
            if num_colors == 0: pass
            elif num_colors <= 2:
                overlay_color = mana[0]
                if num_colors == 2:
                    overlay_blend = mana[1]
                    final_overlay = "C"
            else:
                overlay_color = "Gld"

        elif gamecard.types == Artifact:
            frame = ImageCache.get_texture("frames/Art.png")
            if num_colors == 1: overlay_color = colors[0]
            elif num_colors == 2:
                overlay_color, overlay_blend = colors
                final_overlay = "Gld"
            elif num_colors > 2:
                overlay_color = "Gld"
        else:
            if num_colors == 0:
                frame = ImageCache.get_texture("frames/C.png")
            elif num_colors == 1:
                frame = ImageCache.get_texture("frames/%s.png" % colors[0])
            else:
                frame = ImageCache.get_texture("frames/Gld.png")
                if num_colors == 2:
                    overlay_color, overlay_blend = colors
                    final_overlay = "Gld"

        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)
        frame.blit(0, 0, width=width, height=height)

        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        def blend(texture, width, height):
            tw, th = texture.width, texture.height

            glEnable(texture.target)
            glBindTexture(texture.target, texture.id)
            glBegin(GL_QUADS)
            glColor4f(1., 1., 1., 1.0)
            glTexCoord2f(0.65 * tw, 0)
            glVertex3f(0.65 * width, 0, 0)
            glTexCoord2f(tw, 0)
            glVertex3f(width, 0, 0)
            glTexCoord2f(tw, th)
            glVertex3f(width, height, 0)
            glTexCoord2f(0.65 * tw, th)
            glVertex3f(0.65 * width, height, 0)

            glColor4f(1., 1., 1., 0)
            glTexCoord2f(0.35 * tw, 0)
            glVertex3f(0.35 * width, 0, 0)
            glColor4f(1., 1., 1., 1)
            glTexCoord2f(0.65 * tw, 0)
            glVertex3f(0.65 * width, 0, 0)
            glColor4f(1., 1., 1., 1)
            glTexCoord2f(0.65 * tw, th)
            glVertex3f(0.65 * width, height, 0)
            glColor4f(1., 1., 1., 0)
            glTexCoord2f(0.35 * tw, th)
            glVertex3f(0.35 * width, height, 0)

            glEnd()
            glDisable(texture.target)
            glColor4f(1., 1., 1., 1.)

        if blend_color:
            blend(ImageCache.get_texture("frames/%s.png" % blend_color))

        if overlay_color:
            t = ImageCache.get_texture("overlays/%s.png" % overlay_color)
            t.blit(0, 0, width=wf * t.width, height=hf * t.height)

            if overlay_blend:
                t = ImageCache.get_texture("overlays/%s.png" % overlay_blend)
                blend(t, width=width, height=height)

        if final_overlay:
            t = ImageCache.get_texture("overlays/%s-overlay.png" %
                                       final_overlay)
            t.blit(0, 0, width=wf * t.width, height=hf * t.height)

        # draw card image
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        front.get_region(8, 125, 185, 135).blit(0.087 * width,
                                                0.4484 * height,
                                                width=0.824 * width,
                                                height=0.4368 * height)
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        # Draw all card text first
        name = unicode(gamecard.name)
        font_name = "MatrixBold" if not tiny else tiny_font
        font_size = 0.043 * width if not tiny else tfont_size
        name_label = pyglet.text.Label(name,
                                       font_name=font_name,
                                       font_size=font_size,
                                       color=(0, 0, 0, 255),
                                       x=0.098 * width,
                                       y=0.902 * height)
        supertypes = unicode(gamecard.supertypes)
        types = unicode(gamecard.types)
        subtypes = unicode(gamecard.subtypes)
        typeline = u""
        if supertypes: typeline += supertypes + " "
        typeline += types
        if subtypes: typeline += u" - %s" % subtypes
        font_size = 0.038 * width if not tiny else tfont_size
        type_label = pyglet.text.Label(typeline,
                                       font_name=font_name,
                                       font_size=font_size,
                                       color=(0, 0, 0, 255),
                                       x=0.098 * width,
                                       y=0.40 * height)
        text = unicode("\n\n".join(
            [str(a).replace("~", name) for a in list(gamecard.abilities)]))
        if not text:
            text = gamecard.text.replace('~', name).split('\n')
            text = unicode('\n'.join(text[:4]))

        if text:
            document = mtg_decoder.decode_text(text)
            font_name = "Helvetica" if not tiny else tiny_font
            font_size = 0.035 * width if not tiny else tfont_size
            document.set_style(
                0, len(document.text),
                dict(font_name=font_name,
                     font_size=font_size,
                     color=(0, 0, 0, 255)))

            #textbox = pyglet.text.layout.IncrementalTextLayout(document,
            #                  int(0.82*width), int(0.25*height),
            #                  multiline=True)

            textbox = pyglet.text.DocumentLabel(document,
                                                width=0.80 * width,
                                                height=0.25 * height,
                                                multiline=True)

            textbox.x = int(0.501 * width)
            textbox.y = int(0.25 * height)
            textbox.anchor_x = "center"
            textbox.anchor_y = "center"
            textbox.content_valign = 'center'
            textbox.draw()

        for text in [name_label, type_label]:
            text.draw()

        # mana costs
        tf = 1.9 if tiny else 1
        mana_x, mana_y, diff_x = 0.883 * width, 0.916 * height, 0.053 * width * tf
        mana = set("BCGRUWXYZ")
        for c in str(gamecard.cost)[::-1]:
            if c in mana:
                if tiny: c = 's%s' % c
                ms = ImageCache.get(c)
                ms.blit(mana_x,
                        mana_y,
                        width=tf * wf * ms.width,
                        height=tf * hf * ms.height)
            else:
                ms = ImageCache.get("C" if not tiny else "sC")
                ms.blit(mana_x,
                        mana_y,
                        width=tf * wf * ms.width,
                        height=tf * hf * ms.height)
                font_name = "MPlantin"  # if not tiny else tiny_font
                font_size = 0.043 * width * tf
                pyglet.text.Label(c,
                                  font_name=font_name,
                                  font_size=font_size,
                                  color=(0, 0, 0, 255),
                                  x=mana_x,
                                  y=mana_y + 1,
                                  anchor_x="center",
                                  anchor_y="center").draw()

            mana_x -= diff_x

        if gamecard.types == Creature:
            if num_colors == 0:
                if gamecard.types == Artifact:
                    pt = ImageCache.get_texture("pt/Art.png")
                else:
                    pt = ImageCache.get_texture("pt/C.png")
            elif num_colors == 1:
                pt = ImageCache.get_texture("pt/%s.png" % colors[0])
            elif num_colors > 1:
                if final_overlay: col = final_overlay
                elif overlay_color: col = overlay_color
                else: col = "Gld"
                pt = ImageCache.get_texture("pt/%s.png" % col)

            pt.blit(0, 0, width=wf * pt.width, height=hf * pt.height)

            font_name = "MatrixBoldSmallCaps" if not tiny else tiny_font
            font_size = 0.051 * width if not tiny else tfont_size + 1
            ptbox = pyglet.text.Label('%s/%s' %
                                      (gamecard.power, gamecard.toughness),
                                      font_name=font_name,
                                      font_size=font_size,
                                      color=(0, 0, 0, 255),
                                      x=0.828 * width,
                                      y=0.072 * height,
                                      anchor_x="center",
                                      anchor_y="baseline")

            ptbox.draw()

        # expansion symbol
        exp = ImageCache.get_texture("sets/M10_C.png")
        exp.anchor_x = exp.width / 2.
        exp.anchor_y = exp.height / 2.
        exp.blit(0.866 * width,
                 0.413 * height,
                 width=tf * wf * exp.width,
                 height=tf * hf * exp.height)

        #self.render_extra(width, height)

        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()

        glPopAttrib()
        glPopAttrib()
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
Beispiel #6
0
    def _render(cls, img, front, gamecard, tiny=False):
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, cls.fbo)
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, img.target, img.id, 0);
        width, height = img.width, img.height
        wf, hf = (width/397.), (height/553.)
        tiny_font = "pixelmix"
        tfont_size = 6

        #//-------------------------
        glPushAttrib(GL_VIEWPORT_BIT);
        glViewport(0, 0, width, height)
        glPushAttrib(GL_TRANSFORM_BIT);
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0.0, width, 0.0, height, -1.0, 1.0)
        
        glClearColor(0.,0.,0.,0.)
        glClear(GL_COLOR_BUFFER_BIT)
        #glClearColor(1.,1.,1.,1.)
        
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        
        cmap = dict(zip(["White", "Blue", "Black", "Red", "Green"], "WUBRG"))
        cmap1 = dict(zip("WUBRG", range(5)))
        colors = tuple(sorted([cmap[str(c)] for c in gamecard.color], key=lambda c:cmap1[c]))
        num_colors = len(colors)

        blend_color = None
        overlay_color = None
        overlay_blend = None
        final_overlay = None
        if gamecard.types == Land:
            frame = ImageCache.get_texture("frames/Land.png")
            abilities = map(str,gamecard.abilities)
            mana = list(itertools.chain(*[re.findall("{([WUBRG])}", a) for a in abilities if "Add " in a]))
            num_colors = len(mana)
            if num_colors == 0: pass
            elif num_colors <= 2:
                overlay_color = mana[0]
                if num_colors == 2: 
                    overlay_blend = mana[1]
                    final_overlay = "C"
            else:
                overlay_color = "Gld"

        elif gamecard.types == Artifact:
            frame = ImageCache.get_texture("frames/Art.png")
            if num_colors == 1: overlay_color = colors[0]
            elif num_colors == 2:
                overlay_color, overlay_blend = colors
                final_overlay = "Gld"
            elif num_colors > 2:
                overlay_color = "Gld"
        else:
            if num_colors == 0:
                frame = ImageCache.get_texture("frames/C.png")
            elif num_colors == 1:
                frame = ImageCache.get_texture("frames/%s.png"%colors[0])
            else:
                frame = ImageCache.get_texture("frames/Gld.png")
                if num_colors == 2:
                    overlay_color, overlay_blend = colors
                    final_overlay = "Gld"

        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)
        frame.blit(0,0, width=width, height=height)
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)
   
        def blend(texture, width, height):
            tw, th = texture.width, texture.height
            
            glEnable(texture.target)
            glBindTexture(texture.target, texture.id)
            glBegin(GL_QUADS)
            glColor4f(1., 1., 1., 1.0)
            glTexCoord2f(0.65*tw, 0)
            glVertex3f(0.65*width, 0, 0)
            glTexCoord2f(tw, 0)
            glVertex3f(width, 0, 0)
            glTexCoord2f(tw, th)
            glVertex3f(width, height, 0)
            glTexCoord2f(0.65*tw, th)
            glVertex3f(0.65*width, height, 0)

            glColor4f(1., 1., 1., 0)
            glTexCoord2f(0.35*tw, 0)
            glVertex3f(0.35*width, 0, 0)
            glColor4f(1., 1., 1., 1)
            glTexCoord2f(0.65*tw, 0)
            glVertex3f(0.65*width, 0, 0)
            glColor4f(1., 1., 1., 1)
            glTexCoord2f(0.65*tw, th)
            glVertex3f(0.65*width, height, 0)
            glColor4f(1., 1., 1., 0)
            glTexCoord2f(0.35*tw, th)
            glVertex3f(0.35*width, height, 0)

            glEnd()
            glDisable(texture.target)
            glColor4f(1., 1., 1., 1.)
        
        if blend_color:
            blend(ImageCache.get_texture("frames/%s.png"%blend_color))
        
        if overlay_color:
            t = ImageCache.get_texture("overlays/%s.png"%overlay_color)
            t.blit(0,0,width=wf*t.width,height=hf*t.height)

            if overlay_blend:
                t = ImageCache.get_texture("overlays/%s.png"%overlay_blend)
                blend(t, width=width, height=height)
        
        if final_overlay:
            t = ImageCache.get_texture("overlays/%s-overlay.png"%final_overlay)
            t.blit(0,0,width=wf*t.width,height=hf*t.height)

        # draw card image
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        front.get_region(8, 125, 185, 135).blit(0.087*width, 0.4484*height, width=0.824*width, height=0.4368*height)
        #glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)
       
        # Draw all card text first
        name = unicode(gamecard.name)
        font_name = "MatrixBold" if not tiny else tiny_font
        font_size = 0.043*width if not tiny else tfont_size
        name_label = pyglet.text.Label(name,
                          font_name=font_name, font_size=font_size,
                          color=(0,0,0,255),
                          x=0.098*width, y=0.902*height)
        supertypes = unicode(gamecard.supertypes)
        types = unicode(gamecard.types)
        subtypes = unicode(gamecard.subtypes)
        typeline = u""
        if supertypes: typeline += supertypes + " "
        typeline += types
        if subtypes: typeline += u" - %s"%subtypes
        font_size = 0.038*width if not tiny else tfont_size
        type_label = pyglet.text.Label(typeline,
                          font_name=font_name, font_size=font_size,
                          color=(0,0,0,255),
                          x=0.098*width, y=0.40*height)
        text = unicode("\n\n".join([str(a).replace("~", name) for a in list(gamecard.abilities)]))
        if not text:
            text = gamecard.text.replace('~', name).split('\n')
            text = unicode('\n'.join(text[:4]))

        if text:
            document = mtg_decoder.decode_text(text)
            font_name = "Helvetica" if not tiny else tiny_font
            font_size = 0.035*width if not tiny else tfont_size
            document.set_style(0, len(document.text),
                dict(font_name=font_name, font_size=font_size, color=(0,0,0,255)))

            #textbox = pyglet.text.layout.IncrementalTextLayout(document,
            #                  int(0.82*width), int(0.25*height),
            #                  multiline=True)

            textbox = pyglet.text.DocumentLabel(document,
                    width=0.80*width, height=0.25*height,
                    multiline=True)

            textbox.x = int(0.501*width); textbox.y = int(0.25*height)
            textbox.anchor_x = "center"; textbox.anchor_y = "center"
            textbox.content_valign = 'center'
            textbox.draw()

        for text in [name_label, type_label]:
            text.draw()

        # mana costs
        tf = 1.9 if tiny else 1
        mana_x, mana_y, diff_x = 0.883*width, 0.916*height, 0.053*width*tf
        mana = set("BCGRUWXYZ")
        for c in str(gamecard.cost)[::-1]:
            if c in mana: 
                if tiny: c = 's%s'%c
                ms = ImageCache.get(c)
                ms.blit(mana_x, mana_y,
                        width=tf*wf*ms.width, height=tf*hf*ms.height)
            else: 
                ms = ImageCache.get("C" if not tiny else "sC")
                ms.blit(mana_x, mana_y,
                        width=tf*wf*ms.width, height=tf*hf*ms.height)
                font_name = "MPlantin"# if not tiny else tiny_font
                font_size = 0.043*width*tf
                pyglet.text.Label(c,
                   font_name=font_name, font_size=font_size,
                   color=(0,0,0,255),
                   x=mana_x, y=mana_y+1,
                   anchor_x="center", anchor_y="center").draw()

            mana_x -= diff_x

        if gamecard.types == Creature:
            if num_colors == 0: 
                if gamecard.types == Artifact: pt = ImageCache.get_texture("pt/Art.png")
                else: pt = ImageCache.get_texture("pt/C.png")
            elif num_colors == 1: pt = ImageCache.get_texture("pt/%s.png"%colors[0])
            elif num_colors > 1:
                if final_overlay: col = final_overlay
                elif overlay_color: col = overlay_color
                else: col = "Gld"
                pt = ImageCache.get_texture("pt/%s.png"%col)

            pt.blit(0,0,width=wf*pt.width,height=hf*pt.height)
        
            font_name = "MatrixBoldSmallCaps" if not tiny else tiny_font
            font_size = 0.051*width if not tiny else tfont_size+1
            ptbox = pyglet.text.Label('%s/%s'%(gamecard.power, gamecard.toughness),
                              font_name=font_name, font_size=font_size,
                              color=(0,0,0,255),
                              x=0.828*width, y=0.072*height,
                              anchor_x="center", anchor_y="baseline")

            ptbox.draw()

        # expansion symbol
        exp = ImageCache.get_texture("sets/M10_C.png")
        exp.anchor_x = exp.width / 2.
        exp.anchor_y = exp.height / 2.
        exp.blit(0.866*width, 0.413*height,
                 width=tf*wf*exp.width, height=tf*hf*exp.height)

        #self.render_extra(width, height)
        
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        
        glPopAttrib()
        glPopAttrib()
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)