Пример #1
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)
Пример #2
0
class LayerDescription(Layer):
    """..."""
    def __init__(self, **kwargs):
        """..."""
        super().__init__(**kwargs)

        self.content = ""

        self.db = self.parent.db

        self.create_text()

    def create_text(self, header_rect=None):
        """..."""
        try:
            tab = self.sftext.default_style['h'] * 2
        except AttributeError:
            tab = 6

        manager = self.manager

        y = header_rect.bottom + tab if header_rect else self.y
        self.y = y
        self.height = self.parent.height - self.y

        self.sftext = SFText(text=self.content,
                             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)