示例#1
0
 def gen_labels(self):
     mana_text, pay_text = [], []
     self._render = False
     self._render_pay = False
     for c in self.colors:
         pay_amt, mana_amt = self.pay[c], self.mana[c]
         if pay_amt:
             if c == "C": pay_text.append(u"{%d}" % pay_amt)
             else: pay_text.append((u"{%s}" % c) * pay_amt)
             self._render_pay = True
         if mana_amt:
             if c == "C": mana_text.append(u"{%d}" % mana_amt)
             else: mana_text.append((u"{%s}" % c) * mana_amt)
             self._render = True
     if self._render:
         self.mana_label.content_width = 0
         self.mana_label.document = mtg_decoder.decode_text(
             u'\u2028'.join(mana_text))
         self.mana_label.height = self.mana_label.content_height
         self.mana_label.width = self.mana_label.content_width
     #self.mana_label.set_style("color", (255,255,255,255))
     #self.mana_label.set_style("font_name", "Arial Bold")
     #self.mana_label.set_style("font_size", 12)
     if self._render_pay:
         self.pay_label.content_width = 0
         self.pay_label.document = mtg_decoder.decode_text(
             u'\u2028'.join(pay_text))
         self.pay_label.height = self.pay_label.content_height
         self.pay_label.width = self.pay_label.content_width
示例#2
0
 def gen_labels(self):
     mana_text, pay_text = [], []
     self._render = False
     self._render_pay = False
     for c in self.colors:
         pay_amt, mana_amt = self.pay[c], self.mana[c]
         if pay_amt:
             if c == "C": pay_text.append(u"{%d}"%pay_amt)
             else: pay_text.append((u"{%s}"%c)*pay_amt)
             self._render_pay = True
         if mana_amt:
             if c == "C": mana_text.append(u"{%d}"%mana_amt)
             else: mana_text.append((u"{%s}"%c)*mana_amt)
             self._render = True
     if self._render:
         self.mana_label.content_width = 0
         self.mana_label.document = mtg_decoder.decode_text(u'\u2028'.join(mana_text))
         self.mana_label.height = self.mana_label.content_height
         self.mana_label.width = self.mana_label.content_width
     #self.mana_label.set_style("color", (255,255,255,255))
     #self.mana_label.set_style("font_name", "Arial Bold")
     #self.mana_label.set_style("font_size", 12)
     if self._render_pay:
         self.pay_label.content_width = 0
         self.pay_label.document = mtg_decoder.decode_text(u'\u2028'.join(pay_text))
         self.pay_label.height = self.pay_label.content_height
         self.pay_label.width = self.pay_label.content_width
示例#3
0
 def construct(self, prompt, sellist):
     self.prompt.set_text(prompt)
     max_width = self.max_width
     document = mtg_decoder.decode_text(u'\u2028'.join([str(val[0]) for val in sellist]))
     choice_list = pyglet.text.DocumentLabel(document, multiline=True, width=max_width,
                        anchor_x = "center", anchor_y="center")
     choice_list.set_style("color", (255,255,255,255))
     choice_list.set_style("font_name", "Arial")
     choice_list.set_style("font_size", 13.5)
     choice_list.set_style("halign", "center")
     self.choice_list = choice_list
     self.choices = [val[1] for val in sellist]
     #self.options = [(Label(str(val[0]), size=13.5, halign="center", shadow=False), val[1]) for val in sellist]
     #y = 0
     #for item, val in self.options:
     #    item._scale = anim.animate(1.0, 1.0, dt=dt, method=method)
     #self.focus_idx = len(self.options)/2
     #self.layout()
     #self.width = max([item[0].width for item in self.options]+[self.prompt.width])
     #self.height = sum([item[0].height for item in self.options]+[self.prompt.height])
     #self.scroll = self.height/len(self.options)
     self.width = max(self.prompt.width, choice_list.content_width)
     self.height = choice_list.content_height+self.prompt.height
     self.prompt._pos.set(euclid.Vector3(0,(self.height-self.prompt.height)/2, 0))
     choice_list.x = (max_width-self.width)/2
