bauiv1lib.discord

UI functionality for the Discord window.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI functionality for the Discord window."""
  4
  5from __future__ import annotations
  6
  7import bauiv1 as bui
  8
  9
 10class DiscordWindow(bui.Window):
 11    """Window for joining the Discord."""
 12
 13    def __init__(
 14        self,
 15        transition: str = 'in_right',
 16        origin_widget: bui.Widget | None = None,
 17    ):
 18        if bui.app.classic is None:
 19            raise RuntimeError('This requires classic support.')
 20
 21        app = bui.app
 22        assert app.classic is not None
 23
 24        # If they provided an origin-widget, scale up from that.
 25        scale_origin: tuple[float, float] | None
 26        if origin_widget is not None:
 27            self._transition_out = 'out_scale'
 28            scale_origin = origin_widget.get_screen_space_center()
 29            transition = 'in_scale'
 30        else:
 31            self._transition_out = 'out_right'
 32            scale_origin = None
 33
 34        uiscale = bui.app.ui_v1.uiscale
 35        self._width = 800
 36        x_inset = 100 if uiscale is bui.UIScale.SMALL else 0
 37        self._height = 320
 38        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 39        super().__init__(
 40            root_widget=bui.containerwidget(
 41                size=(self._width, self._height + top_extra),
 42                transition=transition,
 43                toolbar_visibility='menu_minimal',
 44                scale_origin_stack_offset=scale_origin,
 45                scale=(
 46                    1.6
 47                    if uiscale is bui.UIScale.SMALL
 48                    else 1.3
 49                    if uiscale is bui.UIScale.MEDIUM
 50                    else 1.0
 51                ),
 52                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 53            )
 54        )
 55
 56        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 57            bui.containerwidget(
 58                edit=self._root_widget, on_cancel_call=self._do_back
 59            )
 60            self._back_button = None
 61        else:
 62            self._back_button = bui.buttonwidget(
 63                parent=self._root_widget,
 64                position=(53 + x_inset, self._height - 60),
 65                size=(140, 60),
 66                scale=0.8,
 67                autoselect=True,
 68                label=bui.Lstr(resource='backText'),
 69                button_type='back',
 70                on_activate_call=self._do_back,
 71            )
 72            bui.containerwidget(
 73                edit=self._root_widget, cancel_button=self._back_button
 74            )
 75
 76        # Do we need to translate 'Discord'? Or is that always the name?
 77        self._title_text = bui.textwidget(
 78            parent=self._root_widget,
 79            position=(0, self._height - 52),
 80            size=(self._width, 25),
 81            text='Discord',
 82            color=app.ui_v1.title_color,
 83            h_align='center',
 84            v_align='top',
 85        )
 86
 87        min_size = min(self._width - 25, self._height - 25)
 88        bui.imagewidget(
 89            parent=self._root_widget,
 90            position=(40, -15),
 91            size=(min_size, min_size),
 92            texture=bui.gettexture('discordServer'),
 93        )
 94
 95        # Hmm should we translate this? The discord server is mostly
 96        # English so being able to read this might be a good screening
 97        # process?..
 98        bui.textwidget(
 99            parent=self._root_widget,
100            position=(self._width / 2 - 60, self._height - 100),
101            text='We have our own Discord server where you can:\n- Find new'
102            ' friends and people to play with\n- Participate in Office'
103            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
104            ' memes\n- Report bugs and make feature suggestions\n'
105            '- Troubleshoot issues',
106            maxwidth=(self._width - 10) / 2,
107            color=(1, 1, 1, 1),
108            h_align='left',
109            v_align='top',
110        )
111
112        bui.buttonwidget(
113            parent=self._root_widget,
114            position=(self._width / 2 - 30, 20),
115            size=(self._width / 2 - 60, 60),
116            autoselect=True,
117            label=bui.Lstr(resource='discordJoinText'),
118            text_scale=1.0,
119            on_activate_call=bui.Call(
120                bui.open_url, 'https://ballistica.net/discord'
121            ),
122        )
123
124        if self._back_button is not None:
125            bui.buttonwidget(
126                edit=self._back_button,
127                button_type='backSmall',
128                size=(60, 60),
129                label=bui.charstr(bui.SpecialChar.BACK),
130            )
131
132    def _do_back(self) -> None:
133        bui.containerwidget(edit=self._root_widget, transition='out_scale')
class DiscordWindow(bauiv1._uitypes.Window):
 11class DiscordWindow(bui.Window):
 12    """Window for joining the Discord."""
 13
 14    def __init__(
 15        self,
 16        transition: str = 'in_right',
 17        origin_widget: bui.Widget | None = None,
 18    ):
 19        if bui.app.classic is None:
 20            raise RuntimeError('This requires classic support.')
 21
 22        app = bui.app
 23        assert app.classic is not None
 24
 25        # If they provided an origin-widget, scale up from that.
 26        scale_origin: tuple[float, float] | None
 27        if origin_widget is not None:
 28            self._transition_out = 'out_scale'
 29            scale_origin = origin_widget.get_screen_space_center()
 30            transition = 'in_scale'
 31        else:
 32            self._transition_out = 'out_right'
 33            scale_origin = None
 34
 35        uiscale = bui.app.ui_v1.uiscale
 36        self._width = 800
 37        x_inset = 100 if uiscale is bui.UIScale.SMALL else 0
 38        self._height = 320
 39        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 40        super().__init__(
 41            root_widget=bui.containerwidget(
 42                size=(self._width, self._height + top_extra),
 43                transition=transition,
 44                toolbar_visibility='menu_minimal',
 45                scale_origin_stack_offset=scale_origin,
 46                scale=(
 47                    1.6
 48                    if uiscale is bui.UIScale.SMALL
 49                    else 1.3
 50                    if uiscale is bui.UIScale.MEDIUM
 51                    else 1.0
 52                ),
 53                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 54            )
 55        )
 56
 57        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 58            bui.containerwidget(
 59                edit=self._root_widget, on_cancel_call=self._do_back
 60            )
 61            self._back_button = None
 62        else:
 63            self._back_button = bui.buttonwidget(
 64                parent=self._root_widget,
 65                position=(53 + x_inset, self._height - 60),
 66                size=(140, 60),
 67                scale=0.8,
 68                autoselect=True,
 69                label=bui.Lstr(resource='backText'),
 70                button_type='back',
 71                on_activate_call=self._do_back,
 72            )
 73            bui.containerwidget(
 74                edit=self._root_widget, cancel_button=self._back_button
 75            )
 76
 77        # Do we need to translate 'Discord'? Or is that always the name?
 78        self._title_text = bui.textwidget(
 79            parent=self._root_widget,
 80            position=(0, self._height - 52),
 81            size=(self._width, 25),
 82            text='Discord',
 83            color=app.ui_v1.title_color,
 84            h_align='center',
 85            v_align='top',
 86        )
 87
 88        min_size = min(self._width - 25, self._height - 25)
 89        bui.imagewidget(
 90            parent=self._root_widget,
 91            position=(40, -15),
 92            size=(min_size, min_size),
 93            texture=bui.gettexture('discordServer'),
 94        )
 95
 96        # Hmm should we translate this? The discord server is mostly
 97        # English so being able to read this might be a good screening
 98        # process?..
 99        bui.textwidget(
100            parent=self._root_widget,
101            position=(self._width / 2 - 60, self._height - 100),
102            text='We have our own Discord server where you can:\n- Find new'
103            ' friends and people to play with\n- Participate in Office'
104            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
105            ' memes\n- Report bugs and make feature suggestions\n'
106            '- Troubleshoot issues',
107            maxwidth=(self._width - 10) / 2,
108            color=(1, 1, 1, 1),
109            h_align='left',
110            v_align='top',
111        )
112
113        bui.buttonwidget(
114            parent=self._root_widget,
115            position=(self._width / 2 - 30, 20),
116            size=(self._width / 2 - 60, 60),
117            autoselect=True,
118            label=bui.Lstr(resource='discordJoinText'),
119            text_scale=1.0,
120            on_activate_call=bui.Call(
121                bui.open_url, 'https://ballistica.net/discord'
122            ),
123        )
124
125        if self._back_button is not None:
126            bui.buttonwidget(
127                edit=self._back_button,
128                button_type='backSmall',
129                size=(60, 60),
130                label=bui.charstr(bui.SpecialChar.BACK),
131            )
132
133    def _do_back(self) -> None:
134        bui.containerwidget(edit=self._root_widget, transition='out_scale')

Window for joining the Discord.

DiscordWindow( transition: str = 'in_right', origin_widget: _bauiv1.Widget | None = None)
 14    def __init__(
 15        self,
 16        transition: str = 'in_right',
 17        origin_widget: bui.Widget | None = None,
 18    ):
 19        if bui.app.classic is None:
 20            raise RuntimeError('This requires classic support.')
 21
 22        app = bui.app
 23        assert app.classic is not None
 24
 25        # If they provided an origin-widget, scale up from that.
 26        scale_origin: tuple[float, float] | None
 27        if origin_widget is not None:
 28            self._transition_out = 'out_scale'
 29            scale_origin = origin_widget.get_screen_space_center()
 30            transition = 'in_scale'
 31        else:
 32            self._transition_out = 'out_right'
 33            scale_origin = None
 34
 35        uiscale = bui.app.ui_v1.uiscale
 36        self._width = 800
 37        x_inset = 100 if uiscale is bui.UIScale.SMALL else 0
 38        self._height = 320
 39        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 40        super().__init__(
 41            root_widget=bui.containerwidget(
 42                size=(self._width, self._height + top_extra),
 43                transition=transition,
 44                toolbar_visibility='menu_minimal',
 45                scale_origin_stack_offset=scale_origin,
 46                scale=(
 47                    1.6
 48                    if uiscale is bui.UIScale.SMALL
 49                    else 1.3
 50                    if uiscale is bui.UIScale.MEDIUM
 51                    else 1.0
 52                ),
 53                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 54            )
 55        )
 56
 57        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 58            bui.containerwidget(
 59                edit=self._root_widget, on_cancel_call=self._do_back
 60            )
 61            self._back_button = None
 62        else:
 63            self._back_button = bui.buttonwidget(
 64                parent=self._root_widget,
 65                position=(53 + x_inset, self._height - 60),
 66                size=(140, 60),
 67                scale=0.8,
 68                autoselect=True,
 69                label=bui.Lstr(resource='backText'),
 70                button_type='back',
 71                on_activate_call=self._do_back,
 72            )
 73            bui.containerwidget(
 74                edit=self._root_widget, cancel_button=self._back_button
 75            )
 76
 77        # Do we need to translate 'Discord'? Or is that always the name?
 78        self._title_text = bui.textwidget(
 79            parent=self._root_widget,
 80            position=(0, self._height - 52),
 81            size=(self._width, 25),
 82            text='Discord',
 83            color=app.ui_v1.title_color,
 84            h_align='center',
 85            v_align='top',
 86        )
 87
 88        min_size = min(self._width - 25, self._height - 25)
 89        bui.imagewidget(
 90            parent=self._root_widget,
 91            position=(40, -15),
 92            size=(min_size, min_size),
 93            texture=bui.gettexture('discordServer'),
 94        )
 95
 96        # Hmm should we translate this? The discord server is mostly
 97        # English so being able to read this might be a good screening
 98        # process?..
 99        bui.textwidget(
100            parent=self._root_widget,
101            position=(self._width / 2 - 60, self._height - 100),
102            text='We have our own Discord server where you can:\n- Find new'
103            ' friends and people to play with\n- Participate in Office'
104            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
105            ' memes\n- Report bugs and make feature suggestions\n'
106            '- Troubleshoot issues',
107            maxwidth=(self._width - 10) / 2,
108            color=(1, 1, 1, 1),
109            h_align='left',
110            v_align='top',
111        )
112
113        bui.buttonwidget(
114            parent=self._root_widget,
115            position=(self._width / 2 - 30, 20),
116            size=(self._width / 2 - 60, 60),
117            autoselect=True,
118            label=bui.Lstr(resource='discordJoinText'),
119            text_scale=1.0,
120            on_activate_call=bui.Call(
121                bui.open_url, 'https://ballistica.net/discord'
122            ),
123        )
124
125        if self._back_button is not None:
126            bui.buttonwidget(
127                edit=self._back_button,
128                button_type='backSmall',
129                size=(60, 60),
130                label=bui.charstr(bui.SpecialChar.BACK),
131            )
Inherited Members
bauiv1._uitypes.Window
get_root_widget