Exemple #1
0
class Jack(HUDElement):
    def __init__(self):
        HUDElement.__init__(self)
        self.dir = ani.model_dir / 'hud' / 'jack'
        self.text_scale = 0.4
        self.text_color = (1, 1, 1, 1)

        self.arc = OnscreenImage(image=panda_path(self.dir / 'arc.png'),
                                 pos=(1.4, 0, -0.45),
                                 parent=aspect2d,
                                 scale=0.075)
        self.arc.setTransparency(TransparencyAttrib.MAlpha)

        self.cue_cartoon = OnscreenImage(
            image=panda_path(self.dir / 'cue.png'),
            parent=aspect2d,
            pos=(0, 0, 0),
            scale=(0.15, 1, 0.01),
        )
        self.cue_cartoon.setTransparency(TransparencyAttrib.MAlpha)
        autils.alignTo(self.cue_cartoon, self.dummy_right, autils.CL, autils.C)
        self.cue_cartoon.setZ(-0.40)

        autils.alignTo(self.arc, self.cue_cartoon, autils.LR, autils.CR)

        self.rotational_point = OnscreenImage(image=panda_path(
            ani.model_dir / 'hud' / 'english' / 'circle.png'),
                                              parent=self.arc,
                                              scale=0.15)
        self.rotational_point.setTransparency(TransparencyAttrib.MAlpha)
        autils.alignTo(self.rotational_point, self.arc, autils.C, autils.LR)

        self.cue_cartoon.wrtReparentTo(self.rotational_point)

        self.text = OnscreenText(
            text="0 deg",
            pos=(-1, -1.4),
            scale=self.text_scale,
            fg=self.text_color,
            align=TextNode.ACenter,
            mayChange=True,
            parent=self.arc,
        )

    def set(self, theta):
        self.text.setText(f"{theta:.1f} deg")
        self.rotational_point.setR(theta)

    def init(self):
        self.show()

    def show(self):
        self.arc.show()
        self.cue_cartoon.show()

    def hide(self):
        self.arc.hide()
        self.cue_cartoon.hide()

    def destroy(self):
        self.hide()
        del self.arc