Exemplo n.º 1
0
    def create_text(self, group=None, key="character creation"):
        if group:
            text = self.db[group][key]
        else:
            text = self.db[key]

        try:
            old_text = self.sftext.text
        except AttributeError:
            old_text = None

        if old_text != text:
            manager = self.manager
            self.sftext = SFText(text=text,
                                 rect=self,
                                 fonts=manager.fonts,
                                 manager=manager)
Exemplo n.º 2
0
class Description(Layer):
    """..."""

    bottom_color = (31, 15, 15)
    top_color = (0, 0, 0)

    def __init__(self, parent, rect):
        """..."""
        super().__init__(rect=rect)
        fname = os.path.join(dnf_path(), 'data', 'descriptions.bzp')
        self.db = packer.unpack_json(fname)
        # self.create_solid_surface(color=(31, 0, 63))
        self.create_text()

    def selection(self):
        return

    def create_text(self, group=None, key="character creation"):
        if group:
            text = self.db[group][key]
        else:
            text = self.db[key]

        try:
            old_text = self.sftext.text
        except AttributeError:
            old_text = None

        if old_text != text:
            manager = self.manager
            self.sftext = SFText(text=text,
                                 rect=self,
                                 fonts=manager.fonts,
                                 manager=manager)

    def on_update(self):
        """..."""
        super().on_update()
        self.sftext.on_update()

    def on_key_press(self, event, mod):
        """Called on keyboard input, when a key is held down."""
        self.sftext.on_key_press(event, mod)

    def on_mouse_scroll(self, event, offset_x, offset_y):
        """Called when the mouse wheel is scrolled."""
        self.sftext.on_mouse_scroll(event, offset_x, offset_y)
Exemplo n.º 3
0
    def create_text(self):
        """..."""
        def fancy_field(string):
            return string[:1].upper() + string[1:]

        def name():
            if self.selection == 0:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Name:" + ul + c + "{style}" +
                    " {}".format(self.character.name) + "\n\n")

        def gender():
            if self.selection == 1:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Gender:" + ul + c + "{style}" +
                    " {}".format(fancy_field(self.character.gender)) + "\n\n")

        def race():
            if self.selection == 2:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Race:" + ul + c + "{style}" +
                    " {}".format(fancy_field(self.character.race)) + "\n\n")

        def _class():
            if self.selection == 3:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Class:" + ul + c + "{style}" +
                    " {}".format(fancy_field(self.character._class)) + "\n\n")

        def alignment():
            if self.selection == 4:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Alignment:" + ul + c + "{style}" +
                    " {}".format(self.character.alignment) + "\n\n")

        def age():
            if self.selection == 5:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Age:" + ul + c + "{style}" +
                    " {}".format(str(self.character.age)) + "\n\n")

        def height():
            if self.selection == 6:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Height:" + ul + c + "{style}" +
                    " {:.2f}".format(self.character.height, 2) + 'm.' + "\n\n")

        def weight():
            if self.selection == 7:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""
            return ("Weight:" + ul + c + "{style}" +
                    " {:.2f}".format(self.character.weight, 2) + 'kg.' +
                    "\n\n")

        def att(i):
            character = self.character
            if self.selection == 8 + i:
                ul = "{underline True}"
                c = "{color (255, 255, 0)}"
            else:
                ul = ""
                c = ""

            v = self.character.attributes[i]
            if v > 11:
                c2 = "{color (0, 255, 0)}"
            elif v < 10:
                c2 = "{color (255, 0, 0)}"
            else:
                c2 = ""
            bonus = ""
            if character.race_mod[i]:
                if character.race_mod[i] > 0:
                    bonus = "+{}={}".format(character.race_mod[i], v)
                else:
                    bonus = "{}={}".format(character.race_mod[i], v)

            return ("{}:".format(fancy_field(self.att_names[i])) + ul + c +
                    "{style}" + " {}{}".format(character._base_att[i], bonus) +
                    c2 + "\n\n")

        mystyle = {'size': 18, 'color': (223, 223, 255)}

        text = ''.join([
            t for t in [
                "\n",
                name(),
                gender(),
                race(),
                _class(),
                alignment(),
                age(),
                height(),
                weight(), ''.join([att(i) for i in range(len(self.att_names))])
            ]
        ])
        manager = self.manager

        self.sftext = SFText(text=text,
                             style=mystyle,
                             rect=self,
                             fonts=manager.fonts,
                             manager=manager)