bauiv1lib.inventory

Provides help related ui.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Provides help related ui."""
  4
  5from __future__ import annotations
  6
  7from typing import override
  8
  9import bauiv1 as bui
 10
 11
 12class InventoryWindow(bui.MainWindow):
 13    """Shows what you got."""
 14
 15    def __init__(
 16        self,
 17        transition: str | None = 'in_right',
 18        origin_widget: bui.Widget | None = None,
 19    ):
 20
 21        bui.set_analytics_screen('Help Window')
 22
 23        assert bui.app.classic is not None
 24        uiscale = bui.app.ui_v1.uiscale
 25        width = 1050 if uiscale is bui.UIScale.SMALL else 750
 26        height = (
 27            500
 28            if uiscale is bui.UIScale.SMALL
 29            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 30        )
 31        x_offs = 70 if uiscale is bui.UIScale.SMALL else 0
 32        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 33
 34        super().__init__(
 35            root_widget=bui.containerwidget(
 36                size=(width, height),
 37                toolbar_visibility=(
 38                    'menu_minimal'
 39                    if uiscale is bui.UIScale.SMALL
 40                    else 'menu_full'
 41                ),
 42                scale=(
 43                    1.55
 44                    if uiscale is bui.UIScale.SMALL
 45                    else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 46                ),
 47                stack_offset=(
 48                    (0, 0)
 49                    if uiscale is bui.UIScale.SMALL
 50                    else (0, 15) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 51                ),
 52            ),
 53            transition=transition,
 54            origin_widget=origin_widget,
 55        )
 56
 57        bui.textwidget(
 58            parent=self._root_widget,
 59            position=(0, height - 45 + yoffs),
 60            size=(width, 25),
 61            text='INVENTORY',
 62            color=bui.app.ui_v1.title_color,
 63            h_align='center',
 64            v_align='center',
 65        )
 66
 67        if uiscale is bui.UIScale.SMALL:
 68            bui.containerwidget(
 69                edit=self._root_widget, on_cancel_call=self.main_window_back
 70            )
 71        else:
 72            btn = bui.buttonwidget(
 73                parent=self._root_widget,
 74                position=(x_offs + 50, height - 55 + yoffs),
 75                size=(60, 55),
 76                scale=0.8,
 77                label=bui.charstr(bui.SpecialChar.BACK),
 78                button_type='backSmall',
 79                extra_touch_border_scale=2.0,
 80                autoselect=True,
 81                on_activate_call=self.main_window_back,
 82            )
 83            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 84
 85        bui.textwidget(
 86            parent=self._root_widget,
 87            position=(0, height - 120 + yoffs),
 88            size=(width, 25),
 89            text='(under construction)',
 90            scale=0.7,
 91            h_align='center',
 92            v_align='center',
 93        )
 94
 95        button_width = 300
 96        self._player_profiles_button = btn = bui.buttonwidget(
 97            parent=self._root_widget,
 98            position=((width - button_width) * 0.5, height - 200 + yoffs),
 99            autoselect=True,
100            size=(button_width, 60),
101            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
102            color=(0.55, 0.5, 0.6),
103            icon=bui.gettexture('cuteSpaz'),
104            textcolor=(0.75, 0.7, 0.8),
105            on_activate_call=self._player_profiles_press,
106        )
107
108    def _player_profiles_press(self) -> None:
109        # pylint: disable=cyclic-import
110        from bauiv1lib.profile.browser import ProfileBrowserWindow
111
112        # no-op if our underlying widget is dead or on its way out.
113        if not self._root_widget or self._root_widget.transitioning_out:
114            return
115
116        self.main_window_replace(
117            ProfileBrowserWindow(origin_widget=self._player_profiles_button)
118        )
119
120    @override
121    def get_main_window_state(self) -> bui.MainWindowState:
122        # Support recreating our window for back/refresh purposes.
123        cls = type(self)
124        return bui.BasicMainWindowState(
125            create_call=lambda transition, origin_widget: cls(
126                transition=transition, origin_widget=origin_widget
127            )
128        )
class InventoryWindow(bauiv1._uitypes.MainWindow):
 13class InventoryWindow(bui.MainWindow):
 14    """Shows what you got."""
 15
 16    def __init__(
 17        self,
 18        transition: str | None = 'in_right',
 19        origin_widget: bui.Widget | None = None,
 20    ):
 21
 22        bui.set_analytics_screen('Help Window')
 23
 24        assert bui.app.classic is not None
 25        uiscale = bui.app.ui_v1.uiscale
 26        width = 1050 if uiscale is bui.UIScale.SMALL else 750
 27        height = (
 28            500
 29            if uiscale is bui.UIScale.SMALL
 30            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 31        )
 32        x_offs = 70 if uiscale is bui.UIScale.SMALL else 0
 33        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 34
 35        super().__init__(
 36            root_widget=bui.containerwidget(
 37                size=(width, height),
 38                toolbar_visibility=(
 39                    'menu_minimal'
 40                    if uiscale is bui.UIScale.SMALL
 41                    else 'menu_full'
 42                ),
 43                scale=(
 44                    1.55
 45                    if uiscale is bui.UIScale.SMALL
 46                    else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 47                ),
 48                stack_offset=(
 49                    (0, 0)
 50                    if uiscale is bui.UIScale.SMALL
 51                    else (0, 15) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 52                ),
 53            ),
 54            transition=transition,
 55            origin_widget=origin_widget,
 56        )
 57
 58        bui.textwidget(
 59            parent=self._root_widget,
 60            position=(0, height - 45 + yoffs),
 61            size=(width, 25),
 62            text='INVENTORY',
 63            color=bui.app.ui_v1.title_color,
 64            h_align='center',
 65            v_align='center',
 66        )
 67
 68        if uiscale is bui.UIScale.SMALL:
 69            bui.containerwidget(
 70                edit=self._root_widget, on_cancel_call=self.main_window_back
 71            )
 72        else:
 73            btn = bui.buttonwidget(
 74                parent=self._root_widget,
 75                position=(x_offs + 50, height - 55 + yoffs),
 76                size=(60, 55),
 77                scale=0.8,
 78                label=bui.charstr(bui.SpecialChar.BACK),
 79                button_type='backSmall',
 80                extra_touch_border_scale=2.0,
 81                autoselect=True,
 82                on_activate_call=self.main_window_back,
 83            )
 84            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 85
 86        bui.textwidget(
 87            parent=self._root_widget,
 88            position=(0, height - 120 + yoffs),
 89            size=(width, 25),
 90            text='(under construction)',
 91            scale=0.7,
 92            h_align='center',
 93            v_align='center',
 94        )
 95
 96        button_width = 300
 97        self._player_profiles_button = btn = bui.buttonwidget(
 98            parent=self._root_widget,
 99            position=((width - button_width) * 0.5, height - 200 + yoffs),
100            autoselect=True,
101            size=(button_width, 60),
102            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
103            color=(0.55, 0.5, 0.6),
104            icon=bui.gettexture('cuteSpaz'),
105            textcolor=(0.75, 0.7, 0.8),
106            on_activate_call=self._player_profiles_press,
107        )
108
109    def _player_profiles_press(self) -> None:
110        # pylint: disable=cyclic-import
111        from bauiv1lib.profile.browser import ProfileBrowserWindow
112
113        # no-op if our underlying widget is dead or on its way out.
114        if not self._root_widget or self._root_widget.transitioning_out:
115            return
116
117        self.main_window_replace(
118            ProfileBrowserWindow(origin_widget=self._player_profiles_button)
119        )
120
121    @override
122    def get_main_window_state(self) -> bui.MainWindowState:
123        # Support recreating our window for back/refresh purposes.
124        cls = type(self)
125        return bui.BasicMainWindowState(
126            create_call=lambda transition, origin_widget: cls(
127                transition=transition, origin_widget=origin_widget
128            )
129        )

Shows what you got.

InventoryWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
 16    def __init__(
 17        self,
 18        transition: str | None = 'in_right',
 19        origin_widget: bui.Widget | None = None,
 20    ):
 21
 22        bui.set_analytics_screen('Help Window')
 23
 24        assert bui.app.classic is not None
 25        uiscale = bui.app.ui_v1.uiscale
 26        width = 1050 if uiscale is bui.UIScale.SMALL else 750
 27        height = (
 28            500
 29            if uiscale is bui.UIScale.SMALL
 30            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 31        )
 32        x_offs = 70 if uiscale is bui.UIScale.SMALL else 0
 33        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 34
 35        super().__init__(
 36            root_widget=bui.containerwidget(
 37                size=(width, height),
 38                toolbar_visibility=(
 39                    'menu_minimal'
 40                    if uiscale is bui.UIScale.SMALL
 41                    else 'menu_full'
 42                ),
 43                scale=(
 44                    1.55
 45                    if uiscale is bui.UIScale.SMALL
 46                    else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 47                ),
 48                stack_offset=(
 49                    (0, 0)
 50                    if uiscale is bui.UIScale.SMALL
 51                    else (0, 15) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 52                ),
 53            ),
 54            transition=transition,
 55            origin_widget=origin_widget,
 56        )
 57
 58        bui.textwidget(
 59            parent=self._root_widget,
 60            position=(0, height - 45 + yoffs),
 61            size=(width, 25),
 62            text='INVENTORY',
 63            color=bui.app.ui_v1.title_color,
 64            h_align='center',
 65            v_align='center',
 66        )
 67
 68        if uiscale is bui.UIScale.SMALL:
 69            bui.containerwidget(
 70                edit=self._root_widget, on_cancel_call=self.main_window_back
 71            )
 72        else:
 73            btn = bui.buttonwidget(
 74                parent=self._root_widget,
 75                position=(x_offs + 50, height - 55 + yoffs),
 76                size=(60, 55),
 77                scale=0.8,
 78                label=bui.charstr(bui.SpecialChar.BACK),
 79                button_type='backSmall',
 80                extra_touch_border_scale=2.0,
 81                autoselect=True,
 82                on_activate_call=self.main_window_back,
 83            )
 84            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 85
 86        bui.textwidget(
 87            parent=self._root_widget,
 88            position=(0, height - 120 + yoffs),
 89            size=(width, 25),
 90            text='(under construction)',
 91            scale=0.7,
 92            h_align='center',
 93            v_align='center',
 94        )
 95
 96        button_width = 300
 97        self._player_profiles_button = btn = bui.buttonwidget(
 98            parent=self._root_widget,
 99            position=((width - button_width) * 0.5, height - 200 + yoffs),
100            autoselect=True,
101            size=(button_width, 60),
102            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
103            color=(0.55, 0.5, 0.6),
104            icon=bui.gettexture('cuteSpaz'),
105            textcolor=(0.75, 0.7, 0.8),
106            on_activate_call=self._player_profiles_press,
107        )

Create a MainWindow given a root widget and transition info.

Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.

@override
def get_main_window_state(self) -> bauiv1.MainWindowState:
121    @override
122    def get_main_window_state(self) -> bui.MainWindowState:
123        # Support recreating our window for back/refresh purposes.
124        cls = type(self)
125        return bui.BasicMainWindowState(
126            create_call=lambda transition, origin_widget: cls(
127                transition=transition, origin_widget=origin_widget
128            )
129        )

Return a WindowState to recreate this window, if supported.

Inherited Members
bauiv1._uitypes.MainWindow
main_window_back_state
main_window_is_top_level
main_window_is_auxiliary
main_window_close
main_window_has_control
main_window_back
main_window_replace
on_main_window_close
bauiv1._uitypes.Window
get_root_widget