bauiv1lib.resourcetypeinfo

Provides a window which shows info about resource types.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Provides a window which shows info about resource types."""
  4
  5from __future__ import annotations
  6
  7from typing import override, TYPE_CHECKING, assert_never
  8
  9from bauiv1lib.popup import PopupWindow
 10import bauiv1 as bui
 11
 12if TYPE_CHECKING:
 13    from typing import Literal
 14
 15
 16class ResourceTypeInfoWindow(PopupWindow):
 17    """Popup window providing info about resource types."""
 18
 19    def __init__(
 20        self,
 21        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 22        origin_widget: bui.Widget,
 23    ):
 24        assert bui.app.classic is not None
 25        uiscale = bui.app.ui_v1.uiscale
 26        scale = (
 27            2.0
 28            if uiscale is bui.UIScale.SMALL
 29            else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.0
 30        )
 31        self._transitioning_out = False
 32        self._width = 570
 33        self._height = 350
 34        bg_color = (0.5, 0.4, 0.6)
 35        super().__init__(
 36            size=(self._width, self._height),
 37            toolbar_visibility='inherit',
 38            scale=scale,
 39            bg_color=bg_color,
 40            position=origin_widget.get_screen_space_center(),
 41            edge_buffer_scale=4.0,
 42        )
 43        self._cancel_button = bui.buttonwidget(
 44            parent=self.root_widget,
 45            position=(40, self._height - 40),
 46            size=(50, 50),
 47            scale=0.7,
 48            label='',
 49            color=bg_color,
 50            on_activate_call=self._on_cancel_press,
 51            autoselect=True,
 52            icon=bui.gettexture('crossOut'),
 53            iconscale=1.2,
 54        )
 55
 56        yoffs = self._height - 150
 57
 58        if resource_type == 'tickets':
 59            rdesc = (
 60                'Tickets can be used to unlock characters,\n'
 61                'maps, minigames, and more in the store.\n'
 62                '\n'
 63                'Earn tickets by completing achievements\n'
 64                'or by opening chests won in the game.'
 65            )
 66            texname = 'tickets'
 67        elif resource_type == 'tokens':
 68            rdesc = (
 69                'Tokens have various uses in the game such as\n'
 70                'speeding up chest unlocks.\n'
 71                '\n'
 72                'You can buy packs of tokens or you can buy a\n'
 73                'Gold Pass to get unlimited tokens.\n'
 74            )
 75            texname = 'coin'
 76        elif resource_type == 'trophies':
 77            rdesc = 'TODO: Will show trophies & league rankings.'
 78            texname = 'crossOut'
 79        elif resource_type == 'xp':
 80            rdesc = 'TODO: Will describe xp/levels.'
 81            texname = 'crossOut'
 82        else:
 83            assert_never(resource_type)
 84
 85        imgsize = 100.0
 86        bui.imagewidget(
 87            parent=self.root_widget,
 88            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
 89            size=(imgsize, imgsize),
 90            texture=bui.gettexture(texname),
 91        )
 92
 93        bui.textwidget(
 94            parent=self.root_widget,
 95            h_align='center',
 96            v_align='top',
 97            size=(0, 0),
 98            maxwidth=self._width * 0.8,
 99            position=(self._width * 0.5, yoffs - 5.0),
100            text=rdesc,
101            scale=0.8,
102        )
103
104    def _on_cancel_press(self) -> None:
105        self._transition_out()
106
107    def _transition_out(self) -> None:
108        if not self._transitioning_out:
109            self._transitioning_out = True
110            bui.containerwidget(edit=self.root_widget, transition='out_scale')
111
112    @override
113    def on_popup_cancel(self) -> None:
114        bui.getsound('swish').play()
115        self._transition_out()
class ResourceTypeInfoWindow(bauiv1lib.popup.PopupWindow):
 17class ResourceTypeInfoWindow(PopupWindow):
 18    """Popup window providing info about resource types."""
 19
 20    def __init__(
 21        self,
 22        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 23        origin_widget: bui.Widget,
 24    ):
 25        assert bui.app.classic is not None
 26        uiscale = bui.app.ui_v1.uiscale
 27        scale = (
 28            2.0
 29            if uiscale is bui.UIScale.SMALL
 30            else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.0
 31        )
 32        self._transitioning_out = False
 33        self._width = 570
 34        self._height = 350
 35        bg_color = (0.5, 0.4, 0.6)
 36        super().__init__(
 37            size=(self._width, self._height),
 38            toolbar_visibility='inherit',
 39            scale=scale,
 40            bg_color=bg_color,
 41            position=origin_widget.get_screen_space_center(),
 42            edge_buffer_scale=4.0,
 43        )
 44        self._cancel_button = bui.buttonwidget(
 45            parent=self.root_widget,
 46            position=(40, self._height - 40),
 47            size=(50, 50),
 48            scale=0.7,
 49            label='',
 50            color=bg_color,
 51            on_activate_call=self._on_cancel_press,
 52            autoselect=True,
 53            icon=bui.gettexture('crossOut'),
 54            iconscale=1.2,
 55        )
 56
 57        yoffs = self._height - 150
 58
 59        if resource_type == 'tickets':
 60            rdesc = (
 61                'Tickets can be used to unlock characters,\n'
 62                'maps, minigames, and more in the store.\n'
 63                '\n'
 64                'Earn tickets by completing achievements\n'
 65                'or by opening chests won in the game.'
 66            )
 67            texname = 'tickets'
 68        elif resource_type == 'tokens':
 69            rdesc = (
 70                'Tokens have various uses in the game such as\n'
 71                'speeding up chest unlocks.\n'
 72                '\n'
 73                'You can buy packs of tokens or you can buy a\n'
 74                'Gold Pass to get unlimited tokens.\n'
 75            )
 76            texname = 'coin'
 77        elif resource_type == 'trophies':
 78            rdesc = 'TODO: Will show trophies & league rankings.'
 79            texname = 'crossOut'
 80        elif resource_type == 'xp':
 81            rdesc = 'TODO: Will describe xp/levels.'
 82            texname = 'crossOut'
 83        else:
 84            assert_never(resource_type)
 85
 86        imgsize = 100.0
 87        bui.imagewidget(
 88            parent=self.root_widget,
 89            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
 90            size=(imgsize, imgsize),
 91            texture=bui.gettexture(texname),
 92        )
 93
 94        bui.textwidget(
 95            parent=self.root_widget,
 96            h_align='center',
 97            v_align='top',
 98            size=(0, 0),
 99            maxwidth=self._width * 0.8,
100            position=(self._width * 0.5, yoffs - 5.0),
101            text=rdesc,
102            scale=0.8,
103        )
104
105    def _on_cancel_press(self) -> None:
106        self._transition_out()
107
108    def _transition_out(self) -> None:
109        if not self._transitioning_out:
110            self._transitioning_out = True
111            bui.containerwidget(edit=self.root_widget, transition='out_scale')
112
113    @override
114    def on_popup_cancel(self) -> None:
115        bui.getsound('swish').play()
116        self._transition_out()

Popup window providing info about resource types.

ResourceTypeInfoWindow( resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'], origin_widget: _bauiv1.Widget)
 20    def __init__(
 21        self,
 22        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 23        origin_widget: bui.Widget,
 24    ):
 25        assert bui.app.classic is not None
 26        uiscale = bui.app.ui_v1.uiscale
 27        scale = (
 28            2.0
 29            if uiscale is bui.UIScale.SMALL
 30            else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.0
 31        )
 32        self._transitioning_out = False
 33        self._width = 570
 34        self._height = 350
 35        bg_color = (0.5, 0.4, 0.6)
 36        super().__init__(
 37            size=(self._width, self._height),
 38            toolbar_visibility='inherit',
 39            scale=scale,
 40            bg_color=bg_color,
 41            position=origin_widget.get_screen_space_center(),
 42            edge_buffer_scale=4.0,
 43        )
 44        self._cancel_button = bui.buttonwidget(
 45            parent=self.root_widget,
 46            position=(40, self._height - 40),
 47            size=(50, 50),
 48            scale=0.7,
 49            label='',
 50            color=bg_color,
 51            on_activate_call=self._on_cancel_press,
 52            autoselect=True,
 53            icon=bui.gettexture('crossOut'),
 54            iconscale=1.2,
 55        )
 56
 57        yoffs = self._height - 150
 58
 59        if resource_type == 'tickets':
 60            rdesc = (
 61                'Tickets can be used to unlock characters,\n'
 62                'maps, minigames, and more in the store.\n'
 63                '\n'
 64                'Earn tickets by completing achievements\n'
 65                'or by opening chests won in the game.'
 66            )
 67            texname = 'tickets'
 68        elif resource_type == 'tokens':
 69            rdesc = (
 70                'Tokens have various uses in the game such as\n'
 71                'speeding up chest unlocks.\n'
 72                '\n'
 73                'You can buy packs of tokens or you can buy a\n'
 74                'Gold Pass to get unlimited tokens.\n'
 75            )
 76            texname = 'coin'
 77        elif resource_type == 'trophies':
 78            rdesc = 'TODO: Will show trophies & league rankings.'
 79            texname = 'crossOut'
 80        elif resource_type == 'xp':
 81            rdesc = 'TODO: Will describe xp/levels.'
 82            texname = 'crossOut'
 83        else:
 84            assert_never(resource_type)
 85
 86        imgsize = 100.0
 87        bui.imagewidget(
 88            parent=self.root_widget,
 89            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
 90            size=(imgsize, imgsize),
 91            texture=bui.gettexture(texname),
 92        )
 93
 94        bui.textwidget(
 95            parent=self.root_widget,
 96            h_align='center',
 97            v_align='top',
 98            size=(0, 0),
 99            maxwidth=self._width * 0.8,
100            position=(self._width * 0.5, yoffs - 5.0),
101            text=rdesc,
102            scale=0.8,
103        )
@override
def on_popup_cancel(self) -> None:
113    @override
114    def on_popup_cancel(self) -> None:
115        bui.getsound('swish').play()
116        self._transition_out()

Called when the popup is canceled.

Cancels can occur due to clicking outside the window, hitting escape, etc.