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        self._width = 1400 if uiscale is bui.UIScale.SMALL else 750
 26        self._height = (
 27            1200
 28            if uiscale is bui.UIScale.SMALL
 29            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 30        )
 31        # xoffs = 70 if uiscale is bui.UIScale.SMALL else 0
 32        # yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 33
 34        # Do some fancy math to fill all available screen area up to the
 35        # size of our backing container. This lets us fit to the exact
 36        # screen shape at small ui scale.
 37        screensize = bui.get_virtual_screen_size()
 38        scale = (
 39            1.55
 40            if uiscale is bui.UIScale.SMALL
 41            else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 42        )
 43
 44        # Calc screen size in our local container space and clamp to a
 45        # bit smaller than our container size.
 46        # target_width = min(self._width - 60, screensize[0] / scale)
 47        target_height = min(self._height - 100, screensize[1] / scale)
 48
 49        # To get top/left coords, go to the center of our window and
 50        # offset by half the width/height of our target area.
 51        yoffs = 0.5 * self._height + 0.5 * target_height + 30.0
 52
 53        super().__init__(
 54            root_widget=bui.containerwidget(
 55                size=(self._width, self._height),
 56                toolbar_visibility=(
 57                    'menu_full' if uiscale is bui.UIScale.SMALL else 'menu_full'
 58                ),
 59                scale=scale,
 60            ),
 61            transition=transition,
 62            origin_widget=origin_widget,
 63            # We're affected by screen size only at small ui-scale.
 64            refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL,
 65        )
 66
 67        bui.textwidget(
 68            parent=self._root_widget,
 69            position=(
 70                self._width * 0.5,
 71                yoffs - (50 if uiscale is bui.UIScale.SMALL else 30),
 72            ),
 73            size=(0, 0),
 74            text=bui.Lstr(resource='inventoryText'),
 75            color=bui.app.ui_v1.title_color,
 76            scale=0.9 if uiscale is bui.UIScale.SMALL else 1.0,
 77            maxwidth=(130 if uiscale is bui.UIScale.SMALL else 200),
 78            h_align='center',
 79            v_align='center',
 80        )
 81
 82        if uiscale is bui.UIScale.SMALL:
 83            bui.containerwidget(
 84                edit=self._root_widget, on_cancel_call=self.main_window_back
 85            )
 86        else:
 87            btn = bui.buttonwidget(
 88                parent=self._root_widget,
 89                position=(50, yoffs - 50),
 90                size=(60, 55),
 91                scale=0.8,
 92                label=bui.charstr(bui.SpecialChar.BACK),
 93                button_type='backSmall',
 94                extra_touch_border_scale=2.0,
 95                autoselect=True,
 96                on_activate_call=self.main_window_back,
 97            )
 98            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 99