示例#4
0
 def construct(self, text, options=None, msg_type="ask"):
     self.prompt.document = mtg_decoder.decode_text(text)
     self.prompt.set_style("color", (0, 0, 0, 255))
     self.prompt.set_style("font_name", "Arial")
     self.prompt.set_style("font_size", self._size)
     #Now layout
     b1, b2 = self._button1, self._button2
     if msg_type == "prompt":
         b1.visible, b2.visible = 0, 0
     elif msg_type == "notify":
         b1.set_text(options)
         b1.visible, b2.visible = 1, 0
         y = 2.5 * self._padding + (-self.height) / 2
         b1.pos = euclid.Vector3(
             (self.width - b1.width) / 2 - self._padding, y, 0)
     elif msg_type == "ask":
         b1.set_text(options[0])
         b2.set_text(options[1])
         b1.visible, b2.visible = 1, 1
         y = 2.5 * self._padding + (-self.height) / 2
         b1.pos = euclid.Vector3(
             (self.width - b1.width) / 2 - b2.width - 2 * self._padding, y,
             0)
         b2.pos = euclid.Vector3(
             (self.width - b2.width) / 2 - self._padding, y, 0)
示例#5
0
    def __init__(self, is_opponent, pos=zero):
        super(ManaPool, self).__init__(pos)
        document = mtg_decoder.decode_text(u'')
        self.padding = 6
        self.is_opponent = is_opponent
        mana_label = pyglet.text.layout.IncrementalTextLayout(document,
                                                              multiline=True,
                                                              width=50,
                                                              height=0)
        mana_label.anchor_y = "top"
        #mana_label = pyglet.text.DocumentLabel(document, multiline=True,
        #                          width=100, anchor_x="left", anchor_y=anchor_y)
        #mana_label.set_style("color", (255,255,255,255))
        #mana_label.set_style("font_name", "Arial Bold")
        #mana_label.set_style("font_size", 12)
        self.mana_label = mana_label

        pay_label = pyglet.text.layout.IncrementalTextLayout(document,
                                                             multiline=True,
                                                             width=50,
                                                             height=0)
        pay_label.anchor_y = "top"
        self.pay_label = pay_label

        self._render = False
        self._render_pay = False

        self.colors = "WUBRGC"
        self.mana = dict(zip(self.colors, [0] * len(self.colors)))
        self.pay = dict(zip(self.colors, [0] * len(self.colors)))
示例#6
0
 def construct(self, prompt, sellist):
     self.prompt.set_text(prompt)
     max_width = self.max_width
     document = mtg_decoder.decode_text(u'\u2028'.join(
         [str(val[0]) for val in sellist]))
     choice_list = pyglet.text.DocumentLabel(document,
                                             multiline=True,
                                             width=max_width,
                                             anchor_x="center",
                                             anchor_y="center")
     choice_list.set_style("color", (255, 255, 255, 255))
     choice_list.set_style("font_name", "Arial")
     choice_list.set_style("font_size", 13.5)
     choice_list.set_style("halign", "center")
     self.choice_list = choice_list
     self.choices = [val[1] for val in sellist]
     #self.options = [(Label(str(val[0]), size=13.5, halign="center", shadow=False), val[1]) for val in sellist]
     #y = 0
     #for item, val in self.options:
     #    item._scale = anim.animate(1.0, 1.0, dt=dt, method=method)
     #self.focus_idx = len(self.options)/2
     #self.layout()
     #self.width = max([item[0].width for item in self.options]+[self.prompt.width])
     #self.height = sum([item[0].height for item in self.options]+[self.prompt.height])
     #self.scroll = self.height/len(self.options)
     self.width = max(self.prompt.width, choice_list.content_width)
     self.height = choice_list.content_height + self.prompt.height
     self.prompt._pos.set(
         euclid.Vector3(0, (self.height - self.prompt.height) / 2, 0))
     choice_list.x = (max_width - self.width) / 2
