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 if uiscale is bui.UIScale.MEDIUM else 1.0
 49                ),
 50                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 51            )
 52        )
 53
 54        if uiscale is bui.UIScale.SMALL:
 55            bui.containerwidget(
 56                edit=self._root_widget, on_cancel_call=self._do_back
 57            )
 58            self._back_button = None
 59        else:
 60            self._back_button = bui.buttonwidget(
 61                parent=self._root_widget,
 62                position=(53 + x_inset, self._height - 60),
 63                size=(140, 60),
 64                scale=0.8,
 65                autoselect=True,
 66                label=bui.Lstr(resource='backText'),
 67                button_type='back',
 68                on_activate_call=self._do_back,
 69            )
 70            bui.containerwidget(
 71                edit=self._root_widget, cancel_button=self._back_button
 72            )
 73
 74        # Do we need to translate 'Discord'? Or is that always the name?
 75        self._title_text = bui.textwidget(
 76            parent=self._root_widget,
 77            position=(0, self._height - 52),
 78            size=(self._width, 25),
 79            text='Discord',
 80            color=app.ui_v1.title_color,
 81            h_align='center',
 82            v_align='top',
 83        )
 84
 85        min_size = min(self._width - 25, self._height - 25)
 86        bui.imagewidget(
 87            parent=self._root_widget,
 88            position=(40, -15),
 89            size=(min_size, min_size),
 90            texture=bui.gettexture('discordServer'),
 91        )
 92
 93        # Hmm should we translate this? The discord server is mostly
 94        # English so being able to read this might be a good screening
 95        # process?..
 96        bui.textwidget(
 97            parent=self._root_widget,
 98            position=(self._width / 2 - 60, self._height - 100),
 99            text='We have our own Discord server where you can:\n- Find new'
100            ' friends and people to play with\n- Participate in Office'
101            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
102            ' memes\n- Report bugs and make feature suggestions\n'
103            '- Troubleshoot issues',
104            maxwidth=(self._width - 10) / 2,
105            color=(1, 1, 1, 1),
106            h_align='left',
107            v_align='top',
108        )
109
110        bui.buttonwidget(
111            parent=self._root_widget,
112            position=(self._width / 2 - 30, 20),
113            size=(self._width / 2 - 60, 60),
114            autoselect=True,
115            label=bui.Lstr(resource='discordJoinText'),
116            text_scale=1.0,
117            on_activate_call=bui.Call(
118                bui.open_url, 'https://ballistica.net/discord'
119            ),
120        )
121
122        if self._back_button is not None:
123            bui.buttonwidget(
124                edit=self._back_button,
125                button_type='backSmall',
126                size=(60, 60),
127                label=bui.charstr(bui.SpecialChar.BACK),
128            )
129
130    def _do_back(self) -> None:
131        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 if uiscale is bui.UIScale.MEDIUM else 1.0
 50                ),
 51                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 52            )
 53        )
 54
 55        if uiscale is bui.UIScale.SMALL:
 56            bui.containerwidget(
 57                edit=self._root_widget, on_cancel_call=self._do_back
 58            )
 59            self._back_button = None
 60        else:
 61            self._back_button = bui.buttonwidget(
 62                parent=self._root_widget,
 63                position=(53 + x_inset, self._height - 60),
 64                size=(140, 60),
 65                scale=0.8,
 66                autoselect=True,
 67                label=bui.Lstr(resource='backText'),
 68                button_type='back',
 69                on_activate_call=self._do_back,
 70            )
 71            bui.containerwidget(
 72                edit=self._root_widget, cancel_button=self._back_button
 73            )
 74
 75        # Do we need to translate 'Discord'? Or is that always the name?
 76        self._title_text = bui.textwidget(
 77            parent=self._root_widget,
 78            position=(0, self._height - 52),
 79            size=(self._width, 25),
 80            text='Discord',
 81            color=app.ui_v1.title_color,
 82            h_align='center',
 83            v_align='top',
 84        )
 85
 86        min_size = min(self._width - 25, self._height - 25)
 87        bui.imagewidget(
 88            parent=self._root_widget,
 89            position=(40, -15),
 90            size=(min_size, min_size),
 91            texture=bui.gettexture('discordServer'),
 92        )
 93
 94        # Hmm should we translate this? The discord server is mostly
 95        # English so being able to read this might be a good screening
 96        # process?..
 97        bui.textwidget(
 98            parent=self._root_widget,
 99            position=(self._width / 2 - 60, self._height - 100),
100            text='We have our own Discord server where you can:\n- Find new'
101            ' friends and people to play with\n- Participate in Office'
102            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
103            ' memes\n- Report bugs and make feature suggestions\n'
104            '- Troubleshoot issues',
105            maxwidth=(self._width - 10) / 2,
106            color=(1, 1, 1, 1),
107            h_align='left',
108            v_align='top',
109        )
110
111        bui.buttonwidget(
112            parent=self._root_widget,
113            position=(self._width / 2 - 30, 20),
114            size=(self._width / 2 - 60, 60),
115            autoselect=True,
116            label=bui.Lstr(resource='discordJoinText'),
117            text_scale=1.0,
118            on_activate_call=bui.Call(
119                bui.open_url, 'https://ballistica.net/discord'
120            ),
121        )
122
123        if self._back_button is not None:
124            bui.buttonwidget(
125                edit=self._back_button,
126                button_type='backSmall',
127                size=(60, 60),
128                label=bui.charstr(bui.SpecialChar.BACK),
129            )
130
131    def _do_back(self) -> None:
132        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 if uiscale is bui.UIScale.MEDIUM else 1.0
 50                ),
 51                stack_offset=(0, 5) if uiscale is bui.UIScale.SMALL else (0, 0),
 52            )
 53        )
 54
 55        if uiscale is bui.UIScale.SMALL:
 56            bui.containerwidget(
 57                edit=self._root_widget, on_cancel_call=self._do_back
 58            )
 59            self._back_button = None
 60        else:
 61            self._back_button = bui.buttonwidget(
 62                parent=self._root_widget,
 63                position=(53 + x_inset, self._height - 60),
 64                size=(140, 60),
 65                scale=0.8,
 66                autoselect=True,
 67                label=bui.Lstr(resource='backText'),
 68                button_type='back',
 69                on_activate_call=self._do_back,
 70            )
 71            bui.containerwidget(
 72                edit=self._root_widget, cancel_button=self._back_button
 73            )
 74
 75        # Do we need to translate 'Discord'? Or is that always the name?
 76        self._title_text = bui.textwidget(
 77            parent=self._root_widget,
 78            position=(0, self._height - 52),
 79            size=(self._width, 25),
 80            text='Discord',
 81            color=app.ui_v1.title_color,
 82            h_align='center',
 83            v_align='top',
 84        )
 85
 86        min_size = min(self._width - 25, self._height - 25)
 87        bui.imagewidget(
 88            parent=self._root_widget,
 89            position=(40, -15),
 90            size=(min_size, min_size),
 91            texture=bui.gettexture('discordServer'),
 92        )
 93
 94        # Hmm should we translate this? The discord server is mostly
 95        # English so being able to read this might be a good screening
 96        # process?..
 97        bui.textwidget(
 98            parent=self._root_widget,
 99            position=(self._width / 2 - 60, self._height - 100),
100            text='We have our own Discord server where you can:\n- Find new'
101            ' friends and people to play with\n- Participate in Office'
102            ' Hours/Coffee with Eric\n- Share mods, plugins, art, and'
103            ' memes\n- Report bugs and make feature suggestions\n'
104            '- Troubleshoot issues',
105            maxwidth=(self._width - 10) / 2,
106            color=(1, 1, 1, 1),
107            h_align='left',
108            v_align='top',
109        )
110
111        bui.buttonwidget(
112            parent=self._root_widget,
113            position=(self._width / 2 - 30, 20),
114            size=(self._width / 2 - 60, 60),
115            autoselect=True,
116            label=bui.Lstr(resource='discordJoinText'),
117            text_scale=1.0,
118            on_activate_call=bui.Call(
119                bui.open_url, 'https://ballistica.net/discord'
120            ),
121        )
122
123        if self._back_button is not None:
124            bui.buttonwidget(
125                edit=self._back_button,
126                button_type='backSmall',
127                size=(60, 60),
128                label=bui.charstr(bui.SpecialChar.BACK),
129            )
Inherited Members
bauiv1._uitypes.Window
get_root_widget