100        button_width = 300
101        self._player_profiles_button = btn = bui.buttonwidget(
102            parent=self._root_widget,
103            position=(self._width * 0.5 - button_width * 0.5, yoffs - 200),
104            autoselect=True,
105            size=(button_width, 60),
106            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
107            color=(0.55, 0.5, 0.6),
108            icon=bui.gettexture('cuteSpaz'),
109            textcolor=(0.75, 0.7, 0.8),
110            on_activate_call=self._player_profiles_press,
111        )
112        bui.textwidget(
113            parent=self._root_widget,
114            position=(self._width * 0.5, yoffs - 250),
115            size=(0, 0),
116            text=bui.Lstr(resource='moreSoonText'),
117            scale=0.7,
118            maxwidth=self._width * 0.9,
119            h_align='center',
120            v_align='center',
121        )
122
123    def _player_profiles_press(self) -> None:
124        # pylint: disable=cyclic-import
125        from bauiv1lib.profile.browser import ProfileBrowserWindow
126
127        # no-op if our underlying widget is dead or on its way out.
128        if not self._root_widget or self._root_widget.transitioning_out:
129            return
130
131        self.main_window_replace(
132            ProfileBrowserWindow(origin_widget=self._player_profiles_button)
133        )
134
135    @override
136    def get_main_window_state(self) -> bui.MainWindowState:
137        # Support recreating our window for back/refresh purposes.
138        cls = type(self)
139        return bui.BasicMainWindowState(
140            create_call=lambda transition, origin_widget: cls(
141                transition=transition, origin_widget=origin_widget
142            )
143        )
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        self._width = 1400 if uiscale is bui.UIScale.SMALL else 750
 27        self._height = (
 28            1200
 29            if uiscale is bui.UIScale.SMALL
 30            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 31        )
 32        # xoffs = 70 if uiscale is bui.UIScale.SMALL else 0
 33        # yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 34
 35        # Do some fancy math to fill all available screen area up to the
 36        # size of our backing container. This lets us fit to the exact
 37        # screen shape at small ui scale.
 38        screensize = bui.get_virtual_screen_size()
 39        scale = (
 40            1.55
 41            if uiscale is bui.UIScale.SMALL
 42            else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 43        )
 44
 45        # Calc screen size in our local container space and clamp to a
 46        # bit smaller than our container size.
 47        # target_width = min(self._width - 60, screensize[0] / scale)
 48        target_height = min(self._height - 100, screensize[1] / scale)
 49
 50        # To get top/left coords, go to the center of our window and
 51        # offset by half the width/height of our target area.
 52        yoffs = 0.5 * self._height + 0.5 * target_height + 30.0
 53
 54        super().__init__(
 55            root_widget=bui.containerwidget(
 56                size=(self._width, self._height),
 57                toolbar_visibility=(
 58                    'menu_full' if uiscale is bui.UIScale.SMALL else 'menu_full'
 59                ),
 60                scale=scale,
 61            ),
 62            transition=transition,
 63            origin_widget=origin_widget,
 64            # We're affected by screen size only at small ui-scale.
 65            refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL,
 66        )
 67
 68        bui.textwidget(
 69            parent=self._root_widget,
 70            position=(
 71                self._width * 0.5,
 72                yoffs - (50 if uiscale is bui.UIScale.SMALL else 30),
 73            ),
 74            size=(0, 0),
 75            text=bui.Lstr(resource='inventoryText'),
 76            color=bui.app.ui_v1.title_color,
 77            scale=0.9 if uiscale is bui.UIScale.SMALL else 1.0,
 78            maxwidth=(130 if uiscale is bui.UIScale.SMALL else 200),
 79            h_align='center',
 80            v_align='center',
 81        )
 82
 83        if uiscale is bui.UIScale.SMALL:
 84            bui.containerwidget(
 85                edit=self._root_widget, on_cancel_call=self.main_window_back
 86            )
 87        else:
 88            btn = bui.buttonwidget(
 89                parent=self._root_widget,
 90                position=(50, yoffs - 50),
 91                size=(60, 55),
 92                scale=0.8,
 93                label=bui.charstr(bui.SpecialChar.BACK),
 94                button_type='backSmall',
 95                extra_touch_border_scale=2.0,
 96                autoselect=True,
 97                on_activate_call=self.main_window_back,
 98            )
 99            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
