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            460
 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
 33        super().__init__(
 34            root_widget=bui.containerwidget(
 35                size=(width, height),
 36                toolbar_visibility=(
 37                    'menu_minimal'
 38                    if uiscale is bui.UIScale.SMALL
 39                    else 'menu_full'
 40                ),
 41                scale=(
 42                    1.55
 43                    if uiscale is bui.UIScale.SMALL
 44                    else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 45                ),
 46                stack_offset=(
 47                    (0, -24)
 48                    if uiscale is bui.UIScale.SMALL
 49                    else (0, 15) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 50                ),
 51            ),
 52            transition=transition,
 53            origin_widget=origin_widget,
 54        )
 55
 56        bui.textwidget(
 57            parent=self._root_widget,
 58            position=(0, height - (50 if uiscale is bui.UIScale.SMALL else 45)),
 59            size=(width, 25),
 60            text='INVENTORY',
 61            color=bui.app.ui_v1.title_color,
 62            h_align='center',
 63            v_align='center',
 64        )
 65
 66        if uiscale is bui.UIScale.SMALL:
 67            bui.containerwidget(
 68                edit=self._root_widget, on_cancel_call=self.main_window_back
 69            )
 70        else:
 71            btn = bui.buttonwidget(
 72                parent=self._root_widget,
 73                position=(x_offs + 50, height - 55),
 74                size=(60, 55),
 75                scale=0.8,
 76                label=bui.charstr(bui.SpecialChar.BACK),
 77                button_type='backSmall',
 78                extra_touch_border_scale=2.0,
 79                autoselect=True,
 80                on_activate_call=self.main_window_back,
 81            )
 82            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 83
 84        bui.textwidget(
 85            parent=self._root_widget,
 86            position=(0, height - 120),
 87            size=(width, 25),
 88            text='(under construction)',
 89            scale=0.7,
 90            h_align='center',
 91            v_align='center',
 92        )
 93
 94        button_width = 300
 95        self._player_profiles_button = btn = bui.buttonwidget(
 96            parent=self._root_widget,
 97            position=((width - button_width) * 0.5, height - 200),
 98            autoselect=True,
 99            size=(button_width, 60),
100            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
101            color=(0.55, 0.5, 0.6),
102            icon=bui.gettexture('cuteSpaz'),
103            textcolor=(0.75, 0.7, 0.8),
104            on_activate_call=self._player_profiles_press,
105        )
106
107    def _player_profiles_press(self) -> None:
108        # pylint: disable=cyclic-import
109        from bauiv1lib.profile.browser import ProfileBrowserWindow
110
111        # no-op if our underlying widget is dead or on its way out.
112        if not self._root_widget or self._root_widget.transitioning_out:
113            return
114
115        self.main_window_replace(
116            ProfileBrowserWindow(origin_widget=self._player_profiles_button)
117        )
118
119    @override
120    def get_main_window_state(self) -> bui.MainWindowState:
121        # Support recreating our window for back/refresh purposes.
122        cls = type(self)
123        return bui.BasicMainWindowState(
124            create_call=lambda transition, origin_widget: cls(
125                transition=transition, origin_widget=origin_widget
126            )
127        )
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            460
 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
 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, -24)
 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 - (50 if uiscale is bui.UIScale.SMALL else 45)),
 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),
 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),
 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),
 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        )

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            460
 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
 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, -24)
 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 - (50 if uiscale is bui.UIScale.SMALL else 45)),
 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),
 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),
 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),
 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        )

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:
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        )

Return a WindowState to recreate this window, if supported.

Inherited Members
bauiv1._uitypes.MainWindow
main_window_back_state
main_window_close
can_change_main_window
main_window_back
main_window_replace
on_main_window_close
bauiv1._uitypes.Window
get_root_widget