示例#7
0
 def construct(self, text, options=None, msg_type="ask"):
     self.prompt.document = mtg_decoder.decode_text(text)
     self.prompt.set_style("color", (0,0,0,255))
     self.prompt.set_style("font_name", "Arial")
     self.prompt.set_style("font_size", self._size)
     #Now layout
     b1, b2 = self._button1, self._button2
     if msg_type == "prompt":
         b1.visible, b2.visible = 0, 0
     elif msg_type == "notify":
         b1.set_text(options)
         b1.visible, b2.visible = 1, 0
         y = 2.5*self._padding + (-self.height)/2
         b1.pos = euclid.Vector3((self.width-b1.width)/2-self._padding, y, 0)
     elif msg_type == "ask":
         b1.set_text(options[0])
         b2.set_text(options[1])
         b1.visible, b2.visible = 1, 1
         y = 2.5*self._padding + (-self.height)/2
         b1.pos = euclid.Vector3((self.width-b1.width)/2-b2.width-2*self._padding, y, 0)
         b2.pos = euclid.Vector3((self.width-b2.width)/2-self._padding, y, 0)
示例#8
0
    def __init__(self, is_opponent, pos=zero):
        super(ManaPool, self).__init__(pos)
        document = mtg_decoder.decode_text(u'')
        self.padding = 6
        self.is_opponent = is_opponent
        mana_label = pyglet.text.layout.IncrementalTextLayout(document, multiline=True, width=50, height=0)
        mana_label.anchor_y = "top"
        #mana_label = pyglet.text.DocumentLabel(document, multiline=True,
        #                          width=100, anchor_x="left", anchor_y=anchor_y)
        #mana_label.set_style("color", (255,255,255,255))
        #mana_label.set_style("font_name", "Arial Bold")
        #mana_label.set_style("font_size", 12)
        self.mana_label = mana_label
 
        pay_label = pyglet.text.layout.IncrementalTextLayout(document, multiline=True, width=50, height=0)
        pay_label.anchor_y = "top"
        self.pay_label = pay_label

        self._render = False
        self._render_pay = False

        self.colors = "WUBRGC" 
        self.mana = dict(zip(self.colors, [0]*len(self.colors)))
        self.pay = dict(zip(self.colors, [0]*len(self.colors)))
