Ejemplo n.º 1
0
class Splash:
    def __init__(self):
        props = WindowProperties(base.win.getProperties())
        screen_width = props.getXSize()
        screen_height = props.getYSize()
        self.ratio = float(screen_width) / float(screen_height)
        self.text_scale = 0.03
        self.text_offset = self.text_scale / 4
        self.text_height = self.text_scale + self.text_offset
        self.image_scale = 0.3
        self.bg_texture = loader.loadTexture("textures/splash-background.jpg")
        if settings.srgb:
            self.bg_texture.set_format(Texture.F_srgb)
        self.bg_texture.setWrapU(Texture.WM_clamp)
        self.bg_texture.setWrapV(Texture.WM_clamp)
        self.bg_texture_ratio = float(
            self.bg_texture.get_x_size()) / self.bg_texture.get_y_size()
        self.texture = loader.loadTexture("textures/cosmonium-name-tp.png")
        self.texture_ratio = float(
            self.texture.get_x_size()) / self.texture.get_y_size()
        if self.ratio >= 1.0:
            sx = self.ratio
            sy = self.ratio / self.bg_texture_ratio
        else:
            sx = 1.0 / self.ratio
            sy = 1.0 / (self.ratio * self.bg_texture_ratio)
        self.bg_image = OnscreenImage(self.bg_texture,
                                      color=(1, 1, 1, 1),
                                      pos=(0, 0, 0),
                                      scale=(sx, 1, sy),
                                      parent=base.aspect2d)
        self.image = OnscreenImage(
            self.texture,
            color=(1, 1, 1, 1),
            scale=(self.image_scale * self.texture_ratio, 1, self.image_scale),
            parent=base.aspect2d)
        self.image.setTransparency(TransparencyAttrib.MAlpha)
        self.text = DirectLabel(
            text="",
            text_align=TextNode.ACenter,
            text_scale=self.text_scale,
            #text_font=self.font_normal,
            text_fg=(0.5, 0.5, 0.5, 1),
            text_bg=(0, 0, 0, 0),
            text_pos=(0, -self.image_scale - self.text_height))
        #frameSize = (-0.75, 0.75, self.text_height, 0))
        self.text.reparent_to(base.aspect2d)

    def set_text(self, text):
        self.text.setText(text)

    def close(self):
        self.text.destroy()
        self.image.destroy()
        self.bg_image.destroy()
Ejemplo n.º 2
0
class GUI:
    def __init__(self, rootParent=None):
        self.background = loader.load_model("assets/models/highscoreBack.bam")
        self.background.reparent_to(render)

        x = -0.8
        y = 0.8

        xShift = 0.15
        yShift = -0.15

        lb = base.leaderboard.leaderboard()

        self.lbl1 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='1 - {} : {}'.format(lb[0][0], lb[0][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl1.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl2 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='2 - {} : {}'.format(lb[1][0], lb[1][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl2.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl3 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='3 - {} : {}'.format(lb[2][0], lb[2][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl3.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl4 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='4 - {} : {}'.format(lb[3][0], lb[3][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl4.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl5 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='5 - {} : {}'.format(lb[4][0], lb[4][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl5.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl6 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='6 - {} : {}'.format(lb[5][0], lb[5][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl6.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl7 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='7 - {} : {}'.format(lb[6][0], lb[6][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl7.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl8 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='8 - {} : {}'.format(lb[7][0], lb[7][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl8.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl9 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='9 - {} : {}'.format(lb[8][0], lb[8][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl9.setTransparency(0)

        x += xShift
        y += yShift

        self.lbl10 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(0.03750000149011612, 3.3125, -0.11250001192092896,
                       0.699999988079071),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(x, 0, y),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='10 - {} : {}'.format(lb[9][0], lb[9][1]),
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lbl10.setTransparency(0)

        credits = '''
            hendrik-jan - Lead design & Audio
            tizilogic - Procedural Generation
            fireclaw - Graphics
            rdb - Fireworks
        '''
        self.credits = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text=credits,
            text_align=0,  #TextNode.A_left,
            text_scale=(0.5, 0.5),
            text_pos=(-4, 4),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.credits.reparent_to(base.a2dBottomLeft)

        self.wait = 0.3
        self.task = base.task_mgr.add(self.update)

    def update(self, task):
        if self.wait < 0:
            context = base.device_listener.read_context('player')
            if context['move'] or context['accelerate'] or context[
                    "decelerate"]:
                base.messenger.send("do_back")
        else:
            self.wait -= globalClock.get_dt()
        return task.cont

    def show(self):
        self.lbl1.show()
        self.lbl2.show()
        self.lbl3.show()
        self.lbl4.show()
        self.lbl5.show()
        self.lbl6.show()
        self.lbl7.show()
        self.lbl8.show()
        self.lbl9.show()
        self.lbl10.show()

    def hide(self):
        self.lbl1.hide()
        self.lbl2.hide()
        self.lbl3.hide()
        self.lbl4.hide()
        self.lbl5.hide()
        self.lbl6.hide()
        self.lbl7.hide()
        self.lbl8.hide()
        self.lbl9.hide()
        self.lbl10.hide()

    def destroy(self):
        self.task.remove()
        self.credits.destroy()
        self.background.detach_node()
        self.lbl1.destroy()
        self.lbl2.destroy()
        self.lbl3.destroy()
        self.lbl4.destroy()
        self.lbl5.destroy()
        self.lbl6.destroy()
        self.lbl7.destroy()
        self.lbl8.destroy()
        self.lbl9.destroy()
        self.lbl10.destroy()