100
101        button_width = 300
102        self._player_profiles_button = btn = bui.buttonwidget(
103            parent=self._root_widget,
104            position=(self._width * 0.5 - button_width * 0.5, yoffs - 200),
105            autoselect=True,
106            size=(button_width, 60),
107            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
108            color=(0.55, 0.5, 0.6),
109            icon=bui.gettexture('cuteSpaz'),
110            textcolor=(0.75, 0.7, 0.8),
111            on_activate_call=self._player_profiles_press,
112        )
113        bui.textwidget(
114            parent=self._root_widget,
115            position=(self._width * 0.5, yoffs - 250),
116            size=(0, 0),
117            text=bui.Lstr(resource='moreSoonText'),
118            scale=0.7,
119            maxwidth=self._width * 0.9,
120            h_align='center',
121            v_align='center',
122        )
123
124    def _player_profiles_press(self) -> None:
125        # pylint: disable=cyclic-import
126        from bauiv1lib.profile.browser import ProfileBrowserWindow
127
128        # no-op if our underlying widget is dead or on its way out.
129        if not self._root_widget or self._root_widget.transitioning_out:
130            return
131
132        self.main_window_replace(
133            ProfileBrowserWindow(origin_widget=self._player_profiles_button)
134        )
135
136    @override
137    def get_main_window_state(self) -> bui.MainWindowState:
138        # Support recreating our window for back/refresh purposes.
139        cls = type(self)
140        return bui.BasicMainWindowState(
141            create_call=lambda transition, origin_widget: cls(
142                transition=transition, origin_widget=origin_widget
143            )
144        )

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        self._width = 1400 if uiscale is bui.UIScale.SMALL else 750
 27        self._height = (
 28            1200
 29            if uiscale is bui.UIScale.SMALL
 30            else 530 if uiscale is bui.UIScale.MEDIUM else 600
 31        )
 32        # xoffs = 70 if uiscale is bui.UIScale.SMALL else 0
 33        # yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 34
 35        # Do some fancy math to fill all available screen area up to the
 36        # size of our backing container. This lets us fit to the exact
 37        # screen shape at small ui scale.
 38        screensize = bui.get_virtual_screen_size()
 39        scale = (
 40            1.55
 41            if uiscale is bui.UIScale.SMALL
 42            else 1.15 if uiscale is bui.UIScale.MEDIUM else 1.0
 43        )
 44
 45        # Calc screen size in our local container space and clamp to a
 46        # bit smaller than our container size.
 47        # target_width = min(self._width - 60, screensize[0] / scale)
 48        target_height = min(self._height - 100, screensize[1] / scale)
 49
 50        # To get top/left coords, go to the center of our window and
 51        # offset by half the width/height of our target area.
 52        yoffs = 0.5 * self._height + 0.5 * target_height + 30.0
 53
 54        super().__init__(
 55            root_widget=bui.containerwidget(
 56                size=(self._width, self._height),
 57                toolbar_visibility=(
 58                    'menu_full' if uiscale is bui.UIScale.SMALL else 'menu_full'
 59                ),
 60                scale=scale,
 61            ),
 62            transition=transition,
 63            origin_widget=origin_widget,
 64            # We're affected by screen size only at small ui-scale.
 65            refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL,
 66        )
 67
 68        bui.textwidget(
 69            parent=self._root_widget,
 70            position=(
 71                self._width * 0.5,
 72                yoffs - (50 if uiscale is bui.UIScale.SMALL else 30),
 73            ),
 74            size=(0, 0),
 75            text=bui.Lstr(resource='inventoryText'),
 76            color=bui.app.ui_v1.title_color,
 77            scale=0.9 if uiscale is bui.UIScale.SMALL else 1.0,
 78            maxwidth=(130 if uiscale is bui.UIScale.SMALL else 200),
 79            h_align='center',
 80            v_align='center',
 81        )
 82
 83        if uiscale is bui.UIScale.SMALL:
 84            bui.containerwidget(
 85                edit=self._root_widget, on_cancel_call=self.main_window_back
 86            )
 87        else:
 88            btn = bui.buttonwidget(
 89                parent=self._root_widget,
 90                position=(50, yoffs - 50),
 91                size=(60, 55),
 92                scale=0.8,
 93                label=bui.charstr(bui.SpecialChar.BACK),
 94                button_type='backSmall',
 95                extra_touch_border_scale=2.0,
 96                autoselect=True,
 97                on_activate_call=self.main_window_back,
 98            )
 99            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
100
101        button_width = 300
102        self._player_profiles_button = btn = bui.buttonwidget(
103            parent=self._root_widget,
104            position=(self._width * 0.5 - button_width * 0.5, yoffs - 200),
105            autoselect=True,
106            size=(button_width, 60),
107            label=bui.Lstr(resource='playerProfilesWindow.titleText'),
108            color=(0.55, 0.5, 0.6),
109            icon=bui.gettexture('cuteSpaz'),
110            textcolor=(0.75, 0.7, 0.8),
111            on_activate_call=self._player_profiles_press,
112        )
113        bui.textwidget(
114            parent=self._root_widget,
115            position=(self._width * 0.5, yoffs - 250),
116            size=(0, 0),
117            text=bui.Lstr(resource='moreSoonText'),
118            scale=0.7,
119            maxwidth=self._width * 0.9,
120            h_align='center',
121            v_align='center',
122        )

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:
136    @override
137    def get_main_window_state(self) -> bui.MainWindowState:
138        # Support recreating our window for back/refresh purposes.
139        cls = type(self)
140        return bui.BasicMainWindowState(
141            create_call=lambda transition, origin_widget: cls(
142                transition=transition, origin_widget=origin_widget
143            )
144        )

Return a WindowState to recreate this window, if supported.