示例#9
0
    def render_special(self):
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.fbo)
        img = self._texture
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                  img.target, img.id, 0)

        width, height = self.stackwidth, self.stackheight
        #//-------------------------
        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(1., 1., 1., 1.)
        glClear(GL_COLOR_BUFFER_BIT)

        # draw card image
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glColor4f(1., 1., 1., 1.0)
        #art = self.front.get_region(8, 125, 185, 135)
        #art.blit(0.054*width, 0.2428*height, width=0.889*width, height=0.5857*height)

        blend_frac = 0.5
        blend_y = blend_frac * 135
        artsolid = self._art.get_region(8, 125 + blend_y, 185, 135 - blend_y)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        artsolid.blit(0.054 * width,
                      0.54564 * height,
                      width=0.889 * width,
                      height=(0.5857 * height) * blend_frac)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        artfade = self._art.get_region(8, 125, 185, blend_y)

        tc = artfade.tex_coords
        glEnable(artfade.target)
        glBindTexture(artfade.target, artfade.id)
        glBegin(GL_QUADS)
        glColor4f(1., 1., 1., 0.0)
        glTexCoord2f(tc[0], tc[1])
        glVertex3f(0.054 * width, 0.2428 * height, 0)
        glTexCoord2f(tc[3], tc[4])
        glVertex3f(0.943 * width, 0.2428 * height, 0)
        glColor4f(1., 1., 1., 1.0)
        glTexCoord2f(tc[6], tc[7])
        glVertex3f(0.943 * width, 0.54564 * height, 0)
        glTexCoord2f(tc[9], tc[10])
        glVertex3f(0.054 * width, 0.54564 * height, 0)
        glEnd()
        glDisable(artfade.target)

        x, y, x2, y2 = 20, 44, 345, 152
        glBegin(GL_QUADS)
        glColor4f(1., 1., 1., 1.0)
        glVertex3f(x, y, 0)
        glVertex3f(x2, y, 0)
        glColor4f(1., 1., 1., 0.0)
        glVertex3f(x2, y2, 0)
        glVertex3f(x, y2, 0)
        glEnd()

        glColor4f(1., 1., 1., 1.)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        ImageCache.get_texture("frames/Gld-stack.png").blit(0, 0)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        name = str(self.gamecard.name)
        header = "%s ability of\n%s" % (self.style.capitalize(), name)
        document = pyglet.text.decode_text(header)
        document.set_style(
            0, len(document.text),
            dict(font_name="MatrixBold",
                 font_size=0.047 * width,
                 leading=0,
                 color=(0, 0, 0, 255)))
        namebox = pyglet.text.DocumentLabel(document,
                                            multiline=True,
                                            width=width * 0.85,
                                            x=width / 2.05,
                                            y=0.91 * height,
                                            anchor_x="center",
                                            anchor_y="baseline")

        document = mtg_decoder.decode_text(self.text.replace('~', name))
        document.set_style(
            0, len(document.text),
            dict(bold=True,
                 font_name="MPlantin",
                 font_size=0.0353 * width,
                 color=(0, 0, 0, 255)))
        textbox = pyglet.text.DocumentLabel(document,
                                            multiline=True,
                                            width=width * 0.85,
                                            x=width / 2,
                                            y=height * .23,
                                            anchor_x="center",
                                            anchor_y="center")

        for text in [namebox, textbox]:
            text.draw()

        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()

        glPopAttrib()
        glPopAttrib()
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
示例#10
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)
示例#11
0
    def render_special(self):
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.fbo)
        img = self._texture
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, img.target, img.id, 0);

        width, height = self.stackwidth, self.stackheight
        #//-------------------------
        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(1.,1.,1.,1.)
        glClear(GL_COLOR_BUFFER_BIT)

        # draw card image
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        
        glColor4f(1., 1., 1., 1.0)
        #art = self.front.get_region(8, 125, 185, 135)
        #art.blit(0.054*width, 0.2428*height, width=0.889*width, height=0.5857*height)
       
        blend_frac = 0.5
        blend_y = blend_frac*135
        artsolid = self._art.get_region(8, 125+blend_y, 185, 135-blend_y)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        artsolid.blit(0.054*width, 0.54564*height, width=0.889*width, height=(0.5857*height)*blend_frac)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        artfade = self._art.get_region(8, 125, 185, blend_y)
    
        tc = artfade.tex_coords
        glEnable(artfade.target)
        glBindTexture(artfade.target, artfade.id)
        glBegin(GL_QUADS)
        glColor4f(1., 1., 1., 0.0)
        glTexCoord2f(tc[0], tc[1])
        glVertex3f(0.054*width, 0.2428*height, 0)
        glTexCoord2f(tc[3], tc[4])
        glVertex3f(0.943*width, 0.2428*height, 0)
        glColor4f(1., 1., 1., 1.0)
        glTexCoord2f(tc[6], tc[7])
        glVertex3f(0.943*width, 0.54564*height, 0) 
        glTexCoord2f(tc[9], tc[10])
        glVertex3f(0.054*width, 0.54564*height, 0)
        glEnd()
        glDisable(artfade.target)

        x, y, x2, y2 = 20, 44, 345, 152
        glBegin(GL_QUADS)
        glColor4f(1., 1., 1., 1.0)
        glVertex3f(x, y, 0)
        glVertex3f(x2, y, 0)
        glColor4f(1., 1., 1., 0.0)
        glVertex3f(x2, y2, 0)
        glVertex3f(x, y2, 0)
        glEnd()

        glColor4f(1., 1., 1., 1.)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)
        ImageCache.get_texture("frames/Gld-stack.png").blit(0,0)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)

        name = str(self.gamecard.name)
        header = "%s ability of\n%s"%(self.style.capitalize(), name)
        document = pyglet.text.decode_text(header)
        document.set_style(0, len(document.text), dict(font_name="MatrixBold",
                          font_size=0.047*width, leading=0, color=(0,0,0,255)))
        namebox = pyglet.text.DocumentLabel(document, multiline=True,
                          width = width*0.85,
                          x = width/2.05, y=0.91*height,
                          anchor_x="center", anchor_y="baseline")

        document = mtg_decoder.decode_text(self.text.replace('~', name))
        document.set_style(0, len(document.text), dict(bold=True, font_name="MPlantin", font_size=0.0353*width, color=(0,0,0,255)))
        textbox = pyglet.text.DocumentLabel(document,
                              multiline=True, width=width*0.85,
                              x=width/2, y=height*.23,
                              anchor_x="center", anchor_y="center")

        for text in [namebox, textbox]:
            text.draw()
        
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        
        glPopAttrib()
        glPopAttrib()
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
示例#